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
, 0444);
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
, 0444);
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
, 0444);
128 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
130 static ushort hbas_to_enumerate
;
131 module_param(hbas_to_enumerate
, ushort
, 0444);
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, 0444);
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, 0444);
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, 0444);
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 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
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 */
445 ioc_err(ioc
, "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
446 handle
, ioc_status
, __FILE__
, __LINE__
, __func__
);
451 * _scsih_determine_boot_device - determine boot device.
452 * @ioc: per adapter object
453 * @device: sas_device or pcie_device object
454 * @channel: SAS or PCIe channel
456 * Determines whether this device should be first reported device to
457 * to scsi-ml or sas transport, this purpose is for persistent boot device.
458 * There are primary, alternate, and current entries in bios page 2. The order
459 * priority is primary, alternate, then current. This routine saves
460 * the corresponding device object.
461 * The saved data to be used later in _scsih_probe_boot_devices().
464 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
, void *device
,
467 struct _sas_device
*sas_device
;
468 struct _pcie_device
*pcie_device
;
469 struct _raid_device
*raid_device
;
472 u64 enclosure_logical_id
;
475 /* only process this function when driver loads */
476 if (!ioc
->is_driver_loading
)
479 /* no Bios, return immediately */
480 if (!ioc
->bios_pg3
.BiosVersion
)
483 if (channel
== RAID_CHANNEL
) {
484 raid_device
= device
;
485 sas_address
= raid_device
->wwid
;
487 enclosure_logical_id
= 0;
489 } else if (channel
== PCIE_CHANNEL
) {
490 pcie_device
= device
;
491 sas_address
= pcie_device
->wwid
;
493 enclosure_logical_id
= 0;
497 sas_address
= sas_device
->sas_address
;
498 device_name
= sas_device
->device_name
;
499 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
500 slot
= sas_device
->slot
;
503 if (!ioc
->req_boot_device
.device
) {
504 if (_scsih_is_boot_device(sas_address
, device_name
,
505 enclosure_logical_id
, slot
,
506 (ioc
->bios_pg2
.ReqBootDeviceForm
&
507 MPI2_BIOSPAGE2_FORM_MASK
),
508 &ioc
->bios_pg2
.RequestedBootDevice
)) {
510 ioc_info(ioc
, "%s: req_boot_device(0x%016llx)\n",
511 __func__
, (u64
)sas_address
));
512 ioc
->req_boot_device
.device
= device
;
513 ioc
->req_boot_device
.channel
= channel
;
517 if (!ioc
->req_alt_boot_device
.device
) {
518 if (_scsih_is_boot_device(sas_address
, device_name
,
519 enclosure_logical_id
, slot
,
520 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
521 MPI2_BIOSPAGE2_FORM_MASK
),
522 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
524 ioc_info(ioc
, "%s: req_alt_boot_device(0x%016llx)\n",
525 __func__
, (u64
)sas_address
));
526 ioc
->req_alt_boot_device
.device
= device
;
527 ioc
->req_alt_boot_device
.channel
= channel
;
531 if (!ioc
->current_boot_device
.device
) {
532 if (_scsih_is_boot_device(sas_address
, device_name
,
533 enclosure_logical_id
, slot
,
534 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
535 MPI2_BIOSPAGE2_FORM_MASK
),
536 &ioc
->bios_pg2
.CurrentBootDevice
)) {
538 ioc_info(ioc
, "%s: current_boot_device(0x%016llx)\n",
539 __func__
, (u64
)sas_address
));
540 ioc
->current_boot_device
.device
= device
;
541 ioc
->current_boot_device
.channel
= channel
;
546 static struct _sas_device
*
547 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
548 struct MPT3SAS_TARGET
*tgt_priv
)
550 struct _sas_device
*ret
;
552 assert_spin_locked(&ioc
->sas_device_lock
);
554 ret
= tgt_priv
->sas_dev
;
561 static struct _sas_device
*
562 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
563 struct MPT3SAS_TARGET
*tgt_priv
)
565 struct _sas_device
*ret
;
568 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
569 ret
= __mpt3sas_get_sdev_from_target(ioc
, tgt_priv
);
570 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
575 static struct _pcie_device
*
576 __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
577 struct MPT3SAS_TARGET
*tgt_priv
)
579 struct _pcie_device
*ret
;
581 assert_spin_locked(&ioc
->pcie_device_lock
);
583 ret
= tgt_priv
->pcie_dev
;
585 pcie_device_get(ret
);
591 * mpt3sas_get_pdev_from_target - pcie device search
592 * @ioc: per adapter object
593 * @tgt_priv: starget private object
595 * Context: This function will acquire ioc->pcie_device_lock and will release
596 * before returning the pcie_device object.
598 * This searches for pcie_device from target, then return pcie_device object.
600 static struct _pcie_device
*
601 mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
602 struct MPT3SAS_TARGET
*tgt_priv
)
604 struct _pcie_device
*ret
;
607 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
608 ret
= __mpt3sas_get_pdev_from_target(ioc
, tgt_priv
);
609 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
615 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
618 struct _sas_device
*sas_device
;
620 assert_spin_locked(&ioc
->sas_device_lock
);
622 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
623 if (sas_device
->sas_address
== sas_address
)
626 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
627 if (sas_device
->sas_address
== sas_address
)
633 sas_device_get(sas_device
);
638 * mpt3sas_get_sdev_by_addr - sas device search
639 * @ioc: per adapter object
640 * @sas_address: sas address
641 * Context: Calling function should acquire ioc->sas_device_lock
643 * This searches for sas_device based on sas_address, then return sas_device
647 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
650 struct _sas_device
*sas_device
;
653 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
654 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
656 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
661 static struct _sas_device
*
662 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
664 struct _sas_device
*sas_device
;
666 assert_spin_locked(&ioc
->sas_device_lock
);
668 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
669 if (sas_device
->handle
== handle
)
672 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
673 if (sas_device
->handle
== handle
)
679 sas_device_get(sas_device
);
684 * mpt3sas_get_sdev_by_handle - sas device search
685 * @ioc: per adapter object
686 * @handle: sas device handle (assigned by firmware)
687 * Context: Calling function should acquire ioc->sas_device_lock
689 * This searches for sas_device based on sas_address, then return sas_device
693 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
695 struct _sas_device
*sas_device
;
698 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
699 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
700 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
706 * _scsih_display_enclosure_chassis_info - display device location info
707 * @ioc: per adapter object
708 * @sas_device: per sas device object
709 * @sdev: scsi device struct
710 * @starget: scsi target struct
713 _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER
*ioc
,
714 struct _sas_device
*sas_device
, struct scsi_device
*sdev
,
715 struct scsi_target
*starget
)
718 if (sas_device
->enclosure_handle
!= 0)
719 sdev_printk(KERN_INFO
, sdev
,
720 "enclosure logical id (0x%016llx), slot(%d) \n",
722 sas_device
->enclosure_logical_id
,
724 if (sas_device
->connector_name
[0] != '\0')
725 sdev_printk(KERN_INFO
, sdev
,
726 "enclosure level(0x%04x), connector name( %s)\n",
727 sas_device
->enclosure_level
,
728 sas_device
->connector_name
);
729 if (sas_device
->is_chassis_slot_valid
)
730 sdev_printk(KERN_INFO
, sdev
, "chassis slot(0x%04x)\n",
731 sas_device
->chassis_slot
);
732 } else if (starget
) {
733 if (sas_device
->enclosure_handle
!= 0)
734 starget_printk(KERN_INFO
, starget
,
735 "enclosure logical id(0x%016llx), slot(%d) \n",
737 sas_device
->enclosure_logical_id
,
739 if (sas_device
->connector_name
[0] != '\0')
740 starget_printk(KERN_INFO
, starget
,
741 "enclosure level(0x%04x), connector name( %s)\n",
742 sas_device
->enclosure_level
,
743 sas_device
->connector_name
);
744 if (sas_device
->is_chassis_slot_valid
)
745 starget_printk(KERN_INFO
, starget
,
746 "chassis slot(0x%04x)\n",
747 sas_device
->chassis_slot
);
749 if (sas_device
->enclosure_handle
!= 0)
750 ioc_info(ioc
, "enclosure logical id(0x%016llx), slot(%d)\n",
751 (u64
)sas_device
->enclosure_logical_id
,
753 if (sas_device
->connector_name
[0] != '\0')
754 ioc_info(ioc
, "enclosure level(0x%04x), connector name( %s)\n",
755 sas_device
->enclosure_level
,
756 sas_device
->connector_name
);
757 if (sas_device
->is_chassis_slot_valid
)
758 ioc_info(ioc
, "chassis slot(0x%04x)\n",
759 sas_device
->chassis_slot
);
764 * _scsih_sas_device_remove - remove sas_device from list.
765 * @ioc: per adapter object
766 * @sas_device: the sas_device object
767 * Context: This function will acquire ioc->sas_device_lock.
769 * If sas_device is on the list, remove it and decrement its reference count.
772 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
773 struct _sas_device
*sas_device
)
779 ioc_info(ioc
, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
780 sas_device
->handle
, (u64
)sas_device
->sas_address
);
782 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
785 * The lock serializes access to the list, but we still need to verify
786 * that nobody removed the entry while we were waiting on the lock.
788 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
789 if (!list_empty(&sas_device
->list
)) {
790 list_del_init(&sas_device
->list
);
791 sas_device_put(sas_device
);
793 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
797 * _scsih_device_remove_by_handle - removing device object by handle
798 * @ioc: per adapter object
799 * @handle: device handle
802 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
804 struct _sas_device
*sas_device
;
807 if (ioc
->shost_recovery
)
810 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
811 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
813 list_del_init(&sas_device
->list
);
814 sas_device_put(sas_device
);
816 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
818 _scsih_remove_device(ioc
, sas_device
);
819 sas_device_put(sas_device
);
824 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
825 * @ioc: per adapter object
826 * @sas_address: device sas_address
829 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
832 struct _sas_device
*sas_device
;
835 if (ioc
->shost_recovery
)
838 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
839 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
, sas_address
);
841 list_del_init(&sas_device
->list
);
842 sas_device_put(sas_device
);
844 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
846 _scsih_remove_device(ioc
, sas_device
);
847 sas_device_put(sas_device
);
852 * _scsih_sas_device_add - insert sas_device to the list.
853 * @ioc: per adapter object
854 * @sas_device: the sas_device object
855 * Context: This function will acquire ioc->sas_device_lock.
857 * Adding new object to the ioc->sas_device_list.
860 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
861 struct _sas_device
*sas_device
)
866 ioc_info(ioc
, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
867 __func__
, sas_device
->handle
,
868 (u64
)sas_device
->sas_address
));
870 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
873 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
874 sas_device_get(sas_device
);
875 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
876 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
878 if (ioc
->hide_drives
) {
879 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
883 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
884 sas_device
->sas_address_parent
)) {
885 _scsih_sas_device_remove(ioc
, sas_device
);
886 } else if (!sas_device
->starget
) {
888 * When asyn scanning is enabled, its not possible to remove
889 * devices while scanning is turned on due to an oops in
890 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
892 if (!ioc
->is_driver_loading
) {
893 mpt3sas_transport_port_remove(ioc
,
894 sas_device
->sas_address
,
895 sas_device
->sas_address_parent
);
896 _scsih_sas_device_remove(ioc
, sas_device
);
899 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
903 * _scsih_sas_device_init_add - insert sas_device to the list.
904 * @ioc: per adapter object
905 * @sas_device: the sas_device object
906 * Context: This function will acquire ioc->sas_device_lock.
908 * Adding new object at driver load time to the ioc->sas_device_init_list.
911 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
912 struct _sas_device
*sas_device
)
917 ioc_info(ioc
, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
918 __func__
, sas_device
->handle
,
919 (u64
)sas_device
->sas_address
));
921 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
924 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
925 sas_device_get(sas_device
);
926 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
927 _scsih_determine_boot_device(ioc
, sas_device
, 0);
928 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
932 static struct _pcie_device
*
933 __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
935 struct _pcie_device
*pcie_device
;
937 assert_spin_locked(&ioc
->pcie_device_lock
);
939 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
940 if (pcie_device
->wwid
== wwid
)
943 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
944 if (pcie_device
->wwid
== wwid
)
950 pcie_device_get(pcie_device
);
956 * mpt3sas_get_pdev_by_wwid - pcie device search
957 * @ioc: per adapter object
960 * Context: This function will acquire ioc->pcie_device_lock and will release
961 * before returning the pcie_device object.
963 * This searches for pcie_device based on wwid, then return pcie_device object.
965 static struct _pcie_device
*
966 mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
968 struct _pcie_device
*pcie_device
;
971 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
972 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
973 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
979 static struct _pcie_device
*
980 __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER
*ioc
, int id
,
983 struct _pcie_device
*pcie_device
;
985 assert_spin_locked(&ioc
->pcie_device_lock
);
987 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
988 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
991 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
992 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
998 pcie_device_get(pcie_device
);
1002 static struct _pcie_device
*
1003 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1005 struct _pcie_device
*pcie_device
;
1007 assert_spin_locked(&ioc
->pcie_device_lock
);
1009 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
1010 if (pcie_device
->handle
== handle
)
1013 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
1014 if (pcie_device
->handle
== handle
)
1020 pcie_device_get(pcie_device
);
1026 * mpt3sas_get_pdev_by_handle - pcie device search
1027 * @ioc: per adapter object
1028 * @handle: Firmware device handle
1030 * Context: This function will acquire ioc->pcie_device_lock and will release
1031 * before returning the pcie_device object.
1033 * This searches for pcie_device based on handle, then return pcie_device
1036 struct _pcie_device
*
1037 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1039 struct _pcie_device
*pcie_device
;
1040 unsigned long flags
;
1042 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1043 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1044 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1050 * _scsih_pcie_device_remove - remove pcie_device from list.
1051 * @ioc: per adapter object
1052 * @pcie_device: the pcie_device object
1053 * Context: This function will acquire ioc->pcie_device_lock.
1055 * If pcie_device is on the list, remove it and decrement its reference count.
1058 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1059 struct _pcie_device
*pcie_device
)
1061 unsigned long flags
;
1062 int was_on_pcie_device_list
= 0;
1066 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
1067 pcie_device
->handle
, (u64
)pcie_device
->wwid
);
1068 if (pcie_device
->enclosure_handle
!= 0)
1069 ioc_info(ioc
, "removing enclosure logical id(0x%016llx), slot(%d)\n",
1070 (u64
)pcie_device
->enclosure_logical_id
,
1072 if (pcie_device
->connector_name
[0] != '\0')
1073 ioc_info(ioc
, "removing enclosure level(0x%04x), connector name( %s)\n",
1074 pcie_device
->enclosure_level
,
1075 pcie_device
->connector_name
);
1077 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1078 if (!list_empty(&pcie_device
->list
)) {
1079 list_del_init(&pcie_device
->list
);
1080 was_on_pcie_device_list
= 1;
1082 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1083 if (was_on_pcie_device_list
) {
1084 kfree(pcie_device
->serial_number
);
1085 pcie_device_put(pcie_device
);
1091 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1092 * @ioc: per adapter object
1093 * @handle: device handle
1096 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1098 struct _pcie_device
*pcie_device
;
1099 unsigned long flags
;
1100 int was_on_pcie_device_list
= 0;
1102 if (ioc
->shost_recovery
)
1105 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1106 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1108 if (!list_empty(&pcie_device
->list
)) {
1109 list_del_init(&pcie_device
->list
);
1110 was_on_pcie_device_list
= 1;
1111 pcie_device_put(pcie_device
);
1114 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1115 if (was_on_pcie_device_list
) {
1116 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
1117 pcie_device_put(pcie_device
);
1122 * _scsih_pcie_device_add - add pcie_device object
1123 * @ioc: per adapter object
1124 * @pcie_device: pcie_device object
1126 * This is added to the pcie_device_list link list.
1129 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1130 struct _pcie_device
*pcie_device
)
1132 unsigned long flags
;
1135 ioc_info(ioc
, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1137 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
1138 if (pcie_device
->enclosure_handle
!= 0)
1140 ioc_info(ioc
, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1142 (u64
)pcie_device
->enclosure_logical_id
,
1143 pcie_device
->slot
));
1144 if (pcie_device
->connector_name
[0] != '\0')
1146 ioc_info(ioc
, "%s: enclosure level(0x%04x), connector name( %s)\n",
1147 __func__
, pcie_device
->enclosure_level
,
1148 pcie_device
->connector_name
));
1150 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1151 pcie_device_get(pcie_device
);
1152 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
1153 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1155 if (scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, pcie_device
->id
, 0)) {
1156 _scsih_pcie_device_remove(ioc
, pcie_device
);
1157 } else if (!pcie_device
->starget
) {
1158 if (!ioc
->is_driver_loading
) {
1159 /*TODO-- Need to find out whether this condition will occur or not*/
1160 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1163 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1167 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1168 * @ioc: per adapter object
1169 * @pcie_device: the pcie_device object
1170 * Context: This function will acquire ioc->pcie_device_lock.
1172 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1175 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
1176 struct _pcie_device
*pcie_device
)
1178 unsigned long flags
;
1181 ioc_info(ioc
, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1183 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
1184 if (pcie_device
->enclosure_handle
!= 0)
1186 ioc_info(ioc
, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1188 (u64
)pcie_device
->enclosure_logical_id
,
1189 pcie_device
->slot
));
1190 if (pcie_device
->connector_name
[0] != '\0')
1192 ioc_info(ioc
, "%s: enclosure level(0x%04x), connector name( %s)\n",
1193 __func__
, pcie_device
->enclosure_level
,
1194 pcie_device
->connector_name
));
1196 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1197 pcie_device_get(pcie_device
);
1198 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_init_list
);
1199 _scsih_determine_boot_device(ioc
, pcie_device
, PCIE_CHANNEL
);
1200 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1203 * _scsih_raid_device_find_by_id - raid device search
1204 * @ioc: per adapter object
1205 * @id: sas device target id
1206 * @channel: sas device channel
1207 * Context: Calling function should acquire ioc->raid_device_lock
1209 * This searches for raid_device based on target id, then return raid_device
1212 static struct _raid_device
*
1213 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
1215 struct _raid_device
*raid_device
, *r
;
1218 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1219 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
1230 * mpt3sas_raid_device_find_by_handle - raid device search
1231 * @ioc: per adapter object
1232 * @handle: sas device handle (assigned by firmware)
1233 * Context: Calling function should acquire ioc->raid_device_lock
1235 * This searches for raid_device based on handle, then return raid_device
1238 struct _raid_device
*
1239 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1241 struct _raid_device
*raid_device
, *r
;
1244 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1245 if (raid_device
->handle
!= handle
)
1256 * _scsih_raid_device_find_by_wwid - raid device search
1257 * @ioc: per adapter object
1259 * Context: Calling function should acquire ioc->raid_device_lock
1261 * This searches for raid_device based on wwid, then return raid_device
1264 static struct _raid_device
*
1265 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
1267 struct _raid_device
*raid_device
, *r
;
1270 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1271 if (raid_device
->wwid
!= wwid
)
1282 * _scsih_raid_device_add - add raid_device object
1283 * @ioc: per adapter object
1284 * @raid_device: raid_device object
1286 * This is added to the raid_device_list link list.
1289 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1290 struct _raid_device
*raid_device
)
1292 unsigned long flags
;
1295 ioc_info(ioc
, "%s: handle(0x%04x), wwid(0x%016llx)\n",
1297 raid_device
->handle
, (u64
)raid_device
->wwid
));
1299 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1300 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
1301 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1305 * _scsih_raid_device_remove - delete raid_device object
1306 * @ioc: per adapter object
1307 * @raid_device: raid_device object
1311 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1312 struct _raid_device
*raid_device
)
1314 unsigned long flags
;
1316 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1317 list_del(&raid_device
->list
);
1319 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1323 * mpt3sas_scsih_expander_find_by_handle - expander device search
1324 * @ioc: per adapter object
1325 * @handle: expander handle (assigned by firmware)
1326 * Context: Calling function should acquire ioc->sas_device_lock
1328 * This searches for expander device based on handle, then returns the
1332 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1334 struct _sas_node
*sas_expander
, *r
;
1337 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1338 if (sas_expander
->handle
!= handle
)
1348 * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search
1349 * @ioc: per adapter object
1350 * @handle: enclosure handle (assigned by firmware)
1351 * Context: Calling function should acquire ioc->sas_device_lock
1353 * This searches for enclosure device based on handle, then returns the
1356 static struct _enclosure_node
*
1357 mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1359 struct _enclosure_node
*enclosure_dev
, *r
;
1362 list_for_each_entry(enclosure_dev
, &ioc
->enclosure_list
, list
) {
1363 if (le16_to_cpu(enclosure_dev
->pg0
.EnclosureHandle
) != handle
)
1372 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1373 * @ioc: per adapter object
1374 * @sas_address: sas address
1375 * Context: Calling function should acquire ioc->sas_node_lock.
1377 * This searches for expander device based on sas_address, then returns the
1381 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1384 struct _sas_node
*sas_expander
, *r
;
1387 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1388 if (sas_expander
->sas_address
!= sas_address
)
1398 * _scsih_expander_node_add - insert expander device to the list.
1399 * @ioc: per adapter object
1400 * @sas_expander: the sas_device object
1401 * Context: This function will acquire ioc->sas_node_lock.
1403 * Adding new object to the ioc->sas_expander_list.
1406 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1407 struct _sas_node
*sas_expander
)
1409 unsigned long flags
;
1411 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1412 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1413 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1417 * _scsih_is_end_device - determines if device is an end device
1418 * @device_info: bitfield providing information about the device.
1421 * Return: 1 if end device.
1424 _scsih_is_end_device(u32 device_info
)
1426 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1427 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1428 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1429 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1436 * _scsih_is_nvme_device - determines if device is an nvme device
1437 * @device_info: bitfield providing information about the device.
1440 * Return: 1 if nvme device.
1443 _scsih_is_nvme_device(u32 device_info
)
1445 if ((device_info
& MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
)
1446 == MPI26_PCIE_DEVINFO_NVME
)
1453 * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
1454 * @ioc: per adapter object
1455 * @smid: system request message index
1457 * Return: the smid stored scmd pointer.
1458 * Then will dereference the stored scmd pointer.
1461 mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1463 struct scsi_cmnd
*scmd
= NULL
;
1464 struct scsiio_tracker
*st
;
1465 Mpi25SCSIIORequest_t
*mpi_request
;
1468 smid
<= ioc
->scsiio_depth
- INTERNAL_SCSIIO_CMDS_COUNT
) {
1469 u32 unique_tag
= smid
- 1;
1471 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1474 * If SCSI IO request is outstanding at driver level then
1475 * DevHandle filed must be non-zero. If DevHandle is zero
1476 * then it means that this smid is free at driver level,
1479 if (!mpi_request
->DevHandle
)
1482 scmd
= scsi_host_find_tag(ioc
->shost
, unique_tag
);
1484 st
= scsi_cmd_priv(scmd
);
1485 if (st
->cb_idx
== 0xFF || st
->smid
== 0)
1493 * scsih_change_queue_depth - setting device queue depth
1494 * @sdev: scsi device struct
1495 * @qdepth: requested queue depth
1497 * Return: queue depth.
1500 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1502 struct Scsi_Host
*shost
= sdev
->host
;
1504 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1505 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1506 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1507 struct _sas_device
*sas_device
;
1508 unsigned long flags
;
1510 max_depth
= shost
->can_queue
;
1512 /* limit max device queue for SATA to 32 */
1513 sas_device_priv_data
= sdev
->hostdata
;
1514 if (!sas_device_priv_data
)
1516 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1517 if (!sas_target_priv_data
)
1519 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1522 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1523 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1525 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1526 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1528 sas_device_put(sas_device
);
1530 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1534 if (!sdev
->tagged_supported
)
1536 if (qdepth
> max_depth
)
1538 return scsi_change_queue_depth(sdev
, qdepth
);
1542 * scsih_target_alloc - target add routine
1543 * @starget: scsi target struct
1545 * Return: 0 if ok. Any other return is assumed to be an error and
1546 * the device is ignored.
1549 scsih_target_alloc(struct scsi_target
*starget
)
1551 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1552 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1553 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1554 struct _sas_device
*sas_device
;
1555 struct _raid_device
*raid_device
;
1556 struct _pcie_device
*pcie_device
;
1557 unsigned long flags
;
1558 struct sas_rphy
*rphy
;
1560 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1562 if (!sas_target_priv_data
)
1565 starget
->hostdata
= sas_target_priv_data
;
1566 sas_target_priv_data
->starget
= starget
;
1567 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1570 if (starget
->channel
== RAID_CHANNEL
) {
1571 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1572 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1575 sas_target_priv_data
->handle
= raid_device
->handle
;
1576 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1577 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1578 if (ioc
->is_warpdrive
)
1579 sas_target_priv_data
->raid_device
= raid_device
;
1580 raid_device
->starget
= starget
;
1582 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1587 if (starget
->channel
== PCIE_CHANNEL
) {
1588 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1589 pcie_device
= __mpt3sas_get_pdev_by_idchannel(ioc
, starget
->id
,
1592 sas_target_priv_data
->handle
= pcie_device
->handle
;
1593 sas_target_priv_data
->sas_address
= pcie_device
->wwid
;
1594 sas_target_priv_data
->pcie_dev
= pcie_device
;
1595 pcie_device
->starget
= starget
;
1596 pcie_device
->id
= starget
->id
;
1597 pcie_device
->channel
= starget
->channel
;
1598 sas_target_priv_data
->flags
|=
1599 MPT_TARGET_FLAGS_PCIE_DEVICE
;
1600 if (pcie_device
->fast_path
)
1601 sas_target_priv_data
->flags
|=
1602 MPT_TARGET_FASTPATH_IO
;
1604 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1608 /* sas/sata devices */
1609 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1610 rphy
= dev_to_rphy(starget
->dev
.parent
);
1611 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1612 rphy
->identify
.sas_address
);
1615 sas_target_priv_data
->handle
= sas_device
->handle
;
1616 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1617 sas_target_priv_data
->sas_dev
= sas_device
;
1618 sas_device
->starget
= starget
;
1619 sas_device
->id
= starget
->id
;
1620 sas_device
->channel
= starget
->channel
;
1621 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1622 sas_target_priv_data
->flags
|=
1623 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1624 if (sas_device
->fast_path
)
1625 sas_target_priv_data
->flags
|=
1626 MPT_TARGET_FASTPATH_IO
;
1628 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1634 * scsih_target_destroy - target destroy routine
1635 * @starget: scsi target struct
1638 scsih_target_destroy(struct scsi_target
*starget
)
1640 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1641 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1642 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1643 struct _sas_device
*sas_device
;
1644 struct _raid_device
*raid_device
;
1645 struct _pcie_device
*pcie_device
;
1646 unsigned long flags
;
1648 sas_target_priv_data
= starget
->hostdata
;
1649 if (!sas_target_priv_data
)
1652 if (starget
->channel
== RAID_CHANNEL
) {
1653 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1654 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1657 raid_device
->starget
= NULL
;
1658 raid_device
->sdev
= NULL
;
1660 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1664 if (starget
->channel
== PCIE_CHANNEL
) {
1665 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1666 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1667 sas_target_priv_data
);
1668 if (pcie_device
&& (pcie_device
->starget
== starget
) &&
1669 (pcie_device
->id
== starget
->id
) &&
1670 (pcie_device
->channel
== starget
->channel
))
1671 pcie_device
->starget
= NULL
;
1675 * Corresponding get() is in _scsih_target_alloc()
1677 sas_target_priv_data
->pcie_dev
= NULL
;
1678 pcie_device_put(pcie_device
);
1679 pcie_device_put(pcie_device
);
1681 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1685 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1686 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1687 if (sas_device
&& (sas_device
->starget
== starget
) &&
1688 (sas_device
->id
== starget
->id
) &&
1689 (sas_device
->channel
== starget
->channel
))
1690 sas_device
->starget
= NULL
;
1694 * Corresponding get() is in _scsih_target_alloc()
1696 sas_target_priv_data
->sas_dev
= NULL
;
1697 sas_device_put(sas_device
);
1699 sas_device_put(sas_device
);
1701 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1704 kfree(sas_target_priv_data
);
1705 starget
->hostdata
= NULL
;
1709 * scsih_slave_alloc - device add routine
1710 * @sdev: scsi device struct
1712 * Return: 0 if ok. Any other return is assumed to be an error and
1713 * the device is ignored.
1716 scsih_slave_alloc(struct scsi_device
*sdev
)
1718 struct Scsi_Host
*shost
;
1719 struct MPT3SAS_ADAPTER
*ioc
;
1720 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1721 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1722 struct scsi_target
*starget
;
1723 struct _raid_device
*raid_device
;
1724 struct _sas_device
*sas_device
;
1725 struct _pcie_device
*pcie_device
;
1726 unsigned long flags
;
1728 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1730 if (!sas_device_priv_data
)
1733 sas_device_priv_data
->lun
= sdev
->lun
;
1734 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1736 starget
= scsi_target(sdev
);
1737 sas_target_priv_data
= starget
->hostdata
;
1738 sas_target_priv_data
->num_luns
++;
1739 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1740 sdev
->hostdata
= sas_device_priv_data
;
1741 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1742 sdev
->no_uld_attach
= 1;
1744 shost
= dev_to_shost(&starget
->dev
);
1745 ioc
= shost_priv(shost
);
1746 if (starget
->channel
== RAID_CHANNEL
) {
1747 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1748 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1749 starget
->id
, starget
->channel
);
1751 raid_device
->sdev
= sdev
; /* raid is single lun */
1752 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1754 if (starget
->channel
== PCIE_CHANNEL
) {
1755 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1756 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
1757 sas_target_priv_data
->sas_address
);
1758 if (pcie_device
&& (pcie_device
->starget
== NULL
)) {
1759 sdev_printk(KERN_INFO
, sdev
,
1760 "%s : pcie_device->starget set to starget @ %d\n",
1761 __func__
, __LINE__
);
1762 pcie_device
->starget
= starget
;
1766 pcie_device_put(pcie_device
);
1767 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1769 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1770 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1771 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1772 sas_target_priv_data
->sas_address
);
1773 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1774 sdev_printk(KERN_INFO
, sdev
,
1775 "%s : sas_device->starget set to starget @ %d\n",
1776 __func__
, __LINE__
);
1777 sas_device
->starget
= starget
;
1781 sas_device_put(sas_device
);
1783 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1790 * scsih_slave_destroy - device destroy routine
1791 * @sdev: scsi device struct
1794 scsih_slave_destroy(struct scsi_device
*sdev
)
1796 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1797 struct scsi_target
*starget
;
1798 struct Scsi_Host
*shost
;
1799 struct MPT3SAS_ADAPTER
*ioc
;
1800 struct _sas_device
*sas_device
;
1801 struct _pcie_device
*pcie_device
;
1802 unsigned long flags
;
1804 if (!sdev
->hostdata
)
1807 starget
= scsi_target(sdev
);
1808 sas_target_priv_data
= starget
->hostdata
;
1809 sas_target_priv_data
->num_luns
--;
1811 shost
= dev_to_shost(&starget
->dev
);
1812 ioc
= shost_priv(shost
);
1814 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
1815 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1816 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1817 sas_target_priv_data
);
1818 if (pcie_device
&& !sas_target_priv_data
->num_luns
)
1819 pcie_device
->starget
= NULL
;
1822 pcie_device_put(pcie_device
);
1824 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1826 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1827 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1828 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1829 sas_target_priv_data
);
1830 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1831 sas_device
->starget
= NULL
;
1834 sas_device_put(sas_device
);
1835 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1838 kfree(sdev
->hostdata
);
1839 sdev
->hostdata
= NULL
;
1843 * _scsih_display_sata_capabilities - sata capabilities
1844 * @ioc: per adapter object
1845 * @handle: device handle
1846 * @sdev: scsi device struct
1849 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1850 u16 handle
, struct scsi_device
*sdev
)
1852 Mpi2ConfigReply_t mpi_reply
;
1853 Mpi2SasDevicePage0_t sas_device_pg0
;
1858 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1859 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1860 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
1861 __FILE__
, __LINE__
, __func__
);
1865 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1866 MPI2_IOCSTATUS_MASK
;
1867 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1868 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
1869 __FILE__
, __LINE__
, __func__
);
1873 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1874 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1876 sdev_printk(KERN_INFO
, sdev
,
1877 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1878 "sw_preserve(%s)\n",
1879 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1880 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1881 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1883 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1884 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1885 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1889 * raid transport support -
1890 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1891 * unloading the driver followed by a load - I believe that the subroutine
1892 * raid_class_release() is not cleaning up properly.
1896 * scsih_is_raid - return boolean indicating device is raid volume
1897 * @dev: the device struct object
1900 scsih_is_raid(struct device
*dev
)
1902 struct scsi_device
*sdev
= to_scsi_device(dev
);
1903 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1905 if (ioc
->is_warpdrive
)
1907 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1911 scsih_is_nvme(struct device
*dev
)
1913 struct scsi_device
*sdev
= to_scsi_device(dev
);
1915 return (sdev
->channel
== PCIE_CHANNEL
) ? 1 : 0;
1919 * scsih_get_resync - get raid volume resync percent complete
1920 * @dev: the device struct object
1923 scsih_get_resync(struct device
*dev
)
1925 struct scsi_device
*sdev
= to_scsi_device(dev
);
1926 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1927 static struct _raid_device
*raid_device
;
1928 unsigned long flags
;
1929 Mpi2RaidVolPage0_t vol_pg0
;
1930 Mpi2ConfigReply_t mpi_reply
;
1931 u32 volume_status_flags
;
1932 u8 percent_complete
;
1935 percent_complete
= 0;
1937 if (ioc
->is_warpdrive
)
1940 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1941 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1944 handle
= raid_device
->handle
;
1945 percent_complete
= raid_device
->percent_complete
;
1947 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1952 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1953 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1954 sizeof(Mpi2RaidVolPage0_t
))) {
1955 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
1956 __FILE__
, __LINE__
, __func__
);
1957 percent_complete
= 0;
1961 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1962 if (!(volume_status_flags
&
1963 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1964 percent_complete
= 0;
1968 switch (ioc
->hba_mpi_version_belonged
) {
1970 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1974 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1980 * scsih_get_state - get raid volume level
1981 * @dev: the device struct object
1984 scsih_get_state(struct device
*dev
)
1986 struct scsi_device
*sdev
= to_scsi_device(dev
);
1987 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1988 static struct _raid_device
*raid_device
;
1989 unsigned long flags
;
1990 Mpi2RaidVolPage0_t vol_pg0
;
1991 Mpi2ConfigReply_t mpi_reply
;
1993 enum raid_state state
= RAID_STATE_UNKNOWN
;
1996 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1997 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
2000 handle
= raid_device
->handle
;
2001 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2006 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
2007 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
2008 sizeof(Mpi2RaidVolPage0_t
))) {
2009 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
2010 __FILE__
, __LINE__
, __func__
);
2014 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2015 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
2016 state
= RAID_STATE_RESYNCING
;
2020 switch (vol_pg0
.VolumeState
) {
2021 case MPI2_RAID_VOL_STATE_OPTIMAL
:
2022 case MPI2_RAID_VOL_STATE_ONLINE
:
2023 state
= RAID_STATE_ACTIVE
;
2025 case MPI2_RAID_VOL_STATE_DEGRADED
:
2026 state
= RAID_STATE_DEGRADED
;
2028 case MPI2_RAID_VOL_STATE_FAILED
:
2029 case MPI2_RAID_VOL_STATE_MISSING
:
2030 state
= RAID_STATE_OFFLINE
;
2034 switch (ioc
->hba_mpi_version_belonged
) {
2036 raid_set_state(mpt2sas_raid_template
, dev
, state
);
2040 raid_set_state(mpt3sas_raid_template
, dev
, state
);
2046 * _scsih_set_level - set raid level
2048 * @sdev: scsi device struct
2049 * @volume_type: volume type
2052 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
2053 struct scsi_device
*sdev
, u8 volume_type
)
2055 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
2057 switch (volume_type
) {
2058 case MPI2_RAID_VOL_TYPE_RAID0
:
2059 level
= RAID_LEVEL_0
;
2061 case MPI2_RAID_VOL_TYPE_RAID10
:
2062 level
= RAID_LEVEL_10
;
2064 case MPI2_RAID_VOL_TYPE_RAID1E
:
2065 level
= RAID_LEVEL_1E
;
2067 case MPI2_RAID_VOL_TYPE_RAID1
:
2068 level
= RAID_LEVEL_1
;
2072 switch (ioc
->hba_mpi_version_belonged
) {
2074 raid_set_level(mpt2sas_raid_template
,
2075 &sdev
->sdev_gendev
, level
);
2079 raid_set_level(mpt3sas_raid_template
,
2080 &sdev
->sdev_gendev
, level
);
2087 * _scsih_get_volume_capabilities - volume capabilities
2088 * @ioc: per adapter object
2089 * @raid_device: the raid_device object
2091 * Return: 0 for success, else 1
2094 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
2095 struct _raid_device
*raid_device
)
2097 Mpi2RaidVolPage0_t
*vol_pg0
;
2098 Mpi2RaidPhysDiskPage0_t pd_pg0
;
2099 Mpi2SasDevicePage0_t sas_device_pg0
;
2100 Mpi2ConfigReply_t mpi_reply
;
2104 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
2105 &num_pds
)) || !num_pds
) {
2107 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2108 __FILE__
, __LINE__
, __func__
));
2112 raid_device
->num_pds
= num_pds
;
2113 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
2114 sizeof(Mpi2RaidVol0PhysDisk_t
));
2115 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
2118 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2119 __FILE__
, __LINE__
, __func__
));
2123 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
2124 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
2126 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2127 __FILE__
, __LINE__
, __func__
));
2132 raid_device
->volume_type
= vol_pg0
->VolumeType
;
2134 /* figure out what the underlying devices are by
2135 * obtaining the device_info bits for the 1st device
2137 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
2138 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
2139 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
2140 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
2141 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
2142 le16_to_cpu(pd_pg0
.DevHandle
)))) {
2143 raid_device
->device_info
=
2144 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
2153 * _scsih_enable_tlr - setting TLR flags
2154 * @ioc: per adapter object
2155 * @sdev: scsi device struct
2157 * Enabling Transaction Layer Retries for tape devices when
2158 * vpd page 0x90 is present
2162 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
2166 if (sdev
->type
!= TYPE_TAPE
)
2169 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
2172 sas_enable_tlr(sdev
);
2173 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
2174 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
2180 * scsih_slave_configure - device configure routine.
2181 * @sdev: scsi device struct
2183 * Return: 0 if ok. Any other return is assumed to be an error and
2184 * the device is ignored.
2187 scsih_slave_configure(struct scsi_device
*sdev
)
2189 struct Scsi_Host
*shost
= sdev
->host
;
2190 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2191 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2192 struct MPT3SAS_TARGET
*sas_target_priv_data
;
2193 struct _sas_device
*sas_device
;
2194 struct _pcie_device
*pcie_device
;
2195 struct _raid_device
*raid_device
;
2196 unsigned long flags
;
2201 u16 handle
, volume_handle
= 0;
2202 u64 volume_wwid
= 0;
2205 sas_device_priv_data
= sdev
->hostdata
;
2206 sas_device_priv_data
->configured_lun
= 1;
2207 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2208 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2209 handle
= sas_target_priv_data
->handle
;
2211 /* raid volume handling */
2212 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2214 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2215 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
2216 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2219 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2220 __FILE__
, __LINE__
, __func__
));
2224 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2226 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2227 __FILE__
, __LINE__
, __func__
));
2232 * WARPDRIVE: Initialize the required data for Direct IO
2234 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
2236 /* RAID Queue Depth Support
2237 * IS volume = underlying qdepth of drive type, either
2238 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2239 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2241 if (raid_device
->device_info
&
2242 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2243 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2246 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2247 if (raid_device
->device_info
&
2248 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2254 switch (raid_device
->volume_type
) {
2255 case MPI2_RAID_VOL_TYPE_RAID0
:
2258 case MPI2_RAID_VOL_TYPE_RAID1E
:
2259 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2260 if (ioc
->manu_pg10
.OEMIdentifier
&&
2261 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2262 MFG10_GF0_R10_DISPLAY
) &&
2263 !(raid_device
->num_pds
% 2))
2268 case MPI2_RAID_VOL_TYPE_RAID1
:
2269 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2272 case MPI2_RAID_VOL_TYPE_RAID10
:
2273 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2276 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2278 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2283 if (!ioc
->hide_ir_msg
)
2284 sdev_printk(KERN_INFO
, sdev
,
2285 "%s: handle(0x%04x), wwid(0x%016llx),"
2286 " pd_count(%d), type(%s)\n",
2287 r_level
, raid_device
->handle
,
2288 (unsigned long long)raid_device
->wwid
,
2289 raid_device
->num_pds
, ds
);
2291 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
2292 blk_queue_max_hw_sectors(sdev
->request_queue
,
2293 MPT3SAS_RAID_MAX_SECTORS
);
2294 sdev_printk(KERN_INFO
, sdev
,
2295 "Set queue's max_sector to: %u\n",
2296 MPT3SAS_RAID_MAX_SECTORS
);
2299 scsih_change_queue_depth(sdev
, qdepth
);
2301 /* raid transport support */
2302 if (!ioc
->is_warpdrive
)
2303 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
2307 /* non-raid handling */
2308 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2309 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
2312 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2313 __FILE__
, __LINE__
, __func__
));
2316 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
2317 volume_handle
, &volume_wwid
)) {
2319 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2320 __FILE__
, __LINE__
, __func__
));
2326 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2327 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2328 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
2329 sas_device_priv_data
->sas_target
->sas_address
);
2331 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2333 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2334 __FILE__
, __LINE__
, __func__
));
2338 qdepth
= MPT3SAS_NVME_QUEUE_DEPTH
;
2340 sdev_printk(KERN_INFO
, sdev
,
2341 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2342 ds
, handle
, (unsigned long long)pcie_device
->wwid
,
2343 pcie_device
->port_num
);
2344 if (pcie_device
->enclosure_handle
!= 0)
2345 sdev_printk(KERN_INFO
, sdev
,
2346 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2348 (unsigned long long)pcie_device
->enclosure_logical_id
,
2350 if (pcie_device
->connector_name
[0] != '\0')
2351 sdev_printk(KERN_INFO
, sdev
,
2352 "%s: enclosure level(0x%04x),"
2353 "connector name( %s)\n", ds
,
2354 pcie_device
->enclosure_level
,
2355 pcie_device
->connector_name
);
2357 if (pcie_device
->nvme_mdts
)
2358 blk_queue_max_hw_sectors(sdev
->request_queue
,
2359 pcie_device
->nvme_mdts
/512);
2361 pcie_device_put(pcie_device
);
2362 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2363 scsih_change_queue_depth(sdev
, qdepth
);
2364 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2365 ** merged and can eliminate holes created during merging
2368 blk_queue_flag_set(QUEUE_FLAG_NOMERGES
,
2369 sdev
->request_queue
);
2370 blk_queue_virt_boundary(sdev
->request_queue
,
2371 ioc
->page_size
- 1);
2375 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2376 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
2377 sas_device_priv_data
->sas_target
->sas_address
);
2379 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2381 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2382 __FILE__
, __LINE__
, __func__
));
2386 sas_device
->volume_handle
= volume_handle
;
2387 sas_device
->volume_wwid
= volume_wwid
;
2388 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2389 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2391 if (sas_device
->device_info
&
2392 MPI2_SAS_DEVICE_INFO_SEP
) {
2393 sdev_printk(KERN_WARNING
, sdev
,
2394 "set ignore_delay_remove for handle(0x%04x)\n",
2395 sas_device_priv_data
->sas_target
->handle
);
2396 sas_device_priv_data
->ignore_delay_remove
= 1;
2401 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2402 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2404 else if (sas_device
->device_info
&
2405 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2409 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2410 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2411 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2412 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2414 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, sdev
, NULL
);
2416 sas_device_put(sas_device
);
2417 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2420 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2423 scsih_change_queue_depth(sdev
, qdepth
);
2426 sas_read_port_mode_page(sdev
);
2427 _scsih_enable_tlr(ioc
, sdev
);
2434 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2435 * @sdev: scsi device struct
2436 * @bdev: pointer to block device context
2437 * @capacity: device size (in 512 byte sectors)
2438 * @params: three element array to place output:
2439 * params[0] number of heads (max 255)
2440 * params[1] number of sectors (max 63)
2441 * params[2] number of cylinders
2444 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2445 sector_t capacity
, int params
[])
2455 dummy
= heads
* sectors
;
2456 cylinders
= capacity
;
2457 sector_div(cylinders
, dummy
);
2460 * Handle extended translation size for logical drives
2463 if ((ulong
)capacity
>= 0x200000) {
2466 dummy
= heads
* sectors
;
2467 cylinders
= capacity
;
2468 sector_div(cylinders
, dummy
);
2473 params
[1] = sectors
;
2474 params
[2] = cylinders
;
2480 * _scsih_response_code - translation of device response code
2481 * @ioc: per adapter object
2482 * @response_code: response code returned by the device
2485 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2489 switch (response_code
) {
2490 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2491 desc
= "task management request completed";
2493 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2494 desc
= "invalid frame";
2496 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2497 desc
= "task management request not supported";
2499 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2500 desc
= "task management request failed";
2502 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2503 desc
= "task management request succeeded";
2505 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2506 desc
= "invalid lun";
2509 desc
= "overlapped tag attempted";
2511 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2512 desc
= "task queued, however not sent to target";
2518 ioc_warn(ioc
, "response_code(0x%01x): %s\n", response_code
, desc
);
2522 * _scsih_tm_done - tm completion routine
2523 * @ioc: per adapter object
2524 * @smid: system request message index
2525 * @msix_index: MSIX table index supplied by the OS
2526 * @reply: reply message frame(lower 32bit addr)
2529 * The callback handler when using scsih_issue_tm.
2531 * Return: 1 meaning mf should be freed from _base_interrupt
2532 * 0 means the mf is freed from this function.
2535 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2537 MPI2DefaultReply_t
*mpi_reply
;
2539 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2541 if (ioc
->tm_cmds
.smid
!= smid
)
2543 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2544 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2546 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2547 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2549 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2550 complete(&ioc
->tm_cmds
.done
);
2555 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2556 * @ioc: per adapter object
2557 * @handle: device handle
2559 * During taskmangement request, we need to freeze the device queue.
2562 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2564 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2565 struct scsi_device
*sdev
;
2568 shost_for_each_device(sdev
, ioc
->shost
) {
2571 sas_device_priv_data
= sdev
->hostdata
;
2572 if (!sas_device_priv_data
)
2574 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2575 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2577 ioc
->ignore_loginfos
= 1;
2583 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2584 * @ioc: per adapter object
2585 * @handle: device handle
2587 * During taskmangement request, we need to freeze the device queue.
2590 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2592 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2593 struct scsi_device
*sdev
;
2596 shost_for_each_device(sdev
, ioc
->shost
) {
2599 sas_device_priv_data
= sdev
->hostdata
;
2600 if (!sas_device_priv_data
)
2602 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2603 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2605 ioc
->ignore_loginfos
= 0;
2611 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2612 * @ioc: per adapter struct
2613 * @handle: device handle
2615 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2616 * @smid_task: smid assigned to the task
2617 * @msix_task: MSIX table index supplied by the OS
2618 * @timeout: timeout in seconds
2619 * @tr_method: Target Reset Method
2622 * A generic API for sending task management requests to firmware.
2624 * The callback index is set inside `ioc->tm_cb_idx`.
2625 * The caller is responsible to check for outstanding commands.
2627 * Return: SUCCESS or FAILED.
2630 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u64 lun
,
2631 u8 type
, u16 smid_task
, u16 msix_task
, u8 timeout
, u8 tr_method
)
2633 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2634 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2639 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2641 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2642 ioc_info(ioc
, "%s: tm_cmd busy!!!\n", __func__
);
2646 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2647 ioc
->pci_error_recovery
) {
2648 ioc_info(ioc
, "%s: host reset in progress!\n", __func__
);
2652 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2653 if (ioc_state
& MPI2_DOORBELL_USED
) {
2654 dhsprintk(ioc
, ioc_info(ioc
, "unexpected doorbell active!\n"));
2655 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2656 return (!rc
) ? SUCCESS
: FAILED
;
2659 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2660 mpt3sas_base_fault_info(ioc
, ioc_state
&
2661 MPI2_DOORBELL_DATA_MASK
);
2662 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2663 return (!rc
) ? SUCCESS
: FAILED
;
2666 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2668 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
2673 ioc_info(ioc
, "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
2674 handle
, type
, smid_task
, timeout
, tr_method
));
2675 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2676 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2677 ioc
->tm_cmds
.smid
= smid
;
2678 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2679 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2680 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2681 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2682 mpi_request
->TaskType
= type
;
2683 mpi_request
->MsgFlags
= tr_method
;
2684 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2685 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2686 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2687 init_completion(&ioc
->tm_cmds
.done
);
2688 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2689 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2690 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2691 if (mpt3sas_base_check_cmd_timeout(ioc
,
2692 ioc
->tm_cmds
.status
, mpi_request
,
2693 sizeof(Mpi2SCSITaskManagementRequest_t
)/4)) {
2694 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2696 rc
= (!rc
) ? SUCCESS
: FAILED
;
2701 /* sync IRQs in case those were busy during flush. */
2702 mpt3sas_base_sync_reply_irqs(ioc
);
2704 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2705 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2706 mpi_reply
= ioc
->tm_cmds
.reply
;
2708 ioc_info(ioc
, "complete tm: ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2709 le16_to_cpu(mpi_reply
->IOCStatus
),
2710 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2711 le32_to_cpu(mpi_reply
->TerminationCount
)));
2712 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2713 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2714 if (mpi_reply
->IOCStatus
)
2715 _debug_dump_mf(mpi_request
,
2716 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2722 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2723 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2727 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2728 u64 lun
, u8 type
, u16 smid_task
, u16 msix_task
,
2729 u8 timeout
, u8 tr_method
)
2733 mutex_lock(&ioc
->tm_cmds
.mutex
);
2734 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
, type
, smid_task
,
2735 msix_task
, timeout
, tr_method
);
2736 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2742 * _scsih_tm_display_info - displays info about the device
2743 * @ioc: per adapter struct
2744 * @scmd: pointer to scsi command object
2746 * Called by task management callback handlers.
2749 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2751 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2752 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2753 struct _sas_device
*sas_device
= NULL
;
2754 struct _pcie_device
*pcie_device
= NULL
;
2755 unsigned long flags
;
2756 char *device_str
= NULL
;
2760 if (ioc
->hide_ir_msg
)
2761 device_str
= "WarpDrive";
2763 device_str
= "volume";
2765 scsi_print_command(scmd
);
2766 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2767 starget_printk(KERN_INFO
, starget
,
2768 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2769 device_str
, priv_target
->handle
,
2770 device_str
, (unsigned long long)priv_target
->sas_address
);
2772 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2773 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2774 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
, priv_target
);
2776 starget_printk(KERN_INFO
, starget
,
2777 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2778 pcie_device
->handle
,
2779 (unsigned long long)pcie_device
->wwid
,
2780 pcie_device
->port_num
);
2781 if (pcie_device
->enclosure_handle
!= 0)
2782 starget_printk(KERN_INFO
, starget
,
2783 "enclosure logical id(0x%016llx), slot(%d)\n",
2784 (unsigned long long)
2785 pcie_device
->enclosure_logical_id
,
2787 if (pcie_device
->connector_name
[0] != '\0')
2788 starget_printk(KERN_INFO
, starget
,
2789 "enclosure level(0x%04x), connector name( %s)\n",
2790 pcie_device
->enclosure_level
,
2791 pcie_device
->connector_name
);
2792 pcie_device_put(pcie_device
);
2794 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2797 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2798 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2800 if (priv_target
->flags
&
2801 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2802 starget_printk(KERN_INFO
, starget
,
2803 "volume handle(0x%04x), "
2804 "volume wwid(0x%016llx)\n",
2805 sas_device
->volume_handle
,
2806 (unsigned long long)sas_device
->volume_wwid
);
2808 starget_printk(KERN_INFO
, starget
,
2809 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2811 (unsigned long long)sas_device
->sas_address
,
2814 _scsih_display_enclosure_chassis_info(NULL
, sas_device
,
2817 sas_device_put(sas_device
);
2819 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2824 * scsih_abort - eh threads main abort routine
2825 * @scmd: pointer to scsi command object
2827 * Return: SUCCESS if command aborted else FAILED
2830 scsih_abort(struct scsi_cmnd
*scmd
)
2832 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2833 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2834 struct scsiio_tracker
*st
= scsi_cmd_priv(scmd
);
2839 struct _pcie_device
*pcie_device
= NULL
;
2840 sdev_printk(KERN_INFO
, scmd
->device
,
2841 "attempting task abort! scmd(%p)\n", scmd
);
2842 _scsih_tm_display_info(ioc
, scmd
);
2844 sas_device_priv_data
= scmd
->device
->hostdata
;
2845 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2847 sdev_printk(KERN_INFO
, scmd
->device
,
2848 "device been deleted! scmd(%p)\n", scmd
);
2849 scmd
->result
= DID_NO_CONNECT
<< 16;
2850 scmd
->scsi_done(scmd
);
2855 /* check for completed command */
2856 if (st
== NULL
|| st
->cb_idx
== 0xFF) {
2857 scmd
->result
= DID_RESET
<< 16;
2862 /* for hidden raid components and volumes this is not supported */
2863 if (sas_device_priv_data
->sas_target
->flags
&
2864 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2865 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2866 scmd
->result
= DID_RESET
<< 16;
2871 mpt3sas_halt_firmware(ioc
);
2873 handle
= sas_device_priv_data
->sas_target
->handle
;
2874 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
2875 if (pcie_device
&& (!ioc
->tm_custom_handling
))
2876 timeout
= ioc
->nvme_abort_timeout
;
2877 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2878 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
,
2879 st
->smid
, st
->msix_io
, timeout
, 0);
2880 /* Command must be cleared after abort */
2881 if (r
== SUCCESS
&& st
->cb_idx
!= 0xFF)
2884 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2885 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2887 pcie_device_put(pcie_device
);
2892 * scsih_dev_reset - eh threads main device reset routine
2893 * @scmd: pointer to scsi command object
2895 * Return: SUCCESS if command aborted else FAILED
2898 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2900 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2901 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2902 struct _sas_device
*sas_device
= NULL
;
2903 struct _pcie_device
*pcie_device
= NULL
;
2909 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2910 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2912 sdev_printk(KERN_INFO
, scmd
->device
,
2913 "attempting device reset! scmd(%p)\n", scmd
);
2914 _scsih_tm_display_info(ioc
, scmd
);
2916 sas_device_priv_data
= scmd
->device
->hostdata
;
2917 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2919 sdev_printk(KERN_INFO
, scmd
->device
,
2920 "device been deleted! scmd(%p)\n", scmd
);
2921 scmd
->result
= DID_NO_CONNECT
<< 16;
2922 scmd
->scsi_done(scmd
);
2927 /* for hidden raid components obtain the volume_handle */
2929 if (sas_device_priv_data
->sas_target
->flags
&
2930 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2931 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2934 handle
= sas_device
->volume_handle
;
2936 handle
= sas_device_priv_data
->sas_target
->handle
;
2939 scmd
->result
= DID_RESET
<< 16;
2944 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
2946 if (pcie_device
&& (!ioc
->tm_custom_handling
)) {
2947 tr_timeout
= pcie_device
->reset_timeout
;
2948 tr_method
= MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
2950 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
2951 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2952 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 0,
2953 tr_timeout
, tr_method
);
2954 /* Check for busy commands after reset */
2955 if (r
== SUCCESS
&& atomic_read(&scmd
->device
->device_busy
))
2958 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2959 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2962 sas_device_put(sas_device
);
2964 pcie_device_put(pcie_device
);
2970 * scsih_target_reset - eh threads main target reset routine
2971 * @scmd: pointer to scsi command object
2973 * Return: SUCCESS if command aborted else FAILED
2976 scsih_target_reset(struct scsi_cmnd
*scmd
)
2978 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2979 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2980 struct _sas_device
*sas_device
= NULL
;
2981 struct _pcie_device
*pcie_device
= NULL
;
2986 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2987 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2989 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2991 _scsih_tm_display_info(ioc
, scmd
);
2993 sas_device_priv_data
= scmd
->device
->hostdata
;
2994 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2996 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2998 scmd
->result
= DID_NO_CONNECT
<< 16;
2999 scmd
->scsi_done(scmd
);
3004 /* for hidden raid components obtain the volume_handle */
3006 if (sas_device_priv_data
->sas_target
->flags
&
3007 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
3008 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
3011 handle
= sas_device
->volume_handle
;
3013 handle
= sas_device_priv_data
->sas_target
->handle
;
3016 scmd
->result
= DID_RESET
<< 16;
3021 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
3023 if (pcie_device
&& (!ioc
->tm_custom_handling
)) {
3024 tr_timeout
= pcie_device
->reset_timeout
;
3025 tr_method
= MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
3027 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
3028 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, 0,
3029 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 0,
3030 tr_timeout
, tr_method
);
3031 /* Check for busy commands after reset */
3032 if (r
== SUCCESS
&& atomic_read(&starget
->target_busy
))
3035 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
3036 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3039 sas_device_put(sas_device
);
3041 pcie_device_put(pcie_device
);
3047 * scsih_host_reset - eh threads main host reset routine
3048 * @scmd: pointer to scsi command object
3050 * Return: SUCCESS if command aborted else FAILED
3053 scsih_host_reset(struct scsi_cmnd
*scmd
)
3055 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3058 ioc_info(ioc
, "attempting host reset! scmd(%p)\n", scmd
);
3059 scsi_print_command(scmd
);
3061 if (ioc
->is_driver_loading
|| ioc
->remove_host
) {
3062 ioc_info(ioc
, "Blocking the host reset\n");
3067 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
3068 r
= (retval
< 0) ? FAILED
: SUCCESS
;
3070 ioc_info(ioc
, "host reset: %s scmd(%p)\n",
3071 r
== SUCCESS
? "SUCCESS" : "FAILED", scmd
);
3077 * _scsih_fw_event_add - insert and queue up fw_event
3078 * @ioc: per adapter object
3079 * @fw_event: object describing the event
3080 * Context: This function will acquire ioc->fw_event_lock.
3082 * This adds the firmware event object into link list, then queues it up to
3083 * be processed from user context.
3086 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
3088 unsigned long flags
;
3090 if (ioc
->firmware_event_thread
== NULL
)
3093 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3094 fw_event_work_get(fw_event
);
3095 INIT_LIST_HEAD(&fw_event
->list
);
3096 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
3097 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
3098 fw_event_work_get(fw_event
);
3099 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
3100 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3104 * _scsih_fw_event_del_from_list - delete fw_event from the list
3105 * @ioc: per adapter object
3106 * @fw_event: object describing the event
3107 * Context: This function will acquire ioc->fw_event_lock.
3109 * If the fw_event is on the fw_event_list, remove it and do a put.
3112 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
3115 unsigned long flags
;
3117 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3118 if (!list_empty(&fw_event
->list
)) {
3119 list_del_init(&fw_event
->list
);
3120 fw_event_work_put(fw_event
);
3122 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3127 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3128 * @ioc: per adapter object
3129 * @event_data: trigger event data
3132 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
3133 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
3135 struct fw_event_work
*fw_event
;
3138 if (ioc
->is_driver_loading
)
3140 sz
= sizeof(*event_data
);
3141 fw_event
= alloc_fw_event_work(sz
);
3144 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
3145 fw_event
->ioc
= ioc
;
3146 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
3147 _scsih_fw_event_add(ioc
, fw_event
);
3148 fw_event_work_put(fw_event
);
3152 * _scsih_error_recovery_delete_devices - remove devices not responding
3153 * @ioc: per adapter object
3156 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
3158 struct fw_event_work
*fw_event
;
3160 if (ioc
->is_driver_loading
)
3162 fw_event
= alloc_fw_event_work(0);
3165 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
3166 fw_event
->ioc
= ioc
;
3167 _scsih_fw_event_add(ioc
, fw_event
);
3168 fw_event_work_put(fw_event
);
3172 * mpt3sas_port_enable_complete - port enable completed (fake event)
3173 * @ioc: per adapter object
3176 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
3178 struct fw_event_work
*fw_event
;
3180 fw_event
= alloc_fw_event_work(0);
3183 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
3184 fw_event
->ioc
= ioc
;
3185 _scsih_fw_event_add(ioc
, fw_event
);
3186 fw_event_work_put(fw_event
);
3189 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
3191 unsigned long flags
;
3192 struct fw_event_work
*fw_event
= NULL
;
3194 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3195 if (!list_empty(&ioc
->fw_event_list
)) {
3196 fw_event
= list_first_entry(&ioc
->fw_event_list
,
3197 struct fw_event_work
, list
);
3198 list_del_init(&fw_event
->list
);
3200 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3206 * _scsih_fw_event_cleanup_queue - cleanup event queue
3207 * @ioc: per adapter object
3209 * Walk the firmware event queue, either killing timers, or waiting
3210 * for outstanding events to complete
3213 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
3215 struct fw_event_work
*fw_event
;
3217 if (list_empty(&ioc
->fw_event_list
) ||
3218 !ioc
->firmware_event_thread
|| in_interrupt())
3221 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
3223 * Wait on the fw_event to complete. If this returns 1, then
3224 * the event was never executed, and we need a put for the
3225 * reference the work had on the fw_event.
3227 * If it did execute, we wait for it to finish, and the put will
3228 * happen from _firmware_event_work()
3230 if (cancel_work_sync(&fw_event
->work
))
3231 fw_event_work_put(fw_event
);
3233 fw_event_work_put(fw_event
);
3238 * _scsih_internal_device_block - block the sdev device
3239 * @sdev: per device object
3240 * @sas_device_priv_data : per device driver private data
3242 * make sure device is blocked without error, if not
3246 _scsih_internal_device_block(struct scsi_device
*sdev
,
3247 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3251 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
3252 sas_device_priv_data
->sas_target
->handle
);
3253 sas_device_priv_data
->block
= 1;
3255 r
= scsi_internal_device_block_nowait(sdev
);
3257 sdev_printk(KERN_WARNING
, sdev
,
3258 "device_block failed with return(%d) for handle(0x%04x)\n",
3259 r
, sas_device_priv_data
->sas_target
->handle
);
3263 * _scsih_internal_device_unblock - unblock the sdev device
3264 * @sdev: per device object
3265 * @sas_device_priv_data : per device driver private data
3266 * make sure device is unblocked without error, if not retry
3267 * by blocking and then unblocking
3271 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
3272 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3276 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
3277 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
3278 sas_device_priv_data
->block
= 0;
3279 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3281 /* The device has been set to SDEV_RUNNING by SD layer during
3282 * device addition but the request queue is still stopped by
3283 * our earlier block call. We need to perform a block again
3284 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3286 sdev_printk(KERN_WARNING
, sdev
,
3287 "device_unblock failed with return(%d) for handle(0x%04x) "
3288 "performing a block followed by an unblock\n",
3289 r
, sas_device_priv_data
->sas_target
->handle
);
3290 sas_device_priv_data
->block
= 1;
3291 r
= scsi_internal_device_block_nowait(sdev
);
3293 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
3294 "failed with return(%d) for handle(0x%04x)\n",
3295 r
, 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 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
3301 " failed with return(%d) for handle(0x%04x)\n",
3302 r
, sas_device_priv_data
->sas_target
->handle
);
3307 * _scsih_ublock_io_all_device - unblock every device
3308 * @ioc: per adapter object
3310 * change the device state from block to running
3313 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3315 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3316 struct scsi_device
*sdev
;
3318 shost_for_each_device(sdev
, ioc
->shost
) {
3319 sas_device_priv_data
= sdev
->hostdata
;
3320 if (!sas_device_priv_data
)
3322 if (!sas_device_priv_data
->block
)
3325 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3326 "device_running, handle(0x%04x)\n",
3327 sas_device_priv_data
->sas_target
->handle
));
3328 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
3334 * _scsih_ublock_io_device - prepare device to be deleted
3335 * @ioc: per adapter object
3336 * @sas_address: sas address
3338 * unblock then put device in offline state
3341 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
3343 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3344 struct scsi_device
*sdev
;
3346 shost_for_each_device(sdev
, ioc
->shost
) {
3347 sas_device_priv_data
= sdev
->hostdata
;
3348 if (!sas_device_priv_data
)
3350 if (sas_device_priv_data
->sas_target
->sas_address
3353 if (sas_device_priv_data
->block
)
3354 _scsih_internal_device_unblock(sdev
,
3355 sas_device_priv_data
);
3360 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3361 * @ioc: per adapter object
3363 * During device pull we need to appropriately set the sdev state.
3366 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3368 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3369 struct scsi_device
*sdev
;
3371 shost_for_each_device(sdev
, ioc
->shost
) {
3372 sas_device_priv_data
= sdev
->hostdata
;
3373 if (!sas_device_priv_data
)
3375 if (sas_device_priv_data
->block
)
3377 if (sas_device_priv_data
->ignore_delay_remove
) {
3378 sdev_printk(KERN_INFO
, sdev
,
3379 "%s skip device_block for SES handle(0x%04x)\n",
3380 __func__
, sas_device_priv_data
->sas_target
->handle
);
3383 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3388 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3389 * @ioc: per adapter object
3390 * @handle: device handle
3392 * During device pull we need to appropriately set the sdev state.
3395 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3397 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3398 struct scsi_device
*sdev
;
3399 struct _sas_device
*sas_device
;
3401 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3403 shost_for_each_device(sdev
, ioc
->shost
) {
3404 sas_device_priv_data
= sdev
->hostdata
;
3405 if (!sas_device_priv_data
)
3407 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3409 if (sas_device_priv_data
->block
)
3411 if (sas_device
&& sas_device
->pend_sas_rphy_add
)
3413 if (sas_device_priv_data
->ignore_delay_remove
) {
3414 sdev_printk(KERN_INFO
, sdev
,
3415 "%s skip device_block for SES handle(0x%04x)\n",
3416 __func__
, sas_device_priv_data
->sas_target
->handle
);
3419 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3423 sas_device_put(sas_device
);
3427 * _scsih_block_io_to_children_attached_to_ex
3428 * @ioc: per adapter object
3429 * @sas_expander: the sas_device object
3431 * This routine set sdev state to SDEV_BLOCK for all devices
3432 * attached to this expander. This function called when expander is
3436 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3437 struct _sas_node
*sas_expander
)
3439 struct _sas_port
*mpt3sas_port
;
3440 struct _sas_device
*sas_device
;
3441 struct _sas_node
*expander_sibling
;
3442 unsigned long flags
;
3447 list_for_each_entry(mpt3sas_port
,
3448 &sas_expander
->sas_port_list
, port_list
) {
3449 if (mpt3sas_port
->remote_identify
.device_type
==
3451 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3452 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3453 mpt3sas_port
->remote_identify
.sas_address
);
3455 set_bit(sas_device
->handle
,
3456 ioc
->blocking_handles
);
3457 sas_device_put(sas_device
);
3459 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3463 list_for_each_entry(mpt3sas_port
,
3464 &sas_expander
->sas_port_list
, port_list
) {
3466 if (mpt3sas_port
->remote_identify
.device_type
==
3467 SAS_EDGE_EXPANDER_DEVICE
||
3468 mpt3sas_port
->remote_identify
.device_type
==
3469 SAS_FANOUT_EXPANDER_DEVICE
) {
3471 mpt3sas_scsih_expander_find_by_sas_address(
3472 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3473 _scsih_block_io_to_children_attached_to_ex(ioc
,
3480 * _scsih_block_io_to_children_attached_directly
3481 * @ioc: per adapter object
3482 * @event_data: topology change event data
3484 * This routine set sdev state to SDEV_BLOCK for all devices
3485 * direct attached during device pull.
3488 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3489 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3495 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3496 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3499 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3500 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3501 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3502 _scsih_block_io_device(ioc
, handle
);
3507 * _scsih_block_io_to_pcie_children_attached_directly
3508 * @ioc: per adapter object
3509 * @event_data: topology change event data
3511 * This routine set sdev state to SDEV_BLOCK for all devices
3512 * direct attached during device pull/reconnect.
3515 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3516 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
3522 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3524 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
3527 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
3529 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
)
3530 _scsih_block_io_device(ioc
, handle
);
3534 * _scsih_tm_tr_send - send task management request
3535 * @ioc: per adapter object
3536 * @handle: device handle
3537 * Context: interrupt time.
3539 * This code is to initiate the device removal handshake protocol
3540 * with controller firmware. This function will issue target reset
3541 * using high priority request queue. It will send a sas iounit
3542 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3544 * This is designed to send muliple task management request at the same
3545 * time to the fifo. If the fifo is full, we will append the request,
3546 * and process it in a future completion.
3549 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3551 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3553 struct _sas_device
*sas_device
= NULL
;
3554 struct _pcie_device
*pcie_device
= NULL
;
3555 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3556 u64 sas_address
= 0;
3557 unsigned long flags
;
3558 struct _tr_list
*delayed_tr
;
3562 if (ioc
->pci_error_recovery
) {
3564 ioc_info(ioc
, "%s: host in pci error recovery: handle(0x%04x)\n",
3568 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3569 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3571 ioc_info(ioc
, "%s: host is not operational: handle(0x%04x)\n",
3576 /* if PD, then return */
3577 if (test_bit(handle
, ioc
->pd_handles
))
3580 clear_bit(handle
, ioc
->pend_os_device_add
);
3582 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3583 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3584 if (sas_device
&& sas_device
->starget
&&
3585 sas_device
->starget
->hostdata
) {
3586 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3587 sas_target_priv_data
->deleted
= 1;
3588 sas_address
= sas_device
->sas_address
;
3590 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3592 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
3593 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
3594 if (pcie_device
&& pcie_device
->starget
&&
3595 pcie_device
->starget
->hostdata
) {
3596 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
3597 sas_target_priv_data
->deleted
= 1;
3598 sas_address
= pcie_device
->wwid
;
3600 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
3601 if (pcie_device
&& (!ioc
->tm_custom_handling
))
3603 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
3605 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
3607 if (sas_target_priv_data
) {
3609 ioc_info(ioc
, "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3610 handle
, (u64
)sas_address
));
3612 if (sas_device
->enclosure_handle
!= 0)
3614 ioc_info(ioc
, "setting delete flag:enclosure logical id(0x%016llx), slot(%d)\n",
3615 (u64
)sas_device
->enclosure_logical_id
,
3617 if (sas_device
->connector_name
[0] != '\0')
3619 ioc_info(ioc
, "setting delete flag: enclosure level(0x%04x), connector name( %s)\n",
3620 sas_device
->enclosure_level
,
3621 sas_device
->connector_name
));
3622 } else if (pcie_device
) {
3623 if (pcie_device
->enclosure_handle
!= 0)
3625 ioc_info(ioc
, "setting delete flag: logical id(0x%016llx), slot(%d)\n",
3626 (u64
)pcie_device
->enclosure_logical_id
,
3627 pcie_device
->slot
));
3628 if (pcie_device
->connector_name
[0] != '\0')
3630 ioc_info(ioc
, "setting delete flag:, enclosure level(0x%04x), connector name( %s)\n",
3631 pcie_device
->enclosure_level
,
3632 pcie_device
->connector_name
));
3634 _scsih_ublock_io_device(ioc
, sas_address
);
3635 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3638 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3640 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3643 INIT_LIST_HEAD(&delayed_tr
->list
);
3644 delayed_tr
->handle
= handle
;
3645 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3647 ioc_info(ioc
, "DELAYED:tr:handle(0x%04x), (open)\n",
3653 ioc_info(ioc
, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3654 handle
, smid
, ioc
->tm_tr_cb_idx
));
3655 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3656 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3657 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3658 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3659 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3660 mpi_request
->MsgFlags
= tr_method
;
3661 set_bit(handle
, ioc
->device_remove_in_progress
);
3662 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3663 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3667 sas_device_put(sas_device
);
3669 pcie_device_put(pcie_device
);
3673 * _scsih_tm_tr_complete -
3674 * @ioc: per adapter object
3675 * @smid: system request message index
3676 * @msix_index: MSIX table index supplied by the OS
3677 * @reply: reply message frame(lower 32bit addr)
3678 * Context: interrupt time.
3680 * This is the target reset completion routine.
3681 * This code is part of the code to initiate the device removal
3682 * handshake protocol with controller firmware.
3683 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3685 * Return: 1 meaning mf should be freed from _base_interrupt
3686 * 0 means the mf is freed from this function.
3689 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3693 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3694 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3695 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3696 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3699 struct _sc_list
*delayed_sc
;
3701 if (ioc
->pci_error_recovery
) {
3703 ioc_info(ioc
, "%s: host in pci error recovery\n",
3707 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3708 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3710 ioc_info(ioc
, "%s: host is not operational\n",
3714 if (unlikely(!mpi_reply
)) {
3715 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
3716 __FILE__
, __LINE__
, __func__
);
3719 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3720 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3721 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3723 ioc_err(ioc
, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3725 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3729 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3731 ioc_info(ioc
, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
3732 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3733 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3734 le32_to_cpu(mpi_reply
->TerminationCount
)));
3736 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3737 if (!smid_sas_ctrl
) {
3738 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3740 return _scsih_check_for_pending_tm(ioc
, smid
);
3741 INIT_LIST_HEAD(&delayed_sc
->list
);
3742 delayed_sc
->handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3743 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3745 ioc_info(ioc
, "DELAYED:sc:handle(0x%04x), (open)\n",
3747 return _scsih_check_for_pending_tm(ioc
, smid
);
3751 ioc_info(ioc
, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3752 handle
, smid_sas_ctrl
, ioc
->tm_sas_control_cb_idx
));
3753 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3754 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3755 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3756 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3757 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3758 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3760 return _scsih_check_for_pending_tm(ioc
, smid
);
3763 /** _scsih_allow_scmd_to_device - check whether scmd needs to
3764 * issue to IOC or not.
3765 * @ioc: per adapter object
3766 * @scmd: pointer to scsi command object
3768 * Returns true if scmd can be issued to IOC otherwise returns false.
3770 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER
*ioc
,
3771 struct scsi_cmnd
*scmd
)
3774 if (ioc
->pci_error_recovery
)
3777 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
) {
3778 if (ioc
->remove_host
)
3784 if (ioc
->remove_host
) {
3786 switch (scmd
->cmnd
[0]) {
3787 case SYNCHRONIZE_CACHE
:
3799 * _scsih_sas_control_complete - completion routine
3800 * @ioc: per adapter object
3801 * @smid: system request message index
3802 * @msix_index: MSIX table index supplied by the OS
3803 * @reply: reply message frame(lower 32bit addr)
3804 * Context: interrupt time.
3806 * This is the sas iounit control completion routine.
3807 * This code is part of the code to initiate the device removal
3808 * handshake protocol with controller firmware.
3810 * Return: 1 meaning mf should be freed from _base_interrupt
3811 * 0 means the mf is freed from this function.
3814 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3815 u8 msix_index
, u32 reply
)
3817 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3818 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3820 if (likely(mpi_reply
)) {
3822 ioc_info(ioc
, "sc_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3823 le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3824 le16_to_cpu(mpi_reply
->IOCStatus
),
3825 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3826 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3827 MPI2_IOCSTATUS_SUCCESS
) {
3828 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3829 ioc
->device_remove_in_progress
);
3832 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
3833 __FILE__
, __LINE__
, __func__
);
3835 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3839 * _scsih_tm_tr_volume_send - send target reset request for volumes
3840 * @ioc: per adapter object
3841 * @handle: device handle
3842 * Context: interrupt time.
3844 * This is designed to send muliple task management request at the same
3845 * time to the fifo. If the fifo is full, we will append the request,
3846 * and process it in a future completion.
3849 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3851 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3853 struct _tr_list
*delayed_tr
;
3855 if (ioc
->pci_error_recovery
) {
3857 ioc_info(ioc
, "%s: host reset in progress!\n",
3862 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3864 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3867 INIT_LIST_HEAD(&delayed_tr
->list
);
3868 delayed_tr
->handle
= handle
;
3869 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3871 ioc_info(ioc
, "DELAYED:tr:handle(0x%04x), (open)\n",
3877 ioc_info(ioc
, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3878 handle
, smid
, ioc
->tm_tr_volume_cb_idx
));
3879 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3880 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3881 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3882 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3883 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3884 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3888 * _scsih_tm_volume_tr_complete - target reset completion
3889 * @ioc: per adapter object
3890 * @smid: system request message index
3891 * @msix_index: MSIX table index supplied by the OS
3892 * @reply: reply message frame(lower 32bit addr)
3893 * Context: interrupt time.
3895 * Return: 1 meaning mf should be freed from _base_interrupt
3896 * 0 means the mf is freed from this function.
3899 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3900 u8 msix_index
, u32 reply
)
3903 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3904 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3905 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3907 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
) {
3909 ioc_info(ioc
, "%s: host reset in progress!\n",
3913 if (unlikely(!mpi_reply
)) {
3914 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
3915 __FILE__
, __LINE__
, __func__
);
3919 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3920 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3921 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3923 ioc_err(ioc
, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3924 handle
, le16_to_cpu(mpi_reply
->DevHandle
),
3930 ioc_info(ioc
, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
3931 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3932 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3933 le32_to_cpu(mpi_reply
->TerminationCount
)));
3935 return _scsih_check_for_pending_tm(ioc
, smid
);
3939 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3940 * @ioc: per adapter object
3941 * @smid: system request message index
3943 * @event_context: used to track events uniquely
3945 * Context - processed in interrupt context.
3948 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, U16 event
,
3951 Mpi2EventAckRequest_t
*ack_request
;
3952 int i
= smid
- ioc
->internal_smid
;
3953 unsigned long flags
;
3955 /* Without releasing the smid just update the
3956 * call back index and reuse the same smid for
3957 * processing this delayed request
3959 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3960 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3961 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3964 ioc_info(ioc
, "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3965 le16_to_cpu(event
), smid
, ioc
->base_cb_idx
));
3966 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3967 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3968 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3969 ack_request
->Event
= event
;
3970 ack_request
->EventContext
= event_context
;
3971 ack_request
->VF_ID
= 0; /* TODO */
3972 ack_request
->VP_ID
= 0;
3973 ioc
->put_smid_default(ioc
, smid
);
3977 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3978 * sas_io_unit_ctrl messages
3979 * @ioc: per adapter object
3980 * @smid: system request message index
3981 * @handle: device handle
3983 * Context - processed in interrupt context.
3986 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
3987 u16 smid
, u16 handle
)
3989 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3991 int i
= smid
- ioc
->internal_smid
;
3992 unsigned long flags
;
3994 if (ioc
->remove_host
) {
3996 ioc_info(ioc
, "%s: host has been removed\n",
3999 } else if (ioc
->pci_error_recovery
) {
4001 ioc_info(ioc
, "%s: host in pci error recovery\n",
4005 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4006 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4008 ioc_info(ioc
, "%s: host is not operational\n",
4013 /* Without releasing the smid just update the
4014 * call back index and reuse the same smid for
4015 * processing this delayed request
4017 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4018 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
4019 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4022 ioc_info(ioc
, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4023 handle
, smid
, ioc
->tm_sas_control_cb_idx
));
4024 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4025 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4026 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4027 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4028 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4029 ioc
->put_smid_default(ioc
, smid
);
4033 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
4034 * @ioc: per adapter object
4035 * @smid: system request message index
4037 * Context: Executed in interrupt context
4039 * This will check delayed internal messages list, and process the
4042 * Return: 1 meaning mf should be freed from _base_interrupt
4043 * 0 means the mf is freed from this function.
4046 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4048 struct _sc_list
*delayed_sc
;
4049 struct _event_ack_list
*delayed_event_ack
;
4051 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
4052 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
4053 struct _event_ack_list
, list
);
4054 _scsih_issue_delayed_event_ack(ioc
, smid
,
4055 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
4056 list_del(&delayed_event_ack
->list
);
4057 kfree(delayed_event_ack
);
4061 if (!list_empty(&ioc
->delayed_sc_list
)) {
4062 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
4063 struct _sc_list
, list
);
4064 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
4065 delayed_sc
->handle
);
4066 list_del(&delayed_sc
->list
);
4074 * _scsih_check_for_pending_tm - check for pending task management
4075 * @ioc: per adapter object
4076 * @smid: system request message index
4078 * This will check delayed target reset list, and feed the
4081 * Return: 1 meaning mf should be freed from _base_interrupt
4082 * 0 means the mf is freed from this function.
4085 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4087 struct _tr_list
*delayed_tr
;
4089 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
4090 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
4091 struct _tr_list
, list
);
4092 mpt3sas_base_free_smid(ioc
, smid
);
4093 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
4094 list_del(&delayed_tr
->list
);
4099 if (!list_empty(&ioc
->delayed_tr_list
)) {
4100 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
4101 struct _tr_list
, list
);
4102 mpt3sas_base_free_smid(ioc
, smid
);
4103 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
4104 list_del(&delayed_tr
->list
);
4113 * _scsih_check_topo_delete_events - sanity check on topo events
4114 * @ioc: per adapter object
4115 * @event_data: the event data payload
4117 * This routine added to better handle cable breaker.
4119 * This handles the case where driver receives multiple expander
4120 * add and delete events in a single shot. When there is a delete event
4121 * the routine will void any pending add events waiting in the event queue.
4124 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4125 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4127 struct fw_event_work
*fw_event
;
4128 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
4129 u16 expander_handle
;
4130 struct _sas_node
*sas_expander
;
4131 unsigned long flags
;
4135 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
4136 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4139 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4140 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4141 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
4142 _scsih_tm_tr_send(ioc
, handle
);
4145 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4146 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
4147 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4150 if (event_data
->ExpStatus
==
4151 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
4152 /* put expander attached devices into blocking state */
4153 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4154 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
4156 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
4157 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4159 handle
= find_first_bit(ioc
->blocking_handles
,
4160 ioc
->facts
.MaxDevHandle
);
4161 if (handle
< ioc
->facts
.MaxDevHandle
)
4162 _scsih_block_io_device(ioc
, handle
);
4163 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
4164 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
4165 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4167 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4170 /* mark ignore flag for pending events */
4171 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4172 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4173 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
4176 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
4177 fw_event
->event_data
;
4178 if (local_event_data
->ExpStatus
==
4179 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4180 local_event_data
->ExpStatus
==
4181 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4182 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
4185 ioc_info(ioc
, "setting ignoring flag\n"));
4186 fw_event
->ignore
= 1;
4190 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4194 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4196 * @ioc: per adapter object
4197 * @event_data: the event data payload
4199 * This handles the case where driver receives multiple switch
4200 * or device add and delete events in a single shot. When there
4201 * is a delete event the routine will void any pending add
4202 * events waiting in the event queue.
4205 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER
*ioc
,
4206 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
4208 struct fw_event_work
*fw_event
;
4209 Mpi26EventDataPCIeTopologyChangeList_t
*local_event_data
;
4210 unsigned long flags
;
4212 u16 handle
, switch_handle
;
4214 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4216 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
4219 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
4220 if (reason_code
== MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
)
4221 _scsih_tm_tr_send(ioc
, handle
);
4224 switch_handle
= le16_to_cpu(event_data
->SwitchDevHandle
);
4225 if (!switch_handle
) {
4226 _scsih_block_io_to_pcie_children_attached_directly(
4230 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4231 if ((event_data
->SwitchStatus
4232 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
) ||
4233 (event_data
->SwitchStatus
==
4234 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
))
4235 _scsih_block_io_to_pcie_children_attached_directly(
4238 if (event_data
->SwitchStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4241 /* mark ignore flag for pending events */
4242 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4243 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4244 if (fw_event
->event
!= MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
||
4248 (Mpi26EventDataPCIeTopologyChangeList_t
*)
4249 fw_event
->event_data
;
4250 if (local_event_data
->SwitchStatus
==
4251 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4252 local_event_data
->SwitchStatus
==
4253 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4254 if (le16_to_cpu(local_event_data
->SwitchDevHandle
) ==
4257 ioc_info(ioc
, "setting ignoring flag for switch event\n"));
4258 fw_event
->ignore
= 1;
4262 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4266 * _scsih_set_volume_delete_flag - setting volume delete flag
4267 * @ioc: per adapter object
4268 * @handle: device handle
4270 * This returns nothing.
4273 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4275 struct _raid_device
*raid_device
;
4276 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4277 unsigned long flags
;
4279 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4280 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
4281 if (raid_device
&& raid_device
->starget
&&
4282 raid_device
->starget
->hostdata
) {
4283 sas_target_priv_data
=
4284 raid_device
->starget
->hostdata
;
4285 sas_target_priv_data
->deleted
= 1;
4287 ioc_info(ioc
, "setting delete flag: handle(0x%04x), wwid(0x%016llx)\n",
4288 handle
, (u64
)raid_device
->wwid
));
4290 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4294 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4295 * @handle: input handle
4296 * @a: handle for volume a
4297 * @b: handle for volume b
4299 * IR firmware only supports two raid volumes. The purpose of this
4300 * routine is to set the volume handle in either a or b. When the given
4301 * input handle is non-zero, or when a and b have not been set before.
4304 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
4306 if (!handle
|| handle
== *a
|| handle
== *b
)
4315 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4316 * @ioc: per adapter object
4317 * @event_data: the event data payload
4318 * Context: interrupt time.
4320 * This routine will send target reset to volume, followed by target
4321 * resets to the PDs. This is called when a PD has been removed, or
4322 * volume has been deleted or removed. When the target reset is sent
4323 * to volume, the PD target resets need to be queued to start upon
4324 * completion of the volume target reset.
4327 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
4328 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4330 Mpi2EventIrConfigElement_t
*element
;
4332 u16 handle
, volume_handle
, a
, b
;
4333 struct _tr_list
*delayed_tr
;
4338 if (ioc
->is_warpdrive
)
4341 /* Volume Resets for Deleted or Removed */
4342 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4343 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4344 if (le32_to_cpu(event_data
->Flags
) &
4345 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4347 if (element
->ReasonCode
==
4348 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
4349 element
->ReasonCode
==
4350 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
4351 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4352 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
4353 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4357 /* Volume Resets for UNHIDE events */
4358 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4359 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4360 if (le32_to_cpu(event_data
->Flags
) &
4361 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4363 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
4364 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4365 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4370 _scsih_tm_tr_volume_send(ioc
, a
);
4372 _scsih_tm_tr_volume_send(ioc
, b
);
4374 /* PD target resets */
4375 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4376 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4377 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
4379 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4380 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4381 clear_bit(handle
, ioc
->pd_handles
);
4383 _scsih_tm_tr_send(ioc
, handle
);
4384 else if (volume_handle
== a
|| volume_handle
== b
) {
4385 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
4386 BUG_ON(!delayed_tr
);
4387 INIT_LIST_HEAD(&delayed_tr
->list
);
4388 delayed_tr
->handle
= handle
;
4389 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
4391 ioc_info(ioc
, "DELAYED:tr:handle(0x%04x), (open)\n",
4394 _scsih_tm_tr_send(ioc
, handle
);
4400 * _scsih_check_volume_delete_events - set delete flag for volumes
4401 * @ioc: per adapter object
4402 * @event_data: the event data payload
4403 * Context: interrupt time.
4405 * This will handle the case when the cable connected to entire volume is
4406 * pulled. We will take care of setting the deleted flag so normal IO will
4410 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4411 Mpi2EventDataIrVolume_t
*event_data
)
4415 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4417 state
= le32_to_cpu(event_data
->NewValue
);
4418 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
4419 MPI2_RAID_VOL_STATE_FAILED
)
4420 _scsih_set_volume_delete_flag(ioc
,
4421 le16_to_cpu(event_data
->VolDevHandle
));
4425 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4426 * @ioc: per adapter object
4427 * @event_data: the temp threshold event data
4428 * Context: interrupt time.
4431 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
4432 Mpi2EventDataTemperature_t
*event_data
)
4434 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
4435 ioc_err(ioc
, "Temperature Threshold flags %s%s%s%s exceeded for Sensor: %d !!!\n",
4436 le16_to_cpu(event_data
->Status
) & 0x1 ? "0 " : " ",
4437 le16_to_cpu(event_data
->Status
) & 0x2 ? "1 " : " ",
4438 le16_to_cpu(event_data
->Status
) & 0x4 ? "2 " : " ",
4439 le16_to_cpu(event_data
->Status
) & 0x8 ? "3 " : " ",
4440 event_data
->SensorNum
);
4441 ioc_err(ioc
, "Current Temp In Celsius: %d\n",
4442 event_data
->CurrentTemperature
);
4446 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
4448 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
4450 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
4454 return test_and_set_bit(0, &priv
->ata_command_pending
);
4456 clear_bit(0, &priv
->ata_command_pending
);
4461 * _scsih_flush_running_cmds - completing outstanding commands.
4462 * @ioc: per adapter object
4464 * The flushing out of all pending scmd commands following host reset,
4465 * where all IO is dropped to the floor.
4468 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
4470 struct scsi_cmnd
*scmd
;
4471 struct scsiio_tracker
*st
;
4475 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4476 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
4480 _scsih_set_satl_pending(scmd
, false);
4481 st
= scsi_cmd_priv(scmd
);
4482 mpt3sas_base_clear_st(ioc
, st
);
4483 scsi_dma_unmap(scmd
);
4484 if (ioc
->pci_error_recovery
|| ioc
->remove_host
)
4485 scmd
->result
= DID_NO_CONNECT
<< 16;
4487 scmd
->result
= DID_RESET
<< 16;
4488 scmd
->scsi_done(scmd
);
4490 dtmprintk(ioc
, ioc_info(ioc
, "completing %d cmds\n", count
));
4494 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4495 * @ioc: per adapter object
4496 * @scmd: pointer to scsi command object
4497 * @mpi_request: pointer to the SCSI_IO request message frame
4499 * Supporting protection 1 and 3.
4502 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4503 Mpi25SCSIIORequest_t
*mpi_request
)
4506 unsigned char prot_op
= scsi_get_prot_op(scmd
);
4507 unsigned char prot_type
= scsi_get_prot_type(scmd
);
4508 Mpi25SCSIIORequest_t
*mpi_request_3v
=
4509 (Mpi25SCSIIORequest_t
*)mpi_request
;
4511 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
4514 if (prot_op
== SCSI_PROT_READ_STRIP
)
4515 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
4516 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
4517 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
4521 switch (prot_type
) {
4522 case SCSI_PROT_DIF_TYPE1
:
4523 case SCSI_PROT_DIF_TYPE2
:
4526 * enable ref/guard checking
4527 * auto increment ref tag
4529 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4530 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4531 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4532 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4533 cpu_to_be32(t10_pi_ref_tag(scmd
->request
));
4536 case SCSI_PROT_DIF_TYPE3
:
4539 * enable guard checking
4541 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4546 mpi_request_3v
->EEDPBlockSize
=
4547 cpu_to_le16(scmd
->device
->sector_size
);
4549 if (ioc
->is_gen35_ioc
)
4550 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4551 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4555 * _scsih_eedp_error_handling - return sense code for EEDP errors
4556 * @scmd: pointer to scsi command object
4557 * @ioc_status: ioc status
4560 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4564 switch (ioc_status
) {
4565 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4568 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4571 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4578 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4580 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4581 SAM_STAT_CHECK_CONDITION
;
4585 * scsih_qcmd - main scsi request entry point
4586 * @shost: SCSI host pointer
4587 * @scmd: pointer to scsi command object
4589 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4591 * Return: 0 on success. If there's a failure, return either:
4592 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4593 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4596 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4598 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4599 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4600 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4601 struct _raid_device
*raid_device
;
4602 struct request
*rq
= scmd
->request
;
4604 Mpi25SCSIIORequest_t
*mpi_request
;
4605 struct _pcie_device
*pcie_device
= NULL
;
4610 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4611 scsi_print_command(scmd
);
4613 sas_device_priv_data
= scmd
->device
->hostdata
;
4614 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4615 scmd
->result
= DID_NO_CONNECT
<< 16;
4616 scmd
->scsi_done(scmd
);
4620 if (!(_scsih_allow_scmd_to_device(ioc
, scmd
))) {
4621 scmd
->result
= DID_NO_CONNECT
<< 16;
4622 scmd
->scsi_done(scmd
);
4626 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4628 /* invalid device handle */
4629 handle
= sas_target_priv_data
->handle
;
4630 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4631 scmd
->result
= DID_NO_CONNECT
<< 16;
4632 scmd
->scsi_done(scmd
);
4637 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
) {
4638 /* host recovery or link resets sent via IOCTLs */
4639 return SCSI_MLQUEUE_HOST_BUSY
;
4640 } else if (sas_target_priv_data
->deleted
) {
4641 /* device has been deleted */
4642 scmd
->result
= DID_NO_CONNECT
<< 16;
4643 scmd
->scsi_done(scmd
);
4645 } else if (sas_target_priv_data
->tm_busy
||
4646 sas_device_priv_data
->block
) {
4647 /* device busy with task management */
4648 return SCSI_MLQUEUE_DEVICE_BUSY
;
4652 * Bug work around for firmware SATL handling. The loop
4653 * is based on atomic operations and ensures consistency
4654 * since we're lockless at this point
4657 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
)) {
4658 scmd
->result
= SAM_STAT_BUSY
;
4659 scmd
->scsi_done(scmd
);
4662 } while (_scsih_set_satl_pending(scmd
, true));
4664 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4665 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4666 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4667 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4669 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4672 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4673 /* NCQ Prio supported, make sure control indicated high priority */
4674 if (sas_device_priv_data
->ncq_prio_enable
) {
4675 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4676 if (class == IOPRIO_CLASS_RT
)
4677 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4679 /* Make sure Device is not raid volume.
4680 * We do not expose raid functionality to upper layer for warpdrive.
4682 if (((!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
))
4683 && !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
4684 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4685 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4687 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4689 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
4690 _scsih_set_satl_pending(scmd
, false);
4693 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4694 memset(mpi_request
, 0, ioc
->request_sz
);
4695 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4697 if (scmd
->cmd_len
== 32)
4698 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4699 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4700 if (sas_device_priv_data
->sas_target
->flags
&
4701 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4702 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4704 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4705 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4706 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4707 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4708 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4709 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4710 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4711 mpi_request
->SenseBufferLowAddress
=
4712 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4713 mpi_request
->SGLOffset0
= offsetof(Mpi25SCSIIORequest_t
, SGL
) / 4;
4714 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4716 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4718 if (mpi_request
->DataLength
) {
4719 pcie_device
= sas_target_priv_data
->pcie_dev
;
4720 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
, pcie_device
)) {
4721 mpt3sas_base_free_smid(ioc
, smid
);
4722 _scsih_set_satl_pending(scmd
, false);
4726 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4728 raid_device
= sas_target_priv_data
->raid_device
;
4729 if (raid_device
&& raid_device
->direct_io_enabled
)
4730 mpt3sas_setup_direct_io(ioc
, scmd
,
4731 raid_device
, mpi_request
);
4733 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4734 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4735 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4736 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4737 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4739 ioc
->put_smid_scsi_io(ioc
, smid
,
4740 le16_to_cpu(mpi_request
->DevHandle
));
4742 ioc
->put_smid_default(ioc
, smid
);
4746 return SCSI_MLQUEUE_HOST_BUSY
;
4750 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4751 * @sense_buffer: sense data returned by target
4752 * @data: normalized skey/asc/ascq
4755 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4757 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4758 /* descriptor format */
4759 data
->skey
= sense_buffer
[1] & 0x0F;
4760 data
->asc
= sense_buffer
[2];
4761 data
->ascq
= sense_buffer
[3];
4764 data
->skey
= sense_buffer
[2] & 0x0F;
4765 data
->asc
= sense_buffer
[12];
4766 data
->ascq
= sense_buffer
[13];
4771 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4772 * @ioc: per adapter object
4773 * @scmd: pointer to scsi command object
4774 * @mpi_reply: reply mf payload returned from firmware
4777 * scsi_status - SCSI Status code returned from target device
4778 * scsi_state - state info associated with SCSI_IO determined by ioc
4779 * ioc_status - ioc supplied status info
4782 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4783 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4787 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4788 MPI2_IOCSTATUS_MASK
;
4789 u8 scsi_state
= mpi_reply
->SCSIState
;
4790 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4791 char *desc_ioc_state
= NULL
;
4792 char *desc_scsi_status
= NULL
;
4793 char *desc_scsi_state
= ioc
->tmp_string
;
4794 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4795 struct _sas_device
*sas_device
= NULL
;
4796 struct _pcie_device
*pcie_device
= NULL
;
4797 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4798 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4799 char *device_str
= NULL
;
4803 if (ioc
->hide_ir_msg
)
4804 device_str
= "WarpDrive";
4806 device_str
= "volume";
4808 if (log_info
== 0x31170000)
4811 switch (ioc_status
) {
4812 case MPI2_IOCSTATUS_SUCCESS
:
4813 desc_ioc_state
= "success";
4815 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4816 desc_ioc_state
= "invalid function";
4818 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4819 desc_ioc_state
= "scsi recovered error";
4821 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4822 desc_ioc_state
= "scsi invalid dev handle";
4824 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4825 desc_ioc_state
= "scsi device not there";
4827 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4828 desc_ioc_state
= "scsi data overrun";
4830 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4831 desc_ioc_state
= "scsi data underrun";
4833 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4834 desc_ioc_state
= "scsi io data error";
4836 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4837 desc_ioc_state
= "scsi protocol error";
4839 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4840 desc_ioc_state
= "scsi task terminated";
4842 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4843 desc_ioc_state
= "scsi residual mismatch";
4845 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4846 desc_ioc_state
= "scsi task mgmt failed";
4848 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4849 desc_ioc_state
= "scsi ioc terminated";
4851 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4852 desc_ioc_state
= "scsi ext terminated";
4854 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4855 desc_ioc_state
= "eedp guard error";
4857 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4858 desc_ioc_state
= "eedp ref tag error";
4860 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4861 desc_ioc_state
= "eedp app tag error";
4863 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4864 desc_ioc_state
= "insufficient power";
4867 desc_ioc_state
= "unknown";
4871 switch (scsi_status
) {
4872 case MPI2_SCSI_STATUS_GOOD
:
4873 desc_scsi_status
= "good";
4875 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4876 desc_scsi_status
= "check condition";
4878 case MPI2_SCSI_STATUS_CONDITION_MET
:
4879 desc_scsi_status
= "condition met";
4881 case MPI2_SCSI_STATUS_BUSY
:
4882 desc_scsi_status
= "busy";
4884 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4885 desc_scsi_status
= "intermediate";
4887 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4888 desc_scsi_status
= "intermediate condmet";
4890 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4891 desc_scsi_status
= "reservation conflict";
4893 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4894 desc_scsi_status
= "command terminated";
4896 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4897 desc_scsi_status
= "task set full";
4899 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4900 desc_scsi_status
= "aca active";
4902 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4903 desc_scsi_status
= "task aborted";
4906 desc_scsi_status
= "unknown";
4910 desc_scsi_state
[0] = '\0';
4912 desc_scsi_state
= " ";
4913 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4914 strcat(desc_scsi_state
, "response info ");
4915 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4916 strcat(desc_scsi_state
, "state terminated ");
4917 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4918 strcat(desc_scsi_state
, "no status ");
4919 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4920 strcat(desc_scsi_state
, "autosense failed ");
4921 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4922 strcat(desc_scsi_state
, "autosense valid ");
4924 scsi_print_command(scmd
);
4926 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4927 ioc_warn(ioc
, "\t%s wwid(0x%016llx)\n",
4928 device_str
, (u64
)priv_target
->sas_address
);
4929 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
4930 pcie_device
= mpt3sas_get_pdev_from_target(ioc
, priv_target
);
4932 ioc_info(ioc
, "\twwid(0x%016llx), port(%d)\n",
4933 (u64
)pcie_device
->wwid
, pcie_device
->port_num
);
4934 if (pcie_device
->enclosure_handle
!= 0)
4935 ioc_info(ioc
, "\tenclosure logical id(0x%016llx), slot(%d)\n",
4936 (u64
)pcie_device
->enclosure_logical_id
,
4938 if (pcie_device
->connector_name
[0])
4939 ioc_info(ioc
, "\tenclosure level(0x%04x), connector name( %s)\n",
4940 pcie_device
->enclosure_level
,
4941 pcie_device
->connector_name
);
4942 pcie_device_put(pcie_device
);
4945 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4947 ioc_warn(ioc
, "\tsas_address(0x%016llx), phy(%d)\n",
4948 (u64
)sas_device
->sas_address
, sas_device
->phy
);
4950 _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
4953 sas_device_put(sas_device
);
4957 ioc_warn(ioc
, "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4958 le16_to_cpu(mpi_reply
->DevHandle
),
4959 desc_ioc_state
, ioc_status
, smid
);
4960 ioc_warn(ioc
, "\trequest_len(%d), underflow(%d), resid(%d)\n",
4961 scsi_bufflen(scmd
), scmd
->underflow
, scsi_get_resid(scmd
));
4962 ioc_warn(ioc
, "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4963 le16_to_cpu(mpi_reply
->TaskTag
),
4964 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4965 ioc_warn(ioc
, "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4966 desc_scsi_status
, scsi_status
, desc_scsi_state
, scsi_state
);
4968 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4969 struct sense_info data
;
4970 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4971 ioc_warn(ioc
, "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4972 data
.skey
, data
.asc
, data
.ascq
,
4973 le32_to_cpu(mpi_reply
->SenseCount
));
4975 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4976 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4977 response_bytes
= (u8
*)&response_info
;
4978 _scsih_response_code(ioc
, response_bytes
[0]);
4983 * _scsih_turn_on_pfa_led - illuminate PFA LED
4984 * @ioc: per adapter object
4985 * @handle: device handle
4989 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4991 Mpi2SepReply_t mpi_reply
;
4992 Mpi2SepRequest_t mpi_request
;
4993 struct _sas_device
*sas_device
;
4995 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4999 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5000 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5001 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5002 mpi_request
.SlotStatus
=
5003 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
5004 mpi_request
.DevHandle
= cpu_to_le16(handle
);
5005 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
5006 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5007 &mpi_request
)) != 0) {
5008 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5009 __FILE__
, __LINE__
, __func__
);
5012 sas_device
->pfa_led_on
= 1;
5014 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5016 ioc_info(ioc
, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5017 le16_to_cpu(mpi_reply
.IOCStatus
),
5018 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5022 sas_device_put(sas_device
);
5026 * _scsih_turn_off_pfa_led - turn off Fault LED
5027 * @ioc: per adapter object
5028 * @sas_device: sas device whose PFA LED has to turned off
5032 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
5033 struct _sas_device
*sas_device
)
5035 Mpi2SepReply_t mpi_reply
;
5036 Mpi2SepRequest_t mpi_request
;
5038 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5039 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5040 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5041 mpi_request
.SlotStatus
= 0;
5042 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
5043 mpi_request
.DevHandle
= 0;
5044 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
5045 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
5046 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5047 &mpi_request
)) != 0) {
5048 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5049 __FILE__
, __LINE__
, __func__
);
5053 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5055 ioc_info(ioc
, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5056 le16_to_cpu(mpi_reply
.IOCStatus
),
5057 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5063 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5064 * @ioc: per adapter object
5065 * @handle: device handle
5066 * Context: interrupt.
5069 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5071 struct fw_event_work
*fw_event
;
5073 fw_event
= alloc_fw_event_work(0);
5076 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
5077 fw_event
->device_handle
= handle
;
5078 fw_event
->ioc
= ioc
;
5079 _scsih_fw_event_add(ioc
, fw_event
);
5080 fw_event_work_put(fw_event
);
5084 * _scsih_smart_predicted_fault - process smart errors
5085 * @ioc: per adapter object
5086 * @handle: device handle
5087 * Context: interrupt.
5090 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5092 struct scsi_target
*starget
;
5093 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5094 Mpi2EventNotificationReply_t
*event_reply
;
5095 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
5096 struct _sas_device
*sas_device
;
5098 unsigned long flags
;
5100 /* only handle non-raid devices */
5101 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5102 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
5106 starget
= sas_device
->starget
;
5107 sas_target_priv_data
= starget
->hostdata
;
5109 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
5110 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
5113 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, NULL
, starget
);
5115 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5117 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
5118 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
5120 /* insert into event log */
5121 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
5122 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
5123 event_reply
= kzalloc(sz
, GFP_KERNEL
);
5125 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5126 __FILE__
, __LINE__
, __func__
);
5130 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
5131 event_reply
->Event
=
5132 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
5133 event_reply
->MsgLength
= sz
/4;
5134 event_reply
->EventDataLength
=
5135 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
5136 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
5137 event_reply
->EventData
;
5138 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
5139 event_data
->ASC
= 0x5D;
5140 event_data
->DevHandle
= cpu_to_le16(handle
);
5141 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
5142 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
5146 sas_device_put(sas_device
);
5150 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5155 * _scsih_io_done - scsi request callback
5156 * @ioc: per adapter object
5157 * @smid: system request message index
5158 * @msix_index: MSIX table index supplied by the OS
5159 * @reply: reply message frame(lower 32bit addr)
5161 * Callback handler when using _scsih_qcmd.
5163 * Return: 1 meaning mf should be freed from _base_interrupt
5164 * 0 means the mf is freed from this function.
5167 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5169 Mpi25SCSIIORequest_t
*mpi_request
;
5170 Mpi2SCSIIOReply_t
*mpi_reply
;
5171 struct scsi_cmnd
*scmd
;
5172 struct scsiio_tracker
*st
;
5178 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5179 u32 response_code
= 0;
5181 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5183 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
5187 _scsih_set_satl_pending(scmd
, false);
5189 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5191 if (mpi_reply
== NULL
) {
5192 scmd
->result
= DID_OK
<< 16;
5196 sas_device_priv_data
= scmd
->device
->hostdata
;
5197 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
5198 sas_device_priv_data
->sas_target
->deleted
) {
5199 scmd
->result
= DID_NO_CONNECT
<< 16;
5202 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5205 * WARPDRIVE: If direct_io is set then it is directIO,
5206 * the failed direct I/O should be redirected to volume
5208 st
= scsi_cmd_priv(scmd
);
5209 if (st
->direct_io
&&
5210 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
5211 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
5214 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
5215 mpi_request
->DevHandle
=
5216 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
5217 ioc
->put_smid_scsi_io(ioc
, smid
,
5218 sas_device_priv_data
->sas_target
->handle
);
5221 /* turning off TLR */
5222 scsi_state
= mpi_reply
->SCSIState
;
5223 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
5225 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
5226 if (!sas_device_priv_data
->tlr_snoop_check
) {
5227 sas_device_priv_data
->tlr_snoop_check
++;
5228 if ((!ioc
->is_warpdrive
&&
5229 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
5230 !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
5231 && sas_is_tlr_enabled(scmd
->device
) &&
5232 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
5233 sas_disable_tlr(scmd
->device
);
5234 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
5238 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
5239 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
5240 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5241 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5244 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5245 scsi_status
= mpi_reply
->SCSIStatus
;
5247 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
5248 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
5249 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
5250 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
5251 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
5254 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5255 struct sense_info data
;
5256 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
5258 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
5259 le32_to_cpu(mpi_reply
->SenseCount
));
5260 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
5261 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5262 /* failure prediction threshold exceeded */
5263 if (data
.asc
== 0x5D)
5264 _scsih_smart_predicted_fault(ioc
,
5265 le16_to_cpu(mpi_reply
->DevHandle
));
5266 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
5268 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
5269 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
5270 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
5271 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
5272 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5274 switch (ioc_status
) {
5275 case MPI2_IOCSTATUS_BUSY
:
5276 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
5277 scmd
->result
= SAM_STAT_BUSY
;
5280 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
5281 scmd
->result
= DID_NO_CONNECT
<< 16;
5284 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
5285 if (sas_device_priv_data
->block
) {
5286 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
5289 if (log_info
== 0x31110630) {
5290 if (scmd
->retries
> 2) {
5291 scmd
->result
= DID_NO_CONNECT
<< 16;
5292 scsi_device_set_state(scmd
->device
,
5295 scmd
->result
= DID_SOFT_ERROR
<< 16;
5296 scmd
->device
->expecting_cc_ua
= 1;
5299 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
5300 scmd
->result
= DID_RESET
<< 16;
5302 } else if ((scmd
->device
->channel
== RAID_CHANNEL
) &&
5303 (scsi_state
== (MPI2_SCSI_STATE_TERMINATED
|
5304 MPI2_SCSI_STATE_NO_SCSI_STATUS
))) {
5305 scmd
->result
= DID_RESET
<< 16;
5308 scmd
->result
= DID_SOFT_ERROR
<< 16;
5310 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
5311 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
5312 scmd
->result
= DID_RESET
<< 16;
5315 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
5316 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
5317 scmd
->result
= DID_SOFT_ERROR
<< 16;
5319 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5322 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
5323 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5325 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
5328 if (xfer_cnt
< scmd
->underflow
) {
5329 if (scsi_status
== SAM_STAT_BUSY
)
5330 scmd
->result
= SAM_STAT_BUSY
;
5332 scmd
->result
= DID_SOFT_ERROR
<< 16;
5333 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5334 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
5335 scmd
->result
= DID_SOFT_ERROR
<< 16;
5336 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5337 scmd
->result
= DID_RESET
<< 16;
5338 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
5339 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
5340 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
5341 scmd
->result
= (DRIVER_SENSE
<< 24) |
5342 SAM_STAT_CHECK_CONDITION
;
5343 scmd
->sense_buffer
[0] = 0x70;
5344 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
5345 scmd
->sense_buffer
[12] = 0x20;
5346 scmd
->sense_buffer
[13] = 0;
5350 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
5351 scsi_set_resid(scmd
, 0);
5353 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
5354 case MPI2_IOCSTATUS_SUCCESS
:
5355 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5356 if (response_code
==
5357 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
5358 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5359 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
5360 scmd
->result
= DID_SOFT_ERROR
<< 16;
5361 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5362 scmd
->result
= DID_RESET
<< 16;
5365 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
5366 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
5367 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
5368 _scsih_eedp_error_handling(scmd
, ioc_status
);
5371 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
5372 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
5373 case MPI2_IOCSTATUS_INVALID_SGL
:
5374 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
5375 case MPI2_IOCSTATUS_INVALID_FIELD
:
5376 case MPI2_IOCSTATUS_INVALID_STATE
:
5377 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
5378 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
5379 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
5381 scmd
->result
= DID_SOFT_ERROR
<< 16;
5386 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
5387 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5391 scsi_dma_unmap(scmd
);
5392 mpt3sas_base_free_smid(ioc
, smid
);
5393 scmd
->scsi_done(scmd
);
5398 * _scsih_sas_host_refresh - refreshing sas host object contents
5399 * @ioc: per adapter object
5402 * During port enable, fw will send topology events for every device. Its
5403 * possible that the handles may change from the previous setting, so this
5404 * code keeping handles updating if changed.
5407 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
5412 Mpi2ConfigReply_t mpi_reply
;
5413 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5414 u16 attached_handle
;
5418 ioc_info(ioc
, "updating handles for sas_host(0x%016llx)\n",
5419 (u64
)ioc
->sas_hba
.sas_address
));
5421 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
5422 * sizeof(Mpi2SasIOUnit0PhyData_t
));
5423 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5424 if (!sas_iounit_pg0
) {
5425 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5426 __FILE__
, __LINE__
, __func__
);
5430 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5431 sas_iounit_pg0
, sz
)) != 0)
5433 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5434 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5436 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5437 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
5439 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5440 PhyData
[0].ControllerDevHandle
);
5441 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5442 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
5444 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5445 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
5446 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
5447 attached_handle
, i
, link_rate
);
5450 kfree(sas_iounit_pg0
);
5454 * _scsih_sas_host_add - create sas host object
5455 * @ioc: per adapter object
5457 * Creating host side data object, stored in ioc->sas_hba
5460 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
5463 Mpi2ConfigReply_t mpi_reply
;
5464 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5465 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
5466 Mpi2SasPhyPage0_t phy_pg0
;
5467 Mpi2SasDevicePage0_t sas_device_pg0
;
5468 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5471 u8 device_missing_delay
;
5474 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
5476 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5477 __FILE__
, __LINE__
, __func__
);
5480 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
5481 sizeof(struct _sas_phy
), GFP_KERNEL
);
5482 if (!ioc
->sas_hba
.phy
) {
5483 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5484 __FILE__
, __LINE__
, __func__
);
5487 ioc
->sas_hba
.num_phys
= num_phys
;
5489 /* sas_iounit page 0 */
5490 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5491 sizeof(Mpi2SasIOUnit0PhyData_t
));
5492 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5493 if (!sas_iounit_pg0
) {
5494 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5495 __FILE__
, __LINE__
, __func__
);
5498 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5499 sas_iounit_pg0
, sz
))) {
5500 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5501 __FILE__
, __LINE__
, __func__
);
5504 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5505 MPI2_IOCSTATUS_MASK
;
5506 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5507 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5508 __FILE__
, __LINE__
, __func__
);
5512 /* sas_iounit page 1 */
5513 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5514 sizeof(Mpi2SasIOUnit1PhyData_t
));
5515 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5516 if (!sas_iounit_pg1
) {
5517 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5518 __FILE__
, __LINE__
, __func__
);
5521 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5522 sas_iounit_pg1
, sz
))) {
5523 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5524 __FILE__
, __LINE__
, __func__
);
5527 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5528 MPI2_IOCSTATUS_MASK
;
5529 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5530 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5531 __FILE__
, __LINE__
, __func__
);
5535 ioc
->io_missing_delay
=
5536 sas_iounit_pg1
->IODeviceMissingDelay
;
5537 device_missing_delay
=
5538 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5539 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5540 ioc
->device_missing_delay
= (device_missing_delay
&
5541 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5543 ioc
->device_missing_delay
= device_missing_delay
&
5544 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5546 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5547 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5548 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5550 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5551 __FILE__
, __LINE__
, __func__
);
5554 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5555 MPI2_IOCSTATUS_MASK
;
5556 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5557 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5558 __FILE__
, __LINE__
, __func__
);
5563 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5564 PhyData
[0].ControllerDevHandle
);
5565 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5566 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5567 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5568 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5570 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5571 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5572 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5573 __FILE__
, __LINE__
, __func__
);
5576 ioc
->sas_hba
.enclosure_handle
=
5577 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5578 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5579 ioc_info(ioc
, "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5580 ioc
->sas_hba
.handle
,
5581 (u64
)ioc
->sas_hba
.sas_address
,
5582 ioc
->sas_hba
.num_phys
);
5584 if (ioc
->sas_hba
.enclosure_handle
) {
5585 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5586 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5587 ioc
->sas_hba
.enclosure_handle
)))
5588 ioc
->sas_hba
.enclosure_logical_id
=
5589 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5593 kfree(sas_iounit_pg1
);
5594 kfree(sas_iounit_pg0
);
5598 * _scsih_expander_add - creating expander object
5599 * @ioc: per adapter object
5600 * @handle: expander handle
5602 * Creating expander object, stored in ioc->sas_expander_list.
5604 * Return: 0 for success, else error.
5607 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5609 struct _sas_node
*sas_expander
;
5610 struct _enclosure_node
*enclosure_dev
;
5611 Mpi2ConfigReply_t mpi_reply
;
5612 Mpi2ExpanderPage0_t expander_pg0
;
5613 Mpi2ExpanderPage1_t expander_pg1
;
5616 u64 sas_address
, sas_address_parent
= 0;
5618 unsigned long flags
;
5619 struct _sas_port
*mpt3sas_port
= NULL
;
5626 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5629 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5630 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5631 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5632 __FILE__
, __LINE__
, __func__
);
5636 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5637 MPI2_IOCSTATUS_MASK
;
5638 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5639 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5640 __FILE__
, __LINE__
, __func__
);
5644 /* handle out of order topology events */
5645 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5646 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5648 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5649 __FILE__
, __LINE__
, __func__
);
5652 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5653 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5654 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5655 sas_address_parent
);
5656 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5657 if (!sas_expander
) {
5658 rc
= _scsih_expander_add(ioc
, parent_handle
);
5664 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5665 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5666 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5668 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5673 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5675 if (!sas_expander
) {
5676 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5677 __FILE__
, __LINE__
, __func__
);
5681 sas_expander
->handle
= handle
;
5682 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5683 sas_expander
->sas_address_parent
= sas_address_parent
;
5684 sas_expander
->sas_address
= sas_address
;
5686 ioc_info(ioc
, "expander_add: handle(0x%04x), parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5687 handle
, parent_handle
,
5688 (u64
)sas_expander
->sas_address
, sas_expander
->num_phys
);
5690 if (!sas_expander
->num_phys
)
5692 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5693 sizeof(struct _sas_phy
), GFP_KERNEL
);
5694 if (!sas_expander
->phy
) {
5695 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5696 __FILE__
, __LINE__
, __func__
);
5701 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5702 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5703 sas_address_parent
);
5704 if (!mpt3sas_port
) {
5705 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5706 __FILE__
, __LINE__
, __func__
);
5710 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5712 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5713 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5714 &expander_pg1
, i
, handle
))) {
5715 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5716 __FILE__
, __LINE__
, __func__
);
5720 sas_expander
->phy
[i
].handle
= handle
;
5721 sas_expander
->phy
[i
].phy_id
= i
;
5723 if ((mpt3sas_transport_add_expander_phy(ioc
,
5724 &sas_expander
->phy
[i
], expander_pg1
,
5725 sas_expander
->parent_dev
))) {
5726 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5727 __FILE__
, __LINE__
, __func__
);
5733 if (sas_expander
->enclosure_handle
) {
5735 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
5736 sas_expander
->enclosure_handle
);
5738 sas_expander
->enclosure_logical_id
=
5739 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
5742 _scsih_expander_node_add(ioc
, sas_expander
);
5748 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5749 sas_address_parent
);
5750 kfree(sas_expander
);
5755 * mpt3sas_expander_remove - removing expander object
5756 * @ioc: per adapter object
5757 * @sas_address: expander sas_address
5760 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5762 struct _sas_node
*sas_expander
;
5763 unsigned long flags
;
5765 if (ioc
->shost_recovery
)
5768 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5769 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5771 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5773 _scsih_expander_node_remove(ioc
, sas_expander
);
5777 * _scsih_done - internal SCSI_IO callback handler.
5778 * @ioc: per adapter object
5779 * @smid: system request message index
5780 * @msix_index: MSIX table index supplied by the OS
5781 * @reply: reply message frame(lower 32bit addr)
5783 * Callback handler when sending internal generated SCSI_IO.
5784 * The callback index passed is `ioc->scsih_cb_idx`
5786 * Return: 1 meaning mf should be freed from _base_interrupt
5787 * 0 means the mf is freed from this function.
5790 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5792 MPI2DefaultReply_t
*mpi_reply
;
5794 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5795 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5797 if (ioc
->scsih_cmds
.smid
!= smid
)
5799 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5801 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5802 mpi_reply
->MsgLength
*4);
5803 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5805 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5806 complete(&ioc
->scsih_cmds
.done
);
5813 #define MPT3_MAX_LUNS (255)
5817 * _scsih_check_access_status - check access flags
5818 * @ioc: per adapter object
5819 * @sas_address: sas address
5820 * @handle: sas device handle
5821 * @access_status: errors returned during discovery of the device
5823 * Return: 0 for success, else failure
5826 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5827 u16 handle
, u8 access_status
)
5832 switch (access_status
) {
5833 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5834 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5837 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5838 desc
= "sata capability failed";
5840 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5841 desc
= "sata affiliation conflict";
5843 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5844 desc
= "route not addressable";
5846 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5847 desc
= "smp error not addressable";
5849 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5850 desc
= "device blocked";
5852 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5853 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5854 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5855 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5856 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5857 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5858 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5859 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5860 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5861 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5862 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5863 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5864 desc
= "sata initialization failed";
5874 ioc_err(ioc
, "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5875 desc
, (u64
)sas_address
, handle
);
5880 * _scsih_check_device - checking device responsiveness
5881 * @ioc: per adapter object
5882 * @parent_sas_address: sas address of parent expander or sas host
5883 * @handle: attached device handle
5884 * @phy_number: phy number
5885 * @link_rate: new link rate
5888 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5889 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5891 Mpi2ConfigReply_t mpi_reply
;
5892 Mpi2SasDevicePage0_t sas_device_pg0
;
5893 struct _sas_device
*sas_device
;
5894 struct _enclosure_node
*enclosure_dev
= NULL
;
5896 unsigned long flags
;
5898 struct scsi_target
*starget
;
5899 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5902 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5903 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5906 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5907 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5910 /* wide port handling ~ we need only handle device once for the phy that
5911 * is matched in sas device page zero
5913 if (phy_number
!= sas_device_pg0
.PhyNum
)
5916 /* check if this is end device */
5917 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5918 if (!(_scsih_is_end_device(device_info
)))
5921 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5922 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5923 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5929 if (unlikely(sas_device
->handle
!= handle
)) {
5930 starget
= sas_device
->starget
;
5931 sas_target_priv_data
= starget
->hostdata
;
5932 starget_printk(KERN_INFO
, starget
,
5933 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5934 sas_device
->handle
, handle
);
5935 sas_target_priv_data
->handle
= handle
;
5936 sas_device
->handle
= handle
;
5937 if (le16_to_cpu(sas_device_pg0
.Flags
) &
5938 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5939 sas_device
->enclosure_level
=
5940 sas_device_pg0
.EnclosureLevel
;
5941 memcpy(sas_device
->connector_name
,
5942 sas_device_pg0
.ConnectorName
, 4);
5943 sas_device
->connector_name
[4] = '\0';
5945 sas_device
->enclosure_level
= 0;
5946 sas_device
->connector_name
[0] = '\0';
5949 sas_device
->enclosure_handle
=
5950 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5951 sas_device
->is_chassis_slot_valid
= 0;
5952 enclosure_dev
= mpt3sas_scsih_enclosure_find_by_handle(ioc
,
5953 sas_device
->enclosure_handle
);
5954 if (enclosure_dev
) {
5955 sas_device
->enclosure_logical_id
=
5956 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
5957 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
5958 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
5959 sas_device
->is_chassis_slot_valid
= 1;
5960 sas_device
->chassis_slot
=
5961 enclosure_dev
->pg0
.ChassisSlot
;
5966 /* check if device is present */
5967 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5968 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5969 ioc_err(ioc
, "device is not present handle(0x%04x), flags!!!\n",
5974 /* check if there were any issues with discovery */
5975 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5976 sas_device_pg0
.AccessStatus
))
5979 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5980 _scsih_ublock_io_device(ioc
, sas_address
);
5983 sas_device_put(sas_device
);
5987 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5989 sas_device_put(sas_device
);
5993 * _scsih_add_device - creating sas device object
5994 * @ioc: per adapter object
5995 * @handle: sas device handle
5996 * @phy_num: phy number end device attached to
5997 * @is_pd: is this hidden raid component
5999 * Creating end device object, stored in ioc->sas_device_list.
6001 * Return: 0 for success, non-zero for failure.
6004 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
6007 Mpi2ConfigReply_t mpi_reply
;
6008 Mpi2SasDevicePage0_t sas_device_pg0
;
6009 struct _sas_device
*sas_device
;
6010 struct _enclosure_node
*enclosure_dev
= NULL
;
6015 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6016 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6017 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6018 __FILE__
, __LINE__
, __func__
);
6022 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6023 MPI2_IOCSTATUS_MASK
;
6024 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6025 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6026 __FILE__
, __LINE__
, __func__
);
6030 /* check if this is end device */
6031 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6032 if (!(_scsih_is_end_device(device_info
)))
6034 set_bit(handle
, ioc
->pend_os_device_add
);
6035 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6037 /* check if device is present */
6038 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6039 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6040 ioc_err(ioc
, "device is not present handle(0x04%x)!!!\n",
6045 /* check if there were any issues with discovery */
6046 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6047 sas_device_pg0
.AccessStatus
))
6050 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
6053 clear_bit(handle
, ioc
->pend_os_device_add
);
6054 sas_device_put(sas_device
);
6058 if (sas_device_pg0
.EnclosureHandle
) {
6060 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
6061 le16_to_cpu(sas_device_pg0
.EnclosureHandle
));
6062 if (enclosure_dev
== NULL
)
6063 ioc_info(ioc
, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
6064 sas_device_pg0
.EnclosureHandle
);
6067 sas_device
= kzalloc(sizeof(struct _sas_device
),
6070 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6071 __FILE__
, __LINE__
, __func__
);
6075 kref_init(&sas_device
->refcount
);
6076 sas_device
->handle
= handle
;
6077 if (_scsih_get_sas_address(ioc
,
6078 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
6079 &sas_device
->sas_address_parent
) != 0)
6080 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6081 __FILE__
, __LINE__
, __func__
);
6082 sas_device
->enclosure_handle
=
6083 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
6084 if (sas_device
->enclosure_handle
!= 0)
6086 le16_to_cpu(sas_device_pg0
.Slot
);
6087 sas_device
->device_info
= device_info
;
6088 sas_device
->sas_address
= sas_address
;
6089 sas_device
->phy
= sas_device_pg0
.PhyNum
;
6090 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
6091 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6093 if (le16_to_cpu(sas_device_pg0
.Flags
)
6094 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6095 sas_device
->enclosure_level
=
6096 sas_device_pg0
.EnclosureLevel
;
6097 memcpy(sas_device
->connector_name
,
6098 sas_device_pg0
.ConnectorName
, 4);
6099 sas_device
->connector_name
[4] = '\0';
6101 sas_device
->enclosure_level
= 0;
6102 sas_device
->connector_name
[0] = '\0';
6104 /* get enclosure_logical_id & chassis_slot*/
6105 sas_device
->is_chassis_slot_valid
= 0;
6106 if (enclosure_dev
) {
6107 sas_device
->enclosure_logical_id
=
6108 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
6109 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
6110 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6111 sas_device
->is_chassis_slot_valid
= 1;
6112 sas_device
->chassis_slot
=
6113 enclosure_dev
->pg0
.ChassisSlot
;
6117 /* get device name */
6118 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
6120 if (ioc
->wait_for_discovery_to_complete
)
6121 _scsih_sas_device_init_add(ioc
, sas_device
);
6123 _scsih_sas_device_add(ioc
, sas_device
);
6125 sas_device_put(sas_device
);
6130 * _scsih_remove_device - removing sas device object
6131 * @ioc: per adapter object
6132 * @sas_device: the sas_device object
6135 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
6136 struct _sas_device
*sas_device
)
6138 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6140 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
6141 (sas_device
->pfa_led_on
)) {
6142 _scsih_turn_off_pfa_led(ioc
, sas_device
);
6143 sas_device
->pfa_led_on
= 0;
6147 ioc_info(ioc
, "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6149 sas_device
->handle
, (u64
)sas_device
->sas_address
));
6151 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6154 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6155 sas_target_priv_data
= sas_device
->starget
->hostdata
;
6156 sas_target_priv_data
->deleted
= 1;
6157 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
6158 sas_target_priv_data
->handle
=
6159 MPT3SAS_INVALID_DEVICE_HANDLE
;
6162 if (!ioc
->hide_drives
)
6163 mpt3sas_transport_port_remove(ioc
,
6164 sas_device
->sas_address
,
6165 sas_device
->sas_address_parent
);
6167 ioc_info(ioc
, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6168 sas_device
->handle
, (u64
)sas_device
->sas_address
);
6170 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
6173 ioc_info(ioc
, "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6175 sas_device
->handle
, (u64
)sas_device
->sas_address
));
6176 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6181 * _scsih_sas_topology_change_event_debug - debug for topology event
6182 * @ioc: per adapter object
6183 * @event_data: event data payload
6187 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6188 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
6194 char *status_str
= NULL
;
6195 u8 link_rate
, prev_link_rate
;
6197 switch (event_data
->ExpStatus
) {
6198 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
6201 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
6202 status_str
= "remove";
6204 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
6206 status_str
= "responding";
6208 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
6209 status_str
= "remove delay";
6212 status_str
= "unknown status";
6215 ioc_info(ioc
, "sas topology change: (%s)\n", status_str
);
6216 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6217 "start_phy(%02d), count(%d)\n",
6218 le16_to_cpu(event_data
->ExpanderDevHandle
),
6219 le16_to_cpu(event_data
->EnclosureHandle
),
6220 event_data
->StartPhyNum
, event_data
->NumEntries
);
6221 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6222 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6225 phy_number
= event_data
->StartPhyNum
+ i
;
6226 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6227 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6228 switch (reason_code
) {
6229 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6230 status_str
= "target add";
6232 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6233 status_str
= "target remove";
6235 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
6236 status_str
= "delay target remove";
6238 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6239 status_str
= "link rate change";
6241 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
6242 status_str
= "target responding";
6245 status_str
= "unknown";
6248 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6249 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6250 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6251 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
6252 handle
, status_str
, link_rate
, prev_link_rate
);
6258 * _scsih_sas_topology_change_event - handle topology changes
6259 * @ioc: per adapter object
6260 * @fw_event: The fw_event_work object
6265 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6266 struct fw_event_work
*fw_event
)
6269 u16 parent_handle
, handle
;
6271 u8 phy_number
, max_phys
;
6272 struct _sas_node
*sas_expander
;
6274 unsigned long flags
;
6275 u8 link_rate
, prev_link_rate
;
6276 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
6277 (Mpi2EventDataSasTopologyChangeList_t
*)
6278 fw_event
->event_data
;
6280 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6281 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
6283 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
6286 if (!ioc
->sas_hba
.num_phys
)
6287 _scsih_sas_host_add(ioc
);
6289 _scsih_sas_host_refresh(ioc
);
6291 if (fw_event
->ignore
) {
6292 dewtprintk(ioc
, ioc_info(ioc
, "ignoring expander event\n"));
6296 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
6298 /* handle expander add */
6299 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
6300 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
6303 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6304 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
6307 sas_address
= sas_expander
->sas_address
;
6308 max_phys
= sas_expander
->num_phys
;
6309 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
6310 sas_address
= ioc
->sas_hba
.sas_address
;
6311 max_phys
= ioc
->sas_hba
.num_phys
;
6313 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6316 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6318 /* handle siblings events */
6319 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6320 if (fw_event
->ignore
) {
6322 ioc_info(ioc
, "ignoring expander event\n"));
6325 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6327 phy_number
= event_data
->StartPhyNum
+ i
;
6328 if (phy_number
>= max_phys
)
6330 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6331 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6332 if ((event_data
->PHY
[i
].PhyStatus
&
6333 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
6334 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
6336 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6339 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6340 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6341 switch (reason_code
) {
6342 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6344 if (ioc
->shost_recovery
)
6347 if (link_rate
== prev_link_rate
)
6350 mpt3sas_transport_update_links(ioc
, sas_address
,
6351 handle
, phy_number
, link_rate
);
6353 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
6356 _scsih_check_device(ioc
, sas_address
, handle
,
6357 phy_number
, link_rate
);
6359 if (!test_bit(handle
, ioc
->pend_os_device_add
))
6364 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6366 if (ioc
->shost_recovery
)
6369 mpt3sas_transport_update_links(ioc
, sas_address
,
6370 handle
, phy_number
, link_rate
);
6372 _scsih_add_device(ioc
, handle
, phy_number
, 0);
6375 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6377 _scsih_device_remove_by_handle(ioc
, handle
);
6382 /* handle expander removal */
6383 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
6385 mpt3sas_expander_remove(ioc
, sas_address
);
6391 * _scsih_sas_device_status_change_event_debug - debug for device event
6393 * @event_data: event data payload
6397 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6398 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
6400 char *reason_str
= NULL
;
6402 switch (event_data
->ReasonCode
) {
6403 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
6404 reason_str
= "smart data";
6406 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
6407 reason_str
= "unsupported device discovered";
6409 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
6410 reason_str
= "internal device reset";
6412 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
6413 reason_str
= "internal task abort";
6415 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
6416 reason_str
= "internal task abort set";
6418 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
6419 reason_str
= "internal clear task set";
6421 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
6422 reason_str
= "internal query task";
6424 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
6425 reason_str
= "sata init failure";
6427 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
6428 reason_str
= "internal device reset complete";
6430 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
6431 reason_str
= "internal task abort complete";
6433 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
6434 reason_str
= "internal async notification";
6436 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
6437 reason_str
= "expander reduced functionality";
6439 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
6440 reason_str
= "expander reduced functionality complete";
6443 reason_str
= "unknown reason";
6446 ioc_info(ioc
, "device status change: (%s)\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6447 reason_str
, le16_to_cpu(event_data
->DevHandle
),
6448 (u64
)le64_to_cpu(event_data
->SASAddress
),
6449 le16_to_cpu(event_data
->TaskTag
));
6450 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
6451 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
6452 event_data
->ASC
, event_data
->ASCQ
);
6457 * _scsih_sas_device_status_change_event - handle device status change
6458 * @ioc: per adapter object
6459 * @fw_event: The fw_event_work object
6463 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6464 struct fw_event_work
*fw_event
)
6466 struct MPT3SAS_TARGET
*target_priv_data
;
6467 struct _sas_device
*sas_device
;
6469 unsigned long flags
;
6470 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
6471 (Mpi2EventDataSasDeviceStatusChange_t
*)
6472 fw_event
->event_data
;
6474 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6475 _scsih_sas_device_status_change_event_debug(ioc
,
6478 /* In MPI Revision K (0xC), the internal device reset complete was
6479 * implemented, so avoid setting tm_busy flag for older firmware.
6481 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
6484 if (event_data
->ReasonCode
!=
6485 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
6486 event_data
->ReasonCode
!=
6487 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
6490 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6491 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6492 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6495 if (!sas_device
|| !sas_device
->starget
)
6498 target_priv_data
= sas_device
->starget
->hostdata
;
6499 if (!target_priv_data
)
6502 if (event_data
->ReasonCode
==
6503 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6504 target_priv_data
->tm_busy
= 1;
6506 target_priv_data
->tm_busy
= 0;
6510 sas_device_put(sas_device
);
6512 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6517 * _scsih_check_pcie_access_status - check access flags
6518 * @ioc: per adapter object
6520 * @handle: sas device handle
6521 * @access_status: errors returned during discovery of the device
6523 * Return: 0 for success, else failure
6526 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6527 u16 handle
, u8 access_status
)
6532 switch (access_status
) {
6533 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS
:
6534 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION
:
6537 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED
:
6538 desc
= "PCIe device capability failed";
6540 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
:
6541 desc
= "PCIe device blocked";
6543 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED
:
6544 desc
= "PCIe device mem space access failed";
6546 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE
:
6547 desc
= "PCIe device unsupported";
6549 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED
:
6550 desc
= "PCIe device MSIx Required";
6552 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX
:
6553 desc
= "PCIe device init fail max";
6555 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN
:
6556 desc
= "PCIe device status unknown";
6558 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT
:
6559 desc
= "nvme ready timeout";
6561 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED
:
6562 desc
= "nvme device configuration unsupported";
6564 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED
:
6565 desc
= "nvme identify failed";
6567 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED
:
6568 desc
= "nvme qconfig failed";
6570 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED
:
6571 desc
= "nvme qcreation failed";
6573 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED
:
6574 desc
= "nvme eventcfg failed";
6576 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED
:
6577 desc
= "nvme get feature stat failed";
6579 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT
:
6580 desc
= "nvme idle timeout";
6582 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS
:
6583 desc
= "nvme failure status";
6586 ioc_err(ioc
, "NVMe discovery error(0x%02x): wwid(0x%016llx), handle(0x%04x)\n",
6587 access_status
, (u64
)wwid
, handle
);
6594 ioc_info(ioc
, "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6595 desc
, (u64
)wwid
, handle
);
6600 * _scsih_pcie_device_remove_from_sml - removing pcie device
6601 * from SML and free up associated memory
6602 * @ioc: per adapter object
6603 * @pcie_device: the pcie_device object
6606 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
6607 struct _pcie_device
*pcie_device
)
6609 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6612 ioc_info(ioc
, "%s: enter: handle(0x%04x), wwid(0x%016llx)\n",
6614 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
6615 if (pcie_device
->enclosure_handle
!= 0)
6617 ioc_info(ioc
, "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6619 (u64
)pcie_device
->enclosure_logical_id
,
6620 pcie_device
->slot
));
6621 if (pcie_device
->connector_name
[0] != '\0')
6623 ioc_info(ioc
, "%s: enter: enclosure level(0x%04x), connector name(%s)\n",
6625 pcie_device
->enclosure_level
,
6626 pcie_device
->connector_name
));
6628 if (pcie_device
->starget
&& pcie_device
->starget
->hostdata
) {
6629 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
6630 sas_target_priv_data
->deleted
= 1;
6631 _scsih_ublock_io_device(ioc
, pcie_device
->wwid
);
6632 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
6635 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
6636 pcie_device
->handle
, (u64
)pcie_device
->wwid
);
6637 if (pcie_device
->enclosure_handle
!= 0)
6638 ioc_info(ioc
, "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6639 (u64
)pcie_device
->enclosure_logical_id
,
6641 if (pcie_device
->connector_name
[0] != '\0')
6642 ioc_info(ioc
, "removing: enclosure level(0x%04x), connector name( %s)\n",
6643 pcie_device
->enclosure_level
,
6644 pcie_device
->connector_name
);
6646 if (pcie_device
->starget
)
6647 scsi_remove_target(&pcie_device
->starget
->dev
);
6649 ioc_info(ioc
, "%s: exit: handle(0x%04x), wwid(0x%016llx)\n",
6651 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
6652 if (pcie_device
->enclosure_handle
!= 0)
6654 ioc_info(ioc
, "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6656 (u64
)pcie_device
->enclosure_logical_id
,
6657 pcie_device
->slot
));
6658 if (pcie_device
->connector_name
[0] != '\0')
6660 ioc_info(ioc
, "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6662 pcie_device
->enclosure_level
,
6663 pcie_device
->connector_name
));
6665 kfree(pcie_device
->serial_number
);
6670 * _scsih_pcie_check_device - checking device responsiveness
6671 * @ioc: per adapter object
6672 * @handle: attached device handle
6675 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6677 Mpi2ConfigReply_t mpi_reply
;
6678 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6680 struct _pcie_device
*pcie_device
;
6682 unsigned long flags
;
6683 struct scsi_target
*starget
;
6684 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6687 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6688 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6691 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6692 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6695 /* check if this is end device */
6696 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6697 if (!(_scsih_is_nvme_device(device_info
)))
6700 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6701 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
6702 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6705 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6709 if (unlikely(pcie_device
->handle
!= handle
)) {
6710 starget
= pcie_device
->starget
;
6711 sas_target_priv_data
= starget
->hostdata
;
6712 starget_printk(KERN_INFO
, starget
,
6713 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6714 pcie_device
->handle
, handle
);
6715 sas_target_priv_data
->handle
= handle
;
6716 pcie_device
->handle
= handle
;
6718 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6719 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6720 pcie_device
->enclosure_level
=
6721 pcie_device_pg0
.EnclosureLevel
;
6722 memcpy(&pcie_device
->connector_name
[0],
6723 &pcie_device_pg0
.ConnectorName
[0], 4);
6725 pcie_device
->enclosure_level
= 0;
6726 pcie_device
->connector_name
[0] = '\0';
6730 /* check if device is present */
6731 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6732 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6733 ioc_info(ioc
, "device is not present handle(0x%04x), flags!!!\n",
6735 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6736 pcie_device_put(pcie_device
);
6740 /* check if there were any issues with discovery */
6741 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6742 pcie_device_pg0
.AccessStatus
)) {
6743 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6744 pcie_device_put(pcie_device
);
6748 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6749 pcie_device_put(pcie_device
);
6751 _scsih_ublock_io_device(ioc
, wwid
);
6757 * _scsih_pcie_add_device - creating pcie device object
6758 * @ioc: per adapter object
6759 * @handle: pcie device handle
6761 * Creating end device object, stored in ioc->pcie_device_list.
6763 * Return: 1 means queue the event later, 0 means complete the event
6766 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6768 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6769 Mpi26PCIeDevicePage2_t pcie_device_pg2
;
6770 Mpi2ConfigReply_t mpi_reply
;
6771 struct _pcie_device
*pcie_device
;
6772 struct _enclosure_node
*enclosure_dev
;
6776 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6777 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6778 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6779 __FILE__
, __LINE__
, __func__
);
6782 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6783 MPI2_IOCSTATUS_MASK
;
6784 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6785 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6786 __FILE__
, __LINE__
, __func__
);
6790 set_bit(handle
, ioc
->pend_os_device_add
);
6791 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6793 /* check if device is present */
6794 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6795 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6796 ioc_err(ioc
, "device is not present handle(0x04%x)!!!\n",
6801 /* check if there were any issues with discovery */
6802 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6803 pcie_device_pg0
.AccessStatus
))
6806 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
6809 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6811 clear_bit(handle
, ioc
->pend_os_device_add
);
6812 pcie_device_put(pcie_device
);
6816 pcie_device
= kzalloc(sizeof(struct _pcie_device
), GFP_KERNEL
);
6818 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6819 __FILE__
, __LINE__
, __func__
);
6823 kref_init(&pcie_device
->refcount
);
6824 pcie_device
->id
= ioc
->pcie_target_id
++;
6825 pcie_device
->channel
= PCIE_CHANNEL
;
6826 pcie_device
->handle
= handle
;
6827 pcie_device
->device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6828 pcie_device
->wwid
= wwid
;
6829 pcie_device
->port_num
= pcie_device_pg0
.PortNum
;
6830 pcie_device
->fast_path
= (le32_to_cpu(pcie_device_pg0
.Flags
) &
6831 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6833 pcie_device
->enclosure_handle
=
6834 le16_to_cpu(pcie_device_pg0
.EnclosureHandle
);
6835 if (pcie_device
->enclosure_handle
!= 0)
6836 pcie_device
->slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
6838 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6839 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6840 pcie_device
->enclosure_level
= pcie_device_pg0
.EnclosureLevel
;
6841 memcpy(&pcie_device
->connector_name
[0],
6842 &pcie_device_pg0
.ConnectorName
[0], 4);
6844 pcie_device
->enclosure_level
= 0;
6845 pcie_device
->connector_name
[0] = '\0';
6848 /* get enclosure_logical_id */
6849 if (pcie_device
->enclosure_handle
) {
6851 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
6852 pcie_device
->enclosure_handle
);
6854 pcie_device
->enclosure_logical_id
=
6855 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
6857 /* TODO -- Add device name once FW supports it */
6858 if (mpt3sas_config_get_pcie_device_pg2(ioc
, &mpi_reply
,
6859 &pcie_device_pg2
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)) {
6860 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6861 __FILE__
, __LINE__
, __func__
);
6866 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6867 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6868 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6869 __FILE__
, __LINE__
, __func__
);
6873 pcie_device
->nvme_mdts
=
6874 le32_to_cpu(pcie_device_pg2
.MaximumDataTransferSize
);
6875 if (pcie_device_pg2
.ControllerResetTO
)
6876 pcie_device
->reset_timeout
=
6877 pcie_device_pg2
.ControllerResetTO
;
6879 pcie_device
->reset_timeout
= 30;
6881 if (ioc
->wait_for_discovery_to_complete
)
6882 _scsih_pcie_device_init_add(ioc
, pcie_device
);
6884 _scsih_pcie_device_add(ioc
, pcie_device
);
6886 pcie_device_put(pcie_device
);
6891 * _scsih_pcie_topology_change_event_debug - debug for topology
6893 * @ioc: per adapter object
6894 * @event_data: event data payload
6898 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6899 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
6905 char *status_str
= NULL
;
6906 u8 link_rate
, prev_link_rate
;
6908 switch (event_data
->SwitchStatus
) {
6909 case MPI26_EVENT_PCIE_TOPO_SS_ADDED
:
6912 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING
:
6913 status_str
= "remove";
6915 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
:
6917 status_str
= "responding";
6919 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
:
6920 status_str
= "remove delay";
6923 status_str
= "unknown status";
6926 ioc_info(ioc
, "pcie topology change: (%s)\n", status_str
);
6927 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
6928 "start_port(%02d), count(%d)\n",
6929 le16_to_cpu(event_data
->SwitchDevHandle
),
6930 le16_to_cpu(event_data
->EnclosureHandle
),
6931 event_data
->StartPortNum
, event_data
->NumEntries
);
6932 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6934 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
6937 port_number
= event_data
->StartPortNum
+ i
;
6938 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
6939 switch (reason_code
) {
6940 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
6941 status_str
= "target add";
6943 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
6944 status_str
= "target remove";
6946 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
:
6947 status_str
= "delay target remove";
6949 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
6950 status_str
= "link rate change";
6952 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
:
6953 status_str
= "target responding";
6956 status_str
= "unknown";
6959 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
&
6960 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
6961 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
&
6962 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
6963 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
6964 " link rate: new(0x%02x), old(0x%02x)\n", port_number
,
6965 handle
, status_str
, link_rate
, prev_link_rate
);
6970 * _scsih_pcie_topology_change_event - handle PCIe topology
6972 * @ioc: per adapter object
6973 * @fw_event: The fw_event_work object
6978 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6979 struct fw_event_work
*fw_event
)
6984 u8 link_rate
, prev_link_rate
;
6985 unsigned long flags
;
6987 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
=
6988 (Mpi26EventDataPCIeTopologyChangeList_t
*) fw_event
->event_data
;
6989 struct _pcie_device
*pcie_device
;
6991 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6992 _scsih_pcie_topology_change_event_debug(ioc
, event_data
);
6994 if (ioc
->shost_recovery
|| ioc
->remove_host
||
6995 ioc
->pci_error_recovery
)
6998 if (fw_event
->ignore
) {
6999 dewtprintk(ioc
, ioc_info(ioc
, "ignoring switch event\n"));
7003 /* handle siblings events */
7004 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7005 if (fw_event
->ignore
) {
7007 ioc_info(ioc
, "ignoring switch event\n"));
7010 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7012 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7014 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7018 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
7019 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7020 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
7021 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7023 switch (reason_code
) {
7024 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7025 if (ioc
->shost_recovery
)
7027 if (link_rate
== prev_link_rate
)
7029 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7032 _scsih_pcie_check_device(ioc
, handle
);
7034 /* This code after this point handles the test case
7035 * where a device has been added, however its returning
7036 * BUSY for sometime. Then before the Device Missing
7037 * Delay expires and the device becomes READY, the
7038 * device is removed and added back.
7040 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7041 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
7042 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7045 pcie_device_put(pcie_device
);
7049 if (!test_bit(handle
, ioc
->pend_os_device_add
))
7053 ioc_info(ioc
, "handle(0x%04x) device not found: convert event to a device add\n",
7055 event_data
->PortEntry
[i
].PortStatus
&= 0xF0;
7056 event_data
->PortEntry
[i
].PortStatus
|=
7057 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
;
7059 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7060 if (ioc
->shost_recovery
)
7062 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7065 rc
= _scsih_pcie_add_device(ioc
, handle
);
7067 /* mark entry vacant */
7068 /* TODO This needs to be reviewed and fixed,
7069 * we dont have an entry
7070 * to make an event void like vacant
7072 event_data
->PortEntry
[i
].PortStatus
|=
7073 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
;
7076 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7077 _scsih_pcie_device_remove_by_handle(ioc
, handle
);
7084 * _scsih_pcie_device_status_change_event_debug - debug for device event
7086 * @event_data: event data payload
7090 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7091 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
)
7093 char *reason_str
= NULL
;
7095 switch (event_data
->ReasonCode
) {
7096 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
:
7097 reason_str
= "smart data";
7099 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED
:
7100 reason_str
= "unsupported device discovered";
7102 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
:
7103 reason_str
= "internal device reset";
7105 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL
:
7106 reason_str
= "internal task abort";
7108 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
7109 reason_str
= "internal task abort set";
7111 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
7112 reason_str
= "internal clear task set";
7114 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL
:
7115 reason_str
= "internal query task";
7117 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE
:
7118 reason_str
= "device init failure";
7120 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
7121 reason_str
= "internal device reset complete";
7123 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
7124 reason_str
= "internal task abort complete";
7126 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION
:
7127 reason_str
= "internal async notification";
7129 case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED
:
7130 reason_str
= "pcie hot reset failed";
7133 reason_str
= "unknown reason";
7137 ioc_info(ioc
, "PCIE device status change: (%s)\n"
7138 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7139 reason_str
, le16_to_cpu(event_data
->DevHandle
),
7140 (u64
)le64_to_cpu(event_data
->WWID
),
7141 le16_to_cpu(event_data
->TaskTag
));
7142 if (event_data
->ReasonCode
== MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
)
7143 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
7144 event_data
->ASC
, event_data
->ASCQ
);
7149 * _scsih_pcie_device_status_change_event - handle device status
7151 * @ioc: per adapter object
7152 * @fw_event: The fw_event_work object
7156 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7157 struct fw_event_work
*fw_event
)
7159 struct MPT3SAS_TARGET
*target_priv_data
;
7160 struct _pcie_device
*pcie_device
;
7162 unsigned long flags
;
7163 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
=
7164 (Mpi26EventDataPCIeDeviceStatusChange_t
*)fw_event
->event_data
;
7165 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7166 _scsih_pcie_device_status_change_event_debug(ioc
,
7169 if (event_data
->ReasonCode
!=
7170 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
7171 event_data
->ReasonCode
!=
7172 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
7175 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7176 wwid
= le64_to_cpu(event_data
->WWID
);
7177 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
7179 if (!pcie_device
|| !pcie_device
->starget
)
7182 target_priv_data
= pcie_device
->starget
->hostdata
;
7183 if (!target_priv_data
)
7186 if (event_data
->ReasonCode
==
7187 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
)
7188 target_priv_data
->tm_busy
= 1;
7190 target_priv_data
->tm_busy
= 0;
7193 pcie_device_put(pcie_device
);
7195 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7199 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7201 * @ioc: per adapter object
7202 * @event_data: event data payload
7206 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7207 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
7209 char *reason_str
= NULL
;
7211 switch (event_data
->ReasonCode
) {
7212 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7213 reason_str
= "enclosure add";
7215 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7216 reason_str
= "enclosure remove";
7219 reason_str
= "unknown reason";
7223 ioc_info(ioc
, "enclosure status change: (%s)\n"
7224 "\thandle(0x%04x), enclosure logical id(0x%016llx) number slots(%d)\n",
7226 le16_to_cpu(event_data
->EnclosureHandle
),
7227 (u64
)le64_to_cpu(event_data
->EnclosureLogicalID
),
7228 le16_to_cpu(event_data
->StartSlot
));
7232 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7233 * @ioc: per adapter object
7234 * @fw_event: The fw_event_work object
7238 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7239 struct fw_event_work
*fw_event
)
7241 Mpi2ConfigReply_t mpi_reply
;
7242 struct _enclosure_node
*enclosure_dev
= NULL
;
7243 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
=
7244 (Mpi2EventDataSasEnclDevStatusChange_t
*)fw_event
->event_data
;
7246 u16 enclosure_handle
= le16_to_cpu(event_data
->EnclosureHandle
);
7248 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7249 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
7250 (Mpi2EventDataSasEnclDevStatusChange_t
*)
7251 fw_event
->event_data
);
7252 if (ioc
->shost_recovery
)
7255 if (enclosure_handle
)
7257 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
7259 switch (event_data
->ReasonCode
) {
7260 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7261 if (!enclosure_dev
) {
7263 kzalloc(sizeof(struct _enclosure_node
),
7265 if (!enclosure_dev
) {
7266 ioc_info(ioc
, "failure at %s:%d/%s()!\n",
7267 __FILE__
, __LINE__
, __func__
);
7270 rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
7271 &enclosure_dev
->pg0
,
7272 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
7275 if (rc
|| (le16_to_cpu(mpi_reply
.IOCStatus
) &
7276 MPI2_IOCSTATUS_MASK
)) {
7277 kfree(enclosure_dev
);
7281 list_add_tail(&enclosure_dev
->list
,
7282 &ioc
->enclosure_list
);
7285 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7286 if (enclosure_dev
) {
7287 list_del(&enclosure_dev
->list
);
7288 kfree(enclosure_dev
);
7297 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7298 * @ioc: per adapter object
7299 * @fw_event: The fw_event_work object
7303 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
7304 struct fw_event_work
*fw_event
)
7306 struct scsi_cmnd
*scmd
;
7307 struct scsi_device
*sdev
;
7308 struct scsiio_tracker
*st
;
7311 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7312 u32 termination_count
;
7314 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
7315 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
7316 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7317 fw_event
->event_data
;
7319 unsigned long flags
;
7322 u8 task_abort_retries
;
7324 mutex_lock(&ioc
->tm_cmds
.mutex
);
7325 ioc_info(ioc
, "%s: enter: phy number(%d), width(%d)\n",
7326 __func__
, event_data
->PhyNum
, event_data
->PortWidth
);
7328 _scsih_block_io_all_device(ioc
);
7330 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7331 mpi_reply
= ioc
->tm_cmds
.reply
;
7332 broadcast_aen_retry
:
7334 /* sanity checks for retrying this loop */
7335 if (max_retries
++ == 5) {
7336 dewtprintk(ioc
, ioc_info(ioc
, "%s: giving up\n", __func__
));
7338 } else if (max_retries
> 1)
7340 ioc_info(ioc
, "%s: %d retry\n",
7341 __func__
, max_retries
- 1));
7343 termination_count
= 0;
7345 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
7346 if (ioc
->shost_recovery
)
7348 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
7351 st
= scsi_cmd_priv(scmd
);
7352 sdev
= scmd
->device
;
7353 sas_device_priv_data
= sdev
->hostdata
;
7354 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
7356 /* skip hidden raid components */
7357 if (sas_device_priv_data
->sas_target
->flags
&
7358 MPT_TARGET_FLAGS_RAID_COMPONENT
)
7361 if (sas_device_priv_data
->sas_target
->flags
&
7362 MPT_TARGET_FLAGS_VOLUME
)
7364 /* skip PCIe devices */
7365 if (sas_device_priv_data
->sas_target
->flags
&
7366 MPT_TARGET_FLAGS_PCIE_DEVICE
)
7369 handle
= sas_device_priv_data
->sas_target
->handle
;
7370 lun
= sas_device_priv_data
->lun
;
7373 if (ioc
->shost_recovery
)
7376 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7377 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
,
7378 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, st
->smid
,
7379 st
->msix_io
, 30, 0);
7381 sdev_printk(KERN_WARNING
, sdev
,
7382 "mpt3sas_scsih_issue_tm: FAILED when sending "
7383 "QUERY_TASK: scmd(%p)\n", scmd
);
7384 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7385 goto broadcast_aen_retry
;
7387 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
7388 & MPI2_IOCSTATUS_MASK
;
7389 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7390 sdev_printk(KERN_WARNING
, sdev
,
7391 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7393 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7394 goto broadcast_aen_retry
;
7397 /* see if IO is still owned by IOC and target */
7398 if (mpi_reply
->ResponseCode
==
7399 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
7400 mpi_reply
->ResponseCode
==
7401 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
7402 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7405 task_abort_retries
= 0;
7407 if (task_abort_retries
++ == 60) {
7409 ioc_info(ioc
, "%s: ABORT_TASK: giving up\n",
7411 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7412 goto broadcast_aen_retry
;
7415 if (ioc
->shost_recovery
)
7418 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->lun
,
7419 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, st
->smid
,
7420 st
->msix_io
, 30, 0);
7421 if (r
== FAILED
|| st
->cb_idx
!= 0xFF) {
7422 sdev_printk(KERN_WARNING
, sdev
,
7423 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7424 "scmd(%p)\n", scmd
);
7428 if (task_abort_retries
> 1)
7429 sdev_printk(KERN_WARNING
, sdev
,
7430 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7432 task_abort_retries
- 1, scmd
);
7434 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
7435 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7438 if (ioc
->broadcast_aen_pending
) {
7441 "%s: loop back due to pending AEN\n",
7443 ioc
->broadcast_aen_pending
= 0;
7444 goto broadcast_aen_retry
;
7448 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7452 ioc_info(ioc
, "%s - exit, query_count = %d termination_count = %d\n",
7453 __func__
, query_count
, termination_count
));
7455 ioc
->broadcast_aen_busy
= 0;
7456 if (!ioc
->shost_recovery
)
7457 _scsih_ublock_io_all_device(ioc
);
7458 mutex_unlock(&ioc
->tm_cmds
.mutex
);
7462 * _scsih_sas_discovery_event - handle discovery events
7463 * @ioc: per adapter object
7464 * @fw_event: The fw_event_work object
7468 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
7469 struct fw_event_work
*fw_event
)
7471 Mpi2EventDataSasDiscovery_t
*event_data
=
7472 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
7474 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
7475 ioc_info(ioc
, "discovery event: (%s)",
7476 event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
?
7478 if (event_data
->DiscoveryStatus
)
7479 pr_cont("discovery_status(0x%08x)",
7480 le32_to_cpu(event_data
->DiscoveryStatus
));
7484 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
7485 !ioc
->sas_hba
.num_phys
) {
7486 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
7487 /* Wait for the reset to complete */
7488 while (ioc
->shost_recovery
)
7491 _scsih_sas_host_add(ioc
);
7496 * _scsih_sas_device_discovery_error_event - display SAS device discovery error
7498 * @ioc: per adapter object
7499 * @fw_event: The fw_event_work object
7503 _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER
*ioc
,
7504 struct fw_event_work
*fw_event
)
7506 Mpi25EventDataSasDeviceDiscoveryError_t
*event_data
=
7507 (Mpi25EventDataSasDeviceDiscoveryError_t
*)fw_event
->event_data
;
7509 switch (event_data
->ReasonCode
) {
7510 case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED
:
7511 ioc_warn(ioc
, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has failed\n",
7512 le16_to_cpu(event_data
->DevHandle
),
7513 (u64
)le64_to_cpu(event_data
->SASAddress
),
7514 event_data
->PhysicalPort
);
7516 case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT
:
7517 ioc_warn(ioc
, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has timed out\n",
7518 le16_to_cpu(event_data
->DevHandle
),
7519 (u64
)le64_to_cpu(event_data
->SASAddress
),
7520 event_data
->PhysicalPort
);
7528 * _scsih_pcie_enumeration_event - handle enumeration events
7529 * @ioc: per adapter object
7530 * @fw_event: The fw_event_work object
7534 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER
*ioc
,
7535 struct fw_event_work
*fw_event
)
7537 Mpi26EventDataPCIeEnumeration_t
*event_data
=
7538 (Mpi26EventDataPCIeEnumeration_t
*)fw_event
->event_data
;
7540 if (!(ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
))
7543 ioc_info(ioc
, "pcie enumeration event: (%s) Flag 0x%02x",
7544 (event_data
->ReasonCode
== MPI26_EVENT_PCIE_ENUM_RC_STARTED
) ?
7545 "started" : "completed",
7547 if (event_data
->EnumerationStatus
)
7548 pr_cont("enumeration_status(0x%08x)",
7549 le32_to_cpu(event_data
->EnumerationStatus
));
7554 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7555 * @ioc: per adapter object
7556 * @handle: device handle for physical disk
7557 * @phys_disk_num: physical disk number
7559 * Return: 0 for success, else failure.
7562 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
7564 Mpi2RaidActionRequest_t
*mpi_request
;
7565 Mpi2RaidActionReply_t
*mpi_reply
;
7572 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
7575 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7577 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7578 ioc_err(ioc
, "%s: scsih_cmd in use\n", __func__
);
7582 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7584 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7586 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
7587 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7592 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7593 ioc
->scsih_cmds
.smid
= smid
;
7594 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7596 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7597 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
7598 mpi_request
->PhysDiskNum
= phys_disk_num
;
7601 ioc_info(ioc
, "IR RAID_ACTION: turning fast path on for handle(0x%04x), phys_disk_num (0x%02x)\n",
7602 handle
, phys_disk_num
));
7604 init_completion(&ioc
->scsih_cmds
.done
);
7605 ioc
->put_smid_default(ioc
, smid
);
7606 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7608 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7610 mpt3sas_base_check_cmd_timeout(ioc
,
7611 ioc
->scsih_cmds
.status
, mpi_request
,
7612 sizeof(Mpi2RaidActionRequest_t
)/4);
7617 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7619 mpi_reply
= ioc
->scsih_cmds
.reply
;
7620 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
7621 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
7622 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
7625 ioc_status
&= MPI2_IOCSTATUS_MASK
;
7626 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7628 ioc_info(ioc
, "IR RAID_ACTION: failed: ioc_status(0x%04x), loginfo(0x%08x)!!!\n",
7629 ioc_status
, log_info
));
7633 ioc_info(ioc
, "IR RAID_ACTION: completed successfully\n"));
7637 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7638 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7641 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
7646 * _scsih_reprobe_lun - reprobing lun
7647 * @sdev: scsi device struct
7648 * @no_uld_attach: sdev->no_uld_attach flag setting
7652 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
7654 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
7655 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
7656 sdev
->no_uld_attach
? "hiding" : "exposing");
7657 WARN_ON(scsi_device_reprobe(sdev
));
7661 * _scsih_sas_volume_add - add new volume
7662 * @ioc: per adapter object
7663 * @element: IR config element data
7667 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
7668 Mpi2EventIrConfigElement_t
*element
)
7670 struct _raid_device
*raid_device
;
7671 unsigned long flags
;
7673 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
7676 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
7678 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7679 __FILE__
, __LINE__
, __func__
);
7683 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7684 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
7685 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7690 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
7692 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7693 __FILE__
, __LINE__
, __func__
);
7697 raid_device
->id
= ioc
->sas_id
++;
7698 raid_device
->channel
= RAID_CHANNEL
;
7699 raid_device
->handle
= handle
;
7700 raid_device
->wwid
= wwid
;
7701 _scsih_raid_device_add(ioc
, raid_device
);
7702 if (!ioc
->wait_for_discovery_to_complete
) {
7703 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7704 raid_device
->id
, 0);
7706 _scsih_raid_device_remove(ioc
, raid_device
);
7708 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7709 _scsih_determine_boot_device(ioc
, raid_device
, 1);
7710 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7715 * _scsih_sas_volume_delete - delete volume
7716 * @ioc: per adapter object
7717 * @handle: volume device handle
7721 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
7723 struct _raid_device
*raid_device
;
7724 unsigned long flags
;
7725 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7726 struct scsi_target
*starget
= NULL
;
7728 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7729 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7731 if (raid_device
->starget
) {
7732 starget
= raid_device
->starget
;
7733 sas_target_priv_data
= starget
->hostdata
;
7734 sas_target_priv_data
->deleted
= 1;
7736 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
7737 raid_device
->handle
, (u64
)raid_device
->wwid
);
7738 list_del(&raid_device
->list
);
7741 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7743 scsi_remove_target(&starget
->dev
);
7747 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7748 * @ioc: per adapter object
7749 * @element: IR config element data
7753 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
7754 Mpi2EventIrConfigElement_t
*element
)
7756 struct _sas_device
*sas_device
;
7757 struct scsi_target
*starget
= NULL
;
7758 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7759 unsigned long flags
;
7760 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7762 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7763 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7765 sas_device
->volume_handle
= 0;
7766 sas_device
->volume_wwid
= 0;
7767 clear_bit(handle
, ioc
->pd_handles
);
7768 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7769 starget
= sas_device
->starget
;
7770 sas_target_priv_data
= starget
->hostdata
;
7771 sas_target_priv_data
->flags
&=
7772 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
7775 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7779 /* exposing raid component */
7781 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
7783 sas_device_put(sas_device
);
7787 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7788 * @ioc: per adapter object
7789 * @element: IR config element data
7793 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
7794 Mpi2EventIrConfigElement_t
*element
)
7796 struct _sas_device
*sas_device
;
7797 struct scsi_target
*starget
= NULL
;
7798 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7799 unsigned long flags
;
7800 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7801 u16 volume_handle
= 0;
7802 u64 volume_wwid
= 0;
7804 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
7806 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
7809 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7810 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7812 set_bit(handle
, ioc
->pd_handles
);
7813 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7814 starget
= sas_device
->starget
;
7815 sas_target_priv_data
= starget
->hostdata
;
7816 sas_target_priv_data
->flags
|=
7817 MPT_TARGET_FLAGS_RAID_COMPONENT
;
7818 sas_device
->volume_handle
= volume_handle
;
7819 sas_device
->volume_wwid
= volume_wwid
;
7822 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7826 /* hiding raid component */
7827 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7830 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
7832 sas_device_put(sas_device
);
7836 * _scsih_sas_pd_delete - delete pd component
7837 * @ioc: per adapter object
7838 * @element: IR config element data
7842 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
7843 Mpi2EventIrConfigElement_t
*element
)
7845 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7847 _scsih_device_remove_by_handle(ioc
, handle
);
7851 * _scsih_sas_pd_add - remove pd component
7852 * @ioc: per adapter object
7853 * @element: IR config element data
7857 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
7858 Mpi2EventIrConfigElement_t
*element
)
7860 struct _sas_device
*sas_device
;
7861 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7862 Mpi2ConfigReply_t mpi_reply
;
7863 Mpi2SasDevicePage0_t sas_device_pg0
;
7868 set_bit(handle
, ioc
->pd_handles
);
7870 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7872 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7873 sas_device_put(sas_device
);
7877 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
7878 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
7879 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7880 __FILE__
, __LINE__
, __func__
);
7884 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7885 MPI2_IOCSTATUS_MASK
;
7886 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7887 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7888 __FILE__
, __LINE__
, __func__
);
7892 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7893 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
7894 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7895 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7897 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7898 _scsih_add_device(ioc
, handle
, 0, 1);
7902 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
7903 * @ioc: per adapter object
7904 * @event_data: event data payload
7908 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7909 Mpi2EventDataIrConfigChangeList_t
*event_data
)
7911 Mpi2EventIrConfigElement_t
*element
;
7914 char *reason_str
= NULL
, *element_str
= NULL
;
7916 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
7918 ioc_info(ioc
, "raid config change: (%s), elements(%d)\n",
7919 le32_to_cpu(event_data
->Flags
) & MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
?
7920 "foreign" : "native",
7921 event_data
->NumElements
);
7922 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
7923 switch (element
->ReasonCode
) {
7924 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
7927 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
7928 reason_str
= "remove";
7930 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
7931 reason_str
= "no change";
7933 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
7934 reason_str
= "hide";
7936 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
7937 reason_str
= "unhide";
7939 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
7940 reason_str
= "volume_created";
7942 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
7943 reason_str
= "volume_deleted";
7945 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
7946 reason_str
= "pd_created";
7948 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
7949 reason_str
= "pd_deleted";
7952 reason_str
= "unknown reason";
7955 element_type
= le16_to_cpu(element
->ElementFlags
) &
7956 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
7957 switch (element_type
) {
7958 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
7959 element_str
= "volume";
7961 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
7962 element_str
= "phys disk";
7964 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
7965 element_str
= "hot spare";
7968 element_str
= "unknown element";
7971 pr_info("\t(%s:%s), vol handle(0x%04x), " \
7972 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
7973 reason_str
, le16_to_cpu(element
->VolDevHandle
),
7974 le16_to_cpu(element
->PhysDiskDevHandle
),
7975 element
->PhysDiskNum
);
7980 * _scsih_sas_ir_config_change_event - handle ir configuration change events
7981 * @ioc: per adapter object
7982 * @fw_event: The fw_event_work object
7986 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7987 struct fw_event_work
*fw_event
)
7989 Mpi2EventIrConfigElement_t
*element
;
7992 Mpi2EventDataIrConfigChangeList_t
*event_data
=
7993 (Mpi2EventDataIrConfigChangeList_t
*)
7994 fw_event
->event_data
;
7996 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
7997 (!ioc
->hide_ir_msg
))
7998 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
8000 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
8001 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
8003 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8004 if (ioc
->shost_recovery
&&
8005 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
8006 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8007 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
8008 _scsih_ir_fastpath(ioc
,
8009 le16_to_cpu(element
->PhysDiskDevHandle
),
8010 element
->PhysDiskNum
);
8015 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8017 switch (element
->ReasonCode
) {
8018 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8019 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8020 if (!foreign_config
)
8021 _scsih_sas_volume_add(ioc
, element
);
8023 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8024 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8025 if (!foreign_config
)
8026 _scsih_sas_volume_delete(ioc
,
8027 le16_to_cpu(element
->VolDevHandle
));
8029 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8030 if (!ioc
->is_warpdrive
)
8031 _scsih_sas_pd_hide(ioc
, element
);
8033 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8034 if (!ioc
->is_warpdrive
)
8035 _scsih_sas_pd_expose(ioc
, element
);
8037 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8038 if (!ioc
->is_warpdrive
)
8039 _scsih_sas_pd_add(ioc
, element
);
8041 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8042 if (!ioc
->is_warpdrive
)
8043 _scsih_sas_pd_delete(ioc
, element
);
8050 * _scsih_sas_ir_volume_event - IR volume event
8051 * @ioc: per adapter object
8052 * @fw_event: The fw_event_work object
8056 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
8057 struct fw_event_work
*fw_event
)
8060 unsigned long flags
;
8061 struct _raid_device
*raid_device
;
8065 Mpi2EventDataIrVolume_t
*event_data
=
8066 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
8068 if (ioc
->shost_recovery
)
8071 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
8074 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8075 state
= le32_to_cpu(event_data
->NewValue
);
8076 if (!ioc
->hide_ir_msg
)
8078 ioc_info(ioc
, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8080 le32_to_cpu(event_data
->PreviousValue
),
8083 case MPI2_RAID_VOL_STATE_MISSING
:
8084 case MPI2_RAID_VOL_STATE_FAILED
:
8085 _scsih_sas_volume_delete(ioc
, handle
);
8088 case MPI2_RAID_VOL_STATE_ONLINE
:
8089 case MPI2_RAID_VOL_STATE_DEGRADED
:
8090 case MPI2_RAID_VOL_STATE_OPTIMAL
:
8092 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8093 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8094 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8099 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
8101 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8102 __FILE__
, __LINE__
, __func__
);
8106 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
8108 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8109 __FILE__
, __LINE__
, __func__
);
8113 raid_device
->id
= ioc
->sas_id
++;
8114 raid_device
->channel
= RAID_CHANNEL
;
8115 raid_device
->handle
= handle
;
8116 raid_device
->wwid
= wwid
;
8117 _scsih_raid_device_add(ioc
, raid_device
);
8118 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8119 raid_device
->id
, 0);
8121 _scsih_raid_device_remove(ioc
, raid_device
);
8124 case MPI2_RAID_VOL_STATE_INITIALIZING
:
8131 * _scsih_sas_ir_physical_disk_event - PD event
8132 * @ioc: per adapter object
8133 * @fw_event: The fw_event_work object
8137 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
8138 struct fw_event_work
*fw_event
)
8140 u16 handle
, parent_handle
;
8142 struct _sas_device
*sas_device
;
8143 Mpi2ConfigReply_t mpi_reply
;
8144 Mpi2SasDevicePage0_t sas_device_pg0
;
8146 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
8147 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
8150 if (ioc
->shost_recovery
)
8153 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
8156 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
8157 state
= le32_to_cpu(event_data
->NewValue
);
8159 if (!ioc
->hide_ir_msg
)
8161 ioc_info(ioc
, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8163 le32_to_cpu(event_data
->PreviousValue
),
8167 case MPI2_RAID_PD_STATE_ONLINE
:
8168 case MPI2_RAID_PD_STATE_DEGRADED
:
8169 case MPI2_RAID_PD_STATE_REBUILDING
:
8170 case MPI2_RAID_PD_STATE_OPTIMAL
:
8171 case MPI2_RAID_PD_STATE_HOT_SPARE
:
8173 if (!ioc
->is_warpdrive
)
8174 set_bit(handle
, ioc
->pd_handles
);
8176 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8178 sas_device_put(sas_device
);
8182 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8183 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
8185 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8186 __FILE__
, __LINE__
, __func__
);
8190 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8191 MPI2_IOCSTATUS_MASK
;
8192 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8193 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8194 __FILE__
, __LINE__
, __func__
);
8198 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8199 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
8200 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
8201 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
8203 _scsih_add_device(ioc
, handle
, 0, 1);
8207 case MPI2_RAID_PD_STATE_OFFLINE
:
8208 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
8209 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
8216 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8217 * @ioc: per adapter object
8218 * @event_data: event data payload
8222 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8223 Mpi2EventDataIrOperationStatus_t
*event_data
)
8225 char *reason_str
= NULL
;
8227 switch (event_data
->RAIDOperation
) {
8228 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
8229 reason_str
= "resync";
8231 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
8232 reason_str
= "online capacity expansion";
8234 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
8235 reason_str
= "consistency check";
8237 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
8238 reason_str
= "background init";
8240 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
8241 reason_str
= "make data consistent";
8248 ioc_info(ioc
, "raid operational status: (%s)\thandle(0x%04x), percent complete(%d)\n",
8250 le16_to_cpu(event_data
->VolDevHandle
),
8251 event_data
->PercentComplete
);
8255 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8256 * @ioc: per adapter object
8257 * @fw_event: The fw_event_work object
8261 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
8262 struct fw_event_work
*fw_event
)
8264 Mpi2EventDataIrOperationStatus_t
*event_data
=
8265 (Mpi2EventDataIrOperationStatus_t
*)
8266 fw_event
->event_data
;
8267 static struct _raid_device
*raid_device
;
8268 unsigned long flags
;
8271 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8272 (!ioc
->hide_ir_msg
))
8273 _scsih_sas_ir_operation_status_event_debug(ioc
,
8276 /* code added for raid transport support */
8277 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
8279 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8280 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8281 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8283 raid_device
->percent_complete
=
8284 event_data
->PercentComplete
;
8285 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8290 * _scsih_prep_device_scan - initialize parameters prior to device scan
8291 * @ioc: per adapter object
8293 * Set the deleted flag prior to device scan. If the device is found during
8294 * the scan, then we clear the deleted flag.
8297 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
8299 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
8300 struct scsi_device
*sdev
;
8302 shost_for_each_device(sdev
, ioc
->shost
) {
8303 sas_device_priv_data
= sdev
->hostdata
;
8304 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
8305 sas_device_priv_data
->sas_target
->deleted
= 1;
8310 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8311 * @ioc: per adapter object
8312 * @sas_device_pg0: SAS Device page 0
8314 * After host reset, find out whether devices are still responding.
8315 * Used in _scsih_remove_unresponsive_sas_devices.
8318 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
8319 Mpi2SasDevicePage0_t
*sas_device_pg0
)
8321 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8322 struct scsi_target
*starget
;
8323 struct _sas_device
*sas_device
= NULL
;
8324 struct _enclosure_node
*enclosure_dev
= NULL
;
8325 unsigned long flags
;
8327 if (sas_device_pg0
->EnclosureHandle
) {
8329 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
8330 le16_to_cpu(sas_device_pg0
->EnclosureHandle
));
8331 if (enclosure_dev
== NULL
)
8332 ioc_info(ioc
, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
8333 sas_device_pg0
->EnclosureHandle
);
8335 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8336 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
8337 if ((sas_device
->sas_address
== le64_to_cpu(
8338 sas_device_pg0
->SASAddress
)) && (sas_device
->slot
==
8339 le16_to_cpu(sas_device_pg0
->Slot
))) {
8340 sas_device
->responding
= 1;
8341 starget
= sas_device
->starget
;
8342 if (starget
&& starget
->hostdata
) {
8343 sas_target_priv_data
= starget
->hostdata
;
8344 sas_target_priv_data
->tm_busy
= 0;
8345 sas_target_priv_data
->deleted
= 0;
8347 sas_target_priv_data
= NULL
;
8349 starget_printk(KERN_INFO
, starget
,
8350 "handle(0x%04x), sas_addr(0x%016llx)\n",
8351 le16_to_cpu(sas_device_pg0
->DevHandle
),
8352 (unsigned long long)
8353 sas_device
->sas_address
);
8355 if (sas_device
->enclosure_handle
!= 0)
8356 starget_printk(KERN_INFO
, starget
,
8357 "enclosure logical id(0x%016llx),"
8359 (unsigned long long)
8360 sas_device
->enclosure_logical_id
,
8363 if (le16_to_cpu(sas_device_pg0
->Flags
) &
8364 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
8365 sas_device
->enclosure_level
=
8366 sas_device_pg0
->EnclosureLevel
;
8367 memcpy(&sas_device
->connector_name
[0],
8368 &sas_device_pg0
->ConnectorName
[0], 4);
8370 sas_device
->enclosure_level
= 0;
8371 sas_device
->connector_name
[0] = '\0';
8374 sas_device
->enclosure_handle
=
8375 le16_to_cpu(sas_device_pg0
->EnclosureHandle
);
8376 sas_device
->is_chassis_slot_valid
= 0;
8377 if (enclosure_dev
) {
8378 sas_device
->enclosure_logical_id
= le64_to_cpu(
8379 enclosure_dev
->pg0
.EnclosureLogicalID
);
8380 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
8381 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
8382 sas_device
->is_chassis_slot_valid
= 1;
8383 sas_device
->chassis_slot
=
8384 enclosure_dev
->pg0
.ChassisSlot
;
8388 if (sas_device
->handle
== le16_to_cpu(
8389 sas_device_pg0
->DevHandle
))
8391 pr_info("\thandle changed from(0x%04x)!!!\n",
8392 sas_device
->handle
);
8393 sas_device
->handle
= le16_to_cpu(
8394 sas_device_pg0
->DevHandle
);
8395 if (sas_target_priv_data
)
8396 sas_target_priv_data
->handle
=
8397 le16_to_cpu(sas_device_pg0
->DevHandle
);
8402 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8406 * _scsih_create_enclosure_list_after_reset - Free Existing list,
8407 * And create enclosure list by scanning all Enclosure Page(0)s
8408 * @ioc: per adapter object
8411 _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
8413 struct _enclosure_node
*enclosure_dev
;
8414 Mpi2ConfigReply_t mpi_reply
;
8415 u16 enclosure_handle
;
8418 /* Free existing enclosure list */
8419 mpt3sas_free_enclosure_list(ioc
);
8421 /* Re constructing enclosure list after reset*/
8422 enclosure_handle
= 0xFFFF;
8425 kzalloc(sizeof(struct _enclosure_node
), GFP_KERNEL
);
8426 if (!enclosure_dev
) {
8427 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8428 __FILE__
, __LINE__
, __func__
);
8431 rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
8432 &enclosure_dev
->pg0
,
8433 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE
,
8436 if (rc
|| (le16_to_cpu(mpi_reply
.IOCStatus
) &
8437 MPI2_IOCSTATUS_MASK
)) {
8438 kfree(enclosure_dev
);
8441 list_add_tail(&enclosure_dev
->list
,
8442 &ioc
->enclosure_list
);
8444 le16_to_cpu(enclosure_dev
->pg0
.EnclosureHandle
);
8449 * _scsih_search_responding_sas_devices -
8450 * @ioc: per adapter object
8452 * After host reset, find out whether devices are still responding.
8456 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
8458 Mpi2SasDevicePage0_t sas_device_pg0
;
8459 Mpi2ConfigReply_t mpi_reply
;
8464 ioc_info(ioc
, "search for end-devices: start\n");
8466 if (list_empty(&ioc
->sas_device_list
))
8470 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8471 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8473 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8474 MPI2_IOCSTATUS_MASK
;
8475 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8477 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
8478 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
8479 if (!(_scsih_is_end_device(device_info
)))
8481 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
8485 ioc_info(ioc
, "search for end-devices: complete\n");
8489 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8490 * @ioc: per adapter object
8491 * @pcie_device_pg0: PCIe Device page 0
8493 * After host reset, find out whether devices are still responding.
8494 * Used in _scsih_remove_unresponding_devices.
8497 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER
*ioc
,
8498 Mpi26PCIeDevicePage0_t
*pcie_device_pg0
)
8500 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8501 struct scsi_target
*starget
;
8502 struct _pcie_device
*pcie_device
;
8503 unsigned long flags
;
8505 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8506 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
) {
8507 if ((pcie_device
->wwid
== le64_to_cpu(pcie_device_pg0
->WWID
))
8508 && (pcie_device
->slot
== le16_to_cpu(
8509 pcie_device_pg0
->Slot
))) {
8510 pcie_device
->responding
= 1;
8511 starget
= pcie_device
->starget
;
8512 if (starget
&& starget
->hostdata
) {
8513 sas_target_priv_data
= starget
->hostdata
;
8514 sas_target_priv_data
->tm_busy
= 0;
8515 sas_target_priv_data
->deleted
= 0;
8517 sas_target_priv_data
= NULL
;
8519 starget_printk(KERN_INFO
, starget
,
8520 "handle(0x%04x), wwid(0x%016llx) ",
8521 pcie_device
->handle
,
8522 (unsigned long long)pcie_device
->wwid
);
8523 if (pcie_device
->enclosure_handle
!= 0)
8524 starget_printk(KERN_INFO
, starget
,
8525 "enclosure logical id(0x%016llx), "
8527 (unsigned long long)
8528 pcie_device
->enclosure_logical_id
,
8532 if (((le32_to_cpu(pcie_device_pg0
->Flags
)) &
8533 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) &&
8534 (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
)) {
8535 pcie_device
->enclosure_level
=
8536 pcie_device_pg0
->EnclosureLevel
;
8537 memcpy(&pcie_device
->connector_name
[0],
8538 &pcie_device_pg0
->ConnectorName
[0], 4);
8540 pcie_device
->enclosure_level
= 0;
8541 pcie_device
->connector_name
[0] = '\0';
8544 if (pcie_device
->handle
== le16_to_cpu(
8545 pcie_device_pg0
->DevHandle
))
8547 pr_info("\thandle changed from(0x%04x)!!!\n",
8548 pcie_device
->handle
);
8549 pcie_device
->handle
= le16_to_cpu(
8550 pcie_device_pg0
->DevHandle
);
8551 if (sas_target_priv_data
)
8552 sas_target_priv_data
->handle
=
8553 le16_to_cpu(pcie_device_pg0
->DevHandle
);
8559 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8563 * _scsih_search_responding_pcie_devices -
8564 * @ioc: per adapter object
8566 * After host reset, find out whether devices are still responding.
8570 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER
*ioc
)
8572 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
8573 Mpi2ConfigReply_t mpi_reply
;
8578 ioc_info(ioc
, "search for end-devices: start\n");
8580 if (list_empty(&ioc
->pcie_device_list
))
8584 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
8585 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8587 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8588 MPI2_IOCSTATUS_MASK
;
8589 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8590 ioc_info(ioc
, "\tbreak from %s: ioc_status(0x%04x), loginfo(0x%08x)\n",
8591 __func__
, ioc_status
,
8592 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8595 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
8596 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
8597 if (!(_scsih_is_nvme_device(device_info
)))
8599 _scsih_mark_responding_pcie_device(ioc
, &pcie_device_pg0
);
8602 ioc_info(ioc
, "search for PCIe end-devices: complete\n");
8606 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8607 * @ioc: per adapter object
8608 * @wwid: world wide identifier for raid volume
8609 * @handle: device handle
8611 * After host reset, find out whether devices are still responding.
8612 * Used in _scsih_remove_unresponsive_raid_devices.
8615 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
8618 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8619 struct scsi_target
*starget
;
8620 struct _raid_device
*raid_device
;
8621 unsigned long flags
;
8623 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8624 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
8625 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
8626 starget
= raid_device
->starget
;
8627 if (starget
&& starget
->hostdata
) {
8628 sas_target_priv_data
= starget
->hostdata
;
8629 sas_target_priv_data
->deleted
= 0;
8631 sas_target_priv_data
= NULL
;
8632 raid_device
->responding
= 1;
8633 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8634 starget_printk(KERN_INFO
, raid_device
->starget
,
8635 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
8636 (unsigned long long)raid_device
->wwid
);
8639 * WARPDRIVE: The handles of the PDs might have changed
8640 * across the host reset so re-initialize the
8641 * required data for Direct IO
8643 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
8644 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8645 if (raid_device
->handle
== handle
) {
8646 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
8650 pr_info("\thandle changed from(0x%04x)!!!\n",
8651 raid_device
->handle
);
8652 raid_device
->handle
= handle
;
8653 if (sas_target_priv_data
)
8654 sas_target_priv_data
->handle
= handle
;
8655 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8659 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8663 * _scsih_search_responding_raid_devices -
8664 * @ioc: per adapter object
8666 * After host reset, find out whether devices are still responding.
8670 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
8672 Mpi2RaidVolPage1_t volume_pg1
;
8673 Mpi2RaidVolPage0_t volume_pg0
;
8674 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8675 Mpi2ConfigReply_t mpi_reply
;
8680 if (!ioc
->ir_firmware
)
8683 ioc_info(ioc
, "search for raid volumes: start\n");
8685 if (list_empty(&ioc
->raid_device_list
))
8689 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
8690 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
8691 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8692 MPI2_IOCSTATUS_MASK
;
8693 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8695 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
8697 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
8698 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
8699 sizeof(Mpi2RaidVolPage0_t
)))
8702 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
8703 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
8704 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
8705 _scsih_mark_responding_raid_device(ioc
,
8706 le64_to_cpu(volume_pg1
.WWID
), handle
);
8709 /* refresh the pd_handles */
8710 if (!ioc
->is_warpdrive
) {
8711 phys_disk_num
= 0xFF;
8712 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
8713 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
8714 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
8716 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8717 MPI2_IOCSTATUS_MASK
;
8718 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8720 phys_disk_num
= pd_pg0
.PhysDiskNum
;
8721 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
8722 set_bit(handle
, ioc
->pd_handles
);
8726 ioc_info(ioc
, "search for responding raid volumes: complete\n");
8730 * _scsih_mark_responding_expander - mark a expander as responding
8731 * @ioc: per adapter object
8732 * @expander_pg0:SAS Expander Config Page0
8734 * After host reset, find out whether devices are still responding.
8735 * Used in _scsih_remove_unresponsive_expanders.
8738 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
,
8739 Mpi2ExpanderPage0_t
*expander_pg0
)
8741 struct _sas_node
*sas_expander
= NULL
;
8742 unsigned long flags
;
8744 struct _enclosure_node
*enclosure_dev
= NULL
;
8745 u16 handle
= le16_to_cpu(expander_pg0
->DevHandle
);
8746 u16 enclosure_handle
= le16_to_cpu(expander_pg0
->EnclosureHandle
);
8747 u64 sas_address
= le64_to_cpu(expander_pg0
->SASAddress
);
8749 if (enclosure_handle
)
8751 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
8754 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8755 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
8756 if (sas_expander
->sas_address
!= sas_address
)
8758 sas_expander
->responding
= 1;
8760 if (enclosure_dev
) {
8761 sas_expander
->enclosure_logical_id
=
8762 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
8763 sas_expander
->enclosure_handle
=
8764 le16_to_cpu(expander_pg0
->EnclosureHandle
);
8767 if (sas_expander
->handle
== handle
)
8769 pr_info("\texpander(0x%016llx): handle changed" \
8770 " from(0x%04x) to (0x%04x)!!!\n",
8771 (unsigned long long)sas_expander
->sas_address
,
8772 sas_expander
->handle
, handle
);
8773 sas_expander
->handle
= handle
;
8774 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
8775 sas_expander
->phy
[i
].handle
= handle
;
8779 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8783 * _scsih_search_responding_expanders -
8784 * @ioc: per adapter object
8786 * After host reset, find out whether devices are still responding.
8790 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
8792 Mpi2ExpanderPage0_t expander_pg0
;
8793 Mpi2ConfigReply_t mpi_reply
;
8798 ioc_info(ioc
, "search for expanders: start\n");
8800 if (list_empty(&ioc
->sas_expander_list
))
8804 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8805 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8807 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8808 MPI2_IOCSTATUS_MASK
;
8809 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8812 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
8813 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
8814 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8816 (unsigned long long)sas_address
);
8817 _scsih_mark_responding_expander(ioc
, &expander_pg0
);
8821 ioc_info(ioc
, "search for expanders: complete\n");
8825 * _scsih_remove_unresponding_devices - removing unresponding devices
8826 * @ioc: per adapter object
8829 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER
*ioc
)
8831 struct _sas_device
*sas_device
, *sas_device_next
;
8832 struct _sas_node
*sas_expander
, *sas_expander_next
;
8833 struct _raid_device
*raid_device
, *raid_device_next
;
8834 struct _pcie_device
*pcie_device
, *pcie_device_next
;
8835 struct list_head tmp_list
;
8836 unsigned long flags
;
8839 ioc_info(ioc
, "removing unresponding devices: start\n");
8841 /* removing unresponding end devices */
8842 ioc_info(ioc
, "removing unresponding devices: end-devices\n");
8844 * Iterate, pulling off devices marked as non-responding. We become the
8845 * owner for the reference the list had on any object we prune.
8847 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8848 list_for_each_entry_safe(sas_device
, sas_device_next
,
8849 &ioc
->sas_device_list
, list
) {
8850 if (!sas_device
->responding
)
8851 list_move_tail(&sas_device
->list
, &head
);
8853 sas_device
->responding
= 0;
8855 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8858 * Now, uninitialize and remove the unresponding devices we pruned.
8860 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
8861 _scsih_remove_device(ioc
, sas_device
);
8862 list_del_init(&sas_device
->list
);
8863 sas_device_put(sas_device
);
8866 ioc_info(ioc
, "Removing unresponding devices: pcie end-devices\n");
8867 INIT_LIST_HEAD(&head
);
8868 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8869 list_for_each_entry_safe(pcie_device
, pcie_device_next
,
8870 &ioc
->pcie_device_list
, list
) {
8871 if (!pcie_device
->responding
)
8872 list_move_tail(&pcie_device
->list
, &head
);
8874 pcie_device
->responding
= 0;
8876 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8878 list_for_each_entry_safe(pcie_device
, pcie_device_next
, &head
, list
) {
8879 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
8880 list_del_init(&pcie_device
->list
);
8881 pcie_device_put(pcie_device
);
8884 /* removing unresponding volumes */
8885 if (ioc
->ir_firmware
) {
8886 ioc_info(ioc
, "removing unresponding devices: volumes\n");
8887 list_for_each_entry_safe(raid_device
, raid_device_next
,
8888 &ioc
->raid_device_list
, list
) {
8889 if (!raid_device
->responding
)
8890 _scsih_sas_volume_delete(ioc
,
8891 raid_device
->handle
);
8893 raid_device
->responding
= 0;
8897 /* removing unresponding expanders */
8898 ioc_info(ioc
, "removing unresponding devices: expanders\n");
8899 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8900 INIT_LIST_HEAD(&tmp_list
);
8901 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
8902 &ioc
->sas_expander_list
, list
) {
8903 if (!sas_expander
->responding
)
8904 list_move_tail(&sas_expander
->list
, &tmp_list
);
8906 sas_expander
->responding
= 0;
8908 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8909 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
8911 _scsih_expander_node_remove(ioc
, sas_expander
);
8914 ioc_info(ioc
, "removing unresponding devices: complete\n");
8916 /* unblock devices */
8917 _scsih_ublock_io_all_device(ioc
);
8921 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
8922 struct _sas_node
*sas_expander
, u16 handle
)
8924 Mpi2ExpanderPage1_t expander_pg1
;
8925 Mpi2ConfigReply_t mpi_reply
;
8928 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
8929 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
8930 &expander_pg1
, i
, handle
))) {
8931 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8932 __FILE__
, __LINE__
, __func__
);
8936 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
8937 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
8938 expander_pg1
.NegotiatedLinkRate
>> 4);
8943 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
8944 * @ioc: per adapter object
8947 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
8949 Mpi2ExpanderPage0_t expander_pg0
;
8950 Mpi2SasDevicePage0_t sas_device_pg0
;
8951 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
8952 Mpi2RaidVolPage1_t volume_pg1
;
8953 Mpi2RaidVolPage0_t volume_pg0
;
8954 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8955 Mpi2EventIrConfigElement_t element
;
8956 Mpi2ConfigReply_t mpi_reply
;
8959 u16 handle
, parent_handle
;
8961 struct _sas_device
*sas_device
;
8962 struct _pcie_device
*pcie_device
;
8963 struct _sas_node
*expander_device
;
8964 static struct _raid_device
*raid_device
;
8966 unsigned long flags
;
8968 ioc_info(ioc
, "scan devices: start\n");
8970 _scsih_sas_host_refresh(ioc
);
8972 ioc_info(ioc
, "\tscan devices: expanders start\n");
8976 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8977 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8978 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8979 MPI2_IOCSTATUS_MASK
;
8980 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8981 ioc_info(ioc
, "\tbreak from expander scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
8982 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
8985 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
8986 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8987 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
8988 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
8989 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8990 if (expander_device
)
8991 _scsih_refresh_expander_links(ioc
, expander_device
,
8994 ioc_info(ioc
, "\tBEFORE adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
8996 (u64
)le64_to_cpu(expander_pg0
.SASAddress
));
8997 _scsih_expander_add(ioc
, handle
);
8998 ioc_info(ioc
, "\tAFTER adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
9000 (u64
)le64_to_cpu(expander_pg0
.SASAddress
));
9004 ioc_info(ioc
, "\tscan devices: expanders complete\n");
9006 if (!ioc
->ir_firmware
)
9009 ioc_info(ioc
, "\tscan devices: phys disk start\n");
9012 phys_disk_num
= 0xFF;
9013 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
9014 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
9016 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9017 MPI2_IOCSTATUS_MASK
;
9018 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9019 ioc_info(ioc
, "\tbreak from phys disk scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9020 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9023 phys_disk_num
= pd_pg0
.PhysDiskNum
;
9024 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
9025 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
9027 sas_device_put(sas_device
);
9030 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9031 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
9034 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9035 MPI2_IOCSTATUS_MASK
;
9036 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9037 ioc_info(ioc
, "\tbreak from phys disk scan ioc_status(0x%04x), loginfo(0x%08x)\n",
9038 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9041 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9042 if (!_scsih_get_sas_address(ioc
, parent_handle
,
9044 ioc_info(ioc
, "\tBEFORE adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
9046 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9047 mpt3sas_transport_update_links(ioc
, sas_address
,
9048 handle
, sas_device_pg0
.PhyNum
,
9049 MPI2_SAS_NEG_LINK_RATE_1_5
);
9050 set_bit(handle
, ioc
->pd_handles
);
9052 /* This will retry adding the end device.
9053 * _scsih_add_device() will decide on retries and
9054 * return "1" when it should be retried
9056 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9060 ioc_info(ioc
, "\tAFTER adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
9062 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9066 ioc_info(ioc
, "\tscan devices: phys disk complete\n");
9068 ioc_info(ioc
, "\tscan devices: volumes start\n");
9072 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
9073 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
9074 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9075 MPI2_IOCSTATUS_MASK
;
9076 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9077 ioc_info(ioc
, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9078 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9081 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
9082 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
9083 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
9084 le64_to_cpu(volume_pg1
.WWID
));
9085 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
9088 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
9089 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
9090 sizeof(Mpi2RaidVolPage0_t
)))
9092 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9093 MPI2_IOCSTATUS_MASK
;
9094 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9095 ioc_info(ioc
, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9096 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9099 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
9100 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
9101 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
9102 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
9103 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
9104 element
.VolDevHandle
= volume_pg1
.DevHandle
;
9105 ioc_info(ioc
, "\tBEFORE adding volume: handle (0x%04x)\n",
9106 volume_pg1
.DevHandle
);
9107 _scsih_sas_volume_add(ioc
, &element
);
9108 ioc_info(ioc
, "\tAFTER adding volume: handle (0x%04x)\n",
9109 volume_pg1
.DevHandle
);
9113 ioc_info(ioc
, "\tscan devices: volumes complete\n");
9117 ioc_info(ioc
, "\tscan devices: end devices start\n");
9121 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9122 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9124 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9125 MPI2_IOCSTATUS_MASK
;
9126 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9127 ioc_info(ioc
, "\tbreak from end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9128 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9131 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
9132 if (!(_scsih_is_end_device(
9133 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
9135 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
9136 le64_to_cpu(sas_device_pg0
.SASAddress
));
9138 sas_device_put(sas_device
);
9141 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9142 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
9143 ioc_info(ioc
, "\tBEFORE adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
9145 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9146 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
9147 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
9149 /* This will retry adding the end device.
9150 * _scsih_add_device() will decide on retries and
9151 * return "1" when it should be retried
9153 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9157 ioc_info(ioc
, "\tAFTER adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
9159 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9162 ioc_info(ioc
, "\tscan devices: end devices complete\n");
9163 ioc_info(ioc
, "\tscan devices: pcie end devices start\n");
9167 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
9168 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9170 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
)
9171 & MPI2_IOCSTATUS_MASK
;
9172 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9173 ioc_info(ioc
, "\tbreak from pcie end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9174 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9177 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
9178 if (!(_scsih_is_nvme_device(
9179 le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
9181 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
,
9182 le64_to_cpu(pcie_device_pg0
.WWID
));
9184 pcie_device_put(pcie_device
);
9188 parent_handle
= le16_to_cpu(pcie_device_pg0
.ParentDevHandle
);
9189 _scsih_pcie_add_device(ioc
, handle
);
9191 ioc_info(ioc
, "\tAFTER adding pcie end device: handle (0x%04x), wwid(0x%016llx)\n",
9192 handle
, (u64
)le64_to_cpu(pcie_device_pg0
.WWID
));
9194 ioc_info(ioc
, "\tpcie devices: pcie end devices complete\n");
9195 ioc_info(ioc
, "scan devices: complete\n");
9199 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9200 * @ioc: per adapter object
9202 * The handler for doing any required cleanup or initialization.
9204 void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER
*ioc
)
9206 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_PRE_RESET\n", __func__
));
9210 * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih)
9211 * @ioc: per adapter object
9213 * The handler for doing any required cleanup or initialization.
9216 mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER
*ioc
)
9218 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_AFTER_RESET\n", __func__
));
9219 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
9220 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
9221 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
9222 complete(&ioc
->scsih_cmds
.done
);
9224 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
9225 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
9226 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
9227 complete(&ioc
->tm_cmds
.done
);
9230 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
9231 memset(ioc
->device_remove_in_progress
, 0,
9232 ioc
->device_remove_in_progress_sz
);
9233 _scsih_fw_event_cleanup_queue(ioc
);
9234 _scsih_flush_running_cmds(ioc
);
9238 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9239 * @ioc: per adapter object
9241 * The handler for doing any required cleanup or initialization.
9244 mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER
*ioc
)
9246 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_DONE_RESET\n", __func__
));
9247 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
9248 !ioc
->sas_hba
.num_phys
)) {
9249 _scsih_prep_device_scan(ioc
);
9250 _scsih_create_enclosure_list_after_reset(ioc
);
9251 _scsih_search_responding_sas_devices(ioc
);
9252 _scsih_search_responding_pcie_devices(ioc
);
9253 _scsih_search_responding_raid_devices(ioc
);
9254 _scsih_search_responding_expanders(ioc
);
9255 _scsih_error_recovery_delete_devices(ioc
);
9260 * _mpt3sas_fw_work - delayed task for processing firmware events
9261 * @ioc: per adapter object
9262 * @fw_event: The fw_event_work object
9266 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
9268 _scsih_fw_event_del_from_list(ioc
, fw_event
);
9270 /* the queue is being flushed so ignore this event */
9271 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
9272 fw_event_work_put(fw_event
);
9276 switch (fw_event
->event
) {
9277 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
9278 mpt3sas_process_trigger_data(ioc
,
9279 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
9280 fw_event
->event_data
);
9282 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
9283 while (scsi_host_in_recovery(ioc
->shost
) ||
9284 ioc
->shost_recovery
) {
9286 * If we're unloading, bail. Otherwise, this can become
9289 if (ioc
->remove_host
)
9293 _scsih_remove_unresponding_devices(ioc
);
9294 _scsih_scan_for_devices_after_reset(ioc
);
9296 case MPT3SAS_PORT_ENABLE_COMPLETE
:
9297 ioc
->start_scan
= 0;
9298 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
9299 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
9302 ioc_info(ioc
, "port enable: complete from worker thread\n"));
9304 case MPT3SAS_TURN_ON_PFA_LED
:
9305 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
9307 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9308 _scsih_sas_topology_change_event(ioc
, fw_event
);
9310 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9311 _scsih_sas_device_status_change_event(ioc
, fw_event
);
9313 case MPI2_EVENT_SAS_DISCOVERY
:
9314 _scsih_sas_discovery_event(ioc
, fw_event
);
9316 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR
:
9317 _scsih_sas_device_discovery_error_event(ioc
, fw_event
);
9319 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9320 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
9322 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9323 _scsih_sas_enclosure_dev_status_change_event(ioc
,
9326 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9327 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
9329 case MPI2_EVENT_IR_VOLUME
:
9330 _scsih_sas_ir_volume_event(ioc
, fw_event
);
9332 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9333 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
9335 case MPI2_EVENT_IR_OPERATION_STATUS
:
9336 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
9338 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9339 _scsih_pcie_device_status_change_event(ioc
, fw_event
);
9341 case MPI2_EVENT_PCIE_ENUMERATION
:
9342 _scsih_pcie_enumeration_event(ioc
, fw_event
);
9344 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9345 _scsih_pcie_topology_change_event(ioc
, fw_event
);
9350 fw_event_work_put(fw_event
);
9354 * _firmware_event_work
9355 * @work: The fw_event_work object
9358 * wrappers for the work thread handling firmware events
9362 _firmware_event_work(struct work_struct
*work
)
9364 struct fw_event_work
*fw_event
= container_of(work
,
9365 struct fw_event_work
, work
);
9367 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
9371 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9372 * @ioc: per adapter object
9373 * @msix_index: MSIX table index supplied by the OS
9374 * @reply: reply message frame(lower 32bit addr)
9375 * Context: interrupt.
9377 * This function merely adds a new work task into ioc->firmware_event_thread.
9378 * The tasks are worked from _firmware_event_work in user context.
9380 * Return: 1 meaning mf should be freed from _base_interrupt
9381 * 0 means the mf is freed from this function.
9384 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
9387 struct fw_event_work
*fw_event
;
9388 Mpi2EventNotificationReply_t
*mpi_reply
;
9391 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
9393 /* events turned off due to host reset */
9394 if (ioc
->pci_error_recovery
)
9397 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
9399 if (unlikely(!mpi_reply
)) {
9400 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
9401 __FILE__
, __LINE__
, __func__
);
9405 event
= le16_to_cpu(mpi_reply
->Event
);
9407 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
9408 mpt3sas_trigger_event(ioc
, event
, 0);
9412 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9414 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
9415 (Mpi2EventDataSasBroadcastPrimitive_t
*)
9416 mpi_reply
->EventData
;
9418 if (baen_data
->Primitive
!=
9419 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
9422 if (ioc
->broadcast_aen_busy
) {
9423 ioc
->broadcast_aen_pending
++;
9426 ioc
->broadcast_aen_busy
= 1;
9430 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9431 _scsih_check_topo_delete_events(ioc
,
9432 (Mpi2EventDataSasTopologyChangeList_t
*)
9433 mpi_reply
->EventData
);
9435 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9436 _scsih_check_pcie_topo_remove_events(ioc
,
9437 (Mpi26EventDataPCIeTopologyChangeList_t
*)
9438 mpi_reply
->EventData
);
9440 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9441 _scsih_check_ir_config_unhide_events(ioc
,
9442 (Mpi2EventDataIrConfigChangeList_t
*)
9443 mpi_reply
->EventData
);
9445 case MPI2_EVENT_IR_VOLUME
:
9446 _scsih_check_volume_delete_events(ioc
,
9447 (Mpi2EventDataIrVolume_t
*)
9448 mpi_reply
->EventData
);
9450 case MPI2_EVENT_LOG_ENTRY_ADDED
:
9452 Mpi2EventDataLogEntryAdded_t
*log_entry
;
9455 if (!ioc
->is_warpdrive
)
9458 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
9459 mpi_reply
->EventData
;
9460 log_code
= (u32
*)log_entry
->LogData
;
9462 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
9463 != MPT2_WARPDRIVE_LOGENTRY
)
9466 switch (le32_to_cpu(*log_code
)) {
9467 case MPT2_WARPDRIVE_LC_SSDT
:
9468 ioc_warn(ioc
, "WarpDrive Warning: IO Throttling has occurred in the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
9470 case MPT2_WARPDRIVE_LC_SSDLW
:
9471 ioc_warn(ioc
, "WarpDrive Warning: Program/Erase Cycles for the WarpDrive subsystem in degraded range. Check WarpDrive documentation for additional details.\n");
9473 case MPT2_WARPDRIVE_LC_SSDLF
:
9474 ioc_err(ioc
, "WarpDrive Fatal Error: There are no Program/Erase Cycles for the WarpDrive subsystem. The storage device will be in read-only mode. Check WarpDrive documentation for additional details.\n");
9476 case MPT2_WARPDRIVE_LC_BRMF
:
9477 ioc_err(ioc
, "WarpDrive Fatal Error: The Backup Rail Monitor has failed on the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
9483 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9484 case MPI2_EVENT_IR_OPERATION_STATUS
:
9485 case MPI2_EVENT_SAS_DISCOVERY
:
9486 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR
:
9487 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9488 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9489 case MPI2_EVENT_PCIE_ENUMERATION
:
9490 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9493 case MPI2_EVENT_TEMP_THRESHOLD
:
9494 _scsih_temp_threshold_events(ioc
,
9495 (Mpi2EventDataTemperature_t
*)
9496 mpi_reply
->EventData
);
9498 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
9499 ActiveCableEventData
=
9500 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
9501 switch (ActiveCableEventData
->ReasonCode
) {
9502 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
9503 ioc_notice(ioc
, "Currently an active cable with ReceptacleID %d\n",
9504 ActiveCableEventData
->ReceptacleID
);
9505 pr_notice("cannot be powered and devices connected\n");
9506 pr_notice("to this active cable will not be seen\n");
9507 pr_notice("This active cable requires %d mW of power\n",
9508 ActiveCableEventData
->ActiveCablePowerRequirement
);
9511 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
9512 ioc_notice(ioc
, "Currently a cable with ReceptacleID %d\n",
9513 ActiveCableEventData
->ReceptacleID
);
9515 "is not running at optimal speed(12 Gb/s rate)\n");
9521 default: /* ignore the rest */
9525 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
9526 fw_event
= alloc_fw_event_work(sz
);
9528 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
9529 __FILE__
, __LINE__
, __func__
);
9533 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
9534 fw_event
->ioc
= ioc
;
9535 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
9536 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
9537 fw_event
->event
= event
;
9538 _scsih_fw_event_add(ioc
, fw_event
);
9539 fw_event_work_put(fw_event
);
9544 * _scsih_expander_node_remove - removing expander device from list.
9545 * @ioc: per adapter object
9546 * @sas_expander: the sas_device object
9548 * Removing object and freeing associated memory from the
9549 * ioc->sas_expander_list.
9552 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
9553 struct _sas_node
*sas_expander
)
9555 struct _sas_port
*mpt3sas_port
, *next
;
9556 unsigned long flags
;
9558 /* remove sibling ports attached to this expander */
9559 list_for_each_entry_safe(mpt3sas_port
, next
,
9560 &sas_expander
->sas_port_list
, port_list
) {
9561 if (ioc
->shost_recovery
)
9563 if (mpt3sas_port
->remote_identify
.device_type
==
9565 mpt3sas_device_remove_by_sas_address(ioc
,
9566 mpt3sas_port
->remote_identify
.sas_address
);
9567 else if (mpt3sas_port
->remote_identify
.device_type
==
9568 SAS_EDGE_EXPANDER_DEVICE
||
9569 mpt3sas_port
->remote_identify
.device_type
==
9570 SAS_FANOUT_EXPANDER_DEVICE
)
9571 mpt3sas_expander_remove(ioc
,
9572 mpt3sas_port
->remote_identify
.sas_address
);
9575 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
9576 sas_expander
->sas_address_parent
);
9578 ioc_info(ioc
, "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9579 sas_expander
->handle
, (unsigned long long)
9580 sas_expander
->sas_address
);
9582 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9583 list_del(&sas_expander
->list
);
9584 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9586 kfree(sas_expander
->phy
);
9587 kfree(sas_expander
);
9591 * _scsih_ir_shutdown - IR shutdown notification
9592 * @ioc: per adapter object
9594 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9595 * the host system is shutting down.
9598 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
9600 Mpi2RaidActionRequest_t
*mpi_request
;
9601 Mpi2RaidActionReply_t
*mpi_reply
;
9604 /* is IR firmware build loaded ? */
9605 if (!ioc
->ir_firmware
)
9608 /* are there any volumes ? */
9609 if (list_empty(&ioc
->raid_device_list
))
9612 mutex_lock(&ioc
->scsih_cmds
.mutex
);
9614 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
9615 ioc_err(ioc
, "%s: scsih_cmd in use\n", __func__
);
9618 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
9620 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
9622 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
9623 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9627 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
9628 ioc
->scsih_cmds
.smid
= smid
;
9629 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
9631 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
9632 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
9634 if (!ioc
->hide_ir_msg
)
9635 ioc_info(ioc
, "IR shutdown (sending)\n");
9636 init_completion(&ioc
->scsih_cmds
.done
);
9637 ioc
->put_smid_default(ioc
, smid
);
9638 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
9640 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
9641 ioc_err(ioc
, "%s: timeout\n", __func__
);
9645 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
9646 mpi_reply
= ioc
->scsih_cmds
.reply
;
9647 if (!ioc
->hide_ir_msg
)
9648 ioc_info(ioc
, "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9649 le16_to_cpu(mpi_reply
->IOCStatus
),
9650 le32_to_cpu(mpi_reply
->IOCLogInfo
));
9654 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9655 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
9659 * scsih_remove - detach and remove add host
9660 * @pdev: PCI device struct
9662 * Routine called when unloading the driver.
9664 static void scsih_remove(struct pci_dev
*pdev
)
9666 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9667 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9668 struct _sas_port
*mpt3sas_port
, *next_port
;
9669 struct _raid_device
*raid_device
, *next
;
9670 struct MPT3SAS_TARGET
*sas_target_priv_data
;
9671 struct _pcie_device
*pcie_device
, *pcienext
;
9672 struct workqueue_struct
*wq
;
9673 unsigned long flags
;
9674 Mpi2ConfigReply_t mpi_reply
;
9676 ioc
->remove_host
= 1;
9678 mpt3sas_wait_for_commands_to_complete(ioc
);
9679 _scsih_flush_running_cmds(ioc
);
9681 _scsih_fw_event_cleanup_queue(ioc
);
9683 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9684 wq
= ioc
->firmware_event_thread
;
9685 ioc
->firmware_event_thread
= NULL
;
9686 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9688 destroy_workqueue(wq
);
9690 * Copy back the unmodified ioc page1. so that on next driver load,
9691 * current modified changes on ioc page1 won't take effect.
9693 if (ioc
->is_aero_ioc
)
9694 mpt3sas_config_set_ioc_pg1(ioc
, &mpi_reply
,
9695 &ioc
->ioc_pg1_copy
);
9696 /* release all the volumes */
9697 _scsih_ir_shutdown(ioc
);
9698 sas_remove_host(shost
);
9699 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
9701 if (raid_device
->starget
) {
9702 sas_target_priv_data
=
9703 raid_device
->starget
->hostdata
;
9704 sas_target_priv_data
->deleted
= 1;
9705 scsi_remove_target(&raid_device
->starget
->dev
);
9707 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
9708 raid_device
->handle
, (u64
)raid_device
->wwid
);
9709 _scsih_raid_device_remove(ioc
, raid_device
);
9711 list_for_each_entry_safe(pcie_device
, pcienext
, &ioc
->pcie_device_list
,
9713 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
9714 list_del_init(&pcie_device
->list
);
9715 pcie_device_put(pcie_device
);
9718 /* free ports attached to the sas_host */
9719 list_for_each_entry_safe(mpt3sas_port
, next_port
,
9720 &ioc
->sas_hba
.sas_port_list
, port_list
) {
9721 if (mpt3sas_port
->remote_identify
.device_type
==
9723 mpt3sas_device_remove_by_sas_address(ioc
,
9724 mpt3sas_port
->remote_identify
.sas_address
);
9725 else if (mpt3sas_port
->remote_identify
.device_type
==
9726 SAS_EDGE_EXPANDER_DEVICE
||
9727 mpt3sas_port
->remote_identify
.device_type
==
9728 SAS_FANOUT_EXPANDER_DEVICE
)
9729 mpt3sas_expander_remove(ioc
,
9730 mpt3sas_port
->remote_identify
.sas_address
);
9733 /* free phys attached to the sas_host */
9734 if (ioc
->sas_hba
.num_phys
) {
9735 kfree(ioc
->sas_hba
.phy
);
9736 ioc
->sas_hba
.phy
= NULL
;
9737 ioc
->sas_hba
.num_phys
= 0;
9740 mpt3sas_base_detach(ioc
);
9741 spin_lock(&gioc_lock
);
9742 list_del(&ioc
->list
);
9743 spin_unlock(&gioc_lock
);
9744 scsi_host_put(shost
);
9748 * scsih_shutdown - routine call during system shutdown
9749 * @pdev: PCI device struct
9752 scsih_shutdown(struct pci_dev
*pdev
)
9754 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9755 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9756 struct workqueue_struct
*wq
;
9757 unsigned long flags
;
9758 Mpi2ConfigReply_t mpi_reply
;
9760 ioc
->remove_host
= 1;
9762 mpt3sas_wait_for_commands_to_complete(ioc
);
9763 _scsih_flush_running_cmds(ioc
);
9765 _scsih_fw_event_cleanup_queue(ioc
);
9767 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9768 wq
= ioc
->firmware_event_thread
;
9769 ioc
->firmware_event_thread
= NULL
;
9770 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9772 destroy_workqueue(wq
);
9774 * Copy back the unmodified ioc page1 so that on next driver load,
9775 * current modified changes on ioc page1 won't take effect.
9777 if (ioc
->is_aero_ioc
)
9778 mpt3sas_config_set_ioc_pg1(ioc
, &mpi_reply
,
9779 &ioc
->ioc_pg1_copy
);
9781 _scsih_ir_shutdown(ioc
);
9782 mpt3sas_base_detach(ioc
);
9787 * _scsih_probe_boot_devices - reports 1st device
9788 * @ioc: per adapter object
9790 * If specified in bios page 2, this routine reports the 1st
9791 * device scsi-ml or sas transport for persistent boot device
9792 * purposes. Please refer to function _scsih_determine_boot_device()
9795 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
9799 struct _sas_device
*sas_device
;
9800 struct _raid_device
*raid_device
;
9801 struct _pcie_device
*pcie_device
;
9803 u64 sas_address_parent
;
9805 unsigned long flags
;
9809 /* no Bios, return immediately */
9810 if (!ioc
->bios_pg3
.BiosVersion
)
9814 if (ioc
->req_boot_device
.device
) {
9815 device
= ioc
->req_boot_device
.device
;
9816 channel
= ioc
->req_boot_device
.channel
;
9817 } else if (ioc
->req_alt_boot_device
.device
) {
9818 device
= ioc
->req_alt_boot_device
.device
;
9819 channel
= ioc
->req_alt_boot_device
.channel
;
9820 } else if (ioc
->current_boot_device
.device
) {
9821 device
= ioc
->current_boot_device
.device
;
9822 channel
= ioc
->current_boot_device
.channel
;
9828 if (channel
== RAID_CHANNEL
) {
9829 raid_device
= device
;
9830 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9831 raid_device
->id
, 0);
9833 _scsih_raid_device_remove(ioc
, raid_device
);
9834 } else if (channel
== PCIE_CHANNEL
) {
9835 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9836 pcie_device
= device
;
9837 tid
= pcie_device
->id
;
9838 list_move_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
9839 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9840 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, tid
, 0);
9842 _scsih_pcie_device_remove(ioc
, pcie_device
);
9844 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9845 sas_device
= device
;
9846 handle
= sas_device
->handle
;
9847 sas_address_parent
= sas_device
->sas_address_parent
;
9848 sas_address
= sas_device
->sas_address
;
9849 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
9850 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9852 if (ioc
->hide_drives
)
9854 if (!mpt3sas_transport_port_add(ioc
, handle
,
9855 sas_address_parent
)) {
9856 _scsih_sas_device_remove(ioc
, sas_device
);
9857 } else if (!sas_device
->starget
) {
9858 if (!ioc
->is_driver_loading
) {
9859 mpt3sas_transport_port_remove(ioc
,
9861 sas_address_parent
);
9862 _scsih_sas_device_remove(ioc
, sas_device
);
9869 * _scsih_probe_raid - reporting raid volumes to scsi-ml
9870 * @ioc: per adapter object
9872 * Called during initial loading of the driver.
9875 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
9877 struct _raid_device
*raid_device
, *raid_next
;
9880 list_for_each_entry_safe(raid_device
, raid_next
,
9881 &ioc
->raid_device_list
, list
) {
9882 if (raid_device
->starget
)
9884 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9885 raid_device
->id
, 0);
9887 _scsih_raid_device_remove(ioc
, raid_device
);
9891 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
9893 struct _sas_device
*sas_device
= NULL
;
9894 unsigned long flags
;
9896 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9897 if (!list_empty(&ioc
->sas_device_init_list
)) {
9898 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
9899 struct _sas_device
, list
);
9900 sas_device_get(sas_device
);
9902 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9907 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
9908 struct _sas_device
*sas_device
)
9910 unsigned long flags
;
9912 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9915 * Since we dropped the lock during the call to port_add(), we need to
9916 * be careful here that somebody else didn't move or delete this item
9917 * while we were busy with other things.
9919 * If it was on the list, we need a put() for the reference the list
9920 * had. Either way, we need a get() for the destination list.
9922 if (!list_empty(&sas_device
->list
)) {
9923 list_del_init(&sas_device
->list
);
9924 sas_device_put(sas_device
);
9927 sas_device_get(sas_device
);
9928 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
9930 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9934 * _scsih_probe_sas - reporting sas devices to sas transport
9935 * @ioc: per adapter object
9937 * Called during initial loading of the driver.
9940 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
9942 struct _sas_device
*sas_device
;
9944 if (ioc
->hide_drives
)
9947 while ((sas_device
= get_next_sas_device(ioc
))) {
9948 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
9949 sas_device
->sas_address_parent
)) {
9950 _scsih_sas_device_remove(ioc
, sas_device
);
9951 sas_device_put(sas_device
);
9953 } else if (!sas_device
->starget
) {
9955 * When asyn scanning is enabled, its not possible to
9956 * remove devices while scanning is turned on due to an
9957 * oops in scsi_sysfs_add_sdev()->add_device()->
9958 * sysfs_addrm_start()
9960 if (!ioc
->is_driver_loading
) {
9961 mpt3sas_transport_port_remove(ioc
,
9962 sas_device
->sas_address
,
9963 sas_device
->sas_address_parent
);
9964 _scsih_sas_device_remove(ioc
, sas_device
);
9965 sas_device_put(sas_device
);
9969 sas_device_make_active(ioc
, sas_device
);
9970 sas_device_put(sas_device
);
9975 * get_next_pcie_device - Get the next pcie device
9976 * @ioc: per adapter object
9978 * Get the next pcie device from pcie_device_init_list list.
9980 * Return: pcie device structure if pcie_device_init_list list is not empty
9981 * otherwise returns NULL
9983 static struct _pcie_device
*get_next_pcie_device(struct MPT3SAS_ADAPTER
*ioc
)
9985 struct _pcie_device
*pcie_device
= NULL
;
9986 unsigned long flags
;
9988 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9989 if (!list_empty(&ioc
->pcie_device_init_list
)) {
9990 pcie_device
= list_first_entry(&ioc
->pcie_device_init_list
,
9991 struct _pcie_device
, list
);
9992 pcie_device_get(pcie_device
);
9994 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10000 * pcie_device_make_active - Add pcie device to pcie_device_list list
10001 * @ioc: per adapter object
10002 * @pcie_device: pcie device object
10004 * Add the pcie device which has registered with SCSI Transport Later to
10005 * pcie_device_list list
10007 static void pcie_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
10008 struct _pcie_device
*pcie_device
)
10010 unsigned long flags
;
10012 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10014 if (!list_empty(&pcie_device
->list
)) {
10015 list_del_init(&pcie_device
->list
);
10016 pcie_device_put(pcie_device
);
10018 pcie_device_get(pcie_device
);
10019 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
10021 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10025 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
10026 * @ioc: per adapter object
10028 * Called during initial loading of the driver.
10031 _scsih_probe_pcie(struct MPT3SAS_ADAPTER
*ioc
)
10033 struct _pcie_device
*pcie_device
;
10036 /* PCIe Device List */
10037 while ((pcie_device
= get_next_pcie_device(ioc
))) {
10038 if (pcie_device
->starget
) {
10039 pcie_device_put(pcie_device
);
10042 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
,
10043 pcie_device
->id
, 0);
10045 _scsih_pcie_device_remove(ioc
, pcie_device
);
10046 pcie_device_put(pcie_device
);
10048 } else if (!pcie_device
->starget
) {
10050 * When async scanning is enabled, its not possible to
10051 * remove devices while scanning is turned on due to an
10052 * oops in scsi_sysfs_add_sdev()->add_device()->
10053 * sysfs_addrm_start()
10055 if (!ioc
->is_driver_loading
) {
10056 /* TODO-- Need to find out whether this condition will
10059 _scsih_pcie_device_remove(ioc
, pcie_device
);
10060 pcie_device_put(pcie_device
);
10064 pcie_device_make_active(ioc
, pcie_device
);
10065 pcie_device_put(pcie_device
);
10070 * _scsih_probe_devices - probing for devices
10071 * @ioc: per adapter object
10073 * Called during initial loading of the driver.
10076 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
10078 u16 volume_mapping_flags
;
10080 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
10081 return; /* return when IOC doesn't support initiator mode */
10083 _scsih_probe_boot_devices(ioc
);
10085 if (ioc
->ir_firmware
) {
10086 volume_mapping_flags
=
10087 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
10088 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
10089 if (volume_mapping_flags
==
10090 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
10091 _scsih_probe_raid(ioc
);
10092 _scsih_probe_sas(ioc
);
10094 _scsih_probe_sas(ioc
);
10095 _scsih_probe_raid(ioc
);
10098 _scsih_probe_sas(ioc
);
10099 _scsih_probe_pcie(ioc
);
10104 * scsih_scan_start - scsi lld callback for .scan_start
10105 * @shost: SCSI host pointer
10107 * The shost has the ability to discover targets on its own instead
10108 * of scanning the entire bus. In our implemention, we will kick off
10109 * firmware discovery.
10112 scsih_scan_start(struct Scsi_Host
*shost
)
10114 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10116 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
10117 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
10119 if (disable_discovery
> 0)
10122 ioc
->start_scan
= 1;
10123 rc
= mpt3sas_port_enable(ioc
);
10126 ioc_info(ioc
, "port enable: FAILED\n");
10130 * scsih_scan_finished - scsi lld callback for .scan_finished
10131 * @shost: SCSI host pointer
10132 * @time: elapsed time of the scan in jiffies
10134 * This function will be called periodicallyn until it returns 1 with the
10135 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10136 * we wait for firmware discovery to complete, then return 1.
10139 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
10141 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10143 if (disable_discovery
> 0) {
10144 ioc
->is_driver_loading
= 0;
10145 ioc
->wait_for_discovery_to_complete
= 0;
10149 if (time
>= (300 * HZ
)) {
10150 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
10151 ioc_info(ioc
, "port enable: FAILED with timeout (timeout=300s)\n");
10152 ioc
->is_driver_loading
= 0;
10156 if (ioc
->start_scan
)
10159 if (ioc
->start_scan_failed
) {
10160 ioc_info(ioc
, "port enable: FAILED with (ioc_status=0x%08x)\n",
10161 ioc
->start_scan_failed
);
10162 ioc
->is_driver_loading
= 0;
10163 ioc
->wait_for_discovery_to_complete
= 0;
10164 ioc
->remove_host
= 1;
10168 ioc_info(ioc
, "port enable: SUCCESS\n");
10169 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
10171 if (ioc
->wait_for_discovery_to_complete
) {
10172 ioc
->wait_for_discovery_to_complete
= 0;
10173 _scsih_probe_devices(ioc
);
10175 mpt3sas_base_start_watchdog(ioc
);
10176 ioc
->is_driver_loading
= 0;
10180 /* shost template for SAS 2.0 HBA devices */
10181 static struct scsi_host_template mpt2sas_driver_template
= {
10182 .module
= THIS_MODULE
,
10183 .name
= "Fusion MPT SAS Host",
10184 .proc_name
= MPT2SAS_DRIVER_NAME
,
10185 .queuecommand
= scsih_qcmd
,
10186 .target_alloc
= scsih_target_alloc
,
10187 .slave_alloc
= scsih_slave_alloc
,
10188 .slave_configure
= scsih_slave_configure
,
10189 .target_destroy
= scsih_target_destroy
,
10190 .slave_destroy
= scsih_slave_destroy
,
10191 .scan_finished
= scsih_scan_finished
,
10192 .scan_start
= scsih_scan_start
,
10193 .change_queue_depth
= scsih_change_queue_depth
,
10194 .eh_abort_handler
= scsih_abort
,
10195 .eh_device_reset_handler
= scsih_dev_reset
,
10196 .eh_target_reset_handler
= scsih_target_reset
,
10197 .eh_host_reset_handler
= scsih_host_reset
,
10198 .bios_param
= scsih_bios_param
,
10201 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
10202 .max_sectors
= 32767,
10204 .shost_attrs
= mpt3sas_host_attrs
,
10205 .sdev_attrs
= mpt3sas_dev_attrs
,
10206 .track_queue_depth
= 1,
10207 .cmd_size
= sizeof(struct scsiio_tracker
),
10210 /* raid transport support for SAS 2.0 HBA devices */
10211 static struct raid_function_template mpt2sas_raid_functions
= {
10212 .cookie
= &mpt2sas_driver_template
,
10213 .is_raid
= scsih_is_raid
,
10214 .get_resync
= scsih_get_resync
,
10215 .get_state
= scsih_get_state
,
10218 /* shost template for SAS 3.0 HBA devices */
10219 static struct scsi_host_template mpt3sas_driver_template
= {
10220 .module
= THIS_MODULE
,
10221 .name
= "Fusion MPT SAS Host",
10222 .proc_name
= MPT3SAS_DRIVER_NAME
,
10223 .queuecommand
= scsih_qcmd
,
10224 .target_alloc
= scsih_target_alloc
,
10225 .slave_alloc
= scsih_slave_alloc
,
10226 .slave_configure
= scsih_slave_configure
,
10227 .target_destroy
= scsih_target_destroy
,
10228 .slave_destroy
= scsih_slave_destroy
,
10229 .scan_finished
= scsih_scan_finished
,
10230 .scan_start
= scsih_scan_start
,
10231 .change_queue_depth
= scsih_change_queue_depth
,
10232 .eh_abort_handler
= scsih_abort
,
10233 .eh_device_reset_handler
= scsih_dev_reset
,
10234 .eh_target_reset_handler
= scsih_target_reset
,
10235 .eh_host_reset_handler
= scsih_host_reset
,
10236 .bios_param
= scsih_bios_param
,
10239 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
10240 .max_sectors
= 32767,
10241 .max_segment_size
= 0xffffffff,
10243 .shost_attrs
= mpt3sas_host_attrs
,
10244 .sdev_attrs
= mpt3sas_dev_attrs
,
10245 .track_queue_depth
= 1,
10246 .cmd_size
= sizeof(struct scsiio_tracker
),
10249 /* raid transport support for SAS 3.0 HBA devices */
10250 static struct raid_function_template mpt3sas_raid_functions
= {
10251 .cookie
= &mpt3sas_driver_template
,
10252 .is_raid
= scsih_is_raid
,
10253 .get_resync
= scsih_get_resync
,
10254 .get_state
= scsih_get_state
,
10258 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10259 * this device belongs to.
10260 * @pdev: PCI device struct
10262 * return MPI2_VERSION for SAS 2.0 HBA devices,
10263 * MPI25_VERSION for SAS 3.0 HBA devices, and
10264 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10267 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
10270 switch (pdev
->device
) {
10271 case MPI2_MFGPAGE_DEVID_SSS6200
:
10272 case MPI2_MFGPAGE_DEVID_SAS2004
:
10273 case MPI2_MFGPAGE_DEVID_SAS2008
:
10274 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
10275 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
10276 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
10277 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
10278 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
10279 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
10280 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
10281 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
10282 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
10283 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
10284 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
10285 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
10286 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
10287 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
10288 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP
:
10289 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1
:
10290 return MPI2_VERSION
;
10291 case MPI25_MFGPAGE_DEVID_SAS3004
:
10292 case MPI25_MFGPAGE_DEVID_SAS3008
:
10293 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
10294 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
10295 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
10296 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
10297 return MPI25_VERSION
;
10298 case MPI26_MFGPAGE_DEVID_SAS3216
:
10299 case MPI26_MFGPAGE_DEVID_SAS3224
:
10300 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
10301 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
10302 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
10303 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
10304 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
10305 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
10306 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
10307 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
10308 case MPI26_MFGPAGE_DEVID_SAS3508
:
10309 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10310 case MPI26_MFGPAGE_DEVID_SAS3408
:
10311 case MPI26_MFGPAGE_DEVID_SAS3516
:
10312 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10313 case MPI26_MFGPAGE_DEVID_SAS3416
:
10314 case MPI26_MFGPAGE_DEVID_SAS3616
:
10315 case MPI26_ATLAS_PCIe_SWITCH_DEVID
:
10316 case MPI26_MFGPAGE_DEVID_CFG_SEC_3916
:
10317 case MPI26_MFGPAGE_DEVID_HARD_SEC_3916
:
10318 case MPI26_MFGPAGE_DEVID_CFG_SEC_3816
:
10319 case MPI26_MFGPAGE_DEVID_HARD_SEC_3816
:
10320 return MPI26_VERSION
;
10326 * _scsih_probe - attach and add scsi host
10327 * @pdev: PCI device struct
10328 * @id: pci device id
10330 * Return: 0 success, anything else error.
10333 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
10335 struct MPT3SAS_ADAPTER
*ioc
;
10336 struct Scsi_Host
*shost
= NULL
;
10338 u16 hba_mpi_version
;
10340 /* Determine in which MPI version class this pci device belongs */
10341 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
10342 if (hba_mpi_version
== 0)
10345 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10346 * for other generation HBA's return with -ENODEV
10348 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
10351 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10352 * for other generation HBA's return with -ENODEV
10354 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
10355 || hba_mpi_version
== MPI26_VERSION
)))
10358 switch (hba_mpi_version
) {
10360 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
10361 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
10362 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10363 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
10364 sizeof(struct MPT3SAS_ADAPTER
));
10367 ioc
= shost_priv(shost
);
10368 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10369 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10370 ioc
->id
= mpt2_ids
++;
10371 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
10372 switch (pdev
->device
) {
10373 case MPI2_MFGPAGE_DEVID_SSS6200
:
10374 ioc
->is_warpdrive
= 1;
10375 ioc
->hide_ir_msg
= 1;
10377 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP
:
10378 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1
:
10379 ioc
->is_mcpu_endpoint
= 1;
10382 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
10386 case MPI25_VERSION
:
10387 case MPI26_VERSION
:
10388 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10389 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
10390 sizeof(struct MPT3SAS_ADAPTER
));
10393 ioc
= shost_priv(shost
);
10394 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10395 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10396 ioc
->id
= mpt3_ids
++;
10397 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
10398 switch (pdev
->device
) {
10399 case MPI26_MFGPAGE_DEVID_SAS3508
:
10400 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10401 case MPI26_MFGPAGE_DEVID_SAS3408
:
10402 case MPI26_MFGPAGE_DEVID_SAS3516
:
10403 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10404 case MPI26_MFGPAGE_DEVID_SAS3416
:
10405 case MPI26_MFGPAGE_DEVID_SAS3616
:
10406 case MPI26_ATLAS_PCIe_SWITCH_DEVID
:
10407 ioc
->is_gen35_ioc
= 1;
10409 case MPI26_MFGPAGE_DEVID_CFG_SEC_3816
:
10410 case MPI26_MFGPAGE_DEVID_CFG_SEC_3916
:
10411 dev_info(&pdev
->dev
,
10412 "HBA is in Configurable Secure mode\n");
10414 case MPI26_MFGPAGE_DEVID_HARD_SEC_3816
:
10415 case MPI26_MFGPAGE_DEVID_HARD_SEC_3916
:
10416 ioc
->is_aero_ioc
= ioc
->is_gen35_ioc
= 1;
10419 ioc
->is_gen35_ioc
= ioc
->is_aero_ioc
= 0;
10421 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
10422 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
10423 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
10424 ioc
->combined_reply_queue
= 1;
10425 if (ioc
->is_gen35_ioc
)
10426 ioc
->combined_reply_index_count
=
10427 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
10429 ioc
->combined_reply_index_count
=
10430 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
10437 INIT_LIST_HEAD(&ioc
->list
);
10438 spin_lock(&gioc_lock
);
10439 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
10440 spin_unlock(&gioc_lock
);
10441 ioc
->shost
= shost
;
10443 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
10444 ioc
->tm_cb_idx
= tm_cb_idx
;
10445 ioc
->ctl_cb_idx
= ctl_cb_idx
;
10446 ioc
->base_cb_idx
= base_cb_idx
;
10447 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
10448 ioc
->transport_cb_idx
= transport_cb_idx
;
10449 ioc
->scsih_cb_idx
= scsih_cb_idx
;
10450 ioc
->config_cb_idx
= config_cb_idx
;
10451 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
10452 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
10453 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
10454 ioc
->logging_level
= logging_level
;
10455 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
10456 /* misc semaphores and spin locks */
10457 mutex_init(&ioc
->reset_in_progress_mutex
);
10458 /* initializing pci_access_mutex lock */
10459 mutex_init(&ioc
->pci_access_mutex
);
10460 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
10461 spin_lock_init(&ioc
->scsi_lookup_lock
);
10462 spin_lock_init(&ioc
->sas_device_lock
);
10463 spin_lock_init(&ioc
->sas_node_lock
);
10464 spin_lock_init(&ioc
->fw_event_lock
);
10465 spin_lock_init(&ioc
->raid_device_lock
);
10466 spin_lock_init(&ioc
->pcie_device_lock
);
10467 spin_lock_init(&ioc
->diag_trigger_lock
);
10469 INIT_LIST_HEAD(&ioc
->sas_device_list
);
10470 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
10471 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
10472 INIT_LIST_HEAD(&ioc
->enclosure_list
);
10473 INIT_LIST_HEAD(&ioc
->pcie_device_list
);
10474 INIT_LIST_HEAD(&ioc
->pcie_device_init_list
);
10475 INIT_LIST_HEAD(&ioc
->fw_event_list
);
10476 INIT_LIST_HEAD(&ioc
->raid_device_list
);
10477 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
10478 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
10479 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
10480 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
10481 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
10482 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
10484 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
10486 /* init shost parameters */
10487 shost
->max_cmd_len
= 32;
10488 shost
->max_lun
= max_lun
;
10489 shost
->transportt
= mpt3sas_transport_template
;
10490 shost
->unique_id
= ioc
->id
;
10492 if (ioc
->is_mcpu_endpoint
) {
10493 /* mCPU MPI support 64K max IO */
10494 shost
->max_sectors
= 128;
10495 ioc_info(ioc
, "The max_sectors value is set to %d\n",
10496 shost
->max_sectors
);
10498 if (max_sectors
!= 0xFFFF) {
10499 if (max_sectors
< 64) {
10500 shost
->max_sectors
= 64;
10501 ioc_warn(ioc
, "Invalid value %d passed for max_sectors, range is 64 to 32767. Assigning value of 64.\n",
10503 } else if (max_sectors
> 32767) {
10504 shost
->max_sectors
= 32767;
10505 ioc_warn(ioc
, "Invalid value %d passed for max_sectors, range is 64 to 32767.Assigning default value of 32767.\n",
10508 shost
->max_sectors
= max_sectors
& 0xFFFE;
10509 ioc_info(ioc
, "The max_sectors value is set to %d\n",
10510 shost
->max_sectors
);
10514 /* register EEDP capabilities with SCSI layer */
10516 scsi_host_set_prot(shost
, prot_mask
);
10518 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
10519 | SHOST_DIF_TYPE2_PROTECTION
10520 | SHOST_DIF_TYPE3_PROTECTION
);
10522 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
10525 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
10526 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
10527 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
10528 ioc
->firmware_event_name
, 0);
10529 if (!ioc
->firmware_event_thread
) {
10530 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
10531 __FILE__
, __LINE__
, __func__
);
10533 goto out_thread_fail
;
10536 ioc
->is_driver_loading
= 1;
10537 if ((mpt3sas_base_attach(ioc
))) {
10538 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
10539 __FILE__
, __LINE__
, __func__
);
10541 goto out_attach_fail
;
10544 if (ioc
->is_warpdrive
) {
10545 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
10546 ioc
->hide_drives
= 0;
10547 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
10548 ioc
->hide_drives
= 1;
10550 if (mpt3sas_get_num_volumes(ioc
))
10551 ioc
->hide_drives
= 1;
10553 ioc
->hide_drives
= 0;
10556 ioc
->hide_drives
= 0;
10558 rv
= scsi_add_host(shost
, &pdev
->dev
);
10560 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
10561 __FILE__
, __LINE__
, __func__
);
10562 goto out_add_shost_fail
;
10565 scsi_scan_host(shost
);
10567 out_add_shost_fail
:
10568 mpt3sas_base_detach(ioc
);
10570 destroy_workqueue(ioc
->firmware_event_thread
);
10572 spin_lock(&gioc_lock
);
10573 list_del(&ioc
->list
);
10574 spin_unlock(&gioc_lock
);
10575 scsi_host_put(shost
);
10581 * scsih_suspend - power management suspend main entry point
10582 * @pdev: PCI device struct
10583 * @state: PM state change to (usually PCI_D3)
10585 * Return: 0 success, anything else error.
10588 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10590 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10591 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10592 pci_power_t device_state
;
10594 mpt3sas_base_stop_watchdog(ioc
);
10595 flush_scheduled_work();
10596 scsi_block_requests(shost
);
10597 device_state
= pci_choose_state(pdev
, state
);
10598 ioc_info(ioc
, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10599 pdev
, pci_name(pdev
), device_state
);
10601 pci_save_state(pdev
);
10602 mpt3sas_base_free_resources(ioc
);
10603 pci_set_power_state(pdev
, device_state
);
10608 * scsih_resume - power management resume main entry point
10609 * @pdev: PCI device struct
10611 * Return: 0 success, anything else error.
10614 scsih_resume(struct pci_dev
*pdev
)
10616 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10617 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10618 pci_power_t device_state
= pdev
->current_state
;
10621 ioc_info(ioc
, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10622 pdev
, pci_name(pdev
), device_state
);
10624 pci_set_power_state(pdev
, PCI_D0
);
10625 pci_enable_wake(pdev
, PCI_D0
, 0);
10626 pci_restore_state(pdev
);
10628 r
= mpt3sas_base_map_resources(ioc
);
10632 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
10633 scsi_unblock_requests(shost
);
10634 mpt3sas_base_start_watchdog(ioc
);
10637 #endif /* CONFIG_PM */
10640 * scsih_pci_error_detected - Called when a PCI error is detected.
10641 * @pdev: PCI device struct
10642 * @state: PCI channel state
10644 * Description: Called when a PCI error is detected.
10646 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
10648 static pci_ers_result_t
10649 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10651 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10652 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10654 ioc_info(ioc
, "PCI error: detected callback, state(%d)!!\n", state
);
10657 case pci_channel_io_normal
:
10658 return PCI_ERS_RESULT_CAN_RECOVER
;
10659 case pci_channel_io_frozen
:
10660 /* Fatal error, prepare for slot reset */
10661 ioc
->pci_error_recovery
= 1;
10662 scsi_block_requests(ioc
->shost
);
10663 mpt3sas_base_stop_watchdog(ioc
);
10664 mpt3sas_base_free_resources(ioc
);
10665 return PCI_ERS_RESULT_NEED_RESET
;
10666 case pci_channel_io_perm_failure
:
10667 /* Permanent error, prepare for device removal */
10668 ioc
->pci_error_recovery
= 1;
10669 mpt3sas_base_stop_watchdog(ioc
);
10670 _scsih_flush_running_cmds(ioc
);
10671 return PCI_ERS_RESULT_DISCONNECT
;
10673 return PCI_ERS_RESULT_NEED_RESET
;
10677 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10678 * @pdev: PCI device struct
10680 * Description: This routine is called by the pci error recovery
10681 * code after the PCI slot has been reset, just before we
10682 * should resume normal operations.
10684 static pci_ers_result_t
10685 scsih_pci_slot_reset(struct pci_dev
*pdev
)
10687 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10688 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10691 ioc_info(ioc
, "PCI error: slot reset callback!!\n");
10693 ioc
->pci_error_recovery
= 0;
10695 pci_restore_state(pdev
);
10696 rc
= mpt3sas_base_map_resources(ioc
);
10698 return PCI_ERS_RESULT_DISCONNECT
;
10700 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
10702 ioc_warn(ioc
, "hard reset: %s\n",
10703 (rc
== 0) ? "success" : "failed");
10706 return PCI_ERS_RESULT_RECOVERED
;
10708 return PCI_ERS_RESULT_DISCONNECT
;
10712 * scsih_pci_resume() - resume normal ops after PCI reset
10713 * @pdev: pointer to PCI device
10715 * Called when the error recovery driver tells us that its
10716 * OK to resume normal operation. Use completion to allow
10717 * halted scsi ops to resume.
10720 scsih_pci_resume(struct pci_dev
*pdev
)
10722 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10723 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10725 ioc_info(ioc
, "PCI error: resume callback!!\n");
10727 mpt3sas_base_start_watchdog(ioc
);
10728 scsi_unblock_requests(ioc
->shost
);
10732 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10733 * @pdev: pointer to PCI device
10735 static pci_ers_result_t
10736 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
10738 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10739 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10741 ioc_info(ioc
, "PCI error: mmio enabled callback!!\n");
10743 /* TODO - dump whatever for debugging purposes */
10745 /* This called only if scsih_pci_error_detected returns
10746 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10747 * works, no need to reset slot.
10749 return PCI_ERS_RESULT_RECOVERED
;
10753 * scsih__ncq_prio_supp - Check for NCQ command priority support
10754 * @sdev: scsi device struct
10756 * This is called when a user indicates they would like to enable
10757 * ncq command priorities. This works only on SATA devices.
10759 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
10761 unsigned char *buf
;
10762 bool ncq_prio_supp
= false;
10764 if (!scsi_device_supports_vpd(sdev
))
10765 return ncq_prio_supp
;
10767 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
10769 return ncq_prio_supp
;
10771 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
10772 ncq_prio_supp
= (buf
[213] >> 4) & 1;
10775 return ncq_prio_supp
;
10778 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10780 static const struct pci_device_id mpt3sas_pci_table
[] = {
10781 /* Spitfire ~ 2004 */
10782 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
10783 PCI_ANY_ID
, PCI_ANY_ID
},
10784 /* Falcon ~ 2008 */
10785 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
10786 PCI_ANY_ID
, PCI_ANY_ID
},
10787 /* Liberator ~ 2108 */
10788 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
10789 PCI_ANY_ID
, PCI_ANY_ID
},
10790 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
10791 PCI_ANY_ID
, PCI_ANY_ID
},
10792 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
10793 PCI_ANY_ID
, PCI_ANY_ID
},
10794 /* Meteor ~ 2116 */
10795 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
10796 PCI_ANY_ID
, PCI_ANY_ID
},
10797 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
10798 PCI_ANY_ID
, PCI_ANY_ID
},
10799 /* Thunderbolt ~ 2208 */
10800 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
10801 PCI_ANY_ID
, PCI_ANY_ID
},
10802 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
10803 PCI_ANY_ID
, PCI_ANY_ID
},
10804 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
10805 PCI_ANY_ID
, PCI_ANY_ID
},
10806 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
10807 PCI_ANY_ID
, PCI_ANY_ID
},
10808 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
10809 PCI_ANY_ID
, PCI_ANY_ID
},
10810 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
10811 PCI_ANY_ID
, PCI_ANY_ID
},
10812 /* Mustang ~ 2308 */
10813 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
10814 PCI_ANY_ID
, PCI_ANY_ID
},
10815 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
10816 PCI_ANY_ID
, PCI_ANY_ID
},
10817 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
10818 PCI_ANY_ID
, PCI_ANY_ID
},
10819 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP
,
10820 PCI_ANY_ID
, PCI_ANY_ID
},
10821 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1
,
10822 PCI_ANY_ID
, PCI_ANY_ID
},
10824 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
10825 PCI_ANY_ID
, PCI_ANY_ID
},
10826 /* Fury ~ 3004 and 3008 */
10827 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
10828 PCI_ANY_ID
, PCI_ANY_ID
},
10829 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
10830 PCI_ANY_ID
, PCI_ANY_ID
},
10831 /* Invader ~ 3108 */
10832 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
10833 PCI_ANY_ID
, PCI_ANY_ID
},
10834 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
10835 PCI_ANY_ID
, PCI_ANY_ID
},
10836 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
10837 PCI_ANY_ID
, PCI_ANY_ID
},
10838 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
10839 PCI_ANY_ID
, PCI_ANY_ID
},
10840 /* Cutlass ~ 3216 and 3224 */
10841 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
10842 PCI_ANY_ID
, PCI_ANY_ID
},
10843 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
10844 PCI_ANY_ID
, PCI_ANY_ID
},
10845 /* Intruder ~ 3316 and 3324 */
10846 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
10847 PCI_ANY_ID
, PCI_ANY_ID
},
10848 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
10849 PCI_ANY_ID
, PCI_ANY_ID
},
10850 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
10851 PCI_ANY_ID
, PCI_ANY_ID
},
10852 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
10853 PCI_ANY_ID
, PCI_ANY_ID
},
10854 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
10855 PCI_ANY_ID
, PCI_ANY_ID
},
10856 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
10857 PCI_ANY_ID
, PCI_ANY_ID
},
10858 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
10859 PCI_ANY_ID
, PCI_ANY_ID
},
10860 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
10861 PCI_ANY_ID
, PCI_ANY_ID
},
10862 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
10863 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
10864 PCI_ANY_ID
, PCI_ANY_ID
},
10865 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
10866 PCI_ANY_ID
, PCI_ANY_ID
},
10867 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
10868 PCI_ANY_ID
, PCI_ANY_ID
},
10869 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
10870 PCI_ANY_ID
, PCI_ANY_ID
},
10871 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
10872 PCI_ANY_ID
, PCI_ANY_ID
},
10873 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
10874 PCI_ANY_ID
, PCI_ANY_ID
},
10875 /* Mercator ~ 3616*/
10876 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3616
,
10877 PCI_ANY_ID
, PCI_ANY_ID
},
10879 /* Aero SI 0x00E1 Configurable Secure
10880 * 0x00E2 Hard Secure
10882 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_CFG_SEC_3916
,
10883 PCI_ANY_ID
, PCI_ANY_ID
},
10884 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_HARD_SEC_3916
,
10885 PCI_ANY_ID
, PCI_ANY_ID
},
10887 /* Atlas PCIe Switch Management Port */
10888 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_ATLAS_PCIe_SWITCH_DEVID
,
10889 PCI_ANY_ID
, PCI_ANY_ID
},
10891 /* Sea SI 0x00E5 Configurable Secure
10892 * 0x00E6 Hard Secure
10894 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_CFG_SEC_3816
,
10895 PCI_ANY_ID
, PCI_ANY_ID
},
10896 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_HARD_SEC_3816
,
10897 PCI_ANY_ID
, PCI_ANY_ID
},
10899 {0} /* Terminating entry */
10901 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
10903 static struct pci_error_handlers _mpt3sas_err_handler
= {
10904 .error_detected
= scsih_pci_error_detected
,
10905 .mmio_enabled
= scsih_pci_mmio_enabled
,
10906 .slot_reset
= scsih_pci_slot_reset
,
10907 .resume
= scsih_pci_resume
,
10910 static struct pci_driver mpt3sas_driver
= {
10911 .name
= MPT3SAS_DRIVER_NAME
,
10912 .id_table
= mpt3sas_pci_table
,
10913 .probe
= _scsih_probe
,
10914 .remove
= scsih_remove
,
10915 .shutdown
= scsih_shutdown
,
10916 .err_handler
= &_mpt3sas_err_handler
,
10918 .suspend
= scsih_suspend
,
10919 .resume
= scsih_resume
,
10924 * scsih_init - main entry point for this driver.
10926 * Return: 0 success, anything else error.
10934 mpt3sas_base_initialize_callback_handler();
10936 /* queuecommand callback hander */
10937 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
10939 /* task management callback handler */
10940 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
10942 /* base internal commands callback handler */
10943 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
10944 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
10945 mpt3sas_port_enable_done
);
10947 /* transport internal commands callback handler */
10948 transport_cb_idx
= mpt3sas_base_register_callback_handler(
10949 mpt3sas_transport_done
);
10951 /* scsih internal commands callback handler */
10952 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
10954 /* configuration page API internal commands callback handler */
10955 config_cb_idx
= mpt3sas_base_register_callback_handler(
10956 mpt3sas_config_done
);
10958 /* ctl module callback handler */
10959 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
10961 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
10962 _scsih_tm_tr_complete
);
10964 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
10965 _scsih_tm_volume_tr_complete
);
10967 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
10968 _scsih_sas_control_complete
);
10974 * scsih_exit - exit point for this driver (when it is a module).
10976 * Return: 0 success, anything else error.
10982 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
10983 mpt3sas_base_release_callback_handler(tm_cb_idx
);
10984 mpt3sas_base_release_callback_handler(base_cb_idx
);
10985 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
10986 mpt3sas_base_release_callback_handler(transport_cb_idx
);
10987 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
10988 mpt3sas_base_release_callback_handler(config_cb_idx
);
10989 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
10991 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
10992 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
10993 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
10995 /* raid transport support */
10996 if (hbas_to_enumerate
!= 1)
10997 raid_class_release(mpt3sas_raid_template
);
10998 if (hbas_to_enumerate
!= 2)
10999 raid_class_release(mpt2sas_raid_template
);
11000 sas_release_transport(mpt3sas_transport_template
);
11004 * _mpt3sas_init - main entry point for this driver.
11006 * Return: 0 success, anything else error.
11009 _mpt3sas_init(void)
11013 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
11014 MPT3SAS_DRIVER_VERSION
);
11016 mpt3sas_transport_template
=
11017 sas_attach_transport(&mpt3sas_transport_functions
);
11018 if (!mpt3sas_transport_template
)
11021 /* No need attach mpt3sas raid functions template
11022 * if hbas_to_enumarate value is one.
11024 if (hbas_to_enumerate
!= 1) {
11025 mpt3sas_raid_template
=
11026 raid_class_attach(&mpt3sas_raid_functions
);
11027 if (!mpt3sas_raid_template
) {
11028 sas_release_transport(mpt3sas_transport_template
);
11033 /* No need to attach mpt2sas raid functions template
11034 * if hbas_to_enumarate value is two
11036 if (hbas_to_enumerate
!= 2) {
11037 mpt2sas_raid_template
=
11038 raid_class_attach(&mpt2sas_raid_functions
);
11039 if (!mpt2sas_raid_template
) {
11040 sas_release_transport(mpt3sas_transport_template
);
11045 error
= scsih_init();
11051 mpt3sas_ctl_init(hbas_to_enumerate
);
11053 error
= pci_register_driver(&mpt3sas_driver
);
11061 * _mpt3sas_exit - exit point for this driver (when it is a module).
11065 _mpt3sas_exit(void)
11067 pr_info("mpt3sas version %s unloading\n",
11068 MPT3SAS_DRIVER_VERSION
);
11070 mpt3sas_ctl_exit(hbas_to_enumerate
);
11072 pci_unregister_driver(&mpt3sas_driver
);
11077 module_init(_mpt3sas_init
);
11078 module_exit(_mpt3sas_exit
);