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/pci-aspm.h>
55 #include <linux/interrupt.h>
56 #include <linux/aer.h>
57 #include <linux/raid_class.h>
58 #include <asm/unaligned.h>
60 #include "mpt3sas_base.h"
62 #define RAID_CHANNEL 1
64 #define PCIE_CHANNEL 2
67 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
68 struct _sas_node
*sas_expander
);
69 static void _firmware_event_work(struct work_struct
*work
);
71 static void _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
72 struct _sas_device
*sas_device
);
73 static int _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
74 u8 retry_count
, u8 is_pd
);
75 static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
);
76 static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
77 struct _pcie_device
*pcie_device
);
79 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
);
80 static u8
_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
);
82 /* global parameters */
83 LIST_HEAD(mpt3sas_ioc_list
);
84 /* global ioc lock for list operations */
85 DEFINE_SPINLOCK(gioc_lock
);
87 MODULE_AUTHOR(MPT3SAS_AUTHOR
);
88 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION
);
89 MODULE_LICENSE("GPL");
90 MODULE_VERSION(MPT3SAS_DRIVER_VERSION
);
91 MODULE_ALIAS("mpt2sas");
93 /* local parameters */
94 static u8 scsi_io_cb_idx
= -1;
95 static u8 tm_cb_idx
= -1;
96 static u8 ctl_cb_idx
= -1;
97 static u8 base_cb_idx
= -1;
98 static u8 port_enable_cb_idx
= -1;
99 static u8 transport_cb_idx
= -1;
100 static u8 scsih_cb_idx
= -1;
101 static u8 config_cb_idx
= -1;
105 static u8 tm_tr_cb_idx
= -1 ;
106 static u8 tm_tr_volume_cb_idx
= -1 ;
107 static u8 tm_sas_control_cb_idx
= -1;
109 /* command line options */
110 static u32 logging_level
;
111 MODULE_PARM_DESC(logging_level
,
112 " bits for enabling additional logging info (default=0)");
115 static ushort max_sectors
= 0xFFFF;
116 module_param(max_sectors
, ushort
, 0);
117 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
120 static int missing_delay
[2] = {-1, -1};
121 module_param_array(missing_delay
, int, NULL
, 0);
122 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
124 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
125 #define MPT3SAS_MAX_LUN (16895)
126 static u64 max_lun
= MPT3SAS_MAX_LUN
;
127 module_param(max_lun
, ullong
, 0);
128 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
130 static ushort hbas_to_enumerate
;
131 module_param(hbas_to_enumerate
, ushort
, 0);
132 MODULE_PARM_DESC(hbas_to_enumerate
,
133 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
134 1 - enumerates only SAS 2.0 generation HBAs\n \
135 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
137 /* diag_buffer_enable is bitwise
139 * bit 1 set = SNAPSHOT
140 * bit 2 set = EXTENDED
142 * Either bit can be set, or both
144 static int diag_buffer_enable
= -1;
145 module_param(diag_buffer_enable
, int, 0);
146 MODULE_PARM_DESC(diag_buffer_enable
,
147 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
148 static int disable_discovery
= -1;
149 module_param(disable_discovery
, int, 0);
150 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
153 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
154 static int prot_mask
= -1;
155 module_param(prot_mask
, int, 0);
156 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
159 /* raid transport support */
160 static struct raid_template
*mpt3sas_raid_template
;
161 static struct raid_template
*mpt2sas_raid_template
;
165 * struct sense_info - common structure for obtaining sense keys
167 * @asc: additional sense code
168 * @ascq: additional sense code qualifier
176 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
177 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
178 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
179 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
180 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
182 * struct fw_event_work - firmware event struct
183 * @list: link list framework
184 * @work: work object (ioc->fault_reset_work_q)
185 * @ioc: per adapter object
186 * @device_handle: device handle
187 * @VF_ID: virtual function id
188 * @VP_ID: virtual port id
189 * @ignore: flag meaning this event has been marked to ignore
190 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
191 * @refcount: kref for this event
192 * @event_data: reply event data payload follows
194 * This object stored on ioc->fw_event_list.
196 struct fw_event_work
{
197 struct list_head list
;
198 struct work_struct work
;
200 struct MPT3SAS_ADAPTER
*ioc
;
206 struct kref refcount
;
207 char event_data
[0] __aligned(4);
210 static void fw_event_work_free(struct kref
*r
)
212 kfree(container_of(r
, struct fw_event_work
, refcount
));
215 static void fw_event_work_get(struct fw_event_work
*fw_work
)
217 kref_get(&fw_work
->refcount
);
220 static void fw_event_work_put(struct fw_event_work
*fw_work
)
222 kref_put(&fw_work
->refcount
, fw_event_work_free
);
225 static struct fw_event_work
*alloc_fw_event_work(int len
)
227 struct fw_event_work
*fw_event
;
229 fw_event
= kzalloc(sizeof(*fw_event
) + len
, GFP_ATOMIC
);
233 kref_init(&fw_event
->refcount
);
238 * struct _scsi_io_transfer - scsi io transfer
239 * @handle: sas device handle (assigned by firmware)
240 * @is_raid: flag set for hidden raid components
241 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
242 * @data_length: data transfer length
243 * @data_dma: dma pointer to data
246 * @cdb_length: cdb length
248 * @timeout: timeout for this command
249 * @VF_ID: virtual function id
250 * @VP_ID: virtual port id
251 * @valid_reply: flag set for reply message
252 * @sense_length: sense length
253 * @ioc_status: ioc status
254 * @scsi_state: scsi state
255 * @scsi_status: scsi staus
256 * @log_info: log information
257 * @transfer_length: data length transfer when there is a reply message
259 * Used for sending internal scsi commands to devices within this module.
260 * Refer to _scsi_send_scsi_io().
262 struct _scsi_io_transfer
{
265 enum dma_data_direction dir
;
268 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
276 /* the following bits are only valid when 'valid_reply = 1' */
286 * _scsih_set_debug_level - global setting of ioc->logging_level.
290 * Note: The logging levels are defined in mpt3sas_debug.h.
293 _scsih_set_debug_level(const char *val
, const struct kernel_param
*kp
)
295 int ret
= param_set_int(val
, kp
);
296 struct MPT3SAS_ADAPTER
*ioc
;
301 pr_info("setting logging_level(0x%08x)\n", logging_level
);
302 spin_lock(&gioc_lock
);
303 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
304 ioc
->logging_level
= logging_level
;
305 spin_unlock(&gioc_lock
);
308 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
309 &logging_level
, 0644);
312 * _scsih_srch_boot_sas_address - search based on sas_address
313 * @sas_address: sas address
314 * @boot_device: boot device object from bios page 2
316 * Return: 1 when there's a match, 0 means no match.
319 _scsih_srch_boot_sas_address(u64 sas_address
,
320 Mpi2BootDeviceSasWwid_t
*boot_device
)
322 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
326 * _scsih_srch_boot_device_name - search based on device name
327 * @device_name: device name specified in INDENTIFY fram
328 * @boot_device: boot device object from bios page 2
330 * Return: 1 when there's a match, 0 means no match.
333 _scsih_srch_boot_device_name(u64 device_name
,
334 Mpi2BootDeviceDeviceName_t
*boot_device
)
336 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
340 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
341 * @enclosure_logical_id: enclosure logical id
342 * @slot_number: slot number
343 * @boot_device: boot device object from bios page 2
345 * Return: 1 when there's a match, 0 means no match.
348 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
349 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
351 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
352 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
353 SlotNumber
)) ? 1 : 0;
357 * _scsih_is_boot_device - search for matching boot device.
358 * @sas_address: sas address
359 * @device_name: device name specified in INDENTIFY fram
360 * @enclosure_logical_id: enclosure logical id
362 * @form: specifies boot device form
363 * @boot_device: boot device object from bios page 2
365 * Return: 1 when there's a match, 0 means no match.
368 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
369 u64 enclosure_logical_id
, u16 slot
, u8 form
,
370 Mpi2BiosPage2BootDevice_t
*boot_device
)
375 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
378 rc
= _scsih_srch_boot_sas_address(
379 sas_address
, &boot_device
->SasWwid
);
381 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
382 if (!enclosure_logical_id
)
384 rc
= _scsih_srch_boot_encl_slot(
385 enclosure_logical_id
,
386 slot
, &boot_device
->EnclosureSlot
);
388 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
391 rc
= _scsih_srch_boot_device_name(
392 device_name
, &boot_device
->DeviceName
);
394 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
402 * _scsih_get_sas_address - set the sas_address for given device handle
404 * @handle: device handle
405 * @sas_address: sas address
407 * Return: 0 success, non-zero when failure
410 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
413 Mpi2SasDevicePage0_t sas_device_pg0
;
414 Mpi2ConfigReply_t mpi_reply
;
419 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
420 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
421 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
422 __FILE__
, __LINE__
, __func__
);
426 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
427 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
428 /* For HBA, vSES doesn't return HBA SAS address. Instead return
429 * vSES's sas address.
431 if ((handle
<= ioc
->sas_hba
.num_phys
) &&
432 (!(le32_to_cpu(sas_device_pg0
.DeviceInfo
) &
433 MPI2_SAS_DEVICE_INFO_SEP
)))
434 *sas_address
= ioc
->sas_hba
.sas_address
;
436 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
440 /* we hit this because the given parent handle doesn't exist */
441 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
444 /* else error case */
446 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
447 ioc
->name
, handle
, ioc_status
,
448 __FILE__
, __LINE__
, __func__
);
453 * _scsih_determine_boot_device - determine boot device.
454 * @ioc: per adapter object
455 * @device: sas_device or pcie_device object
456 * @channel: SAS or PCIe channel
458 * Determines whether this device should be first reported device to
459 * to scsi-ml or sas transport, this purpose is for persistent boot device.
460 * There are primary, alternate, and current entries in bios page 2. The order
461 * priority is primary, alternate, then current. This routine saves
462 * the corresponding device object.
463 * The saved data to be used later in _scsih_probe_boot_devices().
466 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
, void *device
,
469 struct _sas_device
*sas_device
;
470 struct _pcie_device
*pcie_device
;
471 struct _raid_device
*raid_device
;
474 u64 enclosure_logical_id
;
477 /* only process this function when driver loads */
478 if (!ioc
->is_driver_loading
)
481 /* no Bios, return immediately */
482 if (!ioc
->bios_pg3
.BiosVersion
)
485 if (channel
== RAID_CHANNEL
) {
486 raid_device
= device
;
487 sas_address
= raid_device
->wwid
;
489 enclosure_logical_id
= 0;
491 } else if (channel
== PCIE_CHANNEL
) {
492 pcie_device
= device
;
493 sas_address
= pcie_device
->wwid
;
495 enclosure_logical_id
= 0;
499 sas_address
= sas_device
->sas_address
;
500 device_name
= sas_device
->device_name
;
501 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
502 slot
= sas_device
->slot
;
505 if (!ioc
->req_boot_device
.device
) {
506 if (_scsih_is_boot_device(sas_address
, device_name
,
507 enclosure_logical_id
, slot
,
508 (ioc
->bios_pg2
.ReqBootDeviceForm
&
509 MPI2_BIOSPAGE2_FORM_MASK
),
510 &ioc
->bios_pg2
.RequestedBootDevice
)) {
511 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
512 "%s: req_boot_device(0x%016llx)\n",
514 (unsigned long long)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
)) {
526 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
527 "%s: req_alt_boot_device(0x%016llx)\n",
529 (unsigned long long)sas_address
));
530 ioc
->req_alt_boot_device
.device
= device
;
531 ioc
->req_alt_boot_device
.channel
= channel
;
535 if (!ioc
->current_boot_device
.device
) {
536 if (_scsih_is_boot_device(sas_address
, device_name
,
537 enclosure_logical_id
, slot
,
538 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
539 MPI2_BIOSPAGE2_FORM_MASK
),
540 &ioc
->bios_pg2
.CurrentBootDevice
)) {
541 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
542 "%s: current_boot_device(0x%016llx)\n",
544 (unsigned long long)sas_address
));
545 ioc
->current_boot_device
.device
= device
;
546 ioc
->current_boot_device
.channel
= channel
;
551 static struct _sas_device
*
552 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
553 struct MPT3SAS_TARGET
*tgt_priv
)
555 struct _sas_device
*ret
;
557 assert_spin_locked(&ioc
->sas_device_lock
);
559 ret
= tgt_priv
->sas_dev
;
566 static struct _sas_device
*
567 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
568 struct MPT3SAS_TARGET
*tgt_priv
)
570 struct _sas_device
*ret
;
573 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
574 ret
= __mpt3sas_get_sdev_from_target(ioc
, tgt_priv
);
575 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
580 static struct _pcie_device
*
581 __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
582 struct MPT3SAS_TARGET
*tgt_priv
)
584 struct _pcie_device
*ret
;
586 assert_spin_locked(&ioc
->pcie_device_lock
);
588 ret
= tgt_priv
->pcie_dev
;
590 pcie_device_get(ret
);
596 * mpt3sas_get_pdev_from_target - pcie device search
597 * @ioc: per adapter object
598 * @tgt_priv: starget private object
600 * Context: This function will acquire ioc->pcie_device_lock and will release
601 * before returning the pcie_device object.
603 * This searches for pcie_device from target, then return pcie_device object.
605 static struct _pcie_device
*
606 mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
607 struct MPT3SAS_TARGET
*tgt_priv
)
609 struct _pcie_device
*ret
;
612 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
613 ret
= __mpt3sas_get_pdev_from_target(ioc
, tgt_priv
);
614 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
620 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
623 struct _sas_device
*sas_device
;
625 assert_spin_locked(&ioc
->sas_device_lock
);
627 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
628 if (sas_device
->sas_address
== sas_address
)
631 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
632 if (sas_device
->sas_address
== sas_address
)
638 sas_device_get(sas_device
);
643 * mpt3sas_get_sdev_by_addr - sas device search
644 * @ioc: per adapter object
645 * @sas_address: sas address
646 * Context: Calling function should acquire ioc->sas_device_lock
648 * This searches for sas_device based on sas_address, then return sas_device
652 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
655 struct _sas_device
*sas_device
;
658 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
659 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
661 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
666 static struct _sas_device
*
667 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
669 struct _sas_device
*sas_device
;
671 assert_spin_locked(&ioc
->sas_device_lock
);
673 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
674 if (sas_device
->handle
== handle
)
677 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
678 if (sas_device
->handle
== handle
)
684 sas_device_get(sas_device
);
689 * mpt3sas_get_sdev_by_handle - sas device search
690 * @ioc: per adapter object
691 * @handle: sas device handle (assigned by firmware)
692 * Context: Calling function should acquire ioc->sas_device_lock
694 * This searches for sas_device based on sas_address, then return sas_device
698 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
700 struct _sas_device
*sas_device
;
703 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
704 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
705 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
711 * _scsih_display_enclosure_chassis_info - display device location info
712 * @ioc: per adapter object
713 * @sas_device: per sas device object
714 * @sdev: scsi device struct
715 * @starget: scsi target struct
718 _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER
*ioc
,
719 struct _sas_device
*sas_device
, struct scsi_device
*sdev
,
720 struct scsi_target
*starget
)
723 if (sas_device
->enclosure_handle
!= 0)
724 sdev_printk(KERN_INFO
, sdev
,
725 "enclosure logical id (0x%016llx), slot(%d) \n",
727 sas_device
->enclosure_logical_id
,
729 if (sas_device
->connector_name
[0] != '\0')
730 sdev_printk(KERN_INFO
, sdev
,
731 "enclosure level(0x%04x), connector name( %s)\n",
732 sas_device
->enclosure_level
,
733 sas_device
->connector_name
);
734 if (sas_device
->is_chassis_slot_valid
)
735 sdev_printk(KERN_INFO
, sdev
, "chassis slot(0x%04x)\n",
736 sas_device
->chassis_slot
);
737 } else if (starget
) {
738 if (sas_device
->enclosure_handle
!= 0)
739 starget_printk(KERN_INFO
, starget
,
740 "enclosure logical id(0x%016llx), slot(%d) \n",
742 sas_device
->enclosure_logical_id
,
744 if (sas_device
->connector_name
[0] != '\0')
745 starget_printk(KERN_INFO
, starget
,
746 "enclosure level(0x%04x), connector name( %s)\n",
747 sas_device
->enclosure_level
,
748 sas_device
->connector_name
);
749 if (sas_device
->is_chassis_slot_valid
)
750 starget_printk(KERN_INFO
, starget
,
751 "chassis slot(0x%04x)\n",
752 sas_device
->chassis_slot
);
754 if (sas_device
->enclosure_handle
!= 0)
756 "enclosure logical id(0x%016llx), slot(%d) \n",
757 ioc
->name
, (unsigned long long)
758 sas_device
->enclosure_logical_id
,
760 if (sas_device
->connector_name
[0] != '\0')
762 "enclosure level(0x%04x), connector name( %s)\n",
763 ioc
->name
, sas_device
->enclosure_level
,
764 sas_device
->connector_name
);
765 if (sas_device
->is_chassis_slot_valid
)
766 pr_info(MPT3SAS_FMT
"chassis slot(0x%04x)\n",
767 ioc
->name
, sas_device
->chassis_slot
);
772 * _scsih_sas_device_remove - remove sas_device from list.
773 * @ioc: per adapter object
774 * @sas_device: the sas_device object
775 * Context: This function will acquire ioc->sas_device_lock.
777 * If sas_device is on the list, remove it and decrement its reference count.
780 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
781 struct _sas_device
*sas_device
)
788 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
789 ioc
->name
, sas_device
->handle
,
790 (unsigned long long) sas_device
->sas_address
);
792 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
795 * The lock serializes access to the list, but we still need to verify
796 * that nobody removed the entry while we were waiting on the lock.
798 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
799 if (!list_empty(&sas_device
->list
)) {
800 list_del_init(&sas_device
->list
);
801 sas_device_put(sas_device
);
803 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
807 * _scsih_device_remove_by_handle - removing device object by handle
808 * @ioc: per adapter object
809 * @handle: device handle
812 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
814 struct _sas_device
*sas_device
;
817 if (ioc
->shost_recovery
)
820 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
821 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
823 list_del_init(&sas_device
->list
);
824 sas_device_put(sas_device
);
826 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
828 _scsih_remove_device(ioc
, sas_device
);
829 sas_device_put(sas_device
);
834 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
835 * @ioc: per adapter object
836 * @sas_address: device sas_address
839 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
842 struct _sas_device
*sas_device
;
845 if (ioc
->shost_recovery
)
848 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
849 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
, sas_address
);
851 list_del_init(&sas_device
->list
);
852 sas_device_put(sas_device
);
854 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
856 _scsih_remove_device(ioc
, sas_device
);
857 sas_device_put(sas_device
);
862 * _scsih_sas_device_add - insert sas_device to the list.
863 * @ioc: per adapter object
864 * @sas_device: the sas_device object
865 * Context: This function will acquire ioc->sas_device_lock.
867 * Adding new object to the ioc->sas_device_list.
870 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
871 struct _sas_device
*sas_device
)
875 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
876 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
877 ioc
->name
, __func__
, sas_device
->handle
,
878 (unsigned long long)sas_device
->sas_address
));
880 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
883 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
884 sas_device_get(sas_device
);
885 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
886 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
888 if (ioc
->hide_drives
) {
889 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
893 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
894 sas_device
->sas_address_parent
)) {
895 _scsih_sas_device_remove(ioc
, sas_device
);
896 } else if (!sas_device
->starget
) {
898 * When asyn scanning is enabled, its not possible to remove
899 * devices while scanning is turned on due to an oops in
900 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
902 if (!ioc
->is_driver_loading
) {
903 mpt3sas_transport_port_remove(ioc
,
904 sas_device
->sas_address
,
905 sas_device
->sas_address_parent
);
906 _scsih_sas_device_remove(ioc
, sas_device
);
909 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
913 * _scsih_sas_device_init_add - insert sas_device to the list.
914 * @ioc: per adapter object
915 * @sas_device: the sas_device object
916 * Context: This function will acquire ioc->sas_device_lock.
918 * Adding new object at driver load time to the ioc->sas_device_init_list.
921 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
922 struct _sas_device
*sas_device
)
926 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
927 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
928 __func__
, sas_device
->handle
,
929 (unsigned long long)sas_device
->sas_address
));
931 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
934 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
935 sas_device_get(sas_device
);
936 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
937 _scsih_determine_boot_device(ioc
, sas_device
, 0);
938 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
942 static struct _pcie_device
*
943 __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
945 struct _pcie_device
*pcie_device
;
947 assert_spin_locked(&ioc
->pcie_device_lock
);
949 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
950 if (pcie_device
->wwid
== wwid
)
953 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
954 if (pcie_device
->wwid
== wwid
)
960 pcie_device_get(pcie_device
);
966 * mpt3sas_get_pdev_by_wwid - pcie device search
967 * @ioc: per adapter object
970 * Context: This function will acquire ioc->pcie_device_lock and will release
971 * before returning the pcie_device object.
973 * This searches for pcie_device based on wwid, then return pcie_device object.
975 static struct _pcie_device
*
976 mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
978 struct _pcie_device
*pcie_device
;
981 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
982 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
983 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
989 static struct _pcie_device
*
990 __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER
*ioc
, int id
,
993 struct _pcie_device
*pcie_device
;
995 assert_spin_locked(&ioc
->pcie_device_lock
);
997 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
998 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
1001 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
1002 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
1008 pcie_device_get(pcie_device
);
1012 static struct _pcie_device
*
1013 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1015 struct _pcie_device
*pcie_device
;
1017 assert_spin_locked(&ioc
->pcie_device_lock
);
1019 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
1020 if (pcie_device
->handle
== handle
)
1023 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
1024 if (pcie_device
->handle
== handle
)
1030 pcie_device_get(pcie_device
);
1036 * mpt3sas_get_pdev_by_handle - pcie device search
1037 * @ioc: per adapter object
1038 * @handle: Firmware device handle
1040 * Context: This function will acquire ioc->pcie_device_lock and will release
1041 * before returning the pcie_device object.
1043 * This searches for pcie_device based on handle, then return pcie_device
1046 struct _pcie_device
*
1047 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1049 struct _pcie_device
*pcie_device
;
1050 unsigned long flags
;
1052 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1053 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1054 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1060 * _scsih_pcie_device_remove - remove pcie_device from list.
1061 * @ioc: per adapter object
1062 * @pcie_device: the pcie_device object
1063 * Context: This function will acquire ioc->pcie_device_lock.
1065 * If pcie_device is on the list, remove it and decrement its reference count.
1068 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1069 struct _pcie_device
*pcie_device
)
1071 unsigned long flags
;
1072 int was_on_pcie_device_list
= 0;
1077 "removing handle(0x%04x), wwid(0x%016llx)\n",
1078 ioc
->name
, pcie_device
->handle
,
1079 (unsigned long long) pcie_device
->wwid
);
1080 if (pcie_device
->enclosure_handle
!= 0)
1082 "removing enclosure logical id(0x%016llx), slot(%d)\n",
1084 (unsigned long long)pcie_device
->enclosure_logical_id
,
1086 if (pcie_device
->connector_name
[0] != '\0')
1088 "removing enclosure level(0x%04x), connector name( %s)\n",
1089 ioc
->name
, pcie_device
->enclosure_level
,
1090 pcie_device
->connector_name
);
1092 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1093 if (!list_empty(&pcie_device
->list
)) {
1094 list_del_init(&pcie_device
->list
);
1095 was_on_pcie_device_list
= 1;
1097 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1098 if (was_on_pcie_device_list
) {
1099 kfree(pcie_device
->serial_number
);
1100 pcie_device_put(pcie_device
);
1106 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1107 * @ioc: per adapter object
1108 * @handle: device handle
1111 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1113 struct _pcie_device
*pcie_device
;
1114 unsigned long flags
;
1115 int was_on_pcie_device_list
= 0;
1117 if (ioc
->shost_recovery
)
1120 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1121 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1123 if (!list_empty(&pcie_device
->list
)) {
1124 list_del_init(&pcie_device
->list
);
1125 was_on_pcie_device_list
= 1;
1126 pcie_device_put(pcie_device
);
1129 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1130 if (was_on_pcie_device_list
) {
1131 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
1132 pcie_device_put(pcie_device
);
1137 * _scsih_pcie_device_add - add pcie_device object
1138 * @ioc: per adapter object
1139 * @pcie_device: pcie_device object
1141 * This is added to the pcie_device_list link list.
1144 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1145 struct _pcie_device
*pcie_device
)
1147 unsigned long flags
;
1149 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1150 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1151 pcie_device
->handle
, (unsigned long long)pcie_device
->wwid
));
1152 if (pcie_device
->enclosure_handle
!= 0)
1153 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1154 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1155 ioc
->name
, __func__
,
1156 (unsigned long long)pcie_device
->enclosure_logical_id
,
1157 pcie_device
->slot
));
1158 if (pcie_device
->connector_name
[0] != '\0')
1159 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1160 "%s: enclosure level(0x%04x), connector name( %s)\n",
1161 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
1162 pcie_device
->connector_name
));
1164 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1165 pcie_device_get(pcie_device
);
1166 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
1167 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1169 if (scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, pcie_device
->id
, 0)) {
1170 _scsih_pcie_device_remove(ioc
, pcie_device
);
1171 } else if (!pcie_device
->starget
) {
1172 if (!ioc
->is_driver_loading
) {
1173 /*TODO-- Need to find out whether this condition will occur or not*/
1174 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1177 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1181 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1182 * @ioc: per adapter object
1183 * @pcie_device: the pcie_device object
1184 * Context: This function will acquire ioc->pcie_device_lock.
1186 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1189 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
1190 struct _pcie_device
*pcie_device
)
1192 unsigned long flags
;
1194 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1195 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1196 pcie_device
->handle
, (unsigned long long)pcie_device
->wwid
));
1197 if (pcie_device
->enclosure_handle
!= 0)
1198 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1199 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1200 ioc
->name
, __func__
,
1201 (unsigned long long)pcie_device
->enclosure_logical_id
,
1202 pcie_device
->slot
));
1203 if (pcie_device
->connector_name
[0] != '\0')
1204 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1205 "%s: enclosure level(0x%04x), connector name( %s)\n",
1206 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
1207 pcie_device
->connector_name
));
1209 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1210 pcie_device_get(pcie_device
);
1211 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_init_list
);
1212 _scsih_determine_boot_device(ioc
, pcie_device
, PCIE_CHANNEL
);
1213 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1216 * _scsih_raid_device_find_by_id - raid device search
1217 * @ioc: per adapter object
1218 * @id: sas device target id
1219 * @channel: sas device channel
1220 * Context: Calling function should acquire ioc->raid_device_lock
1222 * This searches for raid_device based on target id, then return raid_device
1225 static struct _raid_device
*
1226 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
1228 struct _raid_device
*raid_device
, *r
;
1231 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1232 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
1243 * mpt3sas_raid_device_find_by_handle - raid device search
1244 * @ioc: per adapter object
1245 * @handle: sas device handle (assigned by firmware)
1246 * Context: Calling function should acquire ioc->raid_device_lock
1248 * This searches for raid_device based on handle, then return raid_device
1251 struct _raid_device
*
1252 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1254 struct _raid_device
*raid_device
, *r
;
1257 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1258 if (raid_device
->handle
!= handle
)
1269 * _scsih_raid_device_find_by_wwid - raid device search
1270 * @ioc: per adapter object
1272 * Context: Calling function should acquire ioc->raid_device_lock
1274 * This searches for raid_device based on wwid, then return raid_device
1277 static struct _raid_device
*
1278 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
1280 struct _raid_device
*raid_device
, *r
;
1283 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1284 if (raid_device
->wwid
!= wwid
)
1295 * _scsih_raid_device_add - add raid_device object
1296 * @ioc: per adapter object
1297 * @raid_device: raid_device object
1299 * This is added to the raid_device_list link list.
1302 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1303 struct _raid_device
*raid_device
)
1305 unsigned long flags
;
1307 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1308 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1309 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
1311 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1312 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
1313 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1317 * _scsih_raid_device_remove - delete raid_device object
1318 * @ioc: per adapter object
1319 * @raid_device: raid_device object
1323 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1324 struct _raid_device
*raid_device
)
1326 unsigned long flags
;
1328 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1329 list_del(&raid_device
->list
);
1331 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1335 * mpt3sas_scsih_expander_find_by_handle - expander device search
1336 * @ioc: per adapter object
1337 * @handle: expander handle (assigned by firmware)
1338 * Context: Calling function should acquire ioc->sas_device_lock
1340 * This searches for expander device based on handle, then returns the
1344 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1346 struct _sas_node
*sas_expander
, *r
;
1349 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1350 if (sas_expander
->handle
!= handle
)
1360 * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search
1361 * @ioc: per adapter object
1362 * @handle: enclosure handle (assigned by firmware)
1363 * Context: Calling function should acquire ioc->sas_device_lock
1365 * This searches for enclosure device based on handle, then returns the
1368 static struct _enclosure_node
*
1369 mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1371 struct _enclosure_node
*enclosure_dev
, *r
;
1374 list_for_each_entry(enclosure_dev
, &ioc
->enclosure_list
, list
) {
1375 if (le16_to_cpu(enclosure_dev
->pg0
.EnclosureHandle
) != handle
)
1384 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1385 * @ioc: per adapter object
1386 * @sas_address: sas address
1387 * Context: Calling function should acquire ioc->sas_node_lock.
1389 * This searches for expander device based on sas_address, then returns the
1393 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1396 struct _sas_node
*sas_expander
, *r
;
1399 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1400 if (sas_expander
->sas_address
!= sas_address
)
1410 * _scsih_expander_node_add - insert expander device to the list.
1411 * @ioc: per adapter object
1412 * @sas_expander: the sas_device object
1413 * Context: This function will acquire ioc->sas_node_lock.
1415 * Adding new object to the ioc->sas_expander_list.
1418 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1419 struct _sas_node
*sas_expander
)
1421 unsigned long flags
;
1423 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1424 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1425 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1429 * _scsih_is_end_device - determines if device is an end device
1430 * @device_info: bitfield providing information about the device.
1433 * Return: 1 if end device.
1436 _scsih_is_end_device(u32 device_info
)
1438 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1439 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1440 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1441 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1448 * _scsih_is_nvme_device - determines if device is an nvme device
1449 * @device_info: bitfield providing information about the device.
1452 * Return: 1 if nvme device.
1455 _scsih_is_nvme_device(u32 device_info
)
1457 if ((device_info
& MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
)
1458 == MPI26_PCIE_DEVINFO_NVME
)
1465 * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
1466 * @ioc: per adapter object
1467 * @smid: system request message index
1469 * Return: the smid stored scmd pointer.
1470 * Then will dereference the stored scmd pointer.
1473 mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1475 struct scsi_cmnd
*scmd
= NULL
;
1476 struct scsiio_tracker
*st
;
1477 Mpi25SCSIIORequest_t
*mpi_request
;
1480 smid
<= ioc
->scsiio_depth
- INTERNAL_SCSIIO_CMDS_COUNT
) {
1481 u32 unique_tag
= smid
- 1;
1483 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1486 * If SCSI IO request is outstanding at driver level then
1487 * DevHandle filed must be non-zero. If DevHandle is zero
1488 * then it means that this smid is free at driver level,
1491 if (!mpi_request
->DevHandle
)
1494 scmd
= scsi_host_find_tag(ioc
->shost
, unique_tag
);
1496 st
= scsi_cmd_priv(scmd
);
1497 if (st
->cb_idx
== 0xFF || st
->smid
== 0)
1505 * scsih_change_queue_depth - setting device queue depth
1506 * @sdev: scsi device struct
1507 * @qdepth: requested queue depth
1509 * Return: queue depth.
1512 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1514 struct Scsi_Host
*shost
= sdev
->host
;
1516 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1517 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1518 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1519 struct _sas_device
*sas_device
;
1520 unsigned long flags
;
1522 max_depth
= shost
->can_queue
;
1524 /* limit max device queue for SATA to 32 */
1525 sas_device_priv_data
= sdev
->hostdata
;
1526 if (!sas_device_priv_data
)
1528 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1529 if (!sas_target_priv_data
)
1531 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1534 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1535 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1537 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1538 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1540 sas_device_put(sas_device
);
1542 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1546 if (!sdev
->tagged_supported
)
1548 if (qdepth
> max_depth
)
1550 return scsi_change_queue_depth(sdev
, qdepth
);
1554 * scsih_target_alloc - target add routine
1555 * @starget: scsi target struct
1557 * Return: 0 if ok. Any other return is assumed to be an error and
1558 * the device is ignored.
1561 scsih_target_alloc(struct scsi_target
*starget
)
1563 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1564 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1565 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1566 struct _sas_device
*sas_device
;
1567 struct _raid_device
*raid_device
;
1568 struct _pcie_device
*pcie_device
;
1569 unsigned long flags
;
1570 struct sas_rphy
*rphy
;
1572 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1574 if (!sas_target_priv_data
)
1577 starget
->hostdata
= sas_target_priv_data
;
1578 sas_target_priv_data
->starget
= starget
;
1579 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1582 if (starget
->channel
== RAID_CHANNEL
) {
1583 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1584 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1587 sas_target_priv_data
->handle
= raid_device
->handle
;
1588 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1589 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1590 if (ioc
->is_warpdrive
)
1591 sas_target_priv_data
->raid_device
= raid_device
;
1592 raid_device
->starget
= starget
;
1594 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1599 if (starget
->channel
== PCIE_CHANNEL
) {
1600 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1601 pcie_device
= __mpt3sas_get_pdev_by_idchannel(ioc
, starget
->id
,
1604 sas_target_priv_data
->handle
= pcie_device
->handle
;
1605 sas_target_priv_data
->sas_address
= pcie_device
->wwid
;
1606 sas_target_priv_data
->pcie_dev
= pcie_device
;
1607 pcie_device
->starget
= starget
;
1608 pcie_device
->id
= starget
->id
;
1609 pcie_device
->channel
= starget
->channel
;
1610 sas_target_priv_data
->flags
|=
1611 MPT_TARGET_FLAGS_PCIE_DEVICE
;
1612 if (pcie_device
->fast_path
)
1613 sas_target_priv_data
->flags
|=
1614 MPT_TARGET_FASTPATH_IO
;
1616 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1620 /* sas/sata devices */
1621 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1622 rphy
= dev_to_rphy(starget
->dev
.parent
);
1623 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1624 rphy
->identify
.sas_address
);
1627 sas_target_priv_data
->handle
= sas_device
->handle
;
1628 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1629 sas_target_priv_data
->sas_dev
= sas_device
;
1630 sas_device
->starget
= starget
;
1631 sas_device
->id
= starget
->id
;
1632 sas_device
->channel
= starget
->channel
;
1633 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1634 sas_target_priv_data
->flags
|=
1635 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1636 if (sas_device
->fast_path
)
1637 sas_target_priv_data
->flags
|=
1638 MPT_TARGET_FASTPATH_IO
;
1640 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1646 * scsih_target_destroy - target destroy routine
1647 * @starget: scsi target struct
1650 scsih_target_destroy(struct scsi_target
*starget
)
1652 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1653 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1654 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1655 struct _sas_device
*sas_device
;
1656 struct _raid_device
*raid_device
;
1657 struct _pcie_device
*pcie_device
;
1658 unsigned long flags
;
1660 sas_target_priv_data
= starget
->hostdata
;
1661 if (!sas_target_priv_data
)
1664 if (starget
->channel
== RAID_CHANNEL
) {
1665 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1666 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1669 raid_device
->starget
= NULL
;
1670 raid_device
->sdev
= NULL
;
1672 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1676 if (starget
->channel
== PCIE_CHANNEL
) {
1677 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1678 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1679 sas_target_priv_data
);
1680 if (pcie_device
&& (pcie_device
->starget
== starget
) &&
1681 (pcie_device
->id
== starget
->id
) &&
1682 (pcie_device
->channel
== starget
->channel
))
1683 pcie_device
->starget
= NULL
;
1687 * Corresponding get() is in _scsih_target_alloc()
1689 sas_target_priv_data
->pcie_dev
= NULL
;
1690 pcie_device_put(pcie_device
);
1691 pcie_device_put(pcie_device
);
1693 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1697 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1698 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1699 if (sas_device
&& (sas_device
->starget
== starget
) &&
1700 (sas_device
->id
== starget
->id
) &&
1701 (sas_device
->channel
== starget
->channel
))
1702 sas_device
->starget
= NULL
;
1706 * Corresponding get() is in _scsih_target_alloc()
1708 sas_target_priv_data
->sas_dev
= NULL
;
1709 sas_device_put(sas_device
);
1711 sas_device_put(sas_device
);
1713 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1716 kfree(sas_target_priv_data
);
1717 starget
->hostdata
= NULL
;
1721 * scsih_slave_alloc - device add routine
1722 * @sdev: scsi device struct
1724 * Return: 0 if ok. Any other return is assumed to be an error and
1725 * the device is ignored.
1728 scsih_slave_alloc(struct scsi_device
*sdev
)
1730 struct Scsi_Host
*shost
;
1731 struct MPT3SAS_ADAPTER
*ioc
;
1732 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1733 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1734 struct scsi_target
*starget
;
1735 struct _raid_device
*raid_device
;
1736 struct _sas_device
*sas_device
;
1737 struct _pcie_device
*pcie_device
;
1738 unsigned long flags
;
1740 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1742 if (!sas_device_priv_data
)
1745 sas_device_priv_data
->lun
= sdev
->lun
;
1746 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1748 starget
= scsi_target(sdev
);
1749 sas_target_priv_data
= starget
->hostdata
;
1750 sas_target_priv_data
->num_luns
++;
1751 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1752 sdev
->hostdata
= sas_device_priv_data
;
1753 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1754 sdev
->no_uld_attach
= 1;
1756 shost
= dev_to_shost(&starget
->dev
);
1757 ioc
= shost_priv(shost
);
1758 if (starget
->channel
== RAID_CHANNEL
) {
1759 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1760 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1761 starget
->id
, starget
->channel
);
1763 raid_device
->sdev
= sdev
; /* raid is single lun */
1764 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1766 if (starget
->channel
== PCIE_CHANNEL
) {
1767 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1768 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
1769 sas_target_priv_data
->sas_address
);
1770 if (pcie_device
&& (pcie_device
->starget
== NULL
)) {
1771 sdev_printk(KERN_INFO
, sdev
,
1772 "%s : pcie_device->starget set to starget @ %d\n",
1773 __func__
, __LINE__
);
1774 pcie_device
->starget
= starget
;
1778 pcie_device_put(pcie_device
);
1779 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1781 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1782 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1783 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1784 sas_target_priv_data
->sas_address
);
1785 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1786 sdev_printk(KERN_INFO
, sdev
,
1787 "%s : sas_device->starget set to starget @ %d\n",
1788 __func__
, __LINE__
);
1789 sas_device
->starget
= starget
;
1793 sas_device_put(sas_device
);
1795 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1802 * scsih_slave_destroy - device destroy routine
1803 * @sdev: scsi device struct
1806 scsih_slave_destroy(struct scsi_device
*sdev
)
1808 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1809 struct scsi_target
*starget
;
1810 struct Scsi_Host
*shost
;
1811 struct MPT3SAS_ADAPTER
*ioc
;
1812 struct _sas_device
*sas_device
;
1813 struct _pcie_device
*pcie_device
;
1814 unsigned long flags
;
1816 if (!sdev
->hostdata
)
1819 starget
= scsi_target(sdev
);
1820 sas_target_priv_data
= starget
->hostdata
;
1821 sas_target_priv_data
->num_luns
--;
1823 shost
= dev_to_shost(&starget
->dev
);
1824 ioc
= shost_priv(shost
);
1826 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
1827 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1828 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1829 sas_target_priv_data
);
1830 if (pcie_device
&& !sas_target_priv_data
->num_luns
)
1831 pcie_device
->starget
= NULL
;
1834 pcie_device_put(pcie_device
);
1836 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1838 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1839 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1840 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1841 sas_target_priv_data
);
1842 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1843 sas_device
->starget
= NULL
;
1846 sas_device_put(sas_device
);
1847 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1850 kfree(sdev
->hostdata
);
1851 sdev
->hostdata
= NULL
;
1855 * _scsih_display_sata_capabilities - sata capabilities
1856 * @ioc: per adapter object
1857 * @handle: device handle
1858 * @sdev: scsi device struct
1861 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1862 u16 handle
, struct scsi_device
*sdev
)
1864 Mpi2ConfigReply_t mpi_reply
;
1865 Mpi2SasDevicePage0_t sas_device_pg0
;
1870 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1871 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1872 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1873 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1877 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1878 MPI2_IOCSTATUS_MASK
;
1879 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1880 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1881 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1885 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1886 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1888 sdev_printk(KERN_INFO
, sdev
,
1889 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1890 "sw_preserve(%s)\n",
1891 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1892 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1893 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1895 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1896 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1897 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1901 * raid transport support -
1902 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1903 * unloading the driver followed by a load - I believe that the subroutine
1904 * raid_class_release() is not cleaning up properly.
1908 * scsih_is_raid - return boolean indicating device is raid volume
1909 * @dev: the device struct object
1912 scsih_is_raid(struct device
*dev
)
1914 struct scsi_device
*sdev
= to_scsi_device(dev
);
1915 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1917 if (ioc
->is_warpdrive
)
1919 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1923 scsih_is_nvme(struct device
*dev
)
1925 struct scsi_device
*sdev
= to_scsi_device(dev
);
1927 return (sdev
->channel
== PCIE_CHANNEL
) ? 1 : 0;
1931 * scsih_get_resync - get raid volume resync percent complete
1932 * @dev: the device struct object
1935 scsih_get_resync(struct device
*dev
)
1937 struct scsi_device
*sdev
= to_scsi_device(dev
);
1938 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1939 static struct _raid_device
*raid_device
;
1940 unsigned long flags
;
1941 Mpi2RaidVolPage0_t vol_pg0
;
1942 Mpi2ConfigReply_t mpi_reply
;
1943 u32 volume_status_flags
;
1944 u8 percent_complete
;
1947 percent_complete
= 0;
1949 if (ioc
->is_warpdrive
)
1952 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1953 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1956 handle
= raid_device
->handle
;
1957 percent_complete
= raid_device
->percent_complete
;
1959 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1964 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1965 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1966 sizeof(Mpi2RaidVolPage0_t
))) {
1967 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1968 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1969 percent_complete
= 0;
1973 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1974 if (!(volume_status_flags
&
1975 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1976 percent_complete
= 0;
1980 switch (ioc
->hba_mpi_version_belonged
) {
1982 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1986 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1992 * scsih_get_state - get raid volume level
1993 * @dev: the device struct object
1996 scsih_get_state(struct device
*dev
)
1998 struct scsi_device
*sdev
= to_scsi_device(dev
);
1999 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2000 static struct _raid_device
*raid_device
;
2001 unsigned long flags
;
2002 Mpi2RaidVolPage0_t vol_pg0
;
2003 Mpi2ConfigReply_t mpi_reply
;
2005 enum raid_state state
= RAID_STATE_UNKNOWN
;
2008 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2009 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
2012 handle
= raid_device
->handle
;
2013 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2018 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
2019 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
2020 sizeof(Mpi2RaidVolPage0_t
))) {
2021 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2022 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2026 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2027 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
2028 state
= RAID_STATE_RESYNCING
;
2032 switch (vol_pg0
.VolumeState
) {
2033 case MPI2_RAID_VOL_STATE_OPTIMAL
:
2034 case MPI2_RAID_VOL_STATE_ONLINE
:
2035 state
= RAID_STATE_ACTIVE
;
2037 case MPI2_RAID_VOL_STATE_DEGRADED
:
2038 state
= RAID_STATE_DEGRADED
;
2040 case MPI2_RAID_VOL_STATE_FAILED
:
2041 case MPI2_RAID_VOL_STATE_MISSING
:
2042 state
= RAID_STATE_OFFLINE
;
2046 switch (ioc
->hba_mpi_version_belonged
) {
2048 raid_set_state(mpt2sas_raid_template
, dev
, state
);
2052 raid_set_state(mpt3sas_raid_template
, dev
, state
);
2058 * _scsih_set_level - set raid level
2060 * @sdev: scsi device struct
2061 * @volume_type: volume type
2064 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
2065 struct scsi_device
*sdev
, u8 volume_type
)
2067 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
2069 switch (volume_type
) {
2070 case MPI2_RAID_VOL_TYPE_RAID0
:
2071 level
= RAID_LEVEL_0
;
2073 case MPI2_RAID_VOL_TYPE_RAID10
:
2074 level
= RAID_LEVEL_10
;
2076 case MPI2_RAID_VOL_TYPE_RAID1E
:
2077 level
= RAID_LEVEL_1E
;
2079 case MPI2_RAID_VOL_TYPE_RAID1
:
2080 level
= RAID_LEVEL_1
;
2084 switch (ioc
->hba_mpi_version_belonged
) {
2086 raid_set_level(mpt2sas_raid_template
,
2087 &sdev
->sdev_gendev
, level
);
2091 raid_set_level(mpt3sas_raid_template
,
2092 &sdev
->sdev_gendev
, level
);
2099 * _scsih_get_volume_capabilities - volume capabilities
2100 * @ioc: per adapter object
2101 * @raid_device: the raid_device object
2103 * Return: 0 for success, else 1
2106 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
2107 struct _raid_device
*raid_device
)
2109 Mpi2RaidVolPage0_t
*vol_pg0
;
2110 Mpi2RaidPhysDiskPage0_t pd_pg0
;
2111 Mpi2SasDevicePage0_t sas_device_pg0
;
2112 Mpi2ConfigReply_t mpi_reply
;
2116 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
2117 &num_pds
)) || !num_pds
) {
2118 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2119 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2124 raid_device
->num_pds
= num_pds
;
2125 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
2126 sizeof(Mpi2RaidVol0PhysDisk_t
));
2127 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
2129 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2130 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2135 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
2136 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
2137 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2138 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2144 raid_device
->volume_type
= vol_pg0
->VolumeType
;
2146 /* figure out what the underlying devices are by
2147 * obtaining the device_info bits for the 1st device
2149 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
2150 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
2151 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
2152 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
2153 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
2154 le16_to_cpu(pd_pg0
.DevHandle
)))) {
2155 raid_device
->device_info
=
2156 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
2165 * _scsih_enable_tlr - setting TLR flags
2166 * @ioc: per adapter object
2167 * @sdev: scsi device struct
2169 * Enabling Transaction Layer Retries for tape devices when
2170 * vpd page 0x90 is present
2174 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
2178 if (sdev
->type
!= TYPE_TAPE
)
2181 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
2184 sas_enable_tlr(sdev
);
2185 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
2186 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
2192 * scsih_slave_configure - device configure routine.
2193 * @sdev: scsi device struct
2195 * Return: 0 if ok. Any other return is assumed to be an error and
2196 * the device is ignored.
2199 scsih_slave_configure(struct scsi_device
*sdev
)
2201 struct Scsi_Host
*shost
= sdev
->host
;
2202 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2203 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2204 struct MPT3SAS_TARGET
*sas_target_priv_data
;
2205 struct _sas_device
*sas_device
;
2206 struct _pcie_device
*pcie_device
;
2207 struct _raid_device
*raid_device
;
2208 unsigned long flags
;
2213 u16 handle
, volume_handle
= 0;
2214 u64 volume_wwid
= 0;
2217 sas_device_priv_data
= sdev
->hostdata
;
2218 sas_device_priv_data
->configured_lun
= 1;
2219 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2220 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2221 handle
= sas_target_priv_data
->handle
;
2223 /* raid volume handling */
2224 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2226 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2227 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
2228 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2230 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2231 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2232 __LINE__
, __func__
));
2236 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2237 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2238 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2239 __LINE__
, __func__
));
2244 * WARPDRIVE: Initialize the required data for Direct IO
2246 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
2248 /* RAID Queue Depth Support
2249 * IS volume = underlying qdepth of drive type, either
2250 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2251 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2253 if (raid_device
->device_info
&
2254 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2255 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2258 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2259 if (raid_device
->device_info
&
2260 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2266 switch (raid_device
->volume_type
) {
2267 case MPI2_RAID_VOL_TYPE_RAID0
:
2270 case MPI2_RAID_VOL_TYPE_RAID1E
:
2271 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2272 if (ioc
->manu_pg10
.OEMIdentifier
&&
2273 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2274 MFG10_GF0_R10_DISPLAY
) &&
2275 !(raid_device
->num_pds
% 2))
2280 case MPI2_RAID_VOL_TYPE_RAID1
:
2281 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2284 case MPI2_RAID_VOL_TYPE_RAID10
:
2285 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2288 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2290 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2295 if (!ioc
->hide_ir_msg
)
2296 sdev_printk(KERN_INFO
, sdev
,
2297 "%s: handle(0x%04x), wwid(0x%016llx),"
2298 " pd_count(%d), type(%s)\n",
2299 r_level
, raid_device
->handle
,
2300 (unsigned long long)raid_device
->wwid
,
2301 raid_device
->num_pds
, ds
);
2303 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
2304 blk_queue_max_hw_sectors(sdev
->request_queue
,
2305 MPT3SAS_RAID_MAX_SECTORS
);
2306 sdev_printk(KERN_INFO
, sdev
,
2307 "Set queue's max_sector to: %u\n",
2308 MPT3SAS_RAID_MAX_SECTORS
);
2311 scsih_change_queue_depth(sdev
, qdepth
);
2313 /* raid transport support */
2314 if (!ioc
->is_warpdrive
)
2315 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
2319 /* non-raid handling */
2320 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2321 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
2323 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2324 "failure at %s:%d/%s()!\n", ioc
->name
,
2325 __FILE__
, __LINE__
, __func__
));
2328 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
2329 volume_handle
, &volume_wwid
)) {
2330 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2331 "failure at %s:%d/%s()!\n", ioc
->name
,
2332 __FILE__
, __LINE__
, __func__
));
2338 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2339 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2340 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
2341 sas_device_priv_data
->sas_target
->sas_address
);
2343 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2344 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2345 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2346 __LINE__
, __func__
));
2350 qdepth
= MPT3SAS_NVME_QUEUE_DEPTH
;
2352 sdev_printk(KERN_INFO
, sdev
,
2353 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2354 ds
, handle
, (unsigned long long)pcie_device
->wwid
,
2355 pcie_device
->port_num
);
2356 if (pcie_device
->enclosure_handle
!= 0)
2357 sdev_printk(KERN_INFO
, sdev
,
2358 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2360 (unsigned long long)pcie_device
->enclosure_logical_id
,
2362 if (pcie_device
->connector_name
[0] != '\0')
2363 sdev_printk(KERN_INFO
, sdev
,
2364 "%s: enclosure level(0x%04x),"
2365 "connector name( %s)\n", ds
,
2366 pcie_device
->enclosure_level
,
2367 pcie_device
->connector_name
);
2369 if (pcie_device
->nvme_mdts
)
2370 blk_queue_max_hw_sectors(sdev
->request_queue
,
2371 pcie_device
->nvme_mdts
/512);
2373 pcie_device_put(pcie_device
);
2374 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2375 scsih_change_queue_depth(sdev
, qdepth
);
2376 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2377 ** merged and can eliminate holes created during merging
2380 blk_queue_flag_set(QUEUE_FLAG_NOMERGES
,
2381 sdev
->request_queue
);
2382 blk_queue_virt_boundary(sdev
->request_queue
,
2383 ioc
->page_size
- 1);
2387 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2388 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
2389 sas_device_priv_data
->sas_target
->sas_address
);
2391 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2392 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2393 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2398 sas_device
->volume_handle
= volume_handle
;
2399 sas_device
->volume_wwid
= volume_wwid
;
2400 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2401 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2403 if (sas_device
->device_info
&
2404 MPI2_SAS_DEVICE_INFO_SEP
) {
2405 sdev_printk(KERN_WARNING
, sdev
,
2406 "set ignore_delay_remove for handle(0x%04x)\n",
2407 sas_device_priv_data
->sas_target
->handle
);
2408 sas_device_priv_data
->ignore_delay_remove
= 1;
2413 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2414 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2416 else if (sas_device
->device_info
&
2417 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2421 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2422 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2423 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2424 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2426 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, sdev
, NULL
);
2428 sas_device_put(sas_device
);
2429 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2432 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2435 scsih_change_queue_depth(sdev
, qdepth
);
2438 sas_read_port_mode_page(sdev
);
2439 _scsih_enable_tlr(ioc
, sdev
);
2446 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2447 * @sdev: scsi device struct
2448 * @bdev: pointer to block device context
2449 * @capacity: device size (in 512 byte sectors)
2450 * @params: three element array to place output:
2451 * params[0] number of heads (max 255)
2452 * params[1] number of sectors (max 63)
2453 * params[2] number of cylinders
2456 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2457 sector_t capacity
, int params
[])
2467 dummy
= heads
* sectors
;
2468 cylinders
= capacity
;
2469 sector_div(cylinders
, dummy
);
2472 * Handle extended translation size for logical drives
2475 if ((ulong
)capacity
>= 0x200000) {
2478 dummy
= heads
* sectors
;
2479 cylinders
= capacity
;
2480 sector_div(cylinders
, dummy
);
2485 params
[1] = sectors
;
2486 params
[2] = cylinders
;
2492 * _scsih_response_code - translation of device response code
2493 * @ioc: per adapter object
2494 * @response_code: response code returned by the device
2497 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2501 switch (response_code
) {
2502 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2503 desc
= "task management request completed";
2505 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2506 desc
= "invalid frame";
2508 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2509 desc
= "task management request not supported";
2511 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2512 desc
= "task management request failed";
2514 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2515 desc
= "task management request succeeded";
2517 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2518 desc
= "invalid lun";
2521 desc
= "overlapped tag attempted";
2523 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2524 desc
= "task queued, however not sent to target";
2530 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2531 ioc
->name
, response_code
, desc
);
2535 * _scsih_tm_done - tm completion routine
2536 * @ioc: per adapter object
2537 * @smid: system request message index
2538 * @msix_index: MSIX table index supplied by the OS
2539 * @reply: reply message frame(lower 32bit addr)
2542 * The callback handler when using scsih_issue_tm.
2544 * Return: 1 meaning mf should be freed from _base_interrupt
2545 * 0 means the mf is freed from this function.
2548 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2550 MPI2DefaultReply_t
*mpi_reply
;
2552 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2554 if (ioc
->tm_cmds
.smid
!= smid
)
2556 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2557 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2559 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2560 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2562 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2563 complete(&ioc
->tm_cmds
.done
);
2568 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2569 * @ioc: per adapter object
2570 * @handle: device handle
2572 * During taskmangement request, we need to freeze the device queue.
2575 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2577 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2578 struct scsi_device
*sdev
;
2581 shost_for_each_device(sdev
, ioc
->shost
) {
2584 sas_device_priv_data
= sdev
->hostdata
;
2585 if (!sas_device_priv_data
)
2587 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2588 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2590 ioc
->ignore_loginfos
= 1;
2596 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2597 * @ioc: per adapter object
2598 * @handle: device handle
2600 * During taskmangement request, we need to freeze the device queue.
2603 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2605 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2606 struct scsi_device
*sdev
;
2609 shost_for_each_device(sdev
, ioc
->shost
) {
2612 sas_device_priv_data
= sdev
->hostdata
;
2613 if (!sas_device_priv_data
)
2615 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2616 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2618 ioc
->ignore_loginfos
= 0;
2624 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2625 * @ioc: per adapter struct
2626 * @handle: device handle
2628 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2629 * @smid_task: smid assigned to the task
2630 * @msix_task: MSIX table index supplied by the OS
2631 * @timeout: timeout in seconds
2632 * @tr_method: Target Reset Method
2635 * A generic API for sending task management requests to firmware.
2637 * The callback index is set inside `ioc->tm_cb_idx`.
2638 * The caller is responsible to check for outstanding commands.
2640 * Return: SUCCESS or FAILED.
2643 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u64 lun
,
2644 u8 type
, u16 smid_task
, u16 msix_task
, u8 timeout
, u8 tr_method
)
2646 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2647 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2652 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2654 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2655 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2656 __func__
, ioc
->name
);
2660 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2661 ioc
->pci_error_recovery
) {
2662 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2663 __func__
, ioc
->name
);
2667 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2668 if (ioc_state
& MPI2_DOORBELL_USED
) {
2669 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2670 "unexpected doorbell active!\n", ioc
->name
));
2671 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2672 return (!rc
) ? SUCCESS
: FAILED
;
2675 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2676 mpt3sas_base_fault_info(ioc
, ioc_state
&
2677 MPI2_DOORBELL_DATA_MASK
);
2678 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2679 return (!rc
) ? SUCCESS
: FAILED
;
2682 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2684 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2685 ioc
->name
, __func__
);
2689 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2690 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
2691 ioc
->name
, handle
, type
, smid_task
, timeout
, tr_method
));
2692 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2693 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2694 ioc
->tm_cmds
.smid
= smid
;
2695 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2696 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2697 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2698 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2699 mpi_request
->TaskType
= type
;
2700 mpi_request
->MsgFlags
= tr_method
;
2701 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2702 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2703 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2704 init_completion(&ioc
->tm_cmds
.done
);
2705 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, msix_task
);
2706 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2707 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2708 if (mpt3sas_base_check_cmd_timeout(ioc
,
2709 ioc
->tm_cmds
.status
, mpi_request
,
2710 sizeof(Mpi2SCSITaskManagementRequest_t
)/4)) {
2711 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2713 rc
= (!rc
) ? SUCCESS
: FAILED
;
2718 /* sync IRQs in case those were busy during flush. */
2719 mpt3sas_base_sync_reply_irqs(ioc
);
2721 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2722 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2723 mpi_reply
= ioc
->tm_cmds
.reply
;
2724 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2725 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2726 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2727 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2728 le32_to_cpu(mpi_reply
->TerminationCount
)));
2729 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2730 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2731 if (mpi_reply
->IOCStatus
)
2732 _debug_dump_mf(mpi_request
,
2733 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2739 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2740 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2744 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2745 u64 lun
, u8 type
, u16 smid_task
, u16 msix_task
,
2746 u8 timeout
, u8 tr_method
)
2750 mutex_lock(&ioc
->tm_cmds
.mutex
);
2751 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
, type
, smid_task
,
2752 msix_task
, timeout
, tr_method
);
2753 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2759 * _scsih_tm_display_info - displays info about the device
2760 * @ioc: per adapter struct
2761 * @scmd: pointer to scsi command object
2763 * Called by task management callback handlers.
2766 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2768 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2769 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2770 struct _sas_device
*sas_device
= NULL
;
2771 struct _pcie_device
*pcie_device
= NULL
;
2772 unsigned long flags
;
2773 char *device_str
= NULL
;
2777 if (ioc
->hide_ir_msg
)
2778 device_str
= "WarpDrive";
2780 device_str
= "volume";
2782 scsi_print_command(scmd
);
2783 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2784 starget_printk(KERN_INFO
, starget
,
2785 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2786 device_str
, priv_target
->handle
,
2787 device_str
, (unsigned long long)priv_target
->sas_address
);
2789 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2790 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2791 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
, priv_target
);
2793 starget_printk(KERN_INFO
, starget
,
2794 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2795 pcie_device
->handle
,
2796 (unsigned long long)pcie_device
->wwid
,
2797 pcie_device
->port_num
);
2798 if (pcie_device
->enclosure_handle
!= 0)
2799 starget_printk(KERN_INFO
, starget
,
2800 "enclosure logical id(0x%016llx), slot(%d)\n",
2801 (unsigned long long)
2802 pcie_device
->enclosure_logical_id
,
2804 if (pcie_device
->connector_name
[0] != '\0')
2805 starget_printk(KERN_INFO
, starget
,
2806 "enclosure level(0x%04x), connector name( %s)\n",
2807 pcie_device
->enclosure_level
,
2808 pcie_device
->connector_name
);
2809 pcie_device_put(pcie_device
);
2811 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2814 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2815 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2817 if (priv_target
->flags
&
2818 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2819 starget_printk(KERN_INFO
, starget
,
2820 "volume handle(0x%04x), "
2821 "volume wwid(0x%016llx)\n",
2822 sas_device
->volume_handle
,
2823 (unsigned long long)sas_device
->volume_wwid
);
2825 starget_printk(KERN_INFO
, starget
,
2826 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2828 (unsigned long long)sas_device
->sas_address
,
2831 _scsih_display_enclosure_chassis_info(NULL
, sas_device
,
2834 sas_device_put(sas_device
);
2836 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2841 * scsih_abort - eh threads main abort routine
2842 * @scmd: pointer to scsi command object
2844 * Return: SUCCESS if command aborted else FAILED
2847 scsih_abort(struct scsi_cmnd
*scmd
)
2849 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2850 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2851 struct scsiio_tracker
*st
= scsi_cmd_priv(scmd
);
2856 struct _pcie_device
*pcie_device
= NULL
;
2857 sdev_printk(KERN_INFO
, scmd
->device
,
2858 "attempting task abort! scmd(%p)\n", scmd
);
2859 _scsih_tm_display_info(ioc
, scmd
);
2861 sas_device_priv_data
= scmd
->device
->hostdata
;
2862 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2864 sdev_printk(KERN_INFO
, scmd
->device
,
2865 "device been deleted! scmd(%p)\n", scmd
);
2866 scmd
->result
= DID_NO_CONNECT
<< 16;
2867 scmd
->scsi_done(scmd
);
2872 /* check for completed command */
2873 if (st
== NULL
|| st
->cb_idx
== 0xFF) {
2874 scmd
->result
= DID_RESET
<< 16;
2879 /* for hidden raid components and volumes this is not supported */
2880 if (sas_device_priv_data
->sas_target
->flags
&
2881 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2882 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2883 scmd
->result
= DID_RESET
<< 16;
2888 mpt3sas_halt_firmware(ioc
);
2890 handle
= sas_device_priv_data
->sas_target
->handle
;
2891 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
2892 if (pcie_device
&& (!ioc
->tm_custom_handling
))
2893 timeout
= ioc
->nvme_abort_timeout
;
2894 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2895 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
,
2896 st
->smid
, st
->msix_io
, timeout
, 0);
2897 /* Command must be cleared after abort */
2898 if (r
== SUCCESS
&& st
->cb_idx
!= 0xFF)
2901 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2902 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2904 pcie_device_put(pcie_device
);
2909 * scsih_dev_reset - eh threads main device reset routine
2910 * @scmd: pointer to scsi command object
2912 * Return: SUCCESS if command aborted else FAILED
2915 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2917 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2918 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2919 struct _sas_device
*sas_device
= NULL
;
2920 struct _pcie_device
*pcie_device
= NULL
;
2926 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2927 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2929 sdev_printk(KERN_INFO
, scmd
->device
,
2930 "attempting device reset! scmd(%p)\n", scmd
);
2931 _scsih_tm_display_info(ioc
, scmd
);
2933 sas_device_priv_data
= scmd
->device
->hostdata
;
2934 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2936 sdev_printk(KERN_INFO
, scmd
->device
,
2937 "device been deleted! scmd(%p)\n", scmd
);
2938 scmd
->result
= DID_NO_CONNECT
<< 16;
2939 scmd
->scsi_done(scmd
);
2944 /* for hidden raid components obtain the volume_handle */
2946 if (sas_device_priv_data
->sas_target
->flags
&
2947 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2948 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2951 handle
= sas_device
->volume_handle
;
2953 handle
= sas_device_priv_data
->sas_target
->handle
;
2956 scmd
->result
= DID_RESET
<< 16;
2961 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
2963 if (pcie_device
&& (!ioc
->tm_custom_handling
)) {
2964 tr_timeout
= pcie_device
->reset_timeout
;
2965 tr_method
= MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
2967 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
2968 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2969 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 0,
2970 tr_timeout
, tr_method
);
2971 /* Check for busy commands after reset */
2972 if (r
== SUCCESS
&& atomic_read(&scmd
->device
->device_busy
))
2975 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2976 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2979 sas_device_put(sas_device
);
2981 pcie_device_put(pcie_device
);
2987 * scsih_target_reset - eh threads main target reset routine
2988 * @scmd: pointer to scsi command object
2990 * Return: SUCCESS if command aborted else FAILED
2993 scsih_target_reset(struct scsi_cmnd
*scmd
)
2995 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2996 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2997 struct _sas_device
*sas_device
= NULL
;
2998 struct _pcie_device
*pcie_device
= NULL
;
3003 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3004 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
3006 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
3008 _scsih_tm_display_info(ioc
, scmd
);
3010 sas_device_priv_data
= scmd
->device
->hostdata
;
3011 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3013 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
3015 scmd
->result
= DID_NO_CONNECT
<< 16;
3016 scmd
->scsi_done(scmd
);
3021 /* for hidden raid components obtain the volume_handle */
3023 if (sas_device_priv_data
->sas_target
->flags
&
3024 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
3025 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
3028 handle
= sas_device
->volume_handle
;
3030 handle
= sas_device_priv_data
->sas_target
->handle
;
3033 scmd
->result
= DID_RESET
<< 16;
3038 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
3040 if (pcie_device
&& (!ioc
->tm_custom_handling
)) {
3041 tr_timeout
= pcie_device
->reset_timeout
;
3042 tr_method
= MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
3044 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
3045 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, 0,
3046 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 0,
3047 tr_timeout
, tr_method
);
3048 /* Check for busy commands after reset */
3049 if (r
== SUCCESS
&& atomic_read(&starget
->target_busy
))
3052 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
3053 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3056 sas_device_put(sas_device
);
3058 pcie_device_put(pcie_device
);
3064 * scsih_host_reset - eh threads main host reset routine
3065 * @scmd: pointer to scsi command object
3067 * Return: SUCCESS if command aborted else FAILED
3070 scsih_host_reset(struct scsi_cmnd
*scmd
)
3072 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3075 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
3077 scsi_print_command(scmd
);
3079 if (ioc
->is_driver_loading
|| ioc
->remove_host
) {
3080 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
3086 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
3087 r
= (retval
< 0) ? FAILED
: SUCCESS
;
3089 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
3090 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3096 * _scsih_fw_event_add - insert and queue up fw_event
3097 * @ioc: per adapter object
3098 * @fw_event: object describing the event
3099 * Context: This function will acquire ioc->fw_event_lock.
3101 * This adds the firmware event object into link list, then queues it up to
3102 * be processed from user context.
3105 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
3107 unsigned long flags
;
3109 if (ioc
->firmware_event_thread
== NULL
)
3112 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3113 fw_event_work_get(fw_event
);
3114 INIT_LIST_HEAD(&fw_event
->list
);
3115 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
3116 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
3117 fw_event_work_get(fw_event
);
3118 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
3119 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3123 * _scsih_fw_event_del_from_list - delete fw_event from the list
3124 * @ioc: per adapter object
3125 * @fw_event: object describing the event
3126 * Context: This function will acquire ioc->fw_event_lock.
3128 * If the fw_event is on the fw_event_list, remove it and do a put.
3131 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
3134 unsigned long flags
;
3136 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3137 if (!list_empty(&fw_event
->list
)) {
3138 list_del_init(&fw_event
->list
);
3139 fw_event_work_put(fw_event
);
3141 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3146 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3147 * @ioc: per adapter object
3148 * @event_data: trigger event data
3151 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
3152 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
3154 struct fw_event_work
*fw_event
;
3157 if (ioc
->is_driver_loading
)
3159 sz
= sizeof(*event_data
);
3160 fw_event
= alloc_fw_event_work(sz
);
3163 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
3164 fw_event
->ioc
= ioc
;
3165 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
3166 _scsih_fw_event_add(ioc
, fw_event
);
3167 fw_event_work_put(fw_event
);
3171 * _scsih_error_recovery_delete_devices - remove devices not responding
3172 * @ioc: per adapter object
3175 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
3177 struct fw_event_work
*fw_event
;
3179 if (ioc
->is_driver_loading
)
3181 fw_event
= alloc_fw_event_work(0);
3184 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
3185 fw_event
->ioc
= ioc
;
3186 _scsih_fw_event_add(ioc
, fw_event
);
3187 fw_event_work_put(fw_event
);
3191 * mpt3sas_port_enable_complete - port enable completed (fake event)
3192 * @ioc: per adapter object
3195 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
3197 struct fw_event_work
*fw_event
;
3199 fw_event
= alloc_fw_event_work(0);
3202 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
3203 fw_event
->ioc
= ioc
;
3204 _scsih_fw_event_add(ioc
, fw_event
);
3205 fw_event_work_put(fw_event
);
3208 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
3210 unsigned long flags
;
3211 struct fw_event_work
*fw_event
= NULL
;
3213 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3214 if (!list_empty(&ioc
->fw_event_list
)) {
3215 fw_event
= list_first_entry(&ioc
->fw_event_list
,
3216 struct fw_event_work
, list
);
3217 list_del_init(&fw_event
->list
);
3219 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3225 * _scsih_fw_event_cleanup_queue - cleanup event queue
3226 * @ioc: per adapter object
3228 * Walk the firmware event queue, either killing timers, or waiting
3229 * for outstanding events to complete
3232 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
3234 struct fw_event_work
*fw_event
;
3236 if (list_empty(&ioc
->fw_event_list
) ||
3237 !ioc
->firmware_event_thread
|| in_interrupt())
3240 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
3242 * Wait on the fw_event to complete. If this returns 1, then
3243 * the event was never executed, and we need a put for the
3244 * reference the work had on the fw_event.
3246 * If it did execute, we wait for it to finish, and the put will
3247 * happen from _firmware_event_work()
3249 if (cancel_work_sync(&fw_event
->work
))
3250 fw_event_work_put(fw_event
);
3252 fw_event_work_put(fw_event
);
3257 * _scsih_internal_device_block - block the sdev device
3258 * @sdev: per device object
3259 * @sas_device_priv_data : per device driver private data
3261 * make sure device is blocked without error, if not
3265 _scsih_internal_device_block(struct scsi_device
*sdev
,
3266 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3270 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
3271 sas_device_priv_data
->sas_target
->handle
);
3272 sas_device_priv_data
->block
= 1;
3274 r
= scsi_internal_device_block_nowait(sdev
);
3276 sdev_printk(KERN_WARNING
, sdev
,
3277 "device_block failed with return(%d) for handle(0x%04x)\n",
3278 r
, sas_device_priv_data
->sas_target
->handle
);
3282 * _scsih_internal_device_unblock - unblock the sdev device
3283 * @sdev: per device object
3284 * @sas_device_priv_data : per device driver private data
3285 * make sure device is unblocked without error, if not retry
3286 * by blocking and then unblocking
3290 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
3291 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3295 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
3296 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
3297 sas_device_priv_data
->block
= 0;
3298 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3300 /* The device has been set to SDEV_RUNNING by SD layer during
3301 * device addition but the request queue is still stopped by
3302 * our earlier block call. We need to perform a block again
3303 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3305 sdev_printk(KERN_WARNING
, sdev
,
3306 "device_unblock failed with return(%d) for handle(0x%04x) "
3307 "performing a block followed by an unblock\n",
3308 r
, sas_device_priv_data
->sas_target
->handle
);
3309 sas_device_priv_data
->block
= 1;
3310 r
= scsi_internal_device_block_nowait(sdev
);
3312 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
3313 "failed with return(%d) for handle(0x%04x)\n",
3314 r
, sas_device_priv_data
->sas_target
->handle
);
3316 sas_device_priv_data
->block
= 0;
3317 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3319 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
3320 " failed with return(%d) for handle(0x%04x)\n",
3321 r
, sas_device_priv_data
->sas_target
->handle
);
3326 * _scsih_ublock_io_all_device - unblock every device
3327 * @ioc: per adapter object
3329 * change the device state from block to running
3332 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3334 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3335 struct scsi_device
*sdev
;
3337 shost_for_each_device(sdev
, ioc
->shost
) {
3338 sas_device_priv_data
= sdev
->hostdata
;
3339 if (!sas_device_priv_data
)
3341 if (!sas_device_priv_data
->block
)
3344 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3345 "device_running, handle(0x%04x)\n",
3346 sas_device_priv_data
->sas_target
->handle
));
3347 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
3353 * _scsih_ublock_io_device - prepare device to be deleted
3354 * @ioc: per adapter object
3355 * @sas_address: sas address
3357 * unblock then put device in offline state
3360 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
3362 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3363 struct scsi_device
*sdev
;
3365 shost_for_each_device(sdev
, ioc
->shost
) {
3366 sas_device_priv_data
= sdev
->hostdata
;
3367 if (!sas_device_priv_data
)
3369 if (sas_device_priv_data
->sas_target
->sas_address
3372 if (sas_device_priv_data
->block
)
3373 _scsih_internal_device_unblock(sdev
,
3374 sas_device_priv_data
);
3379 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3380 * @ioc: per adapter object
3382 * During device pull we need to appropriately set the sdev state.
3385 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3387 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3388 struct scsi_device
*sdev
;
3390 shost_for_each_device(sdev
, ioc
->shost
) {
3391 sas_device_priv_data
= sdev
->hostdata
;
3392 if (!sas_device_priv_data
)
3394 if (sas_device_priv_data
->block
)
3396 if (sas_device_priv_data
->ignore_delay_remove
) {
3397 sdev_printk(KERN_INFO
, sdev
,
3398 "%s skip device_block for SES handle(0x%04x)\n",
3399 __func__
, sas_device_priv_data
->sas_target
->handle
);
3402 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3407 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3408 * @ioc: per adapter object
3409 * @handle: device handle
3411 * During device pull we need to appropriately set the sdev state.
3414 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3416 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3417 struct scsi_device
*sdev
;
3418 struct _sas_device
*sas_device
;
3420 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3422 shost_for_each_device(sdev
, ioc
->shost
) {
3423 sas_device_priv_data
= sdev
->hostdata
;
3424 if (!sas_device_priv_data
)
3426 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3428 if (sas_device_priv_data
->block
)
3430 if (sas_device
&& sas_device
->pend_sas_rphy_add
)
3432 if (sas_device_priv_data
->ignore_delay_remove
) {
3433 sdev_printk(KERN_INFO
, sdev
,
3434 "%s skip device_block for SES handle(0x%04x)\n",
3435 __func__
, sas_device_priv_data
->sas_target
->handle
);
3438 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3442 sas_device_put(sas_device
);
3446 * _scsih_block_io_to_children_attached_to_ex
3447 * @ioc: per adapter object
3448 * @sas_expander: the sas_device object
3450 * This routine set sdev state to SDEV_BLOCK for all devices
3451 * attached to this expander. This function called when expander is
3455 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3456 struct _sas_node
*sas_expander
)
3458 struct _sas_port
*mpt3sas_port
;
3459 struct _sas_device
*sas_device
;
3460 struct _sas_node
*expander_sibling
;
3461 unsigned long flags
;
3466 list_for_each_entry(mpt3sas_port
,
3467 &sas_expander
->sas_port_list
, port_list
) {
3468 if (mpt3sas_port
->remote_identify
.device_type
==
3470 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3471 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3472 mpt3sas_port
->remote_identify
.sas_address
);
3474 set_bit(sas_device
->handle
,
3475 ioc
->blocking_handles
);
3476 sas_device_put(sas_device
);
3478 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3482 list_for_each_entry(mpt3sas_port
,
3483 &sas_expander
->sas_port_list
, port_list
) {
3485 if (mpt3sas_port
->remote_identify
.device_type
==
3486 SAS_EDGE_EXPANDER_DEVICE
||
3487 mpt3sas_port
->remote_identify
.device_type
==
3488 SAS_FANOUT_EXPANDER_DEVICE
) {
3490 mpt3sas_scsih_expander_find_by_sas_address(
3491 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3492 _scsih_block_io_to_children_attached_to_ex(ioc
,
3499 * _scsih_block_io_to_children_attached_directly
3500 * @ioc: per adapter object
3501 * @event_data: topology change event data
3503 * This routine set sdev state to SDEV_BLOCK for all devices
3504 * direct attached during device pull.
3507 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3508 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3514 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3515 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3518 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3519 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3520 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3521 _scsih_block_io_device(ioc
, handle
);
3526 * _scsih_block_io_to_pcie_children_attached_directly
3527 * @ioc: per adapter object
3528 * @event_data: topology change event data
3530 * This routine set sdev state to SDEV_BLOCK for all devices
3531 * direct attached during device pull/reconnect.
3534 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3535 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
3541 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3543 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
3546 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
3548 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
)
3549 _scsih_block_io_device(ioc
, handle
);
3553 * _scsih_tm_tr_send - send task management request
3554 * @ioc: per adapter object
3555 * @handle: device handle
3556 * Context: interrupt time.
3558 * This code is to initiate the device removal handshake protocol
3559 * with controller firmware. This function will issue target reset
3560 * using high priority request queue. It will send a sas iounit
3561 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3563 * This is designed to send muliple task management request at the same
3564 * time to the fifo. If the fifo is full, we will append the request,
3565 * and process it in a future completion.
3568 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3570 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3572 struct _sas_device
*sas_device
= NULL
;
3573 struct _pcie_device
*pcie_device
= NULL
;
3574 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3575 u64 sas_address
= 0;
3576 unsigned long flags
;
3577 struct _tr_list
*delayed_tr
;
3581 if (ioc
->pci_error_recovery
) {
3582 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3583 "%s: host in pci error recovery: handle(0x%04x)\n",
3584 __func__
, ioc
->name
,
3588 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3589 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3590 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3591 "%s: host is not operational: handle(0x%04x)\n",
3592 __func__
, ioc
->name
,
3597 /* if PD, then return */
3598 if (test_bit(handle
, ioc
->pd_handles
))
3601 clear_bit(handle
, ioc
->pend_os_device_add
);
3603 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3604 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3605 if (sas_device
&& sas_device
->starget
&&
3606 sas_device
->starget
->hostdata
) {
3607 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3608 sas_target_priv_data
->deleted
= 1;
3609 sas_address
= sas_device
->sas_address
;
3611 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3613 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
3614 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
3615 if (pcie_device
&& pcie_device
->starget
&&
3616 pcie_device
->starget
->hostdata
) {
3617 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
3618 sas_target_priv_data
->deleted
= 1;
3619 sas_address
= pcie_device
->wwid
;
3621 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
3622 if (pcie_device
&& (!ioc
->tm_custom_handling
))
3624 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
3626 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
3628 if (sas_target_priv_data
) {
3629 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3630 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3632 (unsigned long long)sas_address
));
3634 if (sas_device
->enclosure_handle
!= 0)
3635 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3636 "setting delete flag:enclosure logical "
3637 "id(0x%016llx), slot(%d)\n", ioc
->name
,
3638 (unsigned long long)
3639 sas_device
->enclosure_logical_id
,
3641 if (sas_device
->connector_name
[0] != '\0')
3642 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3643 "setting delete flag: enclosure "
3644 "level(0x%04x), connector name( %s)\n",
3645 ioc
->name
, sas_device
->enclosure_level
,
3646 sas_device
->connector_name
));
3647 } else if (pcie_device
) {
3648 if (pcie_device
->enclosure_handle
!= 0)
3649 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3650 "setting delete flag: logical "
3651 "id(0x%016llx), slot(%d)\n", ioc
->name
,
3652 (unsigned long long)
3653 pcie_device
->enclosure_logical_id
,
3654 pcie_device
->slot
));
3655 if (pcie_device
->connector_name
[0] != '\0')
3656 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3657 "setting delete flag:, enclosure "
3659 "connector name( %s)\n", ioc
->name
,
3660 pcie_device
->enclosure_level
,
3661 pcie_device
->connector_name
));
3663 _scsih_ublock_io_device(ioc
, sas_address
);
3664 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3667 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3669 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3672 INIT_LIST_HEAD(&delayed_tr
->list
);
3673 delayed_tr
->handle
= handle
;
3674 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3675 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3676 "DELAYED:tr:handle(0x%04x), (open)\n",
3677 ioc
->name
, handle
));
3681 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3682 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3683 ioc
->name
, handle
, smid
,
3684 ioc
->tm_tr_cb_idx
));
3685 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3686 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3687 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3688 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3689 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3690 mpi_request
->MsgFlags
= tr_method
;
3691 set_bit(handle
, ioc
->device_remove_in_progress
);
3692 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
3693 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3697 sas_device_put(sas_device
);
3699 pcie_device_put(pcie_device
);
3703 * _scsih_tm_tr_complete -
3704 * @ioc: per adapter object
3705 * @smid: system request message index
3706 * @msix_index: MSIX table index supplied by the OS
3707 * @reply: reply message frame(lower 32bit addr)
3708 * Context: interrupt time.
3710 * This is the target reset completion routine.
3711 * This code is part of the code to initiate the device removal
3712 * handshake protocol with controller firmware.
3713 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3715 * Return: 1 meaning mf should be freed from _base_interrupt
3716 * 0 means the mf is freed from this function.
3719 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3723 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3724 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3725 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3726 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3729 struct _sc_list
*delayed_sc
;
3731 if (ioc
->pci_error_recovery
) {
3732 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3733 "%s: host in pci error recovery\n", __func__
,
3737 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3738 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3739 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3740 "%s: host is not operational\n", __func__
, ioc
->name
));
3743 if (unlikely(!mpi_reply
)) {
3744 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3745 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3748 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3749 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3750 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3751 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3752 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3754 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3758 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3759 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3760 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3761 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3762 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3763 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3764 le32_to_cpu(mpi_reply
->TerminationCount
)));
3766 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3767 if (!smid_sas_ctrl
) {
3768 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3770 return _scsih_check_for_pending_tm(ioc
, smid
);
3771 INIT_LIST_HEAD(&delayed_sc
->list
);
3772 delayed_sc
->handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3773 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3774 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3775 "DELAYED:sc:handle(0x%04x), (open)\n",
3776 ioc
->name
, handle
));
3777 return _scsih_check_for_pending_tm(ioc
, smid
);
3780 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3781 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3782 ioc
->name
, handle
, smid_sas_ctrl
,
3783 ioc
->tm_sas_control_cb_idx
));
3784 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3785 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3786 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3787 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3788 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3789 mpt3sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3791 return _scsih_check_for_pending_tm(ioc
, smid
);
3794 /** _scsih_allow_scmd_to_device - check whether scmd needs to
3795 * issue to IOC or not.
3796 * @ioc: per adapter object
3797 * @scmd: pointer to scsi command object
3799 * Returns true if scmd can be issued to IOC otherwise returns false.
3801 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER
*ioc
,
3802 struct scsi_cmnd
*scmd
)
3805 if (ioc
->pci_error_recovery
)
3808 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
) {
3809 if (ioc
->remove_host
)
3815 if (ioc
->remove_host
) {
3817 switch (scmd
->cmnd
[0]) {
3818 case SYNCHRONIZE_CACHE
:
3830 * _scsih_sas_control_complete - completion routine
3831 * @ioc: per adapter object
3832 * @smid: system request message index
3833 * @msix_index: MSIX table index supplied by the OS
3834 * @reply: reply message frame(lower 32bit addr)
3835 * Context: interrupt time.
3837 * This is the sas iounit control completion routine.
3838 * This code is part of the code to initiate the device removal
3839 * handshake protocol with controller firmware.
3841 * Return: 1 meaning mf should be freed from _base_interrupt
3842 * 0 means the mf is freed from this function.
3845 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3846 u8 msix_index
, u32 reply
)
3848 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3849 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3851 if (likely(mpi_reply
)) {
3852 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3853 "sc_complete:handle(0x%04x), (open) "
3854 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3855 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3856 le16_to_cpu(mpi_reply
->IOCStatus
),
3857 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3858 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3859 MPI2_IOCSTATUS_SUCCESS
) {
3860 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3861 ioc
->device_remove_in_progress
);
3864 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3865 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3867 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3871 * _scsih_tm_tr_volume_send - send target reset request for volumes
3872 * @ioc: per adapter object
3873 * @handle: device handle
3874 * Context: interrupt time.
3876 * This is designed to send muliple task management request at the same
3877 * time to the fifo. If the fifo is full, we will append the request,
3878 * and process it in a future completion.
3881 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3883 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3885 struct _tr_list
*delayed_tr
;
3887 if (ioc
->pci_error_recovery
) {
3888 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3889 "%s: host reset in progress!\n",
3890 __func__
, ioc
->name
));
3894 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3896 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3899 INIT_LIST_HEAD(&delayed_tr
->list
);
3900 delayed_tr
->handle
= handle
;
3901 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3902 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3903 "DELAYED:tr:handle(0x%04x), (open)\n",
3904 ioc
->name
, handle
));
3908 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3909 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3910 ioc
->name
, handle
, smid
,
3911 ioc
->tm_tr_volume_cb_idx
));
3912 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3913 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3914 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3915 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3916 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3917 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
3921 * _scsih_tm_volume_tr_complete - target reset completion
3922 * @ioc: per adapter object
3923 * @smid: system request message index
3924 * @msix_index: MSIX table index supplied by the OS
3925 * @reply: reply message frame(lower 32bit addr)
3926 * Context: interrupt time.
3928 * Return: 1 meaning mf should be freed from _base_interrupt
3929 * 0 means the mf is freed from this function.
3932 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3933 u8 msix_index
, u32 reply
)
3936 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3937 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3938 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3940 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
) {
3941 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3942 "%s: host reset in progress!\n",
3943 __func__
, ioc
->name
));
3946 if (unlikely(!mpi_reply
)) {
3947 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3948 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3952 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3953 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3954 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3955 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3956 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3958 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3962 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3963 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3964 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3965 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3966 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3967 le32_to_cpu(mpi_reply
->TerminationCount
)));
3969 return _scsih_check_for_pending_tm(ioc
, smid
);
3973 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3974 * @ioc: per adapter object
3975 * @smid: system request message index
3977 * @event_context: used to track events uniquely
3979 * Context - processed in interrupt context.
3982 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, U16 event
,
3985 Mpi2EventAckRequest_t
*ack_request
;
3986 int i
= smid
- ioc
->internal_smid
;
3987 unsigned long flags
;
3989 /* Without releasing the smid just update the
3990 * call back index and reuse the same smid for
3991 * processing this delayed request
3993 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3994 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3995 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3997 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3998 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3999 ioc
->name
, le16_to_cpu(event
), smid
,
4001 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4002 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
4003 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
4004 ack_request
->Event
= event
;
4005 ack_request
->EventContext
= event_context
;
4006 ack_request
->VF_ID
= 0; /* TODO */
4007 ack_request
->VP_ID
= 0;
4008 mpt3sas_base_put_smid_default(ioc
, smid
);
4012 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
4013 * sas_io_unit_ctrl messages
4014 * @ioc: per adapter object
4015 * @smid: system request message index
4016 * @handle: device handle
4018 * Context - processed in interrupt context.
4021 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
4022 u16 smid
, u16 handle
)
4024 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
4026 int i
= smid
- ioc
->internal_smid
;
4027 unsigned long flags
;
4029 if (ioc
->remove_host
) {
4030 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4031 "%s: host has been removed\n",
4032 __func__
, ioc
->name
));
4034 } else if (ioc
->pci_error_recovery
) {
4035 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4036 "%s: host in pci error recovery\n",
4037 __func__
, ioc
->name
));
4040 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4041 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4042 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4043 "%s: host is not operational\n",
4044 __func__
, ioc
->name
));
4048 /* Without releasing the smid just update the
4049 * call back index and reuse the same smid for
4050 * processing this delayed request
4052 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4053 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
4054 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4056 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4057 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4058 ioc
->name
, handle
, smid
,
4059 ioc
->tm_sas_control_cb_idx
));
4060 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4061 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4062 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4063 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4064 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4065 mpt3sas_base_put_smid_default(ioc
, smid
);
4069 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
4070 * @ioc: per adapter object
4071 * @smid: system request message index
4073 * Context: Executed in interrupt context
4075 * This will check delayed internal messages list, and process the
4078 * Return: 1 meaning mf should be freed from _base_interrupt
4079 * 0 means the mf is freed from this function.
4082 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4084 struct _sc_list
*delayed_sc
;
4085 struct _event_ack_list
*delayed_event_ack
;
4087 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
4088 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
4089 struct _event_ack_list
, list
);
4090 _scsih_issue_delayed_event_ack(ioc
, smid
,
4091 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
4092 list_del(&delayed_event_ack
->list
);
4093 kfree(delayed_event_ack
);
4097 if (!list_empty(&ioc
->delayed_sc_list
)) {
4098 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
4099 struct _sc_list
, list
);
4100 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
4101 delayed_sc
->handle
);
4102 list_del(&delayed_sc
->list
);
4110 * _scsih_check_for_pending_tm - check for pending task management
4111 * @ioc: per adapter object
4112 * @smid: system request message index
4114 * This will check delayed target reset list, and feed the
4117 * Return: 1 meaning mf should be freed from _base_interrupt
4118 * 0 means the mf is freed from this function.
4121 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4123 struct _tr_list
*delayed_tr
;
4125 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
4126 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
4127 struct _tr_list
, list
);
4128 mpt3sas_base_free_smid(ioc
, smid
);
4129 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
4130 list_del(&delayed_tr
->list
);
4135 if (!list_empty(&ioc
->delayed_tr_list
)) {
4136 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
4137 struct _tr_list
, list
);
4138 mpt3sas_base_free_smid(ioc
, smid
);
4139 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
4140 list_del(&delayed_tr
->list
);
4149 * _scsih_check_topo_delete_events - sanity check on topo events
4150 * @ioc: per adapter object
4151 * @event_data: the event data payload
4153 * This routine added to better handle cable breaker.
4155 * This handles the case where driver receives multiple expander
4156 * add and delete events in a single shot. When there is a delete event
4157 * the routine will void any pending add events waiting in the event queue.
4160 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4161 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4163 struct fw_event_work
*fw_event
;
4164 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
4165 u16 expander_handle
;
4166 struct _sas_node
*sas_expander
;
4167 unsigned long flags
;
4171 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
4172 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4175 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4176 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4177 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
4178 _scsih_tm_tr_send(ioc
, handle
);
4181 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4182 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
4183 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4186 if (event_data
->ExpStatus
==
4187 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
4188 /* put expander attached devices into blocking state */
4189 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4190 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
4192 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
4193 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4195 handle
= find_first_bit(ioc
->blocking_handles
,
4196 ioc
->facts
.MaxDevHandle
);
4197 if (handle
< ioc
->facts
.MaxDevHandle
)
4198 _scsih_block_io_device(ioc
, handle
);
4199 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
4200 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
4201 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4203 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4206 /* mark ignore flag for pending events */
4207 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4208 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4209 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
4212 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
4213 fw_event
->event_data
;
4214 if (local_event_data
->ExpStatus
==
4215 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4216 local_event_data
->ExpStatus
==
4217 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4218 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
4220 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4221 "setting ignoring flag\n", ioc
->name
));
4222 fw_event
->ignore
= 1;
4226 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4230 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4232 * @ioc: per adapter object
4233 * @event_data: the event data payload
4235 * This handles the case where driver receives multiple switch
4236 * or device add and delete events in a single shot. When there
4237 * is a delete event the routine will void any pending add
4238 * events waiting in the event queue.
4241 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER
*ioc
,
4242 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
4244 struct fw_event_work
*fw_event
;
4245 Mpi26EventDataPCIeTopologyChangeList_t
*local_event_data
;
4246 unsigned long flags
;
4248 u16 handle
, switch_handle
;
4250 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4252 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
4255 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
4256 if (reason_code
== MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
)
4257 _scsih_tm_tr_send(ioc
, handle
);
4260 switch_handle
= le16_to_cpu(event_data
->SwitchDevHandle
);
4261 if (!switch_handle
) {
4262 _scsih_block_io_to_pcie_children_attached_directly(
4266 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4267 if ((event_data
->SwitchStatus
4268 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
) ||
4269 (event_data
->SwitchStatus
==
4270 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
))
4271 _scsih_block_io_to_pcie_children_attached_directly(
4274 if (event_data
->SwitchStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4277 /* mark ignore flag for pending events */
4278 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4279 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4280 if (fw_event
->event
!= MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
||
4284 (Mpi26EventDataPCIeTopologyChangeList_t
*)
4285 fw_event
->event_data
;
4286 if (local_event_data
->SwitchStatus
==
4287 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4288 local_event_data
->SwitchStatus
==
4289 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4290 if (le16_to_cpu(local_event_data
->SwitchDevHandle
) ==
4292 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4293 "setting ignoring flag for switch event\n",
4295 fw_event
->ignore
= 1;
4299 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4303 * _scsih_set_volume_delete_flag - setting volume delete flag
4304 * @ioc: per adapter object
4305 * @handle: device handle
4307 * This returns nothing.
4310 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4312 struct _raid_device
*raid_device
;
4313 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4314 unsigned long flags
;
4316 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4317 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
4318 if (raid_device
&& raid_device
->starget
&&
4319 raid_device
->starget
->hostdata
) {
4320 sas_target_priv_data
=
4321 raid_device
->starget
->hostdata
;
4322 sas_target_priv_data
->deleted
= 1;
4323 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4324 "setting delete flag: handle(0x%04x), "
4325 "wwid(0x%016llx)\n", ioc
->name
, handle
,
4326 (unsigned long long) raid_device
->wwid
));
4328 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4332 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4333 * @handle: input handle
4334 * @a: handle for volume a
4335 * @b: handle for volume b
4337 * IR firmware only supports two raid volumes. The purpose of this
4338 * routine is to set the volume handle in either a or b. When the given
4339 * input handle is non-zero, or when a and b have not been set before.
4342 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
4344 if (!handle
|| handle
== *a
|| handle
== *b
)
4353 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4354 * @ioc: per adapter object
4355 * @event_data: the event data payload
4356 * Context: interrupt time.
4358 * This routine will send target reset to volume, followed by target
4359 * resets to the PDs. This is called when a PD has been removed, or
4360 * volume has been deleted or removed. When the target reset is sent
4361 * to volume, the PD target resets need to be queued to start upon
4362 * completion of the volume target reset.
4365 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
4366 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4368 Mpi2EventIrConfigElement_t
*element
;
4370 u16 handle
, volume_handle
, a
, b
;
4371 struct _tr_list
*delayed_tr
;
4376 if (ioc
->is_warpdrive
)
4379 /* Volume Resets for Deleted or Removed */
4380 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4381 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4382 if (le32_to_cpu(event_data
->Flags
) &
4383 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4385 if (element
->ReasonCode
==
4386 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
4387 element
->ReasonCode
==
4388 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
4389 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4390 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
4391 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4395 /* Volume Resets for UNHIDE events */
4396 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4397 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4398 if (le32_to_cpu(event_data
->Flags
) &
4399 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4401 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
4402 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4403 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4408 _scsih_tm_tr_volume_send(ioc
, a
);
4410 _scsih_tm_tr_volume_send(ioc
, b
);
4412 /* PD target resets */
4413 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4414 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4415 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
4417 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4418 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4419 clear_bit(handle
, ioc
->pd_handles
);
4421 _scsih_tm_tr_send(ioc
, handle
);
4422 else if (volume_handle
== a
|| volume_handle
== b
) {
4423 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
4424 BUG_ON(!delayed_tr
);
4425 INIT_LIST_HEAD(&delayed_tr
->list
);
4426 delayed_tr
->handle
= handle
;
4427 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
4428 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4429 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
4432 _scsih_tm_tr_send(ioc
, handle
);
4438 * _scsih_check_volume_delete_events - set delete flag for volumes
4439 * @ioc: per adapter object
4440 * @event_data: the event data payload
4441 * Context: interrupt time.
4443 * This will handle the case when the cable connected to entire volume is
4444 * pulled. We will take care of setting the deleted flag so normal IO will
4448 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4449 Mpi2EventDataIrVolume_t
*event_data
)
4453 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4455 state
= le32_to_cpu(event_data
->NewValue
);
4456 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
4457 MPI2_RAID_VOL_STATE_FAILED
)
4458 _scsih_set_volume_delete_flag(ioc
,
4459 le16_to_cpu(event_data
->VolDevHandle
));
4463 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4464 * @ioc: per adapter object
4465 * @event_data: the temp threshold event data
4466 * Context: interrupt time.
4469 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
4470 Mpi2EventDataTemperature_t
*event_data
)
4472 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
4473 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
4474 " exceeded for Sensor: %d !!!\n", ioc
->name
,
4475 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
4476 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
4477 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
4478 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
4479 event_data
->SensorNum
);
4480 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
4481 ioc
->name
, event_data
->CurrentTemperature
);
4485 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
4487 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
4489 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
4493 return test_and_set_bit(0, &priv
->ata_command_pending
);
4495 clear_bit(0, &priv
->ata_command_pending
);
4500 * _scsih_flush_running_cmds - completing outstanding commands.
4501 * @ioc: per adapter object
4503 * The flushing out of all pending scmd commands following host reset,
4504 * where all IO is dropped to the floor.
4507 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
4509 struct scsi_cmnd
*scmd
;
4510 struct scsiio_tracker
*st
;
4514 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4515 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
4519 _scsih_set_satl_pending(scmd
, false);
4520 st
= scsi_cmd_priv(scmd
);
4521 mpt3sas_base_clear_st(ioc
, st
);
4522 scsi_dma_unmap(scmd
);
4523 if (ioc
->pci_error_recovery
|| ioc
->remove_host
)
4524 scmd
->result
= DID_NO_CONNECT
<< 16;
4526 scmd
->result
= DID_RESET
<< 16;
4527 scmd
->scsi_done(scmd
);
4529 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
4534 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4535 * @ioc: per adapter object
4536 * @scmd: pointer to scsi command object
4537 * @mpi_request: pointer to the SCSI_IO request message frame
4539 * Supporting protection 1 and 3.
4542 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4543 Mpi25SCSIIORequest_t
*mpi_request
)
4546 unsigned char prot_op
= scsi_get_prot_op(scmd
);
4547 unsigned char prot_type
= scsi_get_prot_type(scmd
);
4548 Mpi25SCSIIORequest_t
*mpi_request_3v
=
4549 (Mpi25SCSIIORequest_t
*)mpi_request
;
4551 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
4554 if (prot_op
== SCSI_PROT_READ_STRIP
)
4555 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
4556 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
4557 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
4561 switch (prot_type
) {
4562 case SCSI_PROT_DIF_TYPE1
:
4563 case SCSI_PROT_DIF_TYPE2
:
4566 * enable ref/guard checking
4567 * auto increment ref tag
4569 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4570 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4571 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4572 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4573 cpu_to_be32(t10_pi_ref_tag(scmd
->request
));
4576 case SCSI_PROT_DIF_TYPE3
:
4579 * enable guard checking
4581 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4586 mpi_request_3v
->EEDPBlockSize
=
4587 cpu_to_le16(scmd
->device
->sector_size
);
4589 if (ioc
->is_gen35_ioc
)
4590 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4591 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4595 * _scsih_eedp_error_handling - return sense code for EEDP errors
4596 * @scmd: pointer to scsi command object
4597 * @ioc_status: ioc status
4600 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4604 switch (ioc_status
) {
4605 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4608 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4611 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4618 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4620 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4621 SAM_STAT_CHECK_CONDITION
;
4625 * scsih_qcmd - main scsi request entry point
4626 * @shost: SCSI host pointer
4627 * @scmd: pointer to scsi command object
4629 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4631 * Return: 0 on success. If there's a failure, return either:
4632 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4633 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4636 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4638 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4639 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4640 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4641 struct _raid_device
*raid_device
;
4642 struct request
*rq
= scmd
->request
;
4644 Mpi25SCSIIORequest_t
*mpi_request
;
4645 struct _pcie_device
*pcie_device
= NULL
;
4650 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4651 scsi_print_command(scmd
);
4653 sas_device_priv_data
= scmd
->device
->hostdata
;
4654 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4655 scmd
->result
= DID_NO_CONNECT
<< 16;
4656 scmd
->scsi_done(scmd
);
4660 if (!(_scsih_allow_scmd_to_device(ioc
, scmd
))) {
4661 scmd
->result
= DID_NO_CONNECT
<< 16;
4662 scmd
->scsi_done(scmd
);
4666 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4668 /* invalid device handle */
4669 handle
= sas_target_priv_data
->handle
;
4670 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4671 scmd
->result
= DID_NO_CONNECT
<< 16;
4672 scmd
->scsi_done(scmd
);
4677 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
) {
4678 /* host recovery or link resets sent via IOCTLs */
4679 return SCSI_MLQUEUE_HOST_BUSY
;
4680 } else if (sas_target_priv_data
->deleted
) {
4681 /* device has been deleted */
4682 scmd
->result
= DID_NO_CONNECT
<< 16;
4683 scmd
->scsi_done(scmd
);
4685 } else if (sas_target_priv_data
->tm_busy
||
4686 sas_device_priv_data
->block
) {
4687 /* device busy with task management */
4688 return SCSI_MLQUEUE_DEVICE_BUSY
;
4692 * Bug work around for firmware SATL handling. The loop
4693 * is based on atomic operations and ensures consistency
4694 * since we're lockless at this point
4697 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
)) {
4698 scmd
->result
= SAM_STAT_BUSY
;
4699 scmd
->scsi_done(scmd
);
4702 } while (_scsih_set_satl_pending(scmd
, true));
4704 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4705 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4706 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4707 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4709 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4712 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4713 /* NCQ Prio supported, make sure control indicated high priority */
4714 if (sas_device_priv_data
->ncq_prio_enable
) {
4715 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4716 if (class == IOPRIO_CLASS_RT
)
4717 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4719 /* Make sure Device is not raid volume.
4720 * We do not expose raid functionality to upper layer for warpdrive.
4722 if (((!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
))
4723 && !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
4724 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4725 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4727 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4729 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4730 ioc
->name
, __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 mpt3sas_base_put_smid_fast_path(ioc
, smid
, handle
);
4780 ioc
->put_smid_scsi_io(ioc
, smid
,
4781 le16_to_cpu(mpi_request
->DevHandle
));
4783 mpt3sas_base_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 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4969 device_str
, (unsigned long long)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 pr_info(MPT3SAS_FMT
"\twwid(0x%016llx), port(%d)\n",
4975 (unsigned long long)pcie_device
->wwid
,
4976 pcie_device
->port_num
);
4977 if (pcie_device
->enclosure_handle
!= 0)
4979 "\tenclosure logical id(0x%016llx), "
4980 "slot(%d)\n", ioc
->name
,
4981 (unsigned long long)
4982 pcie_device
->enclosure_logical_id
,
4984 if (pcie_device
->connector_name
[0])
4986 "\tenclosure level(0x%04x),"
4987 "connector name( %s)\n",
4988 ioc
->name
, pcie_device
->enclosure_level
,
4989 pcie_device
->connector_name
);
4990 pcie_device_put(pcie_device
);
4993 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4996 "\tsas_address(0x%016llx), phy(%d)\n",
4997 ioc
->name
, (unsigned long long)
4998 sas_device
->sas_address
, sas_device
->phy
);
5000 _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
5003 sas_device_put(sas_device
);
5008 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
5009 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
5010 desc_ioc_state
, ioc_status
, smid
);
5012 "\trequest_len(%d), underflow(%d), resid(%d)\n",
5013 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
5014 scsi_get_resid(scmd
));
5016 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
5017 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
5018 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
5020 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
5021 ioc
->name
, desc_scsi_status
,
5022 scsi_status
, desc_scsi_state
, scsi_state
);
5024 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5025 struct sense_info data
;
5026 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5028 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
5029 ioc
->name
, data
.skey
,
5030 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
5032 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
5033 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
5034 response_bytes
= (u8
*)&response_info
;
5035 _scsih_response_code(ioc
, response_bytes
[0]);
5040 * _scsih_turn_on_pfa_led - illuminate PFA LED
5041 * @ioc: per adapter object
5042 * @handle: device handle
5046 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5048 Mpi2SepReply_t mpi_reply
;
5049 Mpi2SepRequest_t mpi_request
;
5050 struct _sas_device
*sas_device
;
5052 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
5056 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5057 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5058 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5059 mpi_request
.SlotStatus
=
5060 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
5061 mpi_request
.DevHandle
= cpu_to_le16(handle
);
5062 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
5063 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5064 &mpi_request
)) != 0) {
5065 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5066 __FILE__
, __LINE__
, __func__
);
5069 sas_device
->pfa_led_on
= 1;
5071 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5072 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5073 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5074 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5075 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5079 sas_device_put(sas_device
);
5083 * _scsih_turn_off_pfa_led - turn off Fault LED
5084 * @ioc: per adapter object
5085 * @sas_device: sas device whose PFA LED has to turned off
5089 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
5090 struct _sas_device
*sas_device
)
5092 Mpi2SepReply_t mpi_reply
;
5093 Mpi2SepRequest_t mpi_request
;
5095 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5096 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5097 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5098 mpi_request
.SlotStatus
= 0;
5099 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
5100 mpi_request
.DevHandle
= 0;
5101 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
5102 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
5103 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5104 &mpi_request
)) != 0) {
5105 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5106 __FILE__
, __LINE__
, __func__
);
5110 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5111 dewtprintk(ioc
, printk(MPT3SAS_FMT
5112 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5113 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5114 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5120 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5121 * @ioc: per adapter object
5122 * @handle: device handle
5123 * Context: interrupt.
5126 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5128 struct fw_event_work
*fw_event
;
5130 fw_event
= alloc_fw_event_work(0);
5133 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
5134 fw_event
->device_handle
= handle
;
5135 fw_event
->ioc
= ioc
;
5136 _scsih_fw_event_add(ioc
, fw_event
);
5137 fw_event_work_put(fw_event
);
5141 * _scsih_smart_predicted_fault - process smart errors
5142 * @ioc: per adapter object
5143 * @handle: device handle
5144 * Context: interrupt.
5147 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5149 struct scsi_target
*starget
;
5150 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5151 Mpi2EventNotificationReply_t
*event_reply
;
5152 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
5153 struct _sas_device
*sas_device
;
5155 unsigned long flags
;
5157 /* only handle non-raid devices */
5158 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5159 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
5163 starget
= sas_device
->starget
;
5164 sas_target_priv_data
= starget
->hostdata
;
5166 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
5167 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
5170 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, NULL
, starget
);
5172 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5174 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
5175 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
5177 /* insert into event log */
5178 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
5179 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
5180 event_reply
= kzalloc(sz
, GFP_KERNEL
);
5182 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5183 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5187 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
5188 event_reply
->Event
=
5189 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
5190 event_reply
->MsgLength
= sz
/4;
5191 event_reply
->EventDataLength
=
5192 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
5193 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
5194 event_reply
->EventData
;
5195 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
5196 event_data
->ASC
= 0x5D;
5197 event_data
->DevHandle
= cpu_to_le16(handle
);
5198 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
5199 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
5203 sas_device_put(sas_device
);
5207 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5212 * _scsih_io_done - scsi request callback
5213 * @ioc: per adapter object
5214 * @smid: system request message index
5215 * @msix_index: MSIX table index supplied by the OS
5216 * @reply: reply message frame(lower 32bit addr)
5218 * Callback handler when using _scsih_qcmd.
5220 * Return: 1 meaning mf should be freed from _base_interrupt
5221 * 0 means the mf is freed from this function.
5224 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5226 Mpi25SCSIIORequest_t
*mpi_request
;
5227 Mpi2SCSIIOReply_t
*mpi_reply
;
5228 struct scsi_cmnd
*scmd
;
5229 struct scsiio_tracker
*st
;
5235 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5236 u32 response_code
= 0;
5238 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5240 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
5244 _scsih_set_satl_pending(scmd
, false);
5246 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5248 if (mpi_reply
== NULL
) {
5249 scmd
->result
= DID_OK
<< 16;
5253 sas_device_priv_data
= scmd
->device
->hostdata
;
5254 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
5255 sas_device_priv_data
->sas_target
->deleted
) {
5256 scmd
->result
= DID_NO_CONNECT
<< 16;
5259 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5262 * WARPDRIVE: If direct_io is set then it is directIO,
5263 * the failed direct I/O should be redirected to volume
5265 st
= scsi_cmd_priv(scmd
);
5266 if (st
->direct_io
&&
5267 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
5268 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
5270 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
5271 mpi_request
->DevHandle
=
5272 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
5273 ioc
->put_smid_scsi_io(ioc
, smid
,
5274 sas_device_priv_data
->sas_target
->handle
);
5277 /* turning off TLR */
5278 scsi_state
= mpi_reply
->SCSIState
;
5279 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
5281 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
5282 if (!sas_device_priv_data
->tlr_snoop_check
) {
5283 sas_device_priv_data
->tlr_snoop_check
++;
5284 if ((!ioc
->is_warpdrive
&&
5285 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
5286 !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
5287 && sas_is_tlr_enabled(scmd
->device
) &&
5288 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
5289 sas_disable_tlr(scmd
->device
);
5290 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
5294 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
5295 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
5296 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5297 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5300 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5301 scsi_status
= mpi_reply
->SCSIStatus
;
5303 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
5304 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
5305 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
5306 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
5307 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
5310 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5311 struct sense_info data
;
5312 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
5314 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
5315 le32_to_cpu(mpi_reply
->SenseCount
));
5316 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
5317 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5318 /* failure prediction threshold exceeded */
5319 if (data
.asc
== 0x5D)
5320 _scsih_smart_predicted_fault(ioc
,
5321 le16_to_cpu(mpi_reply
->DevHandle
));
5322 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
5324 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
5325 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
5326 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
5327 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
5328 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5330 switch (ioc_status
) {
5331 case MPI2_IOCSTATUS_BUSY
:
5332 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
5333 scmd
->result
= SAM_STAT_BUSY
;
5336 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
5337 scmd
->result
= DID_NO_CONNECT
<< 16;
5340 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
5341 if (sas_device_priv_data
->block
) {
5342 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
5345 if (log_info
== 0x31110630) {
5346 if (scmd
->retries
> 2) {
5347 scmd
->result
= DID_NO_CONNECT
<< 16;
5348 scsi_device_set_state(scmd
->device
,
5351 scmd
->result
= DID_SOFT_ERROR
<< 16;
5352 scmd
->device
->expecting_cc_ua
= 1;
5355 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
5356 scmd
->result
= DID_RESET
<< 16;
5358 } else if ((scmd
->device
->channel
== RAID_CHANNEL
) &&
5359 (scsi_state
== (MPI2_SCSI_STATE_TERMINATED
|
5360 MPI2_SCSI_STATE_NO_SCSI_STATUS
))) {
5361 scmd
->result
= DID_RESET
<< 16;
5364 scmd
->result
= DID_SOFT_ERROR
<< 16;
5366 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
5367 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
5368 scmd
->result
= DID_RESET
<< 16;
5371 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
5372 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
5373 scmd
->result
= DID_SOFT_ERROR
<< 16;
5375 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5378 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
5379 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5381 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
5384 if (xfer_cnt
< scmd
->underflow
) {
5385 if (scsi_status
== SAM_STAT_BUSY
)
5386 scmd
->result
= SAM_STAT_BUSY
;
5388 scmd
->result
= DID_SOFT_ERROR
<< 16;
5389 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5390 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
5391 scmd
->result
= DID_SOFT_ERROR
<< 16;
5392 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5393 scmd
->result
= DID_RESET
<< 16;
5394 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
5395 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
5396 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
5397 scmd
->result
= (DRIVER_SENSE
<< 24) |
5398 SAM_STAT_CHECK_CONDITION
;
5399 scmd
->sense_buffer
[0] = 0x70;
5400 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
5401 scmd
->sense_buffer
[12] = 0x20;
5402 scmd
->sense_buffer
[13] = 0;
5406 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
5407 scsi_set_resid(scmd
, 0);
5409 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
5410 case MPI2_IOCSTATUS_SUCCESS
:
5411 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5412 if (response_code
==
5413 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
5414 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5415 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
5416 scmd
->result
= DID_SOFT_ERROR
<< 16;
5417 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5418 scmd
->result
= DID_RESET
<< 16;
5421 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
5422 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
5423 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
5424 _scsih_eedp_error_handling(scmd
, ioc_status
);
5427 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
5428 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
5429 case MPI2_IOCSTATUS_INVALID_SGL
:
5430 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
5431 case MPI2_IOCSTATUS_INVALID_FIELD
:
5432 case MPI2_IOCSTATUS_INVALID_STATE
:
5433 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
5434 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
5435 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
5437 scmd
->result
= DID_SOFT_ERROR
<< 16;
5442 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
5443 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5447 scsi_dma_unmap(scmd
);
5448 mpt3sas_base_free_smid(ioc
, smid
);
5449 scmd
->scsi_done(scmd
);
5454 * _scsih_sas_host_refresh - refreshing sas host object contents
5455 * @ioc: per adapter object
5458 * During port enable, fw will send topology events for every device. Its
5459 * possible that the handles may change from the previous setting, so this
5460 * code keeping handles updating if changed.
5463 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
5468 Mpi2ConfigReply_t mpi_reply
;
5469 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5470 u16 attached_handle
;
5473 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
5474 "updating handles for sas_host(0x%016llx)\n",
5475 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
5477 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
5478 * sizeof(Mpi2SasIOUnit0PhyData_t
));
5479 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5480 if (!sas_iounit_pg0
) {
5481 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5482 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5486 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5487 sas_iounit_pg0
, sz
)) != 0)
5489 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5490 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5492 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5493 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
5495 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5496 PhyData
[0].ControllerDevHandle
);
5497 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5498 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
5500 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5501 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
5502 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
5503 attached_handle
, i
, link_rate
);
5506 kfree(sas_iounit_pg0
);
5510 * _scsih_sas_host_add - create sas host object
5511 * @ioc: per adapter object
5513 * Creating host side data object, stored in ioc->sas_hba
5516 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
5519 Mpi2ConfigReply_t mpi_reply
;
5520 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5521 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
5522 Mpi2SasPhyPage0_t phy_pg0
;
5523 Mpi2SasDevicePage0_t sas_device_pg0
;
5524 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5527 u8 device_missing_delay
;
5530 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
5532 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5533 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5536 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
5537 sizeof(struct _sas_phy
), GFP_KERNEL
);
5538 if (!ioc
->sas_hba
.phy
) {
5539 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5540 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5543 ioc
->sas_hba
.num_phys
= num_phys
;
5545 /* sas_iounit page 0 */
5546 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5547 sizeof(Mpi2SasIOUnit0PhyData_t
));
5548 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5549 if (!sas_iounit_pg0
) {
5550 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5551 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5554 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5555 sas_iounit_pg0
, sz
))) {
5556 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5557 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5560 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5561 MPI2_IOCSTATUS_MASK
;
5562 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5563 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5564 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5568 /* sas_iounit page 1 */
5569 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5570 sizeof(Mpi2SasIOUnit1PhyData_t
));
5571 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5572 if (!sas_iounit_pg1
) {
5573 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5574 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5577 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5578 sas_iounit_pg1
, sz
))) {
5579 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5580 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5583 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5584 MPI2_IOCSTATUS_MASK
;
5585 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5586 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5587 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5591 ioc
->io_missing_delay
=
5592 sas_iounit_pg1
->IODeviceMissingDelay
;
5593 device_missing_delay
=
5594 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5595 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5596 ioc
->device_missing_delay
= (device_missing_delay
&
5597 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5599 ioc
->device_missing_delay
= device_missing_delay
&
5600 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5602 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5603 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5604 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5606 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5607 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5610 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5611 MPI2_IOCSTATUS_MASK
;
5612 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5613 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5614 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5619 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5620 PhyData
[0].ControllerDevHandle
);
5621 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5622 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5623 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5624 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5626 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5627 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5628 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5629 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5632 ioc
->sas_hba
.enclosure_handle
=
5633 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5634 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5636 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5637 ioc
->name
, ioc
->sas_hba
.handle
,
5638 (unsigned long long) ioc
->sas_hba
.sas_address
,
5639 ioc
->sas_hba
.num_phys
) ;
5641 if (ioc
->sas_hba
.enclosure_handle
) {
5642 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5643 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5644 ioc
->sas_hba
.enclosure_handle
)))
5645 ioc
->sas_hba
.enclosure_logical_id
=
5646 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5650 kfree(sas_iounit_pg1
);
5651 kfree(sas_iounit_pg0
);
5655 * _scsih_expander_add - creating expander object
5656 * @ioc: per adapter object
5657 * @handle: expander handle
5659 * Creating expander object, stored in ioc->sas_expander_list.
5661 * Return: 0 for success, else error.
5664 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5666 struct _sas_node
*sas_expander
;
5667 struct _enclosure_node
*enclosure_dev
;
5668 Mpi2ConfigReply_t mpi_reply
;
5669 Mpi2ExpanderPage0_t expander_pg0
;
5670 Mpi2ExpanderPage1_t expander_pg1
;
5673 u64 sas_address
, sas_address_parent
= 0;
5675 unsigned long flags
;
5676 struct _sas_port
*mpt3sas_port
= NULL
;
5683 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5686 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5687 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5688 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5689 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5693 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5694 MPI2_IOCSTATUS_MASK
;
5695 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5696 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5697 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5701 /* handle out of order topology events */
5702 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5703 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5705 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5706 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5709 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5710 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5711 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5712 sas_address_parent
);
5713 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5714 if (!sas_expander
) {
5715 rc
= _scsih_expander_add(ioc
, parent_handle
);
5721 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5722 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5723 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5725 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5730 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5732 if (!sas_expander
) {
5733 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5734 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5738 sas_expander
->handle
= handle
;
5739 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5740 sas_expander
->sas_address_parent
= sas_address_parent
;
5741 sas_expander
->sas_address
= sas_address
;
5743 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5744 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5745 handle
, parent_handle
, (unsigned long long)
5746 sas_expander
->sas_address
, sas_expander
->num_phys
);
5748 if (!sas_expander
->num_phys
)
5750 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5751 sizeof(struct _sas_phy
), GFP_KERNEL
);
5752 if (!sas_expander
->phy
) {
5753 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5754 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5759 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5760 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5761 sas_address_parent
);
5762 if (!mpt3sas_port
) {
5763 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5764 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5768 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5770 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5771 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5772 &expander_pg1
, i
, handle
))) {
5773 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5774 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5778 sas_expander
->phy
[i
].handle
= handle
;
5779 sas_expander
->phy
[i
].phy_id
= i
;
5781 if ((mpt3sas_transport_add_expander_phy(ioc
,
5782 &sas_expander
->phy
[i
], expander_pg1
,
5783 sas_expander
->parent_dev
))) {
5784 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5785 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5791 if (sas_expander
->enclosure_handle
) {
5793 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
5794 sas_expander
->enclosure_handle
);
5796 sas_expander
->enclosure_logical_id
=
5797 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
5800 _scsih_expander_node_add(ioc
, sas_expander
);
5806 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5807 sas_address_parent
);
5808 kfree(sas_expander
);
5813 * mpt3sas_expander_remove - removing expander object
5814 * @ioc: per adapter object
5815 * @sas_address: expander sas_address
5818 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5820 struct _sas_node
*sas_expander
;
5821 unsigned long flags
;
5823 if (ioc
->shost_recovery
)
5826 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5827 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5829 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5831 _scsih_expander_node_remove(ioc
, sas_expander
);
5835 * _scsih_done - internal SCSI_IO callback handler.
5836 * @ioc: per adapter object
5837 * @smid: system request message index
5838 * @msix_index: MSIX table index supplied by the OS
5839 * @reply: reply message frame(lower 32bit addr)
5841 * Callback handler when sending internal generated SCSI_IO.
5842 * The callback index passed is `ioc->scsih_cb_idx`
5844 * Return: 1 meaning mf should be freed from _base_interrupt
5845 * 0 means the mf is freed from this function.
5848 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5850 MPI2DefaultReply_t
*mpi_reply
;
5852 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5853 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5855 if (ioc
->scsih_cmds
.smid
!= smid
)
5857 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5859 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5860 mpi_reply
->MsgLength
*4);
5861 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5863 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5864 complete(&ioc
->scsih_cmds
.done
);
5871 #define MPT3_MAX_LUNS (255)
5875 * _scsih_check_access_status - check access flags
5876 * @ioc: per adapter object
5877 * @sas_address: sas address
5878 * @handle: sas device handle
5879 * @access_status: errors returned during discovery of the device
5881 * Return: 0 for success, else failure
5884 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5885 u16 handle
, u8 access_status
)
5890 switch (access_status
) {
5891 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5892 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5895 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5896 desc
= "sata capability failed";
5898 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5899 desc
= "sata affiliation conflict";
5901 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5902 desc
= "route not addressable";
5904 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5905 desc
= "smp error not addressable";
5907 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5908 desc
= "device blocked";
5910 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5911 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5912 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5913 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5914 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5915 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5916 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5917 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5918 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5919 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5920 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5921 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5922 desc
= "sata initialization failed";
5933 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5934 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5939 * _scsih_check_device - checking device responsiveness
5940 * @ioc: per adapter object
5941 * @parent_sas_address: sas address of parent expander or sas host
5942 * @handle: attached device handle
5943 * @phy_number: phy number
5944 * @link_rate: new link rate
5947 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5948 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5950 Mpi2ConfigReply_t mpi_reply
;
5951 Mpi2SasDevicePage0_t sas_device_pg0
;
5952 struct _sas_device
*sas_device
;
5953 struct _enclosure_node
*enclosure_dev
= NULL
;
5955 unsigned long flags
;
5957 struct scsi_target
*starget
;
5958 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5961 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5962 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5965 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5966 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5969 /* wide port handling ~ we need only handle device once for the phy that
5970 * is matched in sas device page zero
5972 if (phy_number
!= sas_device_pg0
.PhyNum
)
5975 /* check if this is end device */
5976 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5977 if (!(_scsih_is_end_device(device_info
)))
5980 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5981 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5982 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5988 if (unlikely(sas_device
->handle
!= handle
)) {
5989 starget
= sas_device
->starget
;
5990 sas_target_priv_data
= starget
->hostdata
;
5991 starget_printk(KERN_INFO
, starget
,
5992 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5993 sas_device
->handle
, handle
);
5994 sas_target_priv_data
->handle
= handle
;
5995 sas_device
->handle
= handle
;
5996 if (le16_to_cpu(sas_device_pg0
.Flags
) &
5997 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5998 sas_device
->enclosure_level
=
5999 sas_device_pg0
.EnclosureLevel
;
6000 memcpy(sas_device
->connector_name
,
6001 sas_device_pg0
.ConnectorName
, 4);
6002 sas_device
->connector_name
[4] = '\0';
6004 sas_device
->enclosure_level
= 0;
6005 sas_device
->connector_name
[0] = '\0';
6008 sas_device
->enclosure_handle
=
6009 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
6010 sas_device
->is_chassis_slot_valid
= 0;
6011 enclosure_dev
= mpt3sas_scsih_enclosure_find_by_handle(ioc
,
6012 sas_device
->enclosure_handle
);
6013 if (enclosure_dev
) {
6014 sas_device
->enclosure_logical_id
=
6015 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
6016 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
6017 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6018 sas_device
->is_chassis_slot_valid
= 1;
6019 sas_device
->chassis_slot
=
6020 enclosure_dev
->pg0
.ChassisSlot
;
6025 /* check if device is present */
6026 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6027 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6029 "device is not present handle(0x%04x), flags!!!\n",
6034 /* check if there were any issues with discovery */
6035 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6036 sas_device_pg0
.AccessStatus
))
6039 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6040 _scsih_ublock_io_device(ioc
, sas_address
);
6043 sas_device_put(sas_device
);
6047 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6049 sas_device_put(sas_device
);
6053 * _scsih_add_device - creating sas device object
6054 * @ioc: per adapter object
6055 * @handle: sas device handle
6056 * @phy_num: phy number end device attached to
6057 * @is_pd: is this hidden raid component
6059 * Creating end device object, stored in ioc->sas_device_list.
6061 * Return: 0 for success, non-zero for failure.
6064 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
6067 Mpi2ConfigReply_t mpi_reply
;
6068 Mpi2SasDevicePage0_t sas_device_pg0
;
6069 struct _sas_device
*sas_device
;
6070 struct _enclosure_node
*enclosure_dev
= NULL
;
6075 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6076 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6077 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6078 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6082 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6083 MPI2_IOCSTATUS_MASK
;
6084 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6085 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6086 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6090 /* check if this is end device */
6091 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6092 if (!(_scsih_is_end_device(device_info
)))
6094 set_bit(handle
, ioc
->pend_os_device_add
);
6095 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6097 /* check if device is present */
6098 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6099 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6100 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
6105 /* check if there were any issues with discovery */
6106 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6107 sas_device_pg0
.AccessStatus
))
6110 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
6113 clear_bit(handle
, ioc
->pend_os_device_add
);
6114 sas_device_put(sas_device
);
6118 if (sas_device_pg0
.EnclosureHandle
) {
6120 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
6121 le16_to_cpu(sas_device_pg0
.EnclosureHandle
));
6122 if (enclosure_dev
== NULL
)
6123 pr_info(MPT3SAS_FMT
"Enclosure handle(0x%04x)"
6124 "doesn't match with enclosure device!\n",
6125 ioc
->name
, sas_device_pg0
.EnclosureHandle
);
6128 sas_device
= kzalloc(sizeof(struct _sas_device
),
6131 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6132 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6136 kref_init(&sas_device
->refcount
);
6137 sas_device
->handle
= handle
;
6138 if (_scsih_get_sas_address(ioc
,
6139 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
6140 &sas_device
->sas_address_parent
) != 0)
6141 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6142 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6143 sas_device
->enclosure_handle
=
6144 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
6145 if (sas_device
->enclosure_handle
!= 0)
6147 le16_to_cpu(sas_device_pg0
.Slot
);
6148 sas_device
->device_info
= device_info
;
6149 sas_device
->sas_address
= sas_address
;
6150 sas_device
->phy
= sas_device_pg0
.PhyNum
;
6151 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
6152 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6154 if (le16_to_cpu(sas_device_pg0
.Flags
)
6155 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6156 sas_device
->enclosure_level
=
6157 sas_device_pg0
.EnclosureLevel
;
6158 memcpy(sas_device
->connector_name
,
6159 sas_device_pg0
.ConnectorName
, 4);
6160 sas_device
->connector_name
[4] = '\0';
6162 sas_device
->enclosure_level
= 0;
6163 sas_device
->connector_name
[0] = '\0';
6165 /* get enclosure_logical_id & chassis_slot*/
6166 sas_device
->is_chassis_slot_valid
= 0;
6167 if (enclosure_dev
) {
6168 sas_device
->enclosure_logical_id
=
6169 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
6170 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
6171 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6172 sas_device
->is_chassis_slot_valid
= 1;
6173 sas_device
->chassis_slot
=
6174 enclosure_dev
->pg0
.ChassisSlot
;
6178 /* get device name */
6179 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
6181 if (ioc
->wait_for_discovery_to_complete
)
6182 _scsih_sas_device_init_add(ioc
, sas_device
);
6184 _scsih_sas_device_add(ioc
, sas_device
);
6186 sas_device_put(sas_device
);
6191 * _scsih_remove_device - removing sas device object
6192 * @ioc: per adapter object
6193 * @sas_device: the sas_device object
6196 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
6197 struct _sas_device
*sas_device
)
6199 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6201 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
6202 (sas_device
->pfa_led_on
)) {
6203 _scsih_turn_off_pfa_led(ioc
, sas_device
);
6204 sas_device
->pfa_led_on
= 0;
6207 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6208 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6209 ioc
->name
, __func__
,
6210 sas_device
->handle
, (unsigned long long)
6211 sas_device
->sas_address
));
6213 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6216 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6217 sas_target_priv_data
= sas_device
->starget
->hostdata
;
6218 sas_target_priv_data
->deleted
= 1;
6219 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
6220 sas_target_priv_data
->handle
=
6221 MPT3SAS_INVALID_DEVICE_HANDLE
;
6224 if (!ioc
->hide_drives
)
6225 mpt3sas_transport_port_remove(ioc
,
6226 sas_device
->sas_address
,
6227 sas_device
->sas_address_parent
);
6230 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6231 ioc
->name
, sas_device
->handle
,
6232 (unsigned long long) sas_device
->sas_address
);
6234 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
6236 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6237 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6238 ioc
->name
, __func__
,
6239 sas_device
->handle
, (unsigned long long)
6240 sas_device
->sas_address
));
6241 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6246 * _scsih_sas_topology_change_event_debug - debug for topology event
6247 * @ioc: per adapter object
6248 * @event_data: event data payload
6252 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6253 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
6259 char *status_str
= NULL
;
6260 u8 link_rate
, prev_link_rate
;
6262 switch (event_data
->ExpStatus
) {
6263 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
6266 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
6267 status_str
= "remove";
6269 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
6271 status_str
= "responding";
6273 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
6274 status_str
= "remove delay";
6277 status_str
= "unknown status";
6280 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
6281 ioc
->name
, status_str
);
6282 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6283 "start_phy(%02d), count(%d)\n",
6284 le16_to_cpu(event_data
->ExpanderDevHandle
),
6285 le16_to_cpu(event_data
->EnclosureHandle
),
6286 event_data
->StartPhyNum
, event_data
->NumEntries
);
6287 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6288 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6291 phy_number
= event_data
->StartPhyNum
+ i
;
6292 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6293 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6294 switch (reason_code
) {
6295 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6296 status_str
= "target add";
6298 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6299 status_str
= "target remove";
6301 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
6302 status_str
= "delay target remove";
6304 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6305 status_str
= "link rate change";
6307 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
6308 status_str
= "target responding";
6311 status_str
= "unknown";
6314 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6315 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6316 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6317 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
6318 handle
, status_str
, link_rate
, prev_link_rate
);
6324 * _scsih_sas_topology_change_event - handle topology changes
6325 * @ioc: per adapter object
6326 * @fw_event: The fw_event_work object
6331 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6332 struct fw_event_work
*fw_event
)
6335 u16 parent_handle
, handle
;
6337 u8 phy_number
, max_phys
;
6338 struct _sas_node
*sas_expander
;
6340 unsigned long flags
;
6341 u8 link_rate
, prev_link_rate
;
6342 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
6343 (Mpi2EventDataSasTopologyChangeList_t
*)
6344 fw_event
->event_data
;
6346 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6347 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
6349 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
6352 if (!ioc
->sas_hba
.num_phys
)
6353 _scsih_sas_host_add(ioc
);
6355 _scsih_sas_host_refresh(ioc
);
6357 if (fw_event
->ignore
) {
6358 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6359 "ignoring expander event\n", ioc
->name
));
6363 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
6365 /* handle expander add */
6366 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
6367 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
6370 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6371 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
6374 sas_address
= sas_expander
->sas_address
;
6375 max_phys
= sas_expander
->num_phys
;
6376 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
6377 sas_address
= ioc
->sas_hba
.sas_address
;
6378 max_phys
= ioc
->sas_hba
.num_phys
;
6380 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6383 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6385 /* handle siblings events */
6386 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6387 if (fw_event
->ignore
) {
6388 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6389 "ignoring expander event\n", ioc
->name
));
6392 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6394 phy_number
= event_data
->StartPhyNum
+ i
;
6395 if (phy_number
>= max_phys
)
6397 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6398 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6399 if ((event_data
->PHY
[i
].PhyStatus
&
6400 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
6401 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
6403 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6406 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6407 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6408 switch (reason_code
) {
6409 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6411 if (ioc
->shost_recovery
)
6414 if (link_rate
== prev_link_rate
)
6417 mpt3sas_transport_update_links(ioc
, sas_address
,
6418 handle
, phy_number
, link_rate
);
6420 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
6423 _scsih_check_device(ioc
, sas_address
, handle
,
6424 phy_number
, link_rate
);
6426 if (!test_bit(handle
, ioc
->pend_os_device_add
))
6431 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6433 if (ioc
->shost_recovery
)
6436 mpt3sas_transport_update_links(ioc
, sas_address
,
6437 handle
, phy_number
, link_rate
);
6439 _scsih_add_device(ioc
, handle
, phy_number
, 0);
6442 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6444 _scsih_device_remove_by_handle(ioc
, handle
);
6449 /* handle expander removal */
6450 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
6452 mpt3sas_expander_remove(ioc
, sas_address
);
6458 * _scsih_sas_device_status_change_event_debug - debug for device event
6460 * @event_data: event data payload
6464 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6465 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
6467 char *reason_str
= NULL
;
6469 switch (event_data
->ReasonCode
) {
6470 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
6471 reason_str
= "smart data";
6473 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
6474 reason_str
= "unsupported device discovered";
6476 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
6477 reason_str
= "internal device reset";
6479 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
6480 reason_str
= "internal task abort";
6482 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
6483 reason_str
= "internal task abort set";
6485 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
6486 reason_str
= "internal clear task set";
6488 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
6489 reason_str
= "internal query task";
6491 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
6492 reason_str
= "sata init failure";
6494 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
6495 reason_str
= "internal device reset complete";
6497 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
6498 reason_str
= "internal task abort complete";
6500 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
6501 reason_str
= "internal async notification";
6503 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
6504 reason_str
= "expander reduced functionality";
6506 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
6507 reason_str
= "expander reduced functionality complete";
6510 reason_str
= "unknown reason";
6513 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
6514 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6515 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
6516 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
6517 le16_to_cpu(event_data
->TaskTag
));
6518 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
6519 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
6520 event_data
->ASC
, event_data
->ASCQ
);
6525 * _scsih_sas_device_status_change_event - handle device status change
6526 * @ioc: per adapter object
6527 * @fw_event: The fw_event_work object
6531 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6532 struct fw_event_work
*fw_event
)
6534 struct MPT3SAS_TARGET
*target_priv_data
;
6535 struct _sas_device
*sas_device
;
6537 unsigned long flags
;
6538 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
6539 (Mpi2EventDataSasDeviceStatusChange_t
*)
6540 fw_event
->event_data
;
6542 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6543 _scsih_sas_device_status_change_event_debug(ioc
,
6546 /* In MPI Revision K (0xC), the internal device reset complete was
6547 * implemented, so avoid setting tm_busy flag for older firmware.
6549 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
6552 if (event_data
->ReasonCode
!=
6553 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
6554 event_data
->ReasonCode
!=
6555 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
6558 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6559 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6560 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6563 if (!sas_device
|| !sas_device
->starget
)
6566 target_priv_data
= sas_device
->starget
->hostdata
;
6567 if (!target_priv_data
)
6570 if (event_data
->ReasonCode
==
6571 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6572 target_priv_data
->tm_busy
= 1;
6574 target_priv_data
->tm_busy
= 0;
6578 sas_device_put(sas_device
);
6580 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6585 * _scsih_check_pcie_access_status - check access flags
6586 * @ioc: per adapter object
6588 * @handle: sas device handle
6589 * @access_status: errors returned during discovery of the device
6591 * Return: 0 for success, else failure
6594 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6595 u16 handle
, u8 access_status
)
6600 switch (access_status
) {
6601 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS
:
6602 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION
:
6605 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED
:
6606 desc
= "PCIe device capability failed";
6608 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
:
6609 desc
= "PCIe device blocked";
6611 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED
:
6612 desc
= "PCIe device mem space access failed";
6614 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE
:
6615 desc
= "PCIe device unsupported";
6617 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED
:
6618 desc
= "PCIe device MSIx Required";
6620 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX
:
6621 desc
= "PCIe device init fail max";
6623 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN
:
6624 desc
= "PCIe device status unknown";
6626 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT
:
6627 desc
= "nvme ready timeout";
6629 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED
:
6630 desc
= "nvme device configuration unsupported";
6632 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED
:
6633 desc
= "nvme identify failed";
6635 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED
:
6636 desc
= "nvme qconfig failed";
6638 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED
:
6639 desc
= "nvme qcreation failed";
6641 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED
:
6642 desc
= "nvme eventcfg failed";
6644 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED
:
6645 desc
= "nvme get feature stat failed";
6647 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT
:
6648 desc
= "nvme idle timeout";
6650 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS
:
6651 desc
= "nvme failure status";
6655 " NVMe discovery error(0x%02x): wwid(0x%016llx),"
6656 "handle(0x%04x)\n", ioc
->name
, access_status
,
6657 (unsigned long long)wwid
, handle
);
6665 "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6667 (unsigned long long)wwid
, handle
);
6672 * _scsih_pcie_device_remove_from_sml - removing pcie device
6673 * from SML and free up associated memory
6674 * @ioc: per adapter object
6675 * @pcie_device: the pcie_device object
6678 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
6679 struct _pcie_device
*pcie_device
)
6681 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6683 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6684 "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6685 pcie_device
->handle
, (unsigned long long)
6686 pcie_device
->wwid
));
6687 if (pcie_device
->enclosure_handle
!= 0)
6688 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6689 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6690 ioc
->name
, __func__
,
6691 (unsigned long long)pcie_device
->enclosure_logical_id
,
6692 pcie_device
->slot
));
6693 if (pcie_device
->connector_name
[0] != '\0')
6694 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6695 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
6696 ioc
->name
, __func__
,
6697 pcie_device
->enclosure_level
,
6698 pcie_device
->connector_name
));
6700 if (pcie_device
->starget
&& pcie_device
->starget
->hostdata
) {
6701 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
6702 sas_target_priv_data
->deleted
= 1;
6703 _scsih_ublock_io_device(ioc
, pcie_device
->wwid
);
6704 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
6708 "removing handle(0x%04x), wwid (0x%016llx)\n",
6709 ioc
->name
, pcie_device
->handle
,
6710 (unsigned long long) pcie_device
->wwid
);
6711 if (pcie_device
->enclosure_handle
!= 0)
6713 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6715 (unsigned long long)pcie_device
->enclosure_logical_id
,
6717 if (pcie_device
->connector_name
[0] != '\0')
6719 "removing: enclosure level(0x%04x), connector name( %s)\n",
6720 ioc
->name
, pcie_device
->enclosure_level
,
6721 pcie_device
->connector_name
);
6723 if (pcie_device
->starget
)
6724 scsi_remove_target(&pcie_device
->starget
->dev
);
6725 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6726 "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6727 pcie_device
->handle
, (unsigned long long)
6728 pcie_device
->wwid
));
6729 if (pcie_device
->enclosure_handle
!= 0)
6730 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6731 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6732 ioc
->name
, __func__
,
6733 (unsigned long long)pcie_device
->enclosure_logical_id
,
6734 pcie_device
->slot
));
6735 if (pcie_device
->connector_name
[0] != '\0')
6736 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6737 "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6738 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
6739 pcie_device
->connector_name
));
6741 kfree(pcie_device
->serial_number
);
6746 * _scsih_pcie_check_device - checking device responsiveness
6747 * @ioc: per adapter object
6748 * @handle: attached device handle
6751 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6753 Mpi2ConfigReply_t mpi_reply
;
6754 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6756 struct _pcie_device
*pcie_device
;
6758 unsigned long flags
;
6759 struct scsi_target
*starget
;
6760 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6763 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6764 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6767 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6768 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6771 /* check if this is end device */
6772 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6773 if (!(_scsih_is_nvme_device(device_info
)))
6776 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6777 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
6778 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6781 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6785 if (unlikely(pcie_device
->handle
!= handle
)) {
6786 starget
= pcie_device
->starget
;
6787 sas_target_priv_data
= starget
->hostdata
;
6788 starget_printk(KERN_INFO
, starget
,
6789 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6790 pcie_device
->handle
, handle
);
6791 sas_target_priv_data
->handle
= handle
;
6792 pcie_device
->handle
= handle
;
6794 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6795 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6796 pcie_device
->enclosure_level
=
6797 pcie_device_pg0
.EnclosureLevel
;
6798 memcpy(&pcie_device
->connector_name
[0],
6799 &pcie_device_pg0
.ConnectorName
[0], 4);
6801 pcie_device
->enclosure_level
= 0;
6802 pcie_device
->connector_name
[0] = '\0';
6806 /* check if device is present */
6807 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6808 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6810 "device is not present handle(0x%04x), flags!!!\n",
6812 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6813 pcie_device_put(pcie_device
);
6817 /* check if there were any issues with discovery */
6818 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6819 pcie_device_pg0
.AccessStatus
)) {
6820 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6821 pcie_device_put(pcie_device
);
6825 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6826 pcie_device_put(pcie_device
);
6828 _scsih_ublock_io_device(ioc
, wwid
);
6834 * _scsih_pcie_add_device - creating pcie device object
6835 * @ioc: per adapter object
6836 * @handle: pcie device handle
6838 * Creating end device object, stored in ioc->pcie_device_list.
6840 * Return: 1 means queue the event later, 0 means complete the event
6843 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6845 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6846 Mpi26PCIeDevicePage2_t pcie_device_pg2
;
6847 Mpi2ConfigReply_t mpi_reply
;
6848 struct _pcie_device
*pcie_device
;
6849 struct _enclosure_node
*enclosure_dev
;
6853 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6854 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6855 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6856 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6859 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6860 MPI2_IOCSTATUS_MASK
;
6861 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6863 "failure at %s:%d/%s()!\n",
6864 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6868 set_bit(handle
, ioc
->pend_os_device_add
);
6869 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6871 /* check if device is present */
6872 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6873 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6875 "device is not present handle(0x04%x)!!!\n",
6880 /* check if there were any issues with discovery */
6881 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6882 pcie_device_pg0
.AccessStatus
))
6885 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
6888 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6890 clear_bit(handle
, ioc
->pend_os_device_add
);
6891 pcie_device_put(pcie_device
);
6895 pcie_device
= kzalloc(sizeof(struct _pcie_device
), GFP_KERNEL
);
6897 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6898 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6902 kref_init(&pcie_device
->refcount
);
6903 pcie_device
->id
= ioc
->pcie_target_id
++;
6904 pcie_device
->channel
= PCIE_CHANNEL
;
6905 pcie_device
->handle
= handle
;
6906 pcie_device
->device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6907 pcie_device
->wwid
= wwid
;
6908 pcie_device
->port_num
= pcie_device_pg0
.PortNum
;
6909 pcie_device
->fast_path
= (le32_to_cpu(pcie_device_pg0
.Flags
) &
6910 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6912 pcie_device
->enclosure_handle
=
6913 le16_to_cpu(pcie_device_pg0
.EnclosureHandle
);
6914 if (pcie_device
->enclosure_handle
!= 0)
6915 pcie_device
->slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
6917 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6918 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6919 pcie_device
->enclosure_level
= pcie_device_pg0
.EnclosureLevel
;
6920 memcpy(&pcie_device
->connector_name
[0],
6921 &pcie_device_pg0
.ConnectorName
[0], 4);
6923 pcie_device
->enclosure_level
= 0;
6924 pcie_device
->connector_name
[0] = '\0';
6927 /* get enclosure_logical_id */
6928 if (pcie_device
->enclosure_handle
) {
6930 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
6931 pcie_device
->enclosure_handle
);
6933 pcie_device
->enclosure_logical_id
=
6934 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
6936 /* TODO -- Add device name once FW supports it */
6937 if (mpt3sas_config_get_pcie_device_pg2(ioc
, &mpi_reply
,
6938 &pcie_device_pg2
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)) {
6939 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6940 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6945 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6946 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6947 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6948 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6952 pcie_device
->nvme_mdts
=
6953 le32_to_cpu(pcie_device_pg2
.MaximumDataTransferSize
);
6954 if (pcie_device_pg2
.ControllerResetTO
)
6955 pcie_device
->reset_timeout
=
6956 pcie_device_pg2
.ControllerResetTO
;
6958 pcie_device
->reset_timeout
= 30;
6960 if (ioc
->wait_for_discovery_to_complete
)
6961 _scsih_pcie_device_init_add(ioc
, pcie_device
);
6963 _scsih_pcie_device_add(ioc
, pcie_device
);
6965 pcie_device_put(pcie_device
);
6970 * _scsih_pcie_topology_change_event_debug - debug for topology
6972 * @ioc: per adapter object
6973 * @event_data: event data payload
6977 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6978 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
6984 char *status_str
= NULL
;
6985 u8 link_rate
, prev_link_rate
;
6987 switch (event_data
->SwitchStatus
) {
6988 case MPI26_EVENT_PCIE_TOPO_SS_ADDED
:
6991 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING
:
6992 status_str
= "remove";
6994 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
:
6996 status_str
= "responding";
6998 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
:
6999 status_str
= "remove delay";
7002 status_str
= "unknown status";
7005 pr_info(MPT3SAS_FMT
"pcie topology change: (%s)\n",
7006 ioc
->name
, status_str
);
7007 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
7008 "start_port(%02d), count(%d)\n",
7009 le16_to_cpu(event_data
->SwitchDevHandle
),
7010 le16_to_cpu(event_data
->EnclosureHandle
),
7011 event_data
->StartPortNum
, event_data
->NumEntries
);
7012 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7014 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7017 port_number
= event_data
->StartPortNum
+ i
;
7018 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7019 switch (reason_code
) {
7020 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7021 status_str
= "target add";
7023 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7024 status_str
= "target remove";
7026 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
:
7027 status_str
= "delay target remove";
7029 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7030 status_str
= "link rate change";
7032 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
:
7033 status_str
= "target responding";
7036 status_str
= "unknown";
7039 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
&
7040 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7041 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
&
7042 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7043 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
7044 " link rate: new(0x%02x), old(0x%02x)\n", port_number
,
7045 handle
, status_str
, link_rate
, prev_link_rate
);
7050 * _scsih_pcie_topology_change_event - handle PCIe topology
7052 * @ioc: per adapter object
7053 * @fw_event: The fw_event_work object
7058 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7059 struct fw_event_work
*fw_event
)
7064 u8 link_rate
, prev_link_rate
;
7065 unsigned long flags
;
7067 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
=
7068 (Mpi26EventDataPCIeTopologyChangeList_t
*) fw_event
->event_data
;
7069 struct _pcie_device
*pcie_device
;
7071 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7072 _scsih_pcie_topology_change_event_debug(ioc
, event_data
);
7074 if (ioc
->shost_recovery
|| ioc
->remove_host
||
7075 ioc
->pci_error_recovery
)
7078 if (fw_event
->ignore
) {
7079 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"ignoring switch event\n",
7084 /* handle siblings events */
7085 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7086 if (fw_event
->ignore
) {
7087 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7088 "ignoring switch event\n", ioc
->name
));
7091 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7093 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7095 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7099 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
7100 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7101 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
7102 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7104 switch (reason_code
) {
7105 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7106 if (ioc
->shost_recovery
)
7108 if (link_rate
== prev_link_rate
)
7110 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7113 _scsih_pcie_check_device(ioc
, handle
);
7115 /* This code after this point handles the test case
7116 * where a device has been added, however its returning
7117 * BUSY for sometime. Then before the Device Missing
7118 * Delay expires and the device becomes READY, the
7119 * device is removed and added back.
7121 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7122 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
7123 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7126 pcie_device_put(pcie_device
);
7130 if (!test_bit(handle
, ioc
->pend_os_device_add
))
7133 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7134 "handle(0x%04x) device not found: convert "
7135 "event to a device add\n", ioc
->name
, handle
));
7136 event_data
->PortEntry
[i
].PortStatus
&= 0xF0;
7137 event_data
->PortEntry
[i
].PortStatus
|=
7138 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
;
7140 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7141 if (ioc
->shost_recovery
)
7143 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7146 rc
= _scsih_pcie_add_device(ioc
, handle
);
7148 /* mark entry vacant */
7149 /* TODO This needs to be reviewed and fixed,
7150 * we dont have an entry
7151 * to make an event void like vacant
7153 event_data
->PortEntry
[i
].PortStatus
|=
7154 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
;
7157 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7158 _scsih_pcie_device_remove_by_handle(ioc
, handle
);
7165 * _scsih_pcie_device_status_change_event_debug - debug for device event
7167 * @event_data: event data payload
7171 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7172 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
)
7174 char *reason_str
= NULL
;
7176 switch (event_data
->ReasonCode
) {
7177 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
:
7178 reason_str
= "smart data";
7180 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED
:
7181 reason_str
= "unsupported device discovered";
7183 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
:
7184 reason_str
= "internal device reset";
7186 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL
:
7187 reason_str
= "internal task abort";
7189 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
7190 reason_str
= "internal task abort set";
7192 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
7193 reason_str
= "internal clear task set";
7195 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL
:
7196 reason_str
= "internal query task";
7198 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE
:
7199 reason_str
= "device init failure";
7201 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
7202 reason_str
= "internal device reset complete";
7204 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
7205 reason_str
= "internal task abort complete";
7207 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION
:
7208 reason_str
= "internal async notification";
7210 case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED
:
7211 reason_str
= "pcie hot reset failed";
7214 reason_str
= "unknown reason";
7218 pr_info(MPT3SAS_FMT
"PCIE device status change: (%s)\n"
7219 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7220 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
7221 (unsigned long long)le64_to_cpu(event_data
->WWID
),
7222 le16_to_cpu(event_data
->TaskTag
));
7223 if (event_data
->ReasonCode
== MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
)
7224 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
7225 event_data
->ASC
, event_data
->ASCQ
);
7230 * _scsih_pcie_device_status_change_event - handle device status
7232 * @ioc: per adapter object
7233 * @fw_event: The fw_event_work object
7237 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7238 struct fw_event_work
*fw_event
)
7240 struct MPT3SAS_TARGET
*target_priv_data
;
7241 struct _pcie_device
*pcie_device
;
7243 unsigned long flags
;
7244 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
=
7245 (Mpi26EventDataPCIeDeviceStatusChange_t
*)fw_event
->event_data
;
7246 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7247 _scsih_pcie_device_status_change_event_debug(ioc
,
7250 if (event_data
->ReasonCode
!=
7251 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
7252 event_data
->ReasonCode
!=
7253 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
7256 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7257 wwid
= le64_to_cpu(event_data
->WWID
);
7258 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
7260 if (!pcie_device
|| !pcie_device
->starget
)
7263 target_priv_data
= pcie_device
->starget
->hostdata
;
7264 if (!target_priv_data
)
7267 if (event_data
->ReasonCode
==
7268 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
)
7269 target_priv_data
->tm_busy
= 1;
7271 target_priv_data
->tm_busy
= 0;
7274 pcie_device_put(pcie_device
);
7276 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7280 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7282 * @ioc: per adapter object
7283 * @event_data: event data payload
7287 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7288 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
7290 char *reason_str
= NULL
;
7292 switch (event_data
->ReasonCode
) {
7293 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7294 reason_str
= "enclosure add";
7296 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7297 reason_str
= "enclosure remove";
7300 reason_str
= "unknown reason";
7304 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
7305 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
7306 " number slots(%d)\n", ioc
->name
, reason_str
,
7307 le16_to_cpu(event_data
->EnclosureHandle
),
7308 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
7309 le16_to_cpu(event_data
->StartSlot
));
7313 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7314 * @ioc: per adapter object
7315 * @fw_event: The fw_event_work object
7319 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7320 struct fw_event_work
*fw_event
)
7322 Mpi2ConfigReply_t mpi_reply
;
7323 struct _enclosure_node
*enclosure_dev
= NULL
;
7324 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
=
7325 (Mpi2EventDataSasEnclDevStatusChange_t
*)fw_event
->event_data
;
7327 u16 enclosure_handle
= le16_to_cpu(event_data
->EnclosureHandle
);
7329 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7330 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
7331 (Mpi2EventDataSasEnclDevStatusChange_t
*)
7332 fw_event
->event_data
);
7333 if (ioc
->shost_recovery
)
7336 if (enclosure_handle
)
7338 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
7340 switch (event_data
->ReasonCode
) {
7341 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7342 if (!enclosure_dev
) {
7344 kzalloc(sizeof(struct _enclosure_node
),
7346 if (!enclosure_dev
) {
7348 "failure at %s:%d/%s()!\n", ioc
->name
,
7349 __FILE__
, __LINE__
, __func__
);
7352 rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
7353 &enclosure_dev
->pg0
,
7354 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
7357 if (rc
|| (le16_to_cpu(mpi_reply
.IOCStatus
) &
7358 MPI2_IOCSTATUS_MASK
)) {
7359 kfree(enclosure_dev
);
7363 list_add_tail(&enclosure_dev
->list
,
7364 &ioc
->enclosure_list
);
7367 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7368 if (enclosure_dev
) {
7369 list_del(&enclosure_dev
->list
);
7370 kfree(enclosure_dev
);
7379 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7380 * @ioc: per adapter object
7381 * @fw_event: The fw_event_work object
7385 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
7386 struct fw_event_work
*fw_event
)
7388 struct scsi_cmnd
*scmd
;
7389 struct scsi_device
*sdev
;
7390 struct scsiio_tracker
*st
;
7393 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7394 u32 termination_count
;
7396 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
7397 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
7398 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7399 fw_event
->event_data
;
7401 unsigned long flags
;
7404 u8 task_abort_retries
;
7406 mutex_lock(&ioc
->tm_cmds
.mutex
);
7408 "%s: enter: phy number(%d), width(%d)\n",
7409 ioc
->name
, __func__
, event_data
->PhyNum
,
7410 event_data
->PortWidth
);
7412 _scsih_block_io_all_device(ioc
);
7414 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7415 mpi_reply
= ioc
->tm_cmds
.reply
;
7416 broadcast_aen_retry
:
7418 /* sanity checks for retrying this loop */
7419 if (max_retries
++ == 5) {
7420 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
7421 ioc
->name
, __func__
));
7423 } else if (max_retries
> 1)
7424 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
7425 ioc
->name
, __func__
, max_retries
- 1));
7427 termination_count
= 0;
7429 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
7430 if (ioc
->shost_recovery
)
7432 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
7435 st
= scsi_cmd_priv(scmd
);
7436 sdev
= scmd
->device
;
7437 sas_device_priv_data
= sdev
->hostdata
;
7438 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
7440 /* skip hidden raid components */
7441 if (sas_device_priv_data
->sas_target
->flags
&
7442 MPT_TARGET_FLAGS_RAID_COMPONENT
)
7445 if (sas_device_priv_data
->sas_target
->flags
&
7446 MPT_TARGET_FLAGS_VOLUME
)
7448 /* skip PCIe devices */
7449 if (sas_device_priv_data
->sas_target
->flags
&
7450 MPT_TARGET_FLAGS_PCIE_DEVICE
)
7453 handle
= sas_device_priv_data
->sas_target
->handle
;
7454 lun
= sas_device_priv_data
->lun
;
7457 if (ioc
->shost_recovery
)
7460 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7461 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
,
7462 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, st
->smid
,
7463 st
->msix_io
, 30, 0);
7465 sdev_printk(KERN_WARNING
, sdev
,
7466 "mpt3sas_scsih_issue_tm: FAILED when sending "
7467 "QUERY_TASK: scmd(%p)\n", scmd
);
7468 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7469 goto broadcast_aen_retry
;
7471 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
7472 & MPI2_IOCSTATUS_MASK
;
7473 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7474 sdev_printk(KERN_WARNING
, sdev
,
7475 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7477 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7478 goto broadcast_aen_retry
;
7481 /* see if IO is still owned by IOC and target */
7482 if (mpi_reply
->ResponseCode
==
7483 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
7484 mpi_reply
->ResponseCode
==
7485 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
7486 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7489 task_abort_retries
= 0;
7491 if (task_abort_retries
++ == 60) {
7492 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7493 "%s: ABORT_TASK: giving up\n", ioc
->name
,
7495 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7496 goto broadcast_aen_retry
;
7499 if (ioc
->shost_recovery
)
7502 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->lun
,
7503 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, st
->smid
,
7504 st
->msix_io
, 30, 0);
7505 if (r
== FAILED
|| st
->cb_idx
!= 0xFF) {
7506 sdev_printk(KERN_WARNING
, sdev
,
7507 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7508 "scmd(%p)\n", scmd
);
7512 if (task_abort_retries
> 1)
7513 sdev_printk(KERN_WARNING
, sdev
,
7514 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7516 task_abort_retries
- 1, scmd
);
7518 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
7519 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7522 if (ioc
->broadcast_aen_pending
) {
7523 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7524 "%s: loop back due to pending AEN\n",
7525 ioc
->name
, __func__
));
7526 ioc
->broadcast_aen_pending
= 0;
7527 goto broadcast_aen_retry
;
7531 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7534 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7535 "%s - exit, query_count = %d termination_count = %d\n",
7536 ioc
->name
, __func__
, query_count
, termination_count
));
7538 ioc
->broadcast_aen_busy
= 0;
7539 if (!ioc
->shost_recovery
)
7540 _scsih_ublock_io_all_device(ioc
);
7541 mutex_unlock(&ioc
->tm_cmds
.mutex
);
7545 * _scsih_sas_discovery_event - handle discovery events
7546 * @ioc: per adapter object
7547 * @fw_event: The fw_event_work object
7551 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
7552 struct fw_event_work
*fw_event
)
7554 Mpi2EventDataSasDiscovery_t
*event_data
=
7555 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
7557 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
7558 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
7559 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
7561 if (event_data
->DiscoveryStatus
)
7562 pr_info("discovery_status(0x%08x)",
7563 le32_to_cpu(event_data
->DiscoveryStatus
));
7567 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
7568 !ioc
->sas_hba
.num_phys
) {
7569 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
7570 /* Wait for the reset to complete */
7571 while (ioc
->shost_recovery
)
7574 _scsih_sas_host_add(ioc
);
7579 * _scsih_sas_device_discovery_error_event - display SAS device discovery error
7581 * @ioc: per adapter object
7582 * @fw_event: The fw_event_work object
7586 _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER
*ioc
,
7587 struct fw_event_work
*fw_event
)
7589 Mpi25EventDataSasDeviceDiscoveryError_t
*event_data
=
7590 (Mpi25EventDataSasDeviceDiscoveryError_t
*)fw_event
->event_data
;
7592 switch (event_data
->ReasonCode
) {
7593 case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED
:
7594 pr_warn(MPT3SAS_FMT
"SMP command sent to the expander"
7595 "(handle:0x%04x, sas_address:0x%016llx,"
7596 "physical_port:0x%02x) has failed",
7597 ioc
->name
, le16_to_cpu(event_data
->DevHandle
),
7598 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
7599 event_data
->PhysicalPort
);
7601 case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT
:
7602 pr_warn(MPT3SAS_FMT
"SMP command sent to the expander"
7603 "(handle:0x%04x, sas_address:0x%016llx,"
7604 "physical_port:0x%02x) has timed out",
7605 ioc
->name
, le16_to_cpu(event_data
->DevHandle
),
7606 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
7607 event_data
->PhysicalPort
);
7615 * _scsih_pcie_enumeration_event - handle enumeration events
7616 * @ioc: per adapter object
7617 * @fw_event: The fw_event_work object
7621 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER
*ioc
,
7622 struct fw_event_work
*fw_event
)
7624 Mpi26EventDataPCIeEnumeration_t
*event_data
=
7625 (Mpi26EventDataPCIeEnumeration_t
*)fw_event
->event_data
;
7627 if (!(ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
))
7630 pr_info(MPT3SAS_FMT
"pcie enumeration event: (%s) Flag 0x%02x",
7632 (event_data
->ReasonCode
== MPI26_EVENT_PCIE_ENUM_RC_STARTED
) ?
7633 "started" : "completed",
7635 if (event_data
->EnumerationStatus
)
7636 pr_cont("enumeration_status(0x%08x)",
7637 le32_to_cpu(event_data
->EnumerationStatus
));
7642 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7643 * @ioc: per adapter object
7644 * @handle: device handle for physical disk
7645 * @phys_disk_num: physical disk number
7647 * Return: 0 for success, else failure.
7650 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
7652 Mpi2RaidActionRequest_t
*mpi_request
;
7653 Mpi2RaidActionReply_t
*mpi_reply
;
7660 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
7663 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7665 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7666 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7667 ioc
->name
, __func__
);
7671 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7673 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7675 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7676 ioc
->name
, __func__
);
7677 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7682 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7683 ioc
->scsih_cmds
.smid
= smid
;
7684 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7686 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7687 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
7688 mpi_request
->PhysDiskNum
= phys_disk_num
;
7690 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
7691 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
7692 handle
, phys_disk_num
));
7694 init_completion(&ioc
->scsih_cmds
.done
);
7695 mpt3sas_base_put_smid_default(ioc
, smid
);
7696 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7698 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7700 mpt3sas_base_check_cmd_timeout(ioc
,
7701 ioc
->scsih_cmds
.status
, mpi_request
,
7702 sizeof(Mpi2RaidActionRequest_t
)/4);
7707 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7709 mpi_reply
= ioc
->scsih_cmds
.reply
;
7710 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
7711 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
7712 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
7715 ioc_status
&= MPI2_IOCSTATUS_MASK
;
7716 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7717 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7718 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
7719 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
7723 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7724 "IR RAID_ACTION: completed successfully\n",
7729 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7730 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7733 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
7738 * _scsih_reprobe_lun - reprobing lun
7739 * @sdev: scsi device struct
7740 * @no_uld_attach: sdev->no_uld_attach flag setting
7744 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
7746 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
7747 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
7748 sdev
->no_uld_attach
? "hiding" : "exposing");
7749 WARN_ON(scsi_device_reprobe(sdev
));
7753 * _scsih_sas_volume_add - add new volume
7754 * @ioc: per adapter object
7755 * @element: IR config element data
7759 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
7760 Mpi2EventIrConfigElement_t
*element
)
7762 struct _raid_device
*raid_device
;
7763 unsigned long flags
;
7765 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
7768 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
7771 "failure at %s:%d/%s()!\n", ioc
->name
,
7772 __FILE__
, __LINE__
, __func__
);
7776 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7777 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
7778 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7783 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
7786 "failure at %s:%d/%s()!\n", ioc
->name
,
7787 __FILE__
, __LINE__
, __func__
);
7791 raid_device
->id
= ioc
->sas_id
++;
7792 raid_device
->channel
= RAID_CHANNEL
;
7793 raid_device
->handle
= handle
;
7794 raid_device
->wwid
= wwid
;
7795 _scsih_raid_device_add(ioc
, raid_device
);
7796 if (!ioc
->wait_for_discovery_to_complete
) {
7797 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7798 raid_device
->id
, 0);
7800 _scsih_raid_device_remove(ioc
, raid_device
);
7802 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7803 _scsih_determine_boot_device(ioc
, raid_device
, 1);
7804 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7809 * _scsih_sas_volume_delete - delete volume
7810 * @ioc: per adapter object
7811 * @handle: volume device handle
7815 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
7817 struct _raid_device
*raid_device
;
7818 unsigned long flags
;
7819 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7820 struct scsi_target
*starget
= NULL
;
7822 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7823 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7825 if (raid_device
->starget
) {
7826 starget
= raid_device
->starget
;
7827 sas_target_priv_data
= starget
->hostdata
;
7828 sas_target_priv_data
->deleted
= 1;
7830 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7831 ioc
->name
, raid_device
->handle
,
7832 (unsigned long long) raid_device
->wwid
);
7833 list_del(&raid_device
->list
);
7836 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7838 scsi_remove_target(&starget
->dev
);
7842 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7843 * @ioc: per adapter object
7844 * @element: IR config element data
7848 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
7849 Mpi2EventIrConfigElement_t
*element
)
7851 struct _sas_device
*sas_device
;
7852 struct scsi_target
*starget
= NULL
;
7853 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7854 unsigned long flags
;
7855 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7857 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7858 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7860 sas_device
->volume_handle
= 0;
7861 sas_device
->volume_wwid
= 0;
7862 clear_bit(handle
, ioc
->pd_handles
);
7863 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7864 starget
= sas_device
->starget
;
7865 sas_target_priv_data
= starget
->hostdata
;
7866 sas_target_priv_data
->flags
&=
7867 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
7870 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7874 /* exposing raid component */
7876 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
7878 sas_device_put(sas_device
);
7882 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7883 * @ioc: per adapter object
7884 * @element: IR config element data
7888 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
7889 Mpi2EventIrConfigElement_t
*element
)
7891 struct _sas_device
*sas_device
;
7892 struct scsi_target
*starget
= NULL
;
7893 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7894 unsigned long flags
;
7895 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7896 u16 volume_handle
= 0;
7897 u64 volume_wwid
= 0;
7899 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
7901 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
7904 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7905 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7907 set_bit(handle
, ioc
->pd_handles
);
7908 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7909 starget
= sas_device
->starget
;
7910 sas_target_priv_data
= starget
->hostdata
;
7911 sas_target_priv_data
->flags
|=
7912 MPT_TARGET_FLAGS_RAID_COMPONENT
;
7913 sas_device
->volume_handle
= volume_handle
;
7914 sas_device
->volume_wwid
= volume_wwid
;
7917 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7921 /* hiding raid component */
7922 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7925 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
7927 sas_device_put(sas_device
);
7931 * _scsih_sas_pd_delete - delete pd component
7932 * @ioc: per adapter object
7933 * @element: IR config element data
7937 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
7938 Mpi2EventIrConfigElement_t
*element
)
7940 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7942 _scsih_device_remove_by_handle(ioc
, handle
);
7946 * _scsih_sas_pd_add - remove pd component
7947 * @ioc: per adapter object
7948 * @element: IR config element data
7952 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
7953 Mpi2EventIrConfigElement_t
*element
)
7955 struct _sas_device
*sas_device
;
7956 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7957 Mpi2ConfigReply_t mpi_reply
;
7958 Mpi2SasDevicePage0_t sas_device_pg0
;
7963 set_bit(handle
, ioc
->pd_handles
);
7965 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7967 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7968 sas_device_put(sas_device
);
7972 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
7973 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
7974 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7975 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7979 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7980 MPI2_IOCSTATUS_MASK
;
7981 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7982 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7983 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7987 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7988 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
7989 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7990 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7992 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7993 _scsih_add_device(ioc
, handle
, 0, 1);
7997 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
7998 * @ioc: per adapter object
7999 * @event_data: event data payload
8003 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8004 Mpi2EventDataIrConfigChangeList_t
*event_data
)
8006 Mpi2EventIrConfigElement_t
*element
;
8009 char *reason_str
= NULL
, *element_str
= NULL
;
8011 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8013 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
8014 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
8015 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
8016 "foreign" : "native", event_data
->NumElements
);
8017 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8018 switch (element
->ReasonCode
) {
8019 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8022 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8023 reason_str
= "remove";
8025 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
8026 reason_str
= "no change";
8028 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8029 reason_str
= "hide";
8031 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8032 reason_str
= "unhide";
8034 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8035 reason_str
= "volume_created";
8037 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8038 reason_str
= "volume_deleted";
8040 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8041 reason_str
= "pd_created";
8043 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8044 reason_str
= "pd_deleted";
8047 reason_str
= "unknown reason";
8050 element_type
= le16_to_cpu(element
->ElementFlags
) &
8051 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
8052 switch (element_type
) {
8053 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
8054 element_str
= "volume";
8056 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
8057 element_str
= "phys disk";
8059 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
8060 element_str
= "hot spare";
8063 element_str
= "unknown element";
8066 pr_info("\t(%s:%s), vol handle(0x%04x), " \
8067 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
8068 reason_str
, le16_to_cpu(element
->VolDevHandle
),
8069 le16_to_cpu(element
->PhysDiskDevHandle
),
8070 element
->PhysDiskNum
);
8075 * _scsih_sas_ir_config_change_event - handle ir configuration change events
8076 * @ioc: per adapter object
8077 * @fw_event: The fw_event_work object
8081 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
8082 struct fw_event_work
*fw_event
)
8084 Mpi2EventIrConfigElement_t
*element
;
8087 Mpi2EventDataIrConfigChangeList_t
*event_data
=
8088 (Mpi2EventDataIrConfigChangeList_t
*)
8089 fw_event
->event_data
;
8091 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8092 (!ioc
->hide_ir_msg
))
8093 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
8095 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
8096 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
8098 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8099 if (ioc
->shost_recovery
&&
8100 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
8101 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8102 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
8103 _scsih_ir_fastpath(ioc
,
8104 le16_to_cpu(element
->PhysDiskDevHandle
),
8105 element
->PhysDiskNum
);
8110 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8112 switch (element
->ReasonCode
) {
8113 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8114 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8115 if (!foreign_config
)
8116 _scsih_sas_volume_add(ioc
, element
);
8118 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8119 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8120 if (!foreign_config
)
8121 _scsih_sas_volume_delete(ioc
,
8122 le16_to_cpu(element
->VolDevHandle
));
8124 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8125 if (!ioc
->is_warpdrive
)
8126 _scsih_sas_pd_hide(ioc
, element
);
8128 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8129 if (!ioc
->is_warpdrive
)
8130 _scsih_sas_pd_expose(ioc
, element
);
8132 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8133 if (!ioc
->is_warpdrive
)
8134 _scsih_sas_pd_add(ioc
, element
);
8136 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8137 if (!ioc
->is_warpdrive
)
8138 _scsih_sas_pd_delete(ioc
, element
);
8145 * _scsih_sas_ir_volume_event - IR volume event
8146 * @ioc: per adapter object
8147 * @fw_event: The fw_event_work object
8151 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
8152 struct fw_event_work
*fw_event
)
8155 unsigned long flags
;
8156 struct _raid_device
*raid_device
;
8160 Mpi2EventDataIrVolume_t
*event_data
=
8161 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
8163 if (ioc
->shost_recovery
)
8166 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
8169 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8170 state
= le32_to_cpu(event_data
->NewValue
);
8171 if (!ioc
->hide_ir_msg
)
8172 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8173 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8174 ioc
->name
, __func__
, handle
,
8175 le32_to_cpu(event_data
->PreviousValue
), state
));
8177 case MPI2_RAID_VOL_STATE_MISSING
:
8178 case MPI2_RAID_VOL_STATE_FAILED
:
8179 _scsih_sas_volume_delete(ioc
, handle
);
8182 case MPI2_RAID_VOL_STATE_ONLINE
:
8183 case MPI2_RAID_VOL_STATE_DEGRADED
:
8184 case MPI2_RAID_VOL_STATE_OPTIMAL
:
8186 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8187 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8188 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8193 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
8196 "failure at %s:%d/%s()!\n", ioc
->name
,
8197 __FILE__
, __LINE__
, __func__
);
8201 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
8204 "failure at %s:%d/%s()!\n", ioc
->name
,
8205 __FILE__
, __LINE__
, __func__
);
8209 raid_device
->id
= ioc
->sas_id
++;
8210 raid_device
->channel
= RAID_CHANNEL
;
8211 raid_device
->handle
= handle
;
8212 raid_device
->wwid
= wwid
;
8213 _scsih_raid_device_add(ioc
, raid_device
);
8214 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8215 raid_device
->id
, 0);
8217 _scsih_raid_device_remove(ioc
, raid_device
);
8220 case MPI2_RAID_VOL_STATE_INITIALIZING
:
8227 * _scsih_sas_ir_physical_disk_event - PD event
8228 * @ioc: per adapter object
8229 * @fw_event: The fw_event_work object
8233 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
8234 struct fw_event_work
*fw_event
)
8236 u16 handle
, parent_handle
;
8238 struct _sas_device
*sas_device
;
8239 Mpi2ConfigReply_t mpi_reply
;
8240 Mpi2SasDevicePage0_t sas_device_pg0
;
8242 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
8243 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
8246 if (ioc
->shost_recovery
)
8249 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
8252 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
8253 state
= le32_to_cpu(event_data
->NewValue
);
8255 if (!ioc
->hide_ir_msg
)
8256 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8257 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8258 ioc
->name
, __func__
, handle
,
8259 le32_to_cpu(event_data
->PreviousValue
), state
));
8262 case MPI2_RAID_PD_STATE_ONLINE
:
8263 case MPI2_RAID_PD_STATE_DEGRADED
:
8264 case MPI2_RAID_PD_STATE_REBUILDING
:
8265 case MPI2_RAID_PD_STATE_OPTIMAL
:
8266 case MPI2_RAID_PD_STATE_HOT_SPARE
:
8268 if (!ioc
->is_warpdrive
)
8269 set_bit(handle
, ioc
->pd_handles
);
8271 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8273 sas_device_put(sas_device
);
8277 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8278 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
8280 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8281 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8285 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8286 MPI2_IOCSTATUS_MASK
;
8287 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8288 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8289 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8293 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8294 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
8295 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
8296 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
8298 _scsih_add_device(ioc
, handle
, 0, 1);
8302 case MPI2_RAID_PD_STATE_OFFLINE
:
8303 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
8304 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
8311 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8312 * @ioc: per adapter object
8313 * @event_data: event data payload
8317 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8318 Mpi2EventDataIrOperationStatus_t
*event_data
)
8320 char *reason_str
= NULL
;
8322 switch (event_data
->RAIDOperation
) {
8323 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
8324 reason_str
= "resync";
8326 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
8327 reason_str
= "online capacity expansion";
8329 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
8330 reason_str
= "consistency check";
8332 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
8333 reason_str
= "background init";
8335 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
8336 reason_str
= "make data consistent";
8343 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
8344 "\thandle(0x%04x), percent complete(%d)\n",
8345 ioc
->name
, reason_str
,
8346 le16_to_cpu(event_data
->VolDevHandle
),
8347 event_data
->PercentComplete
);
8351 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8352 * @ioc: per adapter object
8353 * @fw_event: The fw_event_work object
8357 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
8358 struct fw_event_work
*fw_event
)
8360 Mpi2EventDataIrOperationStatus_t
*event_data
=
8361 (Mpi2EventDataIrOperationStatus_t
*)
8362 fw_event
->event_data
;
8363 static struct _raid_device
*raid_device
;
8364 unsigned long flags
;
8367 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8368 (!ioc
->hide_ir_msg
))
8369 _scsih_sas_ir_operation_status_event_debug(ioc
,
8372 /* code added for raid transport support */
8373 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
8375 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8376 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8377 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8379 raid_device
->percent_complete
=
8380 event_data
->PercentComplete
;
8381 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8386 * _scsih_prep_device_scan - initialize parameters prior to device scan
8387 * @ioc: per adapter object
8389 * Set the deleted flag prior to device scan. If the device is found during
8390 * the scan, then we clear the deleted flag.
8393 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
8395 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
8396 struct scsi_device
*sdev
;
8398 shost_for_each_device(sdev
, ioc
->shost
) {
8399 sas_device_priv_data
= sdev
->hostdata
;
8400 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
8401 sas_device_priv_data
->sas_target
->deleted
= 1;
8406 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8407 * @ioc: per adapter object
8408 * @sas_device_pg0: SAS Device page 0
8410 * After host reset, find out whether devices are still responding.
8411 * Used in _scsih_remove_unresponsive_sas_devices.
8414 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
8415 Mpi2SasDevicePage0_t
*sas_device_pg0
)
8417 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8418 struct scsi_target
*starget
;
8419 struct _sas_device
*sas_device
= NULL
;
8420 struct _enclosure_node
*enclosure_dev
= NULL
;
8421 unsigned long flags
;
8423 if (sas_device_pg0
->EnclosureHandle
) {
8425 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
8426 le16_to_cpu(sas_device_pg0
->EnclosureHandle
));
8427 if (enclosure_dev
== NULL
)
8428 pr_info(MPT3SAS_FMT
"Enclosure handle(0x%04x)"
8429 "doesn't match with enclosure device!\n",
8430 ioc
->name
, sas_device_pg0
->EnclosureHandle
);
8432 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8433 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
8434 if ((sas_device
->sas_address
== le64_to_cpu(
8435 sas_device_pg0
->SASAddress
)) && (sas_device
->slot
==
8436 le16_to_cpu(sas_device_pg0
->Slot
))) {
8437 sas_device
->responding
= 1;
8438 starget
= sas_device
->starget
;
8439 if (starget
&& starget
->hostdata
) {
8440 sas_target_priv_data
= starget
->hostdata
;
8441 sas_target_priv_data
->tm_busy
= 0;
8442 sas_target_priv_data
->deleted
= 0;
8444 sas_target_priv_data
= NULL
;
8446 starget_printk(KERN_INFO
, starget
,
8447 "handle(0x%04x), sas_addr(0x%016llx)\n",
8448 le16_to_cpu(sas_device_pg0
->DevHandle
),
8449 (unsigned long long)
8450 sas_device
->sas_address
);
8452 if (sas_device
->enclosure_handle
!= 0)
8453 starget_printk(KERN_INFO
, starget
,
8454 "enclosure logical id(0x%016llx),"
8456 (unsigned long long)
8457 sas_device
->enclosure_logical_id
,
8460 if (le16_to_cpu(sas_device_pg0
->Flags
) &
8461 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
8462 sas_device
->enclosure_level
=
8463 sas_device_pg0
->EnclosureLevel
;
8464 memcpy(&sas_device
->connector_name
[0],
8465 &sas_device_pg0
->ConnectorName
[0], 4);
8467 sas_device
->enclosure_level
= 0;
8468 sas_device
->connector_name
[0] = '\0';
8471 sas_device
->enclosure_handle
=
8472 le16_to_cpu(sas_device_pg0
->EnclosureHandle
);
8473 sas_device
->is_chassis_slot_valid
= 0;
8474 if (enclosure_dev
) {
8475 sas_device
->enclosure_logical_id
= le64_to_cpu(
8476 enclosure_dev
->pg0
.EnclosureLogicalID
);
8477 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
8478 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
8479 sas_device
->is_chassis_slot_valid
= 1;
8480 sas_device
->chassis_slot
=
8481 enclosure_dev
->pg0
.ChassisSlot
;
8485 if (sas_device
->handle
== le16_to_cpu(
8486 sas_device_pg0
->DevHandle
))
8488 pr_info("\thandle changed from(0x%04x)!!!\n",
8489 sas_device
->handle
);
8490 sas_device
->handle
= le16_to_cpu(
8491 sas_device_pg0
->DevHandle
);
8492 if (sas_target_priv_data
)
8493 sas_target_priv_data
->handle
=
8494 le16_to_cpu(sas_device_pg0
->DevHandle
);
8499 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8503 * _scsih_create_enclosure_list_after_reset - Free Existing list,
8504 * And create enclosure list by scanning all Enclosure Page(0)s
8505 * @ioc: per adapter object
8508 _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
8510 struct _enclosure_node
*enclosure_dev
;
8511 Mpi2ConfigReply_t mpi_reply
;
8512 u16 enclosure_handle
;
8515 /* Free existing enclosure list */
8516 mpt3sas_free_enclosure_list(ioc
);
8518 /* Re constructing enclosure list after reset*/
8519 enclosure_handle
= 0xFFFF;
8522 kzalloc(sizeof(struct _enclosure_node
), GFP_KERNEL
);
8523 if (!enclosure_dev
) {
8525 "failure at %s:%d/%s()!\n", ioc
->name
,
8526 __FILE__
, __LINE__
, __func__
);
8529 rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
8530 &enclosure_dev
->pg0
,
8531 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE
,
8534 if (rc
|| (le16_to_cpu(mpi_reply
.IOCStatus
) &
8535 MPI2_IOCSTATUS_MASK
)) {
8536 kfree(enclosure_dev
);
8539 list_add_tail(&enclosure_dev
->list
,
8540 &ioc
->enclosure_list
);
8542 le16_to_cpu(enclosure_dev
->pg0
.EnclosureHandle
);
8547 * _scsih_search_responding_sas_devices -
8548 * @ioc: per adapter object
8550 * After host reset, find out whether devices are still responding.
8554 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
8556 Mpi2SasDevicePage0_t sas_device_pg0
;
8557 Mpi2ConfigReply_t mpi_reply
;
8562 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
8564 if (list_empty(&ioc
->sas_device_list
))
8568 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8569 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8571 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8572 MPI2_IOCSTATUS_MASK
;
8573 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8575 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
8576 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
8577 if (!(_scsih_is_end_device(device_info
)))
8579 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
8583 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
8588 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8589 * @ioc: per adapter object
8590 * @pcie_device_pg0: PCIe Device page 0
8592 * After host reset, find out whether devices are still responding.
8593 * Used in _scsih_remove_unresponding_devices.
8596 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER
*ioc
,
8597 Mpi26PCIeDevicePage0_t
*pcie_device_pg0
)
8599 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8600 struct scsi_target
*starget
;
8601 struct _pcie_device
*pcie_device
;
8602 unsigned long flags
;
8604 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8605 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
) {
8606 if ((pcie_device
->wwid
== le64_to_cpu(pcie_device_pg0
->WWID
))
8607 && (pcie_device
->slot
== le16_to_cpu(
8608 pcie_device_pg0
->Slot
))) {
8609 pcie_device
->responding
= 1;
8610 starget
= pcie_device
->starget
;
8611 if (starget
&& starget
->hostdata
) {
8612 sas_target_priv_data
= starget
->hostdata
;
8613 sas_target_priv_data
->tm_busy
= 0;
8614 sas_target_priv_data
->deleted
= 0;
8616 sas_target_priv_data
= NULL
;
8618 starget_printk(KERN_INFO
, starget
,
8619 "handle(0x%04x), wwid(0x%016llx) ",
8620 pcie_device
->handle
,
8621 (unsigned long long)pcie_device
->wwid
);
8622 if (pcie_device
->enclosure_handle
!= 0)
8623 starget_printk(KERN_INFO
, starget
,
8624 "enclosure logical id(0x%016llx), "
8626 (unsigned long long)
8627 pcie_device
->enclosure_logical_id
,
8631 if (((le32_to_cpu(pcie_device_pg0
->Flags
)) &
8632 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) &&
8633 (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
)) {
8634 pcie_device
->enclosure_level
=
8635 pcie_device_pg0
->EnclosureLevel
;
8636 memcpy(&pcie_device
->connector_name
[0],
8637 &pcie_device_pg0
->ConnectorName
[0], 4);
8639 pcie_device
->enclosure_level
= 0;
8640 pcie_device
->connector_name
[0] = '\0';
8643 if (pcie_device
->handle
== le16_to_cpu(
8644 pcie_device_pg0
->DevHandle
))
8646 pr_info("\thandle changed from(0x%04x)!!!\n",
8647 pcie_device
->handle
);
8648 pcie_device
->handle
= le16_to_cpu(
8649 pcie_device_pg0
->DevHandle
);
8650 if (sas_target_priv_data
)
8651 sas_target_priv_data
->handle
=
8652 le16_to_cpu(pcie_device_pg0
->DevHandle
);
8658 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8662 * _scsih_search_responding_pcie_devices -
8663 * @ioc: per adapter object
8665 * After host reset, find out whether devices are still responding.
8669 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER
*ioc
)
8671 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
8672 Mpi2ConfigReply_t mpi_reply
;
8677 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
8679 if (list_empty(&ioc
->pcie_device_list
))
8683 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
8684 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8686 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8687 MPI2_IOCSTATUS_MASK
;
8688 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8689 pr_info(MPT3SAS_FMT
"\tbreak from %s: "
8690 "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
8691 __func__
, ioc_status
,
8692 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8695 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
8696 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
8697 if (!(_scsih_is_nvme_device(device_info
)))
8699 _scsih_mark_responding_pcie_device(ioc
, &pcie_device_pg0
);
8702 pr_info(MPT3SAS_FMT
"search for PCIe end-devices: complete\n",
8707 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8708 * @ioc: per adapter object
8709 * @wwid: world wide identifier for raid volume
8710 * @handle: device handle
8712 * After host reset, find out whether devices are still responding.
8713 * Used in _scsih_remove_unresponsive_raid_devices.
8716 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
8719 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8720 struct scsi_target
*starget
;
8721 struct _raid_device
*raid_device
;
8722 unsigned long flags
;
8724 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8725 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
8726 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
8727 starget
= raid_device
->starget
;
8728 if (starget
&& starget
->hostdata
) {
8729 sas_target_priv_data
= starget
->hostdata
;
8730 sas_target_priv_data
->deleted
= 0;
8732 sas_target_priv_data
= NULL
;
8733 raid_device
->responding
= 1;
8734 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8735 starget_printk(KERN_INFO
, raid_device
->starget
,
8736 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
8737 (unsigned long long)raid_device
->wwid
);
8740 * WARPDRIVE: The handles of the PDs might have changed
8741 * across the host reset so re-initialize the
8742 * required data for Direct IO
8744 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
8745 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8746 if (raid_device
->handle
== handle
) {
8747 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
8751 pr_info("\thandle changed from(0x%04x)!!!\n",
8752 raid_device
->handle
);
8753 raid_device
->handle
= handle
;
8754 if (sas_target_priv_data
)
8755 sas_target_priv_data
->handle
= handle
;
8756 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8760 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8764 * _scsih_search_responding_raid_devices -
8765 * @ioc: per adapter object
8767 * After host reset, find out whether devices are still responding.
8771 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
8773 Mpi2RaidVolPage1_t volume_pg1
;
8774 Mpi2RaidVolPage0_t volume_pg0
;
8775 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8776 Mpi2ConfigReply_t mpi_reply
;
8781 if (!ioc
->ir_firmware
)
8784 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
8787 if (list_empty(&ioc
->raid_device_list
))
8791 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
8792 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
8793 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8794 MPI2_IOCSTATUS_MASK
;
8795 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8797 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
8799 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
8800 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
8801 sizeof(Mpi2RaidVolPage0_t
)))
8804 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
8805 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
8806 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
8807 _scsih_mark_responding_raid_device(ioc
,
8808 le64_to_cpu(volume_pg1
.WWID
), handle
);
8811 /* refresh the pd_handles */
8812 if (!ioc
->is_warpdrive
) {
8813 phys_disk_num
= 0xFF;
8814 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
8815 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
8816 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
8818 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8819 MPI2_IOCSTATUS_MASK
;
8820 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8822 phys_disk_num
= pd_pg0
.PhysDiskNum
;
8823 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
8824 set_bit(handle
, ioc
->pd_handles
);
8828 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
8833 * _scsih_mark_responding_expander - mark a expander as responding
8834 * @ioc: per adapter object
8835 * @expander_pg0:SAS Expander Config Page0
8837 * After host reset, find out whether devices are still responding.
8838 * Used in _scsih_remove_unresponsive_expanders.
8841 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
,
8842 Mpi2ExpanderPage0_t
*expander_pg0
)
8844 struct _sas_node
*sas_expander
= NULL
;
8845 unsigned long flags
;
8847 struct _enclosure_node
*enclosure_dev
= NULL
;
8848 u16 handle
= le16_to_cpu(expander_pg0
->DevHandle
);
8849 u16 enclosure_handle
= le16_to_cpu(expander_pg0
->EnclosureHandle
);
8850 u64 sas_address
= le64_to_cpu(expander_pg0
->SASAddress
);
8852 if (enclosure_handle
)
8854 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
8857 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8858 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
8859 if (sas_expander
->sas_address
!= sas_address
)
8861 sas_expander
->responding
= 1;
8863 if (enclosure_dev
) {
8864 sas_expander
->enclosure_logical_id
=
8865 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
8866 sas_expander
->enclosure_handle
=
8867 le16_to_cpu(expander_pg0
->EnclosureHandle
);
8870 if (sas_expander
->handle
== handle
)
8872 pr_info("\texpander(0x%016llx): handle changed" \
8873 " from(0x%04x) to (0x%04x)!!!\n",
8874 (unsigned long long)sas_expander
->sas_address
,
8875 sas_expander
->handle
, handle
);
8876 sas_expander
->handle
= handle
;
8877 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
8878 sas_expander
->phy
[i
].handle
= handle
;
8882 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8886 * _scsih_search_responding_expanders -
8887 * @ioc: per adapter object
8889 * After host reset, find out whether devices are still responding.
8893 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
8895 Mpi2ExpanderPage0_t expander_pg0
;
8896 Mpi2ConfigReply_t mpi_reply
;
8901 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
8903 if (list_empty(&ioc
->sas_expander_list
))
8907 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8908 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8910 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8911 MPI2_IOCSTATUS_MASK
;
8912 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8915 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
8916 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
8917 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8919 (unsigned long long)sas_address
);
8920 _scsih_mark_responding_expander(ioc
, &expander_pg0
);
8924 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
8928 * _scsih_remove_unresponding_devices - removing unresponding devices
8929 * @ioc: per adapter object
8932 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER
*ioc
)
8934 struct _sas_device
*sas_device
, *sas_device_next
;
8935 struct _sas_node
*sas_expander
, *sas_expander_next
;
8936 struct _raid_device
*raid_device
, *raid_device_next
;
8937 struct _pcie_device
*pcie_device
, *pcie_device_next
;
8938 struct list_head tmp_list
;
8939 unsigned long flags
;
8942 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
8945 /* removing unresponding end devices */
8946 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
8949 * Iterate, pulling off devices marked as non-responding. We become the
8950 * owner for the reference the list had on any object we prune.
8952 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8953 list_for_each_entry_safe(sas_device
, sas_device_next
,
8954 &ioc
->sas_device_list
, list
) {
8955 if (!sas_device
->responding
)
8956 list_move_tail(&sas_device
->list
, &head
);
8958 sas_device
->responding
= 0;
8960 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8963 * Now, uninitialize and remove the unresponding devices we pruned.
8965 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
8966 _scsih_remove_device(ioc
, sas_device
);
8967 list_del_init(&sas_device
->list
);
8968 sas_device_put(sas_device
);
8972 " Removing unresponding devices: pcie end-devices\n"
8974 INIT_LIST_HEAD(&head
);
8975 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8976 list_for_each_entry_safe(pcie_device
, pcie_device_next
,
8977 &ioc
->pcie_device_list
, list
) {
8978 if (!pcie_device
->responding
)
8979 list_move_tail(&pcie_device
->list
, &head
);
8981 pcie_device
->responding
= 0;
8983 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8985 list_for_each_entry_safe(pcie_device
, pcie_device_next
, &head
, list
) {
8986 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
8987 list_del_init(&pcie_device
->list
);
8988 pcie_device_put(pcie_device
);
8991 /* removing unresponding volumes */
8992 if (ioc
->ir_firmware
) {
8993 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
8995 list_for_each_entry_safe(raid_device
, raid_device_next
,
8996 &ioc
->raid_device_list
, list
) {
8997 if (!raid_device
->responding
)
8998 _scsih_sas_volume_delete(ioc
,
8999 raid_device
->handle
);
9001 raid_device
->responding
= 0;
9005 /* removing unresponding expanders */
9006 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
9008 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9009 INIT_LIST_HEAD(&tmp_list
);
9010 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
9011 &ioc
->sas_expander_list
, list
) {
9012 if (!sas_expander
->responding
)
9013 list_move_tail(&sas_expander
->list
, &tmp_list
);
9015 sas_expander
->responding
= 0;
9017 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9018 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
9020 _scsih_expander_node_remove(ioc
, sas_expander
);
9023 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
9026 /* unblock devices */
9027 _scsih_ublock_io_all_device(ioc
);
9031 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
9032 struct _sas_node
*sas_expander
, u16 handle
)
9034 Mpi2ExpanderPage1_t expander_pg1
;
9035 Mpi2ConfigReply_t mpi_reply
;
9038 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
9039 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
9040 &expander_pg1
, i
, handle
))) {
9041 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
9042 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9046 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
9047 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
9048 expander_pg1
.NegotiatedLinkRate
>> 4);
9053 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
9054 * @ioc: per adapter object
9057 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
9059 Mpi2ExpanderPage0_t expander_pg0
;
9060 Mpi2SasDevicePage0_t sas_device_pg0
;
9061 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
9062 Mpi2RaidVolPage1_t volume_pg1
;
9063 Mpi2RaidVolPage0_t volume_pg0
;
9064 Mpi2RaidPhysDiskPage0_t pd_pg0
;
9065 Mpi2EventIrConfigElement_t element
;
9066 Mpi2ConfigReply_t mpi_reply
;
9069 u16 handle
, parent_handle
;
9071 struct _sas_device
*sas_device
;
9072 struct _pcie_device
*pcie_device
;
9073 struct _sas_node
*expander_device
;
9074 static struct _raid_device
*raid_device
;
9076 unsigned long flags
;
9078 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
9080 _scsih_sas_host_refresh(ioc
);
9082 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
9086 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
9087 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
9088 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9089 MPI2_IOCSTATUS_MASK
;
9090 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9091 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
9092 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9093 ioc
->name
, ioc_status
,
9094 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9097 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
9098 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9099 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
9100 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
9101 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9102 if (expander_device
)
9103 _scsih_refresh_expander_links(ioc
, expander_device
,
9106 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
9107 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9108 handle
, (unsigned long long)
9109 le64_to_cpu(expander_pg0
.SASAddress
));
9110 _scsih_expander_add(ioc
, handle
);
9111 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
9112 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9113 handle
, (unsigned long long)
9114 le64_to_cpu(expander_pg0
.SASAddress
));
9118 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
9121 if (!ioc
->ir_firmware
)
9124 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
9127 phys_disk_num
= 0xFF;
9128 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
9129 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
9131 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9132 MPI2_IOCSTATUS_MASK
;
9133 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9134 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
9135 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9136 ioc
->name
, ioc_status
,
9137 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9140 phys_disk_num
= pd_pg0
.PhysDiskNum
;
9141 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
9142 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
9144 sas_device_put(sas_device
);
9147 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9148 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
9151 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9152 MPI2_IOCSTATUS_MASK
;
9153 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9154 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
9155 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9156 ioc
->name
, ioc_status
,
9157 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9160 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9161 if (!_scsih_get_sas_address(ioc
, parent_handle
,
9163 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
9164 " handle (0x%04x), sas_addr(0x%016llx)\n",
9165 ioc
->name
, handle
, (unsigned long long)
9166 le64_to_cpu(sas_device_pg0
.SASAddress
));
9167 mpt3sas_transport_update_links(ioc
, sas_address
,
9168 handle
, sas_device_pg0
.PhyNum
,
9169 MPI2_SAS_NEG_LINK_RATE_1_5
);
9170 set_bit(handle
, ioc
->pd_handles
);
9172 /* This will retry adding the end device.
9173 * _scsih_add_device() will decide on retries and
9174 * return "1" when it should be retried
9176 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9180 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
9181 " handle (0x%04x), sas_addr(0x%016llx)\n",
9182 ioc
->name
, handle
, (unsigned long long)
9183 le64_to_cpu(sas_device_pg0
.SASAddress
));
9187 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
9190 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
9194 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
9195 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
9196 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9197 MPI2_IOCSTATUS_MASK
;
9198 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9199 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9200 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9201 ioc
->name
, ioc_status
,
9202 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9205 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
9206 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
9207 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
9208 le64_to_cpu(volume_pg1
.WWID
));
9209 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
9212 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
9213 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
9214 sizeof(Mpi2RaidVolPage0_t
)))
9216 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9217 MPI2_IOCSTATUS_MASK
;
9218 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9219 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9220 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9221 ioc
->name
, ioc_status
,
9222 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9225 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
9226 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
9227 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
9228 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
9229 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
9230 element
.VolDevHandle
= volume_pg1
.DevHandle
;
9232 "\tBEFORE adding volume: handle (0x%04x)\n",
9233 ioc
->name
, volume_pg1
.DevHandle
);
9234 _scsih_sas_volume_add(ioc
, &element
);
9236 "\tAFTER adding volume: handle (0x%04x)\n",
9237 ioc
->name
, volume_pg1
.DevHandle
);
9241 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
9246 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
9251 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9252 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9254 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9255 MPI2_IOCSTATUS_MASK
;
9256 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9257 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
9258 " ioc_status(0x%04x), loginfo(0x%08x)\n",
9259 ioc
->name
, ioc_status
,
9260 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9263 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
9264 if (!(_scsih_is_end_device(
9265 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
9267 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
9268 le64_to_cpu(sas_device_pg0
.SASAddress
));
9270 sas_device_put(sas_device
);
9273 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9274 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
9275 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
9276 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9277 handle
, (unsigned long long)
9278 le64_to_cpu(sas_device_pg0
.SASAddress
));
9279 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
9280 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
9282 /* This will retry adding the end device.
9283 * _scsih_add_device() will decide on retries and
9284 * return "1" when it should be retried
9286 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9290 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
9291 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9292 handle
, (unsigned long long)
9293 le64_to_cpu(sas_device_pg0
.SASAddress
));
9296 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
9298 pr_info(MPT3SAS_FMT
"\tscan devices: pcie end devices start\n",
9303 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
9304 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9306 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
)
9307 & MPI2_IOCSTATUS_MASK
;
9308 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9309 pr_info(MPT3SAS_FMT
"\tbreak from pcie end device"
9310 " scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9311 ioc
->name
, ioc_status
,
9312 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9315 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
9316 if (!(_scsih_is_nvme_device(
9317 le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
9319 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
,
9320 le64_to_cpu(pcie_device_pg0
.WWID
));
9322 pcie_device_put(pcie_device
);
9326 parent_handle
= le16_to_cpu(pcie_device_pg0
.ParentDevHandle
);
9327 _scsih_pcie_add_device(ioc
, handle
);
9329 pr_info(MPT3SAS_FMT
"\tAFTER adding pcie end device: "
9330 "handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
,
9332 (unsigned long long) le64_to_cpu(pcie_device_pg0
.WWID
));
9334 pr_info(MPT3SAS_FMT
"\tpcie devices: pcie end devices complete\n",
9336 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
9340 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9341 * @ioc: per adapter object
9343 * The handler for doing any required cleanup or initialization.
9345 void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER
*ioc
)
9347 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9348 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
9352 * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih)
9353 * @ioc: per adapter object
9355 * The handler for doing any required cleanup or initialization.
9358 mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER
*ioc
)
9360 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9361 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
9362 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
9363 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
9364 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
9365 complete(&ioc
->scsih_cmds
.done
);
9367 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
9368 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
9369 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
9370 complete(&ioc
->tm_cmds
.done
);
9373 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
9374 memset(ioc
->device_remove_in_progress
, 0,
9375 ioc
->device_remove_in_progress_sz
);
9376 _scsih_fw_event_cleanup_queue(ioc
);
9377 _scsih_flush_running_cmds(ioc
);
9381 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9382 * @ioc: per adapter object
9384 * The handler for doing any required cleanup or initialization.
9387 mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER
*ioc
)
9389 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9390 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
9391 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
9392 !ioc
->sas_hba
.num_phys
)) {
9393 _scsih_prep_device_scan(ioc
);
9394 _scsih_create_enclosure_list_after_reset(ioc
);
9395 _scsih_search_responding_sas_devices(ioc
);
9396 _scsih_search_responding_pcie_devices(ioc
);
9397 _scsih_search_responding_raid_devices(ioc
);
9398 _scsih_search_responding_expanders(ioc
);
9399 _scsih_error_recovery_delete_devices(ioc
);
9404 * _mpt3sas_fw_work - delayed task for processing firmware events
9405 * @ioc: per adapter object
9406 * @fw_event: The fw_event_work object
9410 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
9412 _scsih_fw_event_del_from_list(ioc
, fw_event
);
9414 /* the queue is being flushed so ignore this event */
9415 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
9416 fw_event_work_put(fw_event
);
9420 switch (fw_event
->event
) {
9421 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
9422 mpt3sas_process_trigger_data(ioc
,
9423 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
9424 fw_event
->event_data
);
9426 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
9427 while (scsi_host_in_recovery(ioc
->shost
) ||
9428 ioc
->shost_recovery
) {
9430 * If we're unloading, bail. Otherwise, this can become
9433 if (ioc
->remove_host
)
9437 _scsih_remove_unresponding_devices(ioc
);
9438 _scsih_scan_for_devices_after_reset(ioc
);
9440 case MPT3SAS_PORT_ENABLE_COMPLETE
:
9441 ioc
->start_scan
= 0;
9442 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
9443 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
9445 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
9446 "port enable: complete from worker thread\n",
9449 case MPT3SAS_TURN_ON_PFA_LED
:
9450 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
9452 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9453 _scsih_sas_topology_change_event(ioc
, fw_event
);
9455 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9456 _scsih_sas_device_status_change_event(ioc
, fw_event
);
9458 case MPI2_EVENT_SAS_DISCOVERY
:
9459 _scsih_sas_discovery_event(ioc
, fw_event
);
9461 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR
:
9462 _scsih_sas_device_discovery_error_event(ioc
, fw_event
);
9464 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9465 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
9467 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9468 _scsih_sas_enclosure_dev_status_change_event(ioc
,
9471 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9472 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
9474 case MPI2_EVENT_IR_VOLUME
:
9475 _scsih_sas_ir_volume_event(ioc
, fw_event
);
9477 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9478 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
9480 case MPI2_EVENT_IR_OPERATION_STATUS
:
9481 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
9483 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9484 _scsih_pcie_device_status_change_event(ioc
, fw_event
);
9486 case MPI2_EVENT_PCIE_ENUMERATION
:
9487 _scsih_pcie_enumeration_event(ioc
, fw_event
);
9489 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9490 _scsih_pcie_topology_change_event(ioc
, fw_event
);
9495 fw_event_work_put(fw_event
);
9499 * _firmware_event_work
9500 * @work: The fw_event_work object
9503 * wrappers for the work thread handling firmware events
9507 _firmware_event_work(struct work_struct
*work
)
9509 struct fw_event_work
*fw_event
= container_of(work
,
9510 struct fw_event_work
, work
);
9512 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
9516 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9517 * @ioc: per adapter object
9518 * @msix_index: MSIX table index supplied by the OS
9519 * @reply: reply message frame(lower 32bit addr)
9520 * Context: interrupt.
9522 * This function merely adds a new work task into ioc->firmware_event_thread.
9523 * The tasks are worked from _firmware_event_work in user context.
9525 * Return: 1 meaning mf should be freed from _base_interrupt
9526 * 0 means the mf is freed from this function.
9529 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
9532 struct fw_event_work
*fw_event
;
9533 Mpi2EventNotificationReply_t
*mpi_reply
;
9536 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
9538 /* events turned off due to host reset */
9539 if (ioc
->pci_error_recovery
)
9542 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
9544 if (unlikely(!mpi_reply
)) {
9545 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
9546 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9550 event
= le16_to_cpu(mpi_reply
->Event
);
9552 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
9553 mpt3sas_trigger_event(ioc
, event
, 0);
9557 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9559 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
9560 (Mpi2EventDataSasBroadcastPrimitive_t
*)
9561 mpi_reply
->EventData
;
9563 if (baen_data
->Primitive
!=
9564 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
9567 if (ioc
->broadcast_aen_busy
) {
9568 ioc
->broadcast_aen_pending
++;
9571 ioc
->broadcast_aen_busy
= 1;
9575 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9576 _scsih_check_topo_delete_events(ioc
,
9577 (Mpi2EventDataSasTopologyChangeList_t
*)
9578 mpi_reply
->EventData
);
9580 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9581 _scsih_check_pcie_topo_remove_events(ioc
,
9582 (Mpi26EventDataPCIeTopologyChangeList_t
*)
9583 mpi_reply
->EventData
);
9585 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9586 _scsih_check_ir_config_unhide_events(ioc
,
9587 (Mpi2EventDataIrConfigChangeList_t
*)
9588 mpi_reply
->EventData
);
9590 case MPI2_EVENT_IR_VOLUME
:
9591 _scsih_check_volume_delete_events(ioc
,
9592 (Mpi2EventDataIrVolume_t
*)
9593 mpi_reply
->EventData
);
9595 case MPI2_EVENT_LOG_ENTRY_ADDED
:
9597 Mpi2EventDataLogEntryAdded_t
*log_entry
;
9600 if (!ioc
->is_warpdrive
)
9603 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
9604 mpi_reply
->EventData
;
9605 log_code
= (u32
*)log_entry
->LogData
;
9607 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
9608 != MPT2_WARPDRIVE_LOGENTRY
)
9611 switch (le32_to_cpu(*log_code
)) {
9612 case MPT2_WARPDRIVE_LC_SSDT
:
9613 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9614 "IO Throttling has occurred in the WarpDrive "
9615 "subsystem. Check WarpDrive documentation for "
9616 "additional details.\n", ioc
->name
);
9618 case MPT2_WARPDRIVE_LC_SSDLW
:
9619 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9620 "Program/Erase Cycles for the WarpDrive subsystem "
9621 "in degraded range. Check WarpDrive documentation "
9622 "for additional details.\n", ioc
->name
);
9624 case MPT2_WARPDRIVE_LC_SSDLF
:
9625 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9626 "There are no Program/Erase Cycles for the "
9627 "WarpDrive subsystem. The storage device will be "
9628 "in read-only mode. Check WarpDrive documentation "
9629 "for additional details.\n", ioc
->name
);
9631 case MPT2_WARPDRIVE_LC_BRMF
:
9632 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9633 "The Backup Rail Monitor has failed on the "
9634 "WarpDrive subsystem. Check WarpDrive "
9635 "documentation for additional details.\n",
9642 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9643 case MPI2_EVENT_IR_OPERATION_STATUS
:
9644 case MPI2_EVENT_SAS_DISCOVERY
:
9645 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR
:
9646 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9647 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9648 case MPI2_EVENT_PCIE_ENUMERATION
:
9649 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9652 case MPI2_EVENT_TEMP_THRESHOLD
:
9653 _scsih_temp_threshold_events(ioc
,
9654 (Mpi2EventDataTemperature_t
*)
9655 mpi_reply
->EventData
);
9657 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
9658 ActiveCableEventData
=
9659 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
9660 switch (ActiveCableEventData
->ReasonCode
) {
9661 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
9662 pr_notice(MPT3SAS_FMT
9663 "Currently an active cable with ReceptacleID %d\n",
9664 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9665 pr_notice("cannot be powered and devices connected\n");
9666 pr_notice("to this active cable will not be seen\n");
9667 pr_notice("This active cable requires %d mW of power\n",
9668 ActiveCableEventData
->ActiveCablePowerRequirement
);
9671 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
9672 pr_notice(MPT3SAS_FMT
9673 "Currently a cable with ReceptacleID %d\n",
9674 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9676 "is not running at optimal speed(12 Gb/s rate)\n");
9682 default: /* ignore the rest */
9686 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
9687 fw_event
= alloc_fw_event_work(sz
);
9689 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
9690 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9694 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
9695 fw_event
->ioc
= ioc
;
9696 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
9697 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
9698 fw_event
->event
= event
;
9699 _scsih_fw_event_add(ioc
, fw_event
);
9700 fw_event_work_put(fw_event
);
9705 * _scsih_expander_node_remove - removing expander device from list.
9706 * @ioc: per adapter object
9707 * @sas_expander: the sas_device object
9709 * Removing object and freeing associated memory from the
9710 * ioc->sas_expander_list.
9713 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
9714 struct _sas_node
*sas_expander
)
9716 struct _sas_port
*mpt3sas_port
, *next
;
9717 unsigned long flags
;
9719 /* remove sibling ports attached to this expander */
9720 list_for_each_entry_safe(mpt3sas_port
, next
,
9721 &sas_expander
->sas_port_list
, port_list
) {
9722 if (ioc
->shost_recovery
)
9724 if (mpt3sas_port
->remote_identify
.device_type
==
9726 mpt3sas_device_remove_by_sas_address(ioc
,
9727 mpt3sas_port
->remote_identify
.sas_address
);
9728 else if (mpt3sas_port
->remote_identify
.device_type
==
9729 SAS_EDGE_EXPANDER_DEVICE
||
9730 mpt3sas_port
->remote_identify
.device_type
==
9731 SAS_FANOUT_EXPANDER_DEVICE
)
9732 mpt3sas_expander_remove(ioc
,
9733 mpt3sas_port
->remote_identify
.sas_address
);
9736 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
9737 sas_expander
->sas_address_parent
);
9740 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9742 sas_expander
->handle
, (unsigned long long)
9743 sas_expander
->sas_address
);
9745 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9746 list_del(&sas_expander
->list
);
9747 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9749 kfree(sas_expander
->phy
);
9750 kfree(sas_expander
);
9754 * _scsih_ir_shutdown - IR shutdown notification
9755 * @ioc: per adapter object
9757 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9758 * the host system is shutting down.
9761 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
9763 Mpi2RaidActionRequest_t
*mpi_request
;
9764 Mpi2RaidActionReply_t
*mpi_reply
;
9767 /* is IR firmware build loaded ? */
9768 if (!ioc
->ir_firmware
)
9771 /* are there any volumes ? */
9772 if (list_empty(&ioc
->raid_device_list
))
9775 mutex_lock(&ioc
->scsih_cmds
.mutex
);
9777 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
9778 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
9779 ioc
->name
, __func__
);
9782 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
9784 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
9786 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
9787 ioc
->name
, __func__
);
9788 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9792 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
9793 ioc
->scsih_cmds
.smid
= smid
;
9794 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
9796 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
9797 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
9799 if (!ioc
->hide_ir_msg
)
9800 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
9801 init_completion(&ioc
->scsih_cmds
.done
);
9802 mpt3sas_base_put_smid_default(ioc
, smid
);
9803 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
9805 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
9806 pr_err(MPT3SAS_FMT
"%s: timeout\n",
9807 ioc
->name
, __func__
);
9811 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
9812 mpi_reply
= ioc
->scsih_cmds
.reply
;
9813 if (!ioc
->hide_ir_msg
)
9814 pr_info(MPT3SAS_FMT
"IR shutdown "
9815 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9816 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
9817 le32_to_cpu(mpi_reply
->IOCLogInfo
));
9821 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9822 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
9826 * scsih_remove - detach and remove add host
9827 * @pdev: PCI device struct
9829 * Routine called when unloading the driver.
9831 static void scsih_remove(struct pci_dev
*pdev
)
9833 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9834 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9835 struct _sas_port
*mpt3sas_port
, *next_port
;
9836 struct _raid_device
*raid_device
, *next
;
9837 struct MPT3SAS_TARGET
*sas_target_priv_data
;
9838 struct _pcie_device
*pcie_device
, *pcienext
;
9839 struct workqueue_struct
*wq
;
9840 unsigned long flags
;
9842 ioc
->remove_host
= 1;
9844 mpt3sas_wait_for_commands_to_complete(ioc
);
9845 _scsih_flush_running_cmds(ioc
);
9847 _scsih_fw_event_cleanup_queue(ioc
);
9849 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9850 wq
= ioc
->firmware_event_thread
;
9851 ioc
->firmware_event_thread
= NULL
;
9852 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9854 destroy_workqueue(wq
);
9856 /* release all the volumes */
9857 _scsih_ir_shutdown(ioc
);
9858 sas_remove_host(shost
);
9859 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
9861 if (raid_device
->starget
) {
9862 sas_target_priv_data
=
9863 raid_device
->starget
->hostdata
;
9864 sas_target_priv_data
->deleted
= 1;
9865 scsi_remove_target(&raid_device
->starget
->dev
);
9867 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
9868 ioc
->name
, raid_device
->handle
,
9869 (unsigned long long) raid_device
->wwid
);
9870 _scsih_raid_device_remove(ioc
, raid_device
);
9872 list_for_each_entry_safe(pcie_device
, pcienext
, &ioc
->pcie_device_list
,
9874 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
9875 list_del_init(&pcie_device
->list
);
9876 pcie_device_put(pcie_device
);
9879 /* free ports attached to the sas_host */
9880 list_for_each_entry_safe(mpt3sas_port
, next_port
,
9881 &ioc
->sas_hba
.sas_port_list
, port_list
) {
9882 if (mpt3sas_port
->remote_identify
.device_type
==
9884 mpt3sas_device_remove_by_sas_address(ioc
,
9885 mpt3sas_port
->remote_identify
.sas_address
);
9886 else if (mpt3sas_port
->remote_identify
.device_type
==
9887 SAS_EDGE_EXPANDER_DEVICE
||
9888 mpt3sas_port
->remote_identify
.device_type
==
9889 SAS_FANOUT_EXPANDER_DEVICE
)
9890 mpt3sas_expander_remove(ioc
,
9891 mpt3sas_port
->remote_identify
.sas_address
);
9894 /* free phys attached to the sas_host */
9895 if (ioc
->sas_hba
.num_phys
) {
9896 kfree(ioc
->sas_hba
.phy
);
9897 ioc
->sas_hba
.phy
= NULL
;
9898 ioc
->sas_hba
.num_phys
= 0;
9901 mpt3sas_base_detach(ioc
);
9902 spin_lock(&gioc_lock
);
9903 list_del(&ioc
->list
);
9904 spin_unlock(&gioc_lock
);
9905 scsi_host_put(shost
);
9909 * scsih_shutdown - routine call during system shutdown
9910 * @pdev: PCI device struct
9913 scsih_shutdown(struct pci_dev
*pdev
)
9915 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9916 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9917 struct workqueue_struct
*wq
;
9918 unsigned long flags
;
9920 ioc
->remove_host
= 1;
9922 mpt3sas_wait_for_commands_to_complete(ioc
);
9923 _scsih_flush_running_cmds(ioc
);
9925 _scsih_fw_event_cleanup_queue(ioc
);
9927 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9928 wq
= ioc
->firmware_event_thread
;
9929 ioc
->firmware_event_thread
= NULL
;
9930 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9932 destroy_workqueue(wq
);
9934 _scsih_ir_shutdown(ioc
);
9935 mpt3sas_base_detach(ioc
);
9940 * _scsih_probe_boot_devices - reports 1st device
9941 * @ioc: per adapter object
9943 * If specified in bios page 2, this routine reports the 1st
9944 * device scsi-ml or sas transport for persistent boot device
9945 * purposes. Please refer to function _scsih_determine_boot_device()
9948 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
9952 struct _sas_device
*sas_device
;
9953 struct _raid_device
*raid_device
;
9954 struct _pcie_device
*pcie_device
;
9956 u64 sas_address_parent
;
9958 unsigned long flags
;
9962 /* no Bios, return immediately */
9963 if (!ioc
->bios_pg3
.BiosVersion
)
9967 if (ioc
->req_boot_device
.device
) {
9968 device
= ioc
->req_boot_device
.device
;
9969 channel
= ioc
->req_boot_device
.channel
;
9970 } else if (ioc
->req_alt_boot_device
.device
) {
9971 device
= ioc
->req_alt_boot_device
.device
;
9972 channel
= ioc
->req_alt_boot_device
.channel
;
9973 } else if (ioc
->current_boot_device
.device
) {
9974 device
= ioc
->current_boot_device
.device
;
9975 channel
= ioc
->current_boot_device
.channel
;
9981 if (channel
== RAID_CHANNEL
) {
9982 raid_device
= device
;
9983 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9984 raid_device
->id
, 0);
9986 _scsih_raid_device_remove(ioc
, raid_device
);
9987 } else if (channel
== PCIE_CHANNEL
) {
9988 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9989 pcie_device
= device
;
9990 tid
= pcie_device
->id
;
9991 list_move_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
9992 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9993 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, tid
, 0);
9995 _scsih_pcie_device_remove(ioc
, pcie_device
);
9997 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9998 sas_device
= device
;
9999 handle
= sas_device
->handle
;
10000 sas_address_parent
= sas_device
->sas_address_parent
;
10001 sas_address
= sas_device
->sas_address
;
10002 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
10003 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
10005 if (ioc
->hide_drives
)
10007 if (!mpt3sas_transport_port_add(ioc
, handle
,
10008 sas_address_parent
)) {
10009 _scsih_sas_device_remove(ioc
, sas_device
);
10010 } else if (!sas_device
->starget
) {
10011 if (!ioc
->is_driver_loading
) {
10012 mpt3sas_transport_port_remove(ioc
,
10014 sas_address_parent
);
10015 _scsih_sas_device_remove(ioc
, sas_device
);
10022 * _scsih_probe_raid - reporting raid volumes to scsi-ml
10023 * @ioc: per adapter object
10025 * Called during initial loading of the driver.
10028 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
10030 struct _raid_device
*raid_device
, *raid_next
;
10033 list_for_each_entry_safe(raid_device
, raid_next
,
10034 &ioc
->raid_device_list
, list
) {
10035 if (raid_device
->starget
)
10037 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
10038 raid_device
->id
, 0);
10040 _scsih_raid_device_remove(ioc
, raid_device
);
10044 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
10046 struct _sas_device
*sas_device
= NULL
;
10047 unsigned long flags
;
10049 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
10050 if (!list_empty(&ioc
->sas_device_init_list
)) {
10051 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
10052 struct _sas_device
, list
);
10053 sas_device_get(sas_device
);
10055 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
10060 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
10061 struct _sas_device
*sas_device
)
10063 unsigned long flags
;
10065 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
10068 * Since we dropped the lock during the call to port_add(), we need to
10069 * be careful here that somebody else didn't move or delete this item
10070 * while we were busy with other things.
10072 * If it was on the list, we need a put() for the reference the list
10073 * had. Either way, we need a get() for the destination list.
10075 if (!list_empty(&sas_device
->list
)) {
10076 list_del_init(&sas_device
->list
);
10077 sas_device_put(sas_device
);
10080 sas_device_get(sas_device
);
10081 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
10083 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
10087 * _scsih_probe_sas - reporting sas devices to sas transport
10088 * @ioc: per adapter object
10090 * Called during initial loading of the driver.
10093 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
10095 struct _sas_device
*sas_device
;
10097 if (ioc
->hide_drives
)
10100 while ((sas_device
= get_next_sas_device(ioc
))) {
10101 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
10102 sas_device
->sas_address_parent
)) {
10103 _scsih_sas_device_remove(ioc
, sas_device
);
10104 sas_device_put(sas_device
);
10106 } else if (!sas_device
->starget
) {
10108 * When asyn scanning is enabled, its not possible to
10109 * remove devices while scanning is turned on due to an
10110 * oops in scsi_sysfs_add_sdev()->add_device()->
10111 * sysfs_addrm_start()
10113 if (!ioc
->is_driver_loading
) {
10114 mpt3sas_transport_port_remove(ioc
,
10115 sas_device
->sas_address
,
10116 sas_device
->sas_address_parent
);
10117 _scsih_sas_device_remove(ioc
, sas_device
);
10118 sas_device_put(sas_device
);
10122 sas_device_make_active(ioc
, sas_device
);
10123 sas_device_put(sas_device
);
10128 * get_next_pcie_device - Get the next pcie device
10129 * @ioc: per adapter object
10131 * Get the next pcie device from pcie_device_init_list list.
10133 * Return: pcie device structure if pcie_device_init_list list is not empty
10134 * otherwise returns NULL
10136 static struct _pcie_device
*get_next_pcie_device(struct MPT3SAS_ADAPTER
*ioc
)
10138 struct _pcie_device
*pcie_device
= NULL
;
10139 unsigned long flags
;
10141 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10142 if (!list_empty(&ioc
->pcie_device_init_list
)) {
10143 pcie_device
= list_first_entry(&ioc
->pcie_device_init_list
,
10144 struct _pcie_device
, list
);
10145 pcie_device_get(pcie_device
);
10147 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10149 return pcie_device
;
10153 * pcie_device_make_active - Add pcie device to pcie_device_list list
10154 * @ioc: per adapter object
10155 * @pcie_device: pcie device object
10157 * Add the pcie device which has registered with SCSI Transport Later to
10158 * pcie_device_list list
10160 static void pcie_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
10161 struct _pcie_device
*pcie_device
)
10163 unsigned long flags
;
10165 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10167 if (!list_empty(&pcie_device
->list
)) {
10168 list_del_init(&pcie_device
->list
);
10169 pcie_device_put(pcie_device
);
10171 pcie_device_get(pcie_device
);
10172 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
10174 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10178 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
10179 * @ioc: per adapter object
10181 * Called during initial loading of the driver.
10184 _scsih_probe_pcie(struct MPT3SAS_ADAPTER
*ioc
)
10186 struct _pcie_device
*pcie_device
;
10189 /* PCIe Device List */
10190 while ((pcie_device
= get_next_pcie_device(ioc
))) {
10191 if (pcie_device
->starget
) {
10192 pcie_device_put(pcie_device
);
10195 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
,
10196 pcie_device
->id
, 0);
10198 _scsih_pcie_device_remove(ioc
, pcie_device
);
10199 pcie_device_put(pcie_device
);
10201 } else if (!pcie_device
->starget
) {
10203 * When async scanning is enabled, its not possible to
10204 * remove devices while scanning is turned on due to an
10205 * oops in scsi_sysfs_add_sdev()->add_device()->
10206 * sysfs_addrm_start()
10208 if (!ioc
->is_driver_loading
) {
10209 /* TODO-- Need to find out whether this condition will
10212 _scsih_pcie_device_remove(ioc
, pcie_device
);
10213 pcie_device_put(pcie_device
);
10217 pcie_device_make_active(ioc
, pcie_device
);
10218 pcie_device_put(pcie_device
);
10223 * _scsih_probe_devices - probing for devices
10224 * @ioc: per adapter object
10226 * Called during initial loading of the driver.
10229 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
10231 u16 volume_mapping_flags
;
10233 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
10234 return; /* return when IOC doesn't support initiator mode */
10236 _scsih_probe_boot_devices(ioc
);
10238 if (ioc
->ir_firmware
) {
10239 volume_mapping_flags
=
10240 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
10241 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
10242 if (volume_mapping_flags
==
10243 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
10244 _scsih_probe_raid(ioc
);
10245 _scsih_probe_sas(ioc
);
10247 _scsih_probe_sas(ioc
);
10248 _scsih_probe_raid(ioc
);
10251 _scsih_probe_sas(ioc
);
10252 _scsih_probe_pcie(ioc
);
10257 * scsih_scan_start - scsi lld callback for .scan_start
10258 * @shost: SCSI host pointer
10260 * The shost has the ability to discover targets on its own instead
10261 * of scanning the entire bus. In our implemention, we will kick off
10262 * firmware discovery.
10265 scsih_scan_start(struct Scsi_Host
*shost
)
10267 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10269 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
10270 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
10272 if (disable_discovery
> 0)
10275 ioc
->start_scan
= 1;
10276 rc
= mpt3sas_port_enable(ioc
);
10279 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
10283 * scsih_scan_finished - scsi lld callback for .scan_finished
10284 * @shost: SCSI host pointer
10285 * @time: elapsed time of the scan in jiffies
10287 * This function will be called periodicallyn until it returns 1 with the
10288 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10289 * we wait for firmware discovery to complete, then return 1.
10292 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
10294 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10296 if (disable_discovery
> 0) {
10297 ioc
->is_driver_loading
= 0;
10298 ioc
->wait_for_discovery_to_complete
= 0;
10302 if (time
>= (300 * HZ
)) {
10303 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
10304 pr_info(MPT3SAS_FMT
10305 "port enable: FAILED with timeout (timeout=300s)\n",
10307 ioc
->is_driver_loading
= 0;
10311 if (ioc
->start_scan
)
10314 if (ioc
->start_scan_failed
) {
10315 pr_info(MPT3SAS_FMT
10316 "port enable: FAILED with (ioc_status=0x%08x)\n",
10317 ioc
->name
, ioc
->start_scan_failed
);
10318 ioc
->is_driver_loading
= 0;
10319 ioc
->wait_for_discovery_to_complete
= 0;
10320 ioc
->remove_host
= 1;
10324 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
10325 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
10327 if (ioc
->wait_for_discovery_to_complete
) {
10328 ioc
->wait_for_discovery_to_complete
= 0;
10329 _scsih_probe_devices(ioc
);
10331 mpt3sas_base_start_watchdog(ioc
);
10332 ioc
->is_driver_loading
= 0;
10336 /* shost template for SAS 2.0 HBA devices */
10337 static struct scsi_host_template mpt2sas_driver_template
= {
10338 .module
= THIS_MODULE
,
10339 .name
= "Fusion MPT SAS Host",
10340 .proc_name
= MPT2SAS_DRIVER_NAME
,
10341 .queuecommand
= scsih_qcmd
,
10342 .target_alloc
= scsih_target_alloc
,
10343 .slave_alloc
= scsih_slave_alloc
,
10344 .slave_configure
= scsih_slave_configure
,
10345 .target_destroy
= scsih_target_destroy
,
10346 .slave_destroy
= scsih_slave_destroy
,
10347 .scan_finished
= scsih_scan_finished
,
10348 .scan_start
= scsih_scan_start
,
10349 .change_queue_depth
= scsih_change_queue_depth
,
10350 .eh_abort_handler
= scsih_abort
,
10351 .eh_device_reset_handler
= scsih_dev_reset
,
10352 .eh_target_reset_handler
= scsih_target_reset
,
10353 .eh_host_reset_handler
= scsih_host_reset
,
10354 .bios_param
= scsih_bios_param
,
10357 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
10358 .max_sectors
= 32767,
10360 .use_clustering
= ENABLE_CLUSTERING
,
10361 .shost_attrs
= mpt3sas_host_attrs
,
10362 .sdev_attrs
= mpt3sas_dev_attrs
,
10363 .track_queue_depth
= 1,
10364 .cmd_size
= sizeof(struct scsiio_tracker
),
10367 /* raid transport support for SAS 2.0 HBA devices */
10368 static struct raid_function_template mpt2sas_raid_functions
= {
10369 .cookie
= &mpt2sas_driver_template
,
10370 .is_raid
= scsih_is_raid
,
10371 .get_resync
= scsih_get_resync
,
10372 .get_state
= scsih_get_state
,
10375 /* shost template for SAS 3.0 HBA devices */
10376 static struct scsi_host_template mpt3sas_driver_template
= {
10377 .module
= THIS_MODULE
,
10378 .name
= "Fusion MPT SAS Host",
10379 .proc_name
= MPT3SAS_DRIVER_NAME
,
10380 .queuecommand
= scsih_qcmd
,
10381 .target_alloc
= scsih_target_alloc
,
10382 .slave_alloc
= scsih_slave_alloc
,
10383 .slave_configure
= scsih_slave_configure
,
10384 .target_destroy
= scsih_target_destroy
,
10385 .slave_destroy
= scsih_slave_destroy
,
10386 .scan_finished
= scsih_scan_finished
,
10387 .scan_start
= scsih_scan_start
,
10388 .change_queue_depth
= scsih_change_queue_depth
,
10389 .eh_abort_handler
= scsih_abort
,
10390 .eh_device_reset_handler
= scsih_dev_reset
,
10391 .eh_target_reset_handler
= scsih_target_reset
,
10392 .eh_host_reset_handler
= scsih_host_reset
,
10393 .bios_param
= scsih_bios_param
,
10396 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
10397 .max_sectors
= 32767,
10399 .use_clustering
= ENABLE_CLUSTERING
,
10400 .shost_attrs
= mpt3sas_host_attrs
,
10401 .sdev_attrs
= mpt3sas_dev_attrs
,
10402 .track_queue_depth
= 1,
10403 .cmd_size
= sizeof(struct scsiio_tracker
),
10406 /* raid transport support for SAS 3.0 HBA devices */
10407 static struct raid_function_template mpt3sas_raid_functions
= {
10408 .cookie
= &mpt3sas_driver_template
,
10409 .is_raid
= scsih_is_raid
,
10410 .get_resync
= scsih_get_resync
,
10411 .get_state
= scsih_get_state
,
10415 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10416 * this device belongs to.
10417 * @pdev: PCI device struct
10419 * return MPI2_VERSION for SAS 2.0 HBA devices,
10420 * MPI25_VERSION for SAS 3.0 HBA devices, and
10421 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10424 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
10427 switch (pdev
->device
) {
10428 case MPI2_MFGPAGE_DEVID_SSS6200
:
10429 case MPI2_MFGPAGE_DEVID_SAS2004
:
10430 case MPI2_MFGPAGE_DEVID_SAS2008
:
10431 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
10432 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
10433 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
10434 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
10435 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
10436 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
10437 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
10438 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
10439 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
10440 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
10441 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
10442 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
10443 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
10444 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
10445 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP
:
10446 return MPI2_VERSION
;
10447 case MPI25_MFGPAGE_DEVID_SAS3004
:
10448 case MPI25_MFGPAGE_DEVID_SAS3008
:
10449 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
10450 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
10451 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
10452 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
10453 return MPI25_VERSION
;
10454 case MPI26_MFGPAGE_DEVID_SAS3216
:
10455 case MPI26_MFGPAGE_DEVID_SAS3224
:
10456 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
10457 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
10458 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
10459 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
10460 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
10461 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
10462 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
10463 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
10464 case MPI26_MFGPAGE_DEVID_SAS3508
:
10465 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10466 case MPI26_MFGPAGE_DEVID_SAS3408
:
10467 case MPI26_MFGPAGE_DEVID_SAS3516
:
10468 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10469 case MPI26_MFGPAGE_DEVID_SAS3416
:
10470 case MPI26_MFGPAGE_DEVID_SAS3616
:
10471 return MPI26_VERSION
;
10477 * _scsih_probe - attach and add scsi host
10478 * @pdev: PCI device struct
10479 * @id: pci device id
10481 * Return: 0 success, anything else error.
10484 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
10486 struct MPT3SAS_ADAPTER
*ioc
;
10487 struct Scsi_Host
*shost
= NULL
;
10489 u16 hba_mpi_version
;
10491 /* Determine in which MPI version class this pci device belongs */
10492 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
10493 if (hba_mpi_version
== 0)
10496 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10497 * for other generation HBA's return with -ENODEV
10499 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
10502 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10503 * for other generation HBA's return with -ENODEV
10505 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
10506 || hba_mpi_version
== MPI26_VERSION
)))
10509 switch (hba_mpi_version
) {
10511 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
10512 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
10513 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10514 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
10515 sizeof(struct MPT3SAS_ADAPTER
));
10518 ioc
= shost_priv(shost
);
10519 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10520 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10521 ioc
->id
= mpt2_ids
++;
10522 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
10523 switch (pdev
->device
) {
10524 case MPI2_MFGPAGE_DEVID_SSS6200
:
10525 ioc
->is_warpdrive
= 1;
10526 ioc
->hide_ir_msg
= 1;
10528 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP
:
10529 ioc
->is_mcpu_endpoint
= 1;
10532 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
10536 case MPI25_VERSION
:
10537 case MPI26_VERSION
:
10538 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10539 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
10540 sizeof(struct MPT3SAS_ADAPTER
));
10543 ioc
= shost_priv(shost
);
10544 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10545 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10546 ioc
->id
= mpt3_ids
++;
10547 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
10548 switch (pdev
->device
) {
10549 case MPI26_MFGPAGE_DEVID_SAS3508
:
10550 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10551 case MPI26_MFGPAGE_DEVID_SAS3408
:
10552 case MPI26_MFGPAGE_DEVID_SAS3516
:
10553 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10554 case MPI26_MFGPAGE_DEVID_SAS3416
:
10555 case MPI26_MFGPAGE_DEVID_SAS3616
:
10556 ioc
->is_gen35_ioc
= 1;
10559 ioc
->is_gen35_ioc
= 0;
10561 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
10562 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
10563 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
10564 ioc
->combined_reply_queue
= 1;
10565 if (ioc
->is_gen35_ioc
)
10566 ioc
->combined_reply_index_count
=
10567 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
10569 ioc
->combined_reply_index_count
=
10570 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
10577 INIT_LIST_HEAD(&ioc
->list
);
10578 spin_lock(&gioc_lock
);
10579 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
10580 spin_unlock(&gioc_lock
);
10581 ioc
->shost
= shost
;
10583 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
10584 ioc
->tm_cb_idx
= tm_cb_idx
;
10585 ioc
->ctl_cb_idx
= ctl_cb_idx
;
10586 ioc
->base_cb_idx
= base_cb_idx
;
10587 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
10588 ioc
->transport_cb_idx
= transport_cb_idx
;
10589 ioc
->scsih_cb_idx
= scsih_cb_idx
;
10590 ioc
->config_cb_idx
= config_cb_idx
;
10591 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
10592 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
10593 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
10594 ioc
->logging_level
= logging_level
;
10595 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
10596 /* misc semaphores and spin locks */
10597 mutex_init(&ioc
->reset_in_progress_mutex
);
10598 /* initializing pci_access_mutex lock */
10599 mutex_init(&ioc
->pci_access_mutex
);
10600 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
10601 spin_lock_init(&ioc
->scsi_lookup_lock
);
10602 spin_lock_init(&ioc
->sas_device_lock
);
10603 spin_lock_init(&ioc
->sas_node_lock
);
10604 spin_lock_init(&ioc
->fw_event_lock
);
10605 spin_lock_init(&ioc
->raid_device_lock
);
10606 spin_lock_init(&ioc
->pcie_device_lock
);
10607 spin_lock_init(&ioc
->diag_trigger_lock
);
10609 INIT_LIST_HEAD(&ioc
->sas_device_list
);
10610 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
10611 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
10612 INIT_LIST_HEAD(&ioc
->enclosure_list
);
10613 INIT_LIST_HEAD(&ioc
->pcie_device_list
);
10614 INIT_LIST_HEAD(&ioc
->pcie_device_init_list
);
10615 INIT_LIST_HEAD(&ioc
->fw_event_list
);
10616 INIT_LIST_HEAD(&ioc
->raid_device_list
);
10617 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
10618 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
10619 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
10620 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
10621 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
10622 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
10624 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
10626 /* init shost parameters */
10627 shost
->max_cmd_len
= 32;
10628 shost
->max_lun
= max_lun
;
10629 shost
->transportt
= mpt3sas_transport_template
;
10630 shost
->unique_id
= ioc
->id
;
10632 if (ioc
->is_mcpu_endpoint
) {
10633 /* mCPU MPI support 64K max IO */
10634 shost
->max_sectors
= 128;
10635 pr_info(MPT3SAS_FMT
10636 "The max_sectors value is set to %d\n",
10637 ioc
->name
, shost
->max_sectors
);
10639 if (max_sectors
!= 0xFFFF) {
10640 if (max_sectors
< 64) {
10641 shost
->max_sectors
= 64;
10642 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10643 "for max_sectors, range is 64 to 32767. " \
10644 "Assigning value of 64.\n", \
10645 ioc
->name
, max_sectors
);
10646 } else if (max_sectors
> 32767) {
10647 shost
->max_sectors
= 32767;
10648 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10649 "for max_sectors, range is 64 to 32767." \
10650 "Assigning default value of 32767.\n", \
10651 ioc
->name
, max_sectors
);
10653 shost
->max_sectors
= max_sectors
& 0xFFFE;
10654 pr_info(MPT3SAS_FMT
10655 "The max_sectors value is set to %d\n",
10656 ioc
->name
, shost
->max_sectors
);
10660 /* register EEDP capabilities with SCSI layer */
10662 scsi_host_set_prot(shost
, prot_mask
);
10664 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
10665 | SHOST_DIF_TYPE2_PROTECTION
10666 | SHOST_DIF_TYPE3_PROTECTION
);
10668 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
10671 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
10672 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
10673 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
10674 ioc
->firmware_event_name
, 0);
10675 if (!ioc
->firmware_event_thread
) {
10676 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10677 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10679 goto out_thread_fail
;
10682 ioc
->is_driver_loading
= 1;
10683 if ((mpt3sas_base_attach(ioc
))) {
10684 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10685 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10687 goto out_attach_fail
;
10690 if (ioc
->is_warpdrive
) {
10691 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
10692 ioc
->hide_drives
= 0;
10693 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
10694 ioc
->hide_drives
= 1;
10696 if (mpt3sas_get_num_volumes(ioc
))
10697 ioc
->hide_drives
= 1;
10699 ioc
->hide_drives
= 0;
10702 ioc
->hide_drives
= 0;
10704 rv
= scsi_add_host(shost
, &pdev
->dev
);
10706 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10707 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10708 goto out_add_shost_fail
;
10711 scsi_scan_host(shost
);
10713 out_add_shost_fail
:
10714 mpt3sas_base_detach(ioc
);
10716 destroy_workqueue(ioc
->firmware_event_thread
);
10718 spin_lock(&gioc_lock
);
10719 list_del(&ioc
->list
);
10720 spin_unlock(&gioc_lock
);
10721 scsi_host_put(shost
);
10727 * scsih_suspend - power management suspend main entry point
10728 * @pdev: PCI device struct
10729 * @state: PM state change to (usually PCI_D3)
10731 * Return: 0 success, anything else error.
10734 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10736 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10737 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10738 pci_power_t device_state
;
10740 mpt3sas_base_stop_watchdog(ioc
);
10741 flush_scheduled_work();
10742 scsi_block_requests(shost
);
10743 device_state
= pci_choose_state(pdev
, state
);
10744 pr_info(MPT3SAS_FMT
10745 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10746 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10748 pci_save_state(pdev
);
10749 mpt3sas_base_free_resources(ioc
);
10750 pci_set_power_state(pdev
, device_state
);
10755 * scsih_resume - power management resume main entry point
10756 * @pdev: PCI device struct
10758 * Return: 0 success, anything else error.
10761 scsih_resume(struct pci_dev
*pdev
)
10763 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10764 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10765 pci_power_t device_state
= pdev
->current_state
;
10768 pr_info(MPT3SAS_FMT
10769 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10770 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10772 pci_set_power_state(pdev
, PCI_D0
);
10773 pci_enable_wake(pdev
, PCI_D0
, 0);
10774 pci_restore_state(pdev
);
10776 r
= mpt3sas_base_map_resources(ioc
);
10780 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
10781 scsi_unblock_requests(shost
);
10782 mpt3sas_base_start_watchdog(ioc
);
10785 #endif /* CONFIG_PM */
10788 * scsih_pci_error_detected - Called when a PCI error is detected.
10789 * @pdev: PCI device struct
10790 * @state: PCI channel state
10792 * Description: Called when a PCI error is detected.
10794 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
10796 static pci_ers_result_t
10797 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10799 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10800 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10802 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
10806 case pci_channel_io_normal
:
10807 return PCI_ERS_RESULT_CAN_RECOVER
;
10808 case pci_channel_io_frozen
:
10809 /* Fatal error, prepare for slot reset */
10810 ioc
->pci_error_recovery
= 1;
10811 scsi_block_requests(ioc
->shost
);
10812 mpt3sas_base_stop_watchdog(ioc
);
10813 mpt3sas_base_free_resources(ioc
);
10814 return PCI_ERS_RESULT_NEED_RESET
;
10815 case pci_channel_io_perm_failure
:
10816 /* Permanent error, prepare for device removal */
10817 ioc
->pci_error_recovery
= 1;
10818 mpt3sas_base_stop_watchdog(ioc
);
10819 _scsih_flush_running_cmds(ioc
);
10820 return PCI_ERS_RESULT_DISCONNECT
;
10822 return PCI_ERS_RESULT_NEED_RESET
;
10826 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10827 * @pdev: PCI device struct
10829 * Description: This routine is called by the pci error recovery
10830 * code after the PCI slot has been reset, just before we
10831 * should resume normal operations.
10833 static pci_ers_result_t
10834 scsih_pci_slot_reset(struct pci_dev
*pdev
)
10836 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10837 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10840 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
10843 ioc
->pci_error_recovery
= 0;
10845 pci_restore_state(pdev
);
10846 rc
= mpt3sas_base_map_resources(ioc
);
10848 return PCI_ERS_RESULT_DISCONNECT
;
10850 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
10852 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
10853 (rc
== 0) ? "success" : "failed");
10856 return PCI_ERS_RESULT_RECOVERED
;
10858 return PCI_ERS_RESULT_DISCONNECT
;
10862 * scsih_pci_resume() - resume normal ops after PCI reset
10863 * @pdev: pointer to PCI device
10865 * Called when the error recovery driver tells us that its
10866 * OK to resume normal operation. Use completion to allow
10867 * halted scsi ops to resume.
10870 scsih_pci_resume(struct pci_dev
*pdev
)
10872 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10873 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10875 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
10877 pci_cleanup_aer_uncorrect_error_status(pdev
);
10878 mpt3sas_base_start_watchdog(ioc
);
10879 scsi_unblock_requests(ioc
->shost
);
10883 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10884 * @pdev: pointer to PCI device
10886 static pci_ers_result_t
10887 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
10889 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10890 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10892 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
10895 /* TODO - dump whatever for debugging purposes */
10897 /* This called only if scsih_pci_error_detected returns
10898 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10899 * works, no need to reset slot.
10901 return PCI_ERS_RESULT_RECOVERED
;
10905 * scsih__ncq_prio_supp - Check for NCQ command priority support
10906 * @sdev: scsi device struct
10908 * This is called when a user indicates they would like to enable
10909 * ncq command priorities. This works only on SATA devices.
10911 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
10913 unsigned char *buf
;
10914 bool ncq_prio_supp
= false;
10916 if (!scsi_device_supports_vpd(sdev
))
10917 return ncq_prio_supp
;
10919 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
10921 return ncq_prio_supp
;
10923 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
10924 ncq_prio_supp
= (buf
[213] >> 4) & 1;
10927 return ncq_prio_supp
;
10930 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10932 static const struct pci_device_id mpt3sas_pci_table
[] = {
10933 /* Spitfire ~ 2004 */
10934 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
10935 PCI_ANY_ID
, PCI_ANY_ID
},
10936 /* Falcon ~ 2008 */
10937 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
10938 PCI_ANY_ID
, PCI_ANY_ID
},
10939 /* Liberator ~ 2108 */
10940 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
10941 PCI_ANY_ID
, PCI_ANY_ID
},
10942 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
10943 PCI_ANY_ID
, PCI_ANY_ID
},
10944 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
10945 PCI_ANY_ID
, PCI_ANY_ID
},
10946 /* Meteor ~ 2116 */
10947 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
10948 PCI_ANY_ID
, PCI_ANY_ID
},
10949 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
10950 PCI_ANY_ID
, PCI_ANY_ID
},
10951 /* Thunderbolt ~ 2208 */
10952 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
10953 PCI_ANY_ID
, PCI_ANY_ID
},
10954 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
10955 PCI_ANY_ID
, PCI_ANY_ID
},
10956 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
10957 PCI_ANY_ID
, PCI_ANY_ID
},
10958 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
10959 PCI_ANY_ID
, PCI_ANY_ID
},
10960 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
10961 PCI_ANY_ID
, PCI_ANY_ID
},
10962 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
10963 PCI_ANY_ID
, PCI_ANY_ID
},
10964 /* Mustang ~ 2308 */
10965 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
10966 PCI_ANY_ID
, PCI_ANY_ID
},
10967 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
10968 PCI_ANY_ID
, PCI_ANY_ID
},
10969 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
10970 PCI_ANY_ID
, PCI_ANY_ID
},
10971 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP
,
10972 PCI_ANY_ID
, PCI_ANY_ID
},
10974 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
10975 PCI_ANY_ID
, PCI_ANY_ID
},
10976 /* Fury ~ 3004 and 3008 */
10977 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
10978 PCI_ANY_ID
, PCI_ANY_ID
},
10979 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
10980 PCI_ANY_ID
, PCI_ANY_ID
},
10981 /* Invader ~ 3108 */
10982 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
10983 PCI_ANY_ID
, PCI_ANY_ID
},
10984 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
10985 PCI_ANY_ID
, PCI_ANY_ID
},
10986 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
10987 PCI_ANY_ID
, PCI_ANY_ID
},
10988 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
10989 PCI_ANY_ID
, PCI_ANY_ID
},
10990 /* Cutlass ~ 3216 and 3224 */
10991 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
10992 PCI_ANY_ID
, PCI_ANY_ID
},
10993 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
10994 PCI_ANY_ID
, PCI_ANY_ID
},
10995 /* Intruder ~ 3316 and 3324 */
10996 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
10997 PCI_ANY_ID
, PCI_ANY_ID
},
10998 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
10999 PCI_ANY_ID
, PCI_ANY_ID
},
11000 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
11001 PCI_ANY_ID
, PCI_ANY_ID
},
11002 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
11003 PCI_ANY_ID
, PCI_ANY_ID
},
11004 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
11005 PCI_ANY_ID
, PCI_ANY_ID
},
11006 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
11007 PCI_ANY_ID
, PCI_ANY_ID
},
11008 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
11009 PCI_ANY_ID
, PCI_ANY_ID
},
11010 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
11011 PCI_ANY_ID
, PCI_ANY_ID
},
11012 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
11013 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
11014 PCI_ANY_ID
, PCI_ANY_ID
},
11015 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
11016 PCI_ANY_ID
, PCI_ANY_ID
},
11017 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
11018 PCI_ANY_ID
, PCI_ANY_ID
},
11019 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
11020 PCI_ANY_ID
, PCI_ANY_ID
},
11021 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
11022 PCI_ANY_ID
, PCI_ANY_ID
},
11023 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
11024 PCI_ANY_ID
, PCI_ANY_ID
},
11025 /* Mercator ~ 3616*/
11026 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3616
,
11027 PCI_ANY_ID
, PCI_ANY_ID
},
11028 {0} /* Terminating entry */
11030 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
11032 static struct pci_error_handlers _mpt3sas_err_handler
= {
11033 .error_detected
= scsih_pci_error_detected
,
11034 .mmio_enabled
= scsih_pci_mmio_enabled
,
11035 .slot_reset
= scsih_pci_slot_reset
,
11036 .resume
= scsih_pci_resume
,
11039 static struct pci_driver mpt3sas_driver
= {
11040 .name
= MPT3SAS_DRIVER_NAME
,
11041 .id_table
= mpt3sas_pci_table
,
11042 .probe
= _scsih_probe
,
11043 .remove
= scsih_remove
,
11044 .shutdown
= scsih_shutdown
,
11045 .err_handler
= &_mpt3sas_err_handler
,
11047 .suspend
= scsih_suspend
,
11048 .resume
= scsih_resume
,
11053 * scsih_init - main entry point for this driver.
11055 * Return: 0 success, anything else error.
11063 mpt3sas_base_initialize_callback_handler();
11065 /* queuecommand callback hander */
11066 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
11068 /* task management callback handler */
11069 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
11071 /* base internal commands callback handler */
11072 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
11073 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
11074 mpt3sas_port_enable_done
);
11076 /* transport internal commands callback handler */
11077 transport_cb_idx
= mpt3sas_base_register_callback_handler(
11078 mpt3sas_transport_done
);
11080 /* scsih internal commands callback handler */
11081 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
11083 /* configuration page API internal commands callback handler */
11084 config_cb_idx
= mpt3sas_base_register_callback_handler(
11085 mpt3sas_config_done
);
11087 /* ctl module callback handler */
11088 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
11090 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
11091 _scsih_tm_tr_complete
);
11093 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
11094 _scsih_tm_volume_tr_complete
);
11096 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
11097 _scsih_sas_control_complete
);
11103 * scsih_exit - exit point for this driver (when it is a module).
11105 * Return: 0 success, anything else error.
11111 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
11112 mpt3sas_base_release_callback_handler(tm_cb_idx
);
11113 mpt3sas_base_release_callback_handler(base_cb_idx
);
11114 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
11115 mpt3sas_base_release_callback_handler(transport_cb_idx
);
11116 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
11117 mpt3sas_base_release_callback_handler(config_cb_idx
);
11118 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
11120 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
11121 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
11122 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
11124 /* raid transport support */
11125 if (hbas_to_enumerate
!= 1)
11126 raid_class_release(mpt3sas_raid_template
);
11127 if (hbas_to_enumerate
!= 2)
11128 raid_class_release(mpt2sas_raid_template
);
11129 sas_release_transport(mpt3sas_transport_template
);
11133 * _mpt3sas_init - main entry point for this driver.
11135 * Return: 0 success, anything else error.
11138 _mpt3sas_init(void)
11142 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
11143 MPT3SAS_DRIVER_VERSION
);
11145 mpt3sas_transport_template
=
11146 sas_attach_transport(&mpt3sas_transport_functions
);
11147 if (!mpt3sas_transport_template
)
11150 /* No need attach mpt3sas raid functions template
11151 * if hbas_to_enumarate value is one.
11153 if (hbas_to_enumerate
!= 1) {
11154 mpt3sas_raid_template
=
11155 raid_class_attach(&mpt3sas_raid_functions
);
11156 if (!mpt3sas_raid_template
) {
11157 sas_release_transport(mpt3sas_transport_template
);
11162 /* No need to attach mpt2sas raid functions template
11163 * if hbas_to_enumarate value is two
11165 if (hbas_to_enumerate
!= 2) {
11166 mpt2sas_raid_template
=
11167 raid_class_attach(&mpt2sas_raid_functions
);
11168 if (!mpt2sas_raid_template
) {
11169 sas_release_transport(mpt3sas_transport_template
);
11174 error
= scsih_init();
11180 mpt3sas_ctl_init(hbas_to_enumerate
);
11182 error
= pci_register_driver(&mpt3sas_driver
);
11190 * _mpt3sas_exit - exit point for this driver (when it is a module).
11194 _mpt3sas_exit(void)
11196 pr_info("mpt3sas version %s unloading\n",
11197 MPT3SAS_DRIVER_VERSION
);
11199 mpt3sas_ctl_exit(hbas_to_enumerate
);
11201 pci_unregister_driver(&mpt3sas_driver
);
11206 module_init(_mpt3sas_init
);
11207 module_exit(_mpt3sas_exit
);