2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/pci-aspm.h>
55 #include <linux/interrupt.h>
56 #include <linux/aer.h>
57 #include <linux/raid_class.h>
58 #include <asm/unaligned.h>
60 #include "mpt3sas_base.h"
62 #define RAID_CHANNEL 1
64 #define PCIE_CHANNEL 2
67 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
68 struct _sas_node
*sas_expander
);
69 static void _firmware_event_work(struct work_struct
*work
);
71 static void _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
72 struct _sas_device
*sas_device
);
73 static int _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
74 u8 retry_count
, u8 is_pd
);
75 static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
);
76 static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
77 struct _pcie_device
*pcie_device
);
79 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
);
80 static u8
_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
);
82 /* global parameters */
83 LIST_HEAD(mpt3sas_ioc_list
);
84 /* global ioc lock for list operations */
85 DEFINE_SPINLOCK(gioc_lock
);
87 MODULE_AUTHOR(MPT3SAS_AUTHOR
);
88 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION
);
89 MODULE_LICENSE("GPL");
90 MODULE_VERSION(MPT3SAS_DRIVER_VERSION
);
91 MODULE_ALIAS("mpt2sas");
93 /* local parameters */
94 static u8 scsi_io_cb_idx
= -1;
95 static u8 tm_cb_idx
= -1;
96 static u8 ctl_cb_idx
= -1;
97 static u8 base_cb_idx
= -1;
98 static u8 port_enable_cb_idx
= -1;
99 static u8 transport_cb_idx
= -1;
100 static u8 scsih_cb_idx
= -1;
101 static u8 config_cb_idx
= -1;
105 static u8 tm_tr_cb_idx
= -1 ;
106 static u8 tm_tr_volume_cb_idx
= -1 ;
107 static u8 tm_sas_control_cb_idx
= -1;
109 /* command line options */
110 static u32 logging_level
;
111 MODULE_PARM_DESC(logging_level
,
112 " bits for enabling additional logging info (default=0)");
115 static ushort max_sectors
= 0xFFFF;
116 module_param(max_sectors
, ushort
, 0);
117 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
120 static int missing_delay
[2] = {-1, -1};
121 module_param_array(missing_delay
, int, NULL
, 0);
122 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
124 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
125 #define MPT3SAS_MAX_LUN (16895)
126 static u64 max_lun
= MPT3SAS_MAX_LUN
;
127 module_param(max_lun
, ullong
, 0);
128 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
130 static ushort hbas_to_enumerate
;
131 module_param(hbas_to_enumerate
, ushort
, 0);
132 MODULE_PARM_DESC(hbas_to_enumerate
,
133 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
134 1 - enumerates only SAS 2.0 generation HBAs\n \
135 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
137 /* diag_buffer_enable is bitwise
139 * bit 1 set = SNAPSHOT
140 * bit 2 set = EXTENDED
142 * Either bit can be set, or both
144 static int diag_buffer_enable
= -1;
145 module_param(diag_buffer_enable
, int, 0);
146 MODULE_PARM_DESC(diag_buffer_enable
,
147 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
148 static int disable_discovery
= -1;
149 module_param(disable_discovery
, int, 0);
150 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
153 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
154 static int prot_mask
= -1;
155 module_param(prot_mask
, int, 0);
156 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
159 /* raid transport support */
160 struct raid_template
*mpt3sas_raid_template
;
161 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.
288 * Note: The logging levels are defined in mpt3sas_debug.h.
291 _scsih_set_debug_level(const char *val
, const struct kernel_param
*kp
)
293 int ret
= param_set_int(val
, kp
);
294 struct MPT3SAS_ADAPTER
*ioc
;
299 pr_info("setting logging_level(0x%08x)\n", logging_level
);
300 spin_lock(&gioc_lock
);
301 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
302 ioc
->logging_level
= logging_level
;
303 spin_unlock(&gioc_lock
);
306 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
307 &logging_level
, 0644);
310 * _scsih_srch_boot_sas_address - search based on sas_address
311 * @sas_address: sas address
312 * @boot_device: boot device object from bios page 2
314 * Returns 1 when there's a match, 0 means no match.
317 _scsih_srch_boot_sas_address(u64 sas_address
,
318 Mpi2BootDeviceSasWwid_t
*boot_device
)
320 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
324 * _scsih_srch_boot_device_name - search based on device name
325 * @device_name: device name specified in INDENTIFY fram
326 * @boot_device: boot device object from bios page 2
328 * Returns 1 when there's a match, 0 means no match.
331 _scsih_srch_boot_device_name(u64 device_name
,
332 Mpi2BootDeviceDeviceName_t
*boot_device
)
334 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
338 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
339 * @enclosure_logical_id: enclosure logical id
340 * @slot_number: slot number
341 * @boot_device: boot device object from bios page 2
343 * Returns 1 when there's a match, 0 means no match.
346 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
347 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
349 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
350 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
351 SlotNumber
)) ? 1 : 0;
355 * _scsih_is_boot_device - search for matching boot device.
356 * @sas_address: sas address
357 * @device_name: device name specified in INDENTIFY fram
358 * @enclosure_logical_id: enclosure logical id
359 * @slot_number: slot number
360 * @form: specifies boot device form
361 * @boot_device: boot device object from bios page 2
363 * Returns 1 when there's a match, 0 means no match.
366 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
367 u64 enclosure_logical_id
, u16 slot
, u8 form
,
368 Mpi2BiosPage2BootDevice_t
*boot_device
)
373 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
376 rc
= _scsih_srch_boot_sas_address(
377 sas_address
, &boot_device
->SasWwid
);
379 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
380 if (!enclosure_logical_id
)
382 rc
= _scsih_srch_boot_encl_slot(
383 enclosure_logical_id
,
384 slot
, &boot_device
->EnclosureSlot
);
386 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
389 rc
= _scsih_srch_boot_device_name(
390 device_name
, &boot_device
->DeviceName
);
392 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
400 * _scsih_get_sas_address - set the sas_address for given device handle
401 * @handle: device handle
402 * @sas_address: sas address
404 * Returns 0 success, non-zero when failure
407 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
410 Mpi2SasDevicePage0_t sas_device_pg0
;
411 Mpi2ConfigReply_t mpi_reply
;
416 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
417 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
418 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
419 __FILE__
, __LINE__
, __func__
);
423 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
424 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
425 /* For HBA, vSES doesn't return HBA SAS address. Instead return
426 * vSES's sas address.
428 if ((handle
<= ioc
->sas_hba
.num_phys
) &&
429 (!(le32_to_cpu(sas_device_pg0
.DeviceInfo
) &
430 MPI2_SAS_DEVICE_INFO_SEP
)))
431 *sas_address
= ioc
->sas_hba
.sas_address
;
433 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
437 /* we hit this because the given parent handle doesn't exist */
438 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
441 /* else error case */
443 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
444 ioc
->name
, handle
, ioc_status
,
445 __FILE__
, __LINE__
, __func__
);
450 * _scsih_determine_boot_device - determine boot device.
451 * @ioc: per adapter object
452 * @device: sas_device or pcie_device object
453 * @channel: SAS or PCIe channel
455 * Determines whether this device should be first reported device to
456 * to scsi-ml or sas transport, this purpose is for persistent boot device.
457 * There are primary, alternate, and current entries in bios page 2. The order
458 * priority is primary, alternate, then current. This routine saves
459 * the corresponding device object.
460 * The saved data to be used later in _scsih_probe_boot_devices().
463 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
, void *device
,
466 struct _sas_device
*sas_device
;
467 struct _pcie_device
*pcie_device
;
468 struct _raid_device
*raid_device
;
471 u64 enclosure_logical_id
;
474 /* only process this function when driver loads */
475 if (!ioc
->is_driver_loading
)
478 /* no Bios, return immediately */
479 if (!ioc
->bios_pg3
.BiosVersion
)
482 if (channel
== RAID_CHANNEL
) {
483 raid_device
= device
;
484 sas_address
= raid_device
->wwid
;
486 enclosure_logical_id
= 0;
488 } else if (channel
== PCIE_CHANNEL
) {
489 pcie_device
= device
;
490 sas_address
= pcie_device
->wwid
;
492 enclosure_logical_id
= 0;
496 sas_address
= sas_device
->sas_address
;
497 device_name
= sas_device
->device_name
;
498 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
499 slot
= sas_device
->slot
;
502 if (!ioc
->req_boot_device
.device
) {
503 if (_scsih_is_boot_device(sas_address
, device_name
,
504 enclosure_logical_id
, slot
,
505 (ioc
->bios_pg2
.ReqBootDeviceForm
&
506 MPI2_BIOSPAGE2_FORM_MASK
),
507 &ioc
->bios_pg2
.RequestedBootDevice
)) {
508 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
509 "%s: req_boot_device(0x%016llx)\n",
511 (unsigned long long)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
)) {
523 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
524 "%s: req_alt_boot_device(0x%016llx)\n",
526 (unsigned long long)sas_address
));
527 ioc
->req_alt_boot_device
.device
= device
;
528 ioc
->req_alt_boot_device
.channel
= channel
;
532 if (!ioc
->current_boot_device
.device
) {
533 if (_scsih_is_boot_device(sas_address
, device_name
,
534 enclosure_logical_id
, slot
,
535 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
536 MPI2_BIOSPAGE2_FORM_MASK
),
537 &ioc
->bios_pg2
.CurrentBootDevice
)) {
538 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
539 "%s: current_boot_device(0x%016llx)\n",
541 (unsigned long long)sas_address
));
542 ioc
->current_boot_device
.device
= device
;
543 ioc
->current_boot_device
.channel
= channel
;
548 static struct _sas_device
*
549 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
550 struct MPT3SAS_TARGET
*tgt_priv
)
552 struct _sas_device
*ret
;
554 assert_spin_locked(&ioc
->sas_device_lock
);
556 ret
= tgt_priv
->sas_dev
;
563 static struct _sas_device
*
564 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
565 struct MPT3SAS_TARGET
*tgt_priv
)
567 struct _sas_device
*ret
;
570 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
571 ret
= __mpt3sas_get_sdev_from_target(ioc
, tgt_priv
);
572 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
577 static struct _pcie_device
*
578 __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
579 struct MPT3SAS_TARGET
*tgt_priv
)
581 struct _pcie_device
*ret
;
583 assert_spin_locked(&ioc
->pcie_device_lock
);
585 ret
= tgt_priv
->pcie_dev
;
587 pcie_device_get(ret
);
593 * mpt3sas_get_pdev_from_target - pcie device search
594 * @ioc: per adapter object
595 * @tgt_priv: starget private object
597 * Context: This function will acquire ioc->pcie_device_lock and will release
598 * before returning the pcie_device object.
600 * This searches for pcie_device from target, then return pcie_device object.
602 static struct _pcie_device
*
603 mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
604 struct MPT3SAS_TARGET
*tgt_priv
)
606 struct _pcie_device
*ret
;
609 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
610 ret
= __mpt3sas_get_pdev_from_target(ioc
, tgt_priv
);
611 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
617 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
620 struct _sas_device
*sas_device
;
622 assert_spin_locked(&ioc
->sas_device_lock
);
624 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
625 if (sas_device
->sas_address
== sas_address
)
628 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
629 if (sas_device
->sas_address
== sas_address
)
635 sas_device_get(sas_device
);
640 * mpt3sas_get_sdev_by_addr - sas device search
641 * @ioc: per adapter object
642 * @sas_address: sas address
643 * Context: Calling function should acquire ioc->sas_device_lock
645 * This searches for sas_device based on sas_address, then return sas_device
649 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
652 struct _sas_device
*sas_device
;
655 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
656 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
658 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
663 static struct _sas_device
*
664 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
666 struct _sas_device
*sas_device
;
668 assert_spin_locked(&ioc
->sas_device_lock
);
670 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
671 if (sas_device
->handle
== handle
)
674 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
675 if (sas_device
->handle
== handle
)
681 sas_device_get(sas_device
);
686 * mpt3sas_get_sdev_by_handle - sas device search
687 * @ioc: per adapter object
688 * @handle: sas device handle (assigned by firmware)
689 * Context: Calling function should acquire ioc->sas_device_lock
691 * This searches for sas_device based on sas_address, then return sas_device
695 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
697 struct _sas_device
*sas_device
;
700 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
701 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
702 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
708 * _scsih_display_enclosure_chassis_info - display device location info
709 * @ioc: per adapter object
710 * @sas_device: per sas device object
711 * @sdev: scsi device struct
712 * @starget: scsi target struct
717 _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER
*ioc
,
718 struct _sas_device
*sas_device
, struct scsi_device
*sdev
,
719 struct scsi_target
*starget
)
722 if (sas_device
->enclosure_handle
!= 0)
723 sdev_printk(KERN_INFO
, sdev
,
724 "enclosure logical id (0x%016llx), slot(%d) \n",
726 sas_device
->enclosure_logical_id
,
728 if (sas_device
->connector_name
[0] != '\0')
729 sdev_printk(KERN_INFO
, sdev
,
730 "enclosure level(0x%04x), connector name( %s)\n",
731 sas_device
->enclosure_level
,
732 sas_device
->connector_name
);
733 if (sas_device
->is_chassis_slot_valid
)
734 sdev_printk(KERN_INFO
, sdev
, "chassis slot(0x%04x)\n",
735 sas_device
->chassis_slot
);
736 } else if (starget
) {
737 if (sas_device
->enclosure_handle
!= 0)
738 starget_printk(KERN_INFO
, starget
,
739 "enclosure logical id(0x%016llx), slot(%d) \n",
741 sas_device
->enclosure_logical_id
,
743 if (sas_device
->connector_name
[0] != '\0')
744 starget_printk(KERN_INFO
, starget
,
745 "enclosure level(0x%04x), connector name( %s)\n",
746 sas_device
->enclosure_level
,
747 sas_device
->connector_name
);
748 if (sas_device
->is_chassis_slot_valid
)
749 starget_printk(KERN_INFO
, starget
,
750 "chassis slot(0x%04x)\n",
751 sas_device
->chassis_slot
);
753 if (sas_device
->enclosure_handle
!= 0)
755 "enclosure logical id(0x%016llx), slot(%d) \n",
756 ioc
->name
, (unsigned long long)
757 sas_device
->enclosure_logical_id
,
759 if (sas_device
->connector_name
[0] != '\0')
761 "enclosure level(0x%04x), connector name( %s)\n",
762 ioc
->name
, sas_device
->enclosure_level
,
763 sas_device
->connector_name
);
764 if (sas_device
->is_chassis_slot_valid
)
765 pr_info(MPT3SAS_FMT
"chassis slot(0x%04x)\n",
766 ioc
->name
, sas_device
->chassis_slot
);
771 * _scsih_sas_device_remove - remove sas_device from list.
772 * @ioc: per adapter object
773 * @sas_device: the sas_device object
774 * Context: This function will acquire ioc->sas_device_lock.
776 * If sas_device is on the list, remove it and decrement its reference count.
779 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
780 struct _sas_device
*sas_device
)
787 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
788 ioc
->name
, sas_device
->handle
,
789 (unsigned long long) sas_device
->sas_address
);
791 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
794 * The lock serializes access to the list, but we still need to verify
795 * that nobody removed the entry while we were waiting on the lock.
797 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
798 if (!list_empty(&sas_device
->list
)) {
799 list_del_init(&sas_device
->list
);
800 sas_device_put(sas_device
);
802 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
806 * _scsih_device_remove_by_handle - removing device object by handle
807 * @ioc: per adapter object
808 * @handle: device handle
813 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
815 struct _sas_device
*sas_device
;
818 if (ioc
->shost_recovery
)
821 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
822 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
824 list_del_init(&sas_device
->list
);
825 sas_device_put(sas_device
);
827 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
829 _scsih_remove_device(ioc
, sas_device
);
830 sas_device_put(sas_device
);
835 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
836 * @ioc: per adapter object
837 * @sas_address: device sas_address
842 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
845 struct _sas_device
*sas_device
;
848 if (ioc
->shost_recovery
)
851 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
852 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
, sas_address
);
854 list_del_init(&sas_device
->list
);
855 sas_device_put(sas_device
);
857 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
859 _scsih_remove_device(ioc
, sas_device
);
860 sas_device_put(sas_device
);
865 * _scsih_sas_device_add - insert sas_device to the list.
866 * @ioc: per adapter object
867 * @sas_device: the sas_device object
868 * Context: This function will acquire ioc->sas_device_lock.
870 * Adding new object to the ioc->sas_device_list.
873 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
874 struct _sas_device
*sas_device
)
878 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
879 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
880 ioc
->name
, __func__
, sas_device
->handle
,
881 (unsigned long long)sas_device
->sas_address
));
883 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
886 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
887 sas_device_get(sas_device
);
888 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
889 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
891 if (ioc
->hide_drives
) {
892 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
896 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
897 sas_device
->sas_address_parent
)) {
898 _scsih_sas_device_remove(ioc
, sas_device
);
899 } else if (!sas_device
->starget
) {
901 * When asyn scanning is enabled, its not possible to remove
902 * devices while scanning is turned on due to an oops in
903 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
905 if (!ioc
->is_driver_loading
) {
906 mpt3sas_transport_port_remove(ioc
,
907 sas_device
->sas_address
,
908 sas_device
->sas_address_parent
);
909 _scsih_sas_device_remove(ioc
, sas_device
);
912 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
916 * _scsih_sas_device_init_add - insert sas_device to the list.
917 * @ioc: per adapter object
918 * @sas_device: the sas_device object
919 * Context: This function will acquire ioc->sas_device_lock.
921 * Adding new object at driver load time to the ioc->sas_device_init_list.
924 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
925 struct _sas_device
*sas_device
)
929 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
930 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
931 __func__
, sas_device
->handle
,
932 (unsigned long long)sas_device
->sas_address
));
934 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
937 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
938 sas_device_get(sas_device
);
939 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
940 _scsih_determine_boot_device(ioc
, sas_device
, 0);
941 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
945 static struct _pcie_device
*
946 __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
948 struct _pcie_device
*pcie_device
;
950 assert_spin_locked(&ioc
->pcie_device_lock
);
952 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
953 if (pcie_device
->wwid
== wwid
)
956 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
957 if (pcie_device
->wwid
== wwid
)
963 pcie_device_get(pcie_device
);
969 * mpt3sas_get_pdev_by_wwid - pcie device search
970 * @ioc: per adapter object
973 * Context: This function will acquire ioc->pcie_device_lock and will release
974 * before returning the pcie_device object.
976 * This searches for pcie_device based on wwid, then return pcie_device object.
978 static struct _pcie_device
*
979 mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
981 struct _pcie_device
*pcie_device
;
984 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
985 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
986 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
992 static struct _pcie_device
*
993 __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER
*ioc
, int id
,
996 struct _pcie_device
*pcie_device
;
998 assert_spin_locked(&ioc
->pcie_device_lock
);
1000 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
1001 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
1004 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
1005 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
1011 pcie_device_get(pcie_device
);
1015 static struct _pcie_device
*
1016 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1018 struct _pcie_device
*pcie_device
;
1020 assert_spin_locked(&ioc
->pcie_device_lock
);
1022 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
1023 if (pcie_device
->handle
== handle
)
1026 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
1027 if (pcie_device
->handle
== handle
)
1033 pcie_device_get(pcie_device
);
1039 * mpt3sas_get_pdev_by_handle - pcie device search
1040 * @ioc: per adapter object
1041 * @handle: Firmware device handle
1043 * Context: This function will acquire ioc->pcie_device_lock and will release
1044 * before returning the pcie_device object.
1046 * This searches for pcie_device based on handle, then return pcie_device
1049 struct _pcie_device
*
1050 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1052 struct _pcie_device
*pcie_device
;
1053 unsigned long flags
;
1055 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1056 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1057 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1063 * _scsih_pcie_device_remove - remove pcie_device from list.
1064 * @ioc: per adapter object
1065 * @pcie_device: the pcie_device object
1066 * Context: This function will acquire ioc->pcie_device_lock.
1068 * If pcie_device is on the list, remove it and decrement its reference count.
1071 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1072 struct _pcie_device
*pcie_device
)
1074 unsigned long flags
;
1075 int was_on_pcie_device_list
= 0;
1080 "removing handle(0x%04x), wwid(0x%016llx)\n",
1081 ioc
->name
, pcie_device
->handle
,
1082 (unsigned long long) pcie_device
->wwid
);
1083 if (pcie_device
->enclosure_handle
!= 0)
1085 "removing enclosure logical id(0x%016llx), slot(%d)\n",
1087 (unsigned long long)pcie_device
->enclosure_logical_id
,
1089 if (pcie_device
->connector_name
[0] != '\0')
1091 "removing enclosure level(0x%04x), connector name( %s)\n",
1092 ioc
->name
, pcie_device
->enclosure_level
,
1093 pcie_device
->connector_name
);
1095 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1096 if (!list_empty(&pcie_device
->list
)) {
1097 list_del_init(&pcie_device
->list
);
1098 was_on_pcie_device_list
= 1;
1100 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1101 if (was_on_pcie_device_list
) {
1102 kfree(pcie_device
->serial_number
);
1103 pcie_device_put(pcie_device
);
1109 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1110 * @ioc: per adapter object
1111 * @handle: device handle
1116 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1118 struct _pcie_device
*pcie_device
;
1119 unsigned long flags
;
1120 int was_on_pcie_device_list
= 0;
1122 if (ioc
->shost_recovery
)
1125 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1126 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1128 if (!list_empty(&pcie_device
->list
)) {
1129 list_del_init(&pcie_device
->list
);
1130 was_on_pcie_device_list
= 1;
1131 pcie_device_put(pcie_device
);
1134 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1135 if (was_on_pcie_device_list
) {
1136 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
1137 pcie_device_put(pcie_device
);
1142 * _scsih_pcie_device_add - add pcie_device object
1143 * @ioc: per adapter object
1144 * @pcie_device: pcie_device object
1146 * This is added to the pcie_device_list link list.
1149 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1150 struct _pcie_device
*pcie_device
)
1152 unsigned long flags
;
1154 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1155 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1156 pcie_device
->handle
, (unsigned long long)pcie_device
->wwid
));
1157 if (pcie_device
->enclosure_handle
!= 0)
1158 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1159 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1160 ioc
->name
, __func__
,
1161 (unsigned long long)pcie_device
->enclosure_logical_id
,
1162 pcie_device
->slot
));
1163 if (pcie_device
->connector_name
[0] != '\0')
1164 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1165 "%s: enclosure level(0x%04x), connector name( %s)\n",
1166 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
1167 pcie_device
->connector_name
));
1169 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1170 pcie_device_get(pcie_device
);
1171 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
1172 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1174 if (scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, pcie_device
->id
, 0)) {
1175 _scsih_pcie_device_remove(ioc
, pcie_device
);
1176 } else if (!pcie_device
->starget
) {
1177 if (!ioc
->is_driver_loading
) {
1178 /*TODO-- Need to find out whether this condition will occur or not*/
1179 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1182 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1186 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1187 * @ioc: per adapter object
1188 * @pcie_device: the pcie_device object
1189 * Context: This function will acquire ioc->pcie_device_lock.
1191 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1194 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
1195 struct _pcie_device
*pcie_device
)
1197 unsigned long flags
;
1199 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1200 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1201 pcie_device
->handle
, (unsigned long long)pcie_device
->wwid
));
1202 if (pcie_device
->enclosure_handle
!= 0)
1203 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1204 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1205 ioc
->name
, __func__
,
1206 (unsigned long long)pcie_device
->enclosure_logical_id
,
1207 pcie_device
->slot
));
1208 if (pcie_device
->connector_name
[0] != '\0')
1209 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1210 "%s: enclosure level(0x%04x), connector name( %s)\n",
1211 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
1212 pcie_device
->connector_name
));
1214 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1215 pcie_device_get(pcie_device
);
1216 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_init_list
);
1217 _scsih_determine_boot_device(ioc
, pcie_device
, PCIE_CHANNEL
);
1218 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1221 * _scsih_raid_device_find_by_id - raid device search
1222 * @ioc: per adapter object
1223 * @id: sas device target id
1224 * @channel: sas device channel
1225 * Context: Calling function should acquire ioc->raid_device_lock
1227 * This searches for raid_device based on target id, then return raid_device
1230 static struct _raid_device
*
1231 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
1233 struct _raid_device
*raid_device
, *r
;
1236 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1237 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
1248 * mpt3sas_raid_device_find_by_handle - raid device search
1249 * @ioc: per adapter object
1250 * @handle: sas device handle (assigned by firmware)
1251 * Context: Calling function should acquire ioc->raid_device_lock
1253 * This searches for raid_device based on handle, then return raid_device
1256 struct _raid_device
*
1257 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1259 struct _raid_device
*raid_device
, *r
;
1262 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1263 if (raid_device
->handle
!= handle
)
1274 * _scsih_raid_device_find_by_wwid - raid device search
1275 * @ioc: per adapter object
1276 * @handle: sas device handle (assigned by firmware)
1277 * Context: Calling function should acquire ioc->raid_device_lock
1279 * This searches for raid_device based on wwid, then return raid_device
1282 static struct _raid_device
*
1283 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
1285 struct _raid_device
*raid_device
, *r
;
1288 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1289 if (raid_device
->wwid
!= wwid
)
1300 * _scsih_raid_device_add - add raid_device object
1301 * @ioc: per adapter object
1302 * @raid_device: raid_device object
1304 * This is added to the raid_device_list link list.
1307 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1308 struct _raid_device
*raid_device
)
1310 unsigned long flags
;
1312 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1313 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1314 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
1316 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1317 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
1318 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1322 * _scsih_raid_device_remove - delete raid_device object
1323 * @ioc: per adapter object
1324 * @raid_device: raid_device object
1328 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1329 struct _raid_device
*raid_device
)
1331 unsigned long flags
;
1333 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1334 list_del(&raid_device
->list
);
1336 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1340 * mpt3sas_scsih_expander_find_by_handle - expander device search
1341 * @ioc: per adapter object
1342 * @handle: expander handle (assigned by firmware)
1343 * Context: Calling function should acquire ioc->sas_device_lock
1345 * This searches for expander device based on handle, then returns the
1349 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1351 struct _sas_node
*sas_expander
, *r
;
1354 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1355 if (sas_expander
->handle
!= handle
)
1365 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1366 * @ioc: per adapter object
1367 * @sas_address: sas address
1368 * Context: Calling function should acquire ioc->sas_node_lock.
1370 * This searches for expander device based on sas_address, then returns the
1374 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1377 struct _sas_node
*sas_expander
, *r
;
1380 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1381 if (sas_expander
->sas_address
!= sas_address
)
1391 * _scsih_expander_node_add - insert expander device to the list.
1392 * @ioc: per adapter object
1393 * @sas_expander: the sas_device object
1394 * Context: This function will acquire ioc->sas_node_lock.
1396 * Adding new object to the ioc->sas_expander_list.
1401 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1402 struct _sas_node
*sas_expander
)
1404 unsigned long flags
;
1406 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1407 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1408 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1412 * _scsih_is_end_device - determines if device is an end device
1413 * @device_info: bitfield providing information about the device.
1416 * Returns 1 if end device.
1419 _scsih_is_end_device(u32 device_info
)
1421 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1422 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1423 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1424 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1431 * _scsih_is_nvme_device - determines if device is an nvme device
1432 * @device_info: bitfield providing information about the device.
1435 * Returns 1 if nvme device.
1438 _scsih_is_nvme_device(u32 device_info
)
1440 if ((device_info
& MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
)
1441 == MPI26_PCIE_DEVINFO_NVME
)
1448 * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
1449 * @ioc: per adapter object
1450 * @smid: system request message index
1452 * Returns the smid stored scmd pointer.
1453 * Then will dereference the stored scmd pointer.
1456 mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1458 struct scsi_cmnd
*scmd
= NULL
;
1459 struct scsiio_tracker
*st
;
1462 smid
<= ioc
->scsiio_depth
- INTERNAL_SCSIIO_CMDS_COUNT
) {
1463 u32 unique_tag
= smid
- 1;
1465 scmd
= scsi_host_find_tag(ioc
->shost
, unique_tag
);
1467 st
= scsi_cmd_priv(scmd
);
1468 if (st
->cb_idx
== 0xFF)
1476 * scsih_change_queue_depth - setting device queue depth
1477 * @sdev: scsi device struct
1478 * @qdepth: requested queue depth
1480 * Returns queue depth.
1483 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1485 struct Scsi_Host
*shost
= sdev
->host
;
1487 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1488 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1489 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1490 struct _sas_device
*sas_device
;
1491 unsigned long flags
;
1493 max_depth
= shost
->can_queue
;
1495 /* limit max device queue for SATA to 32 */
1496 sas_device_priv_data
= sdev
->hostdata
;
1497 if (!sas_device_priv_data
)
1499 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1500 if (!sas_target_priv_data
)
1502 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1505 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1506 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1508 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1509 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1511 sas_device_put(sas_device
);
1513 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1517 if (!sdev
->tagged_supported
)
1519 if (qdepth
> max_depth
)
1521 return scsi_change_queue_depth(sdev
, qdepth
);
1525 * scsih_target_alloc - target add routine
1526 * @starget: scsi target struct
1528 * Returns 0 if ok. Any other return is assumed to be an error and
1529 * the device is ignored.
1532 scsih_target_alloc(struct scsi_target
*starget
)
1534 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1535 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1536 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1537 struct _sas_device
*sas_device
;
1538 struct _raid_device
*raid_device
;
1539 struct _pcie_device
*pcie_device
;
1540 unsigned long flags
;
1541 struct sas_rphy
*rphy
;
1543 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1545 if (!sas_target_priv_data
)
1548 starget
->hostdata
= sas_target_priv_data
;
1549 sas_target_priv_data
->starget
= starget
;
1550 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1553 if (starget
->channel
== RAID_CHANNEL
) {
1554 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1555 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1558 sas_target_priv_data
->handle
= raid_device
->handle
;
1559 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1560 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1561 if (ioc
->is_warpdrive
)
1562 sas_target_priv_data
->raid_device
= raid_device
;
1563 raid_device
->starget
= starget
;
1565 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1570 if (starget
->channel
== PCIE_CHANNEL
) {
1571 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1572 pcie_device
= __mpt3sas_get_pdev_by_idchannel(ioc
, starget
->id
,
1575 sas_target_priv_data
->handle
= pcie_device
->handle
;
1576 sas_target_priv_data
->sas_address
= pcie_device
->wwid
;
1577 sas_target_priv_data
->pcie_dev
= pcie_device
;
1578 pcie_device
->starget
= starget
;
1579 pcie_device
->id
= starget
->id
;
1580 pcie_device
->channel
= starget
->channel
;
1581 sas_target_priv_data
->flags
|=
1582 MPT_TARGET_FLAGS_PCIE_DEVICE
;
1583 if (pcie_device
->fast_path
)
1584 sas_target_priv_data
->flags
|=
1585 MPT_TARGET_FASTPATH_IO
;
1587 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1591 /* sas/sata devices */
1592 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1593 rphy
= dev_to_rphy(starget
->dev
.parent
);
1594 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1595 rphy
->identify
.sas_address
);
1598 sas_target_priv_data
->handle
= sas_device
->handle
;
1599 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1600 sas_target_priv_data
->sas_dev
= sas_device
;
1601 sas_device
->starget
= starget
;
1602 sas_device
->id
= starget
->id
;
1603 sas_device
->channel
= starget
->channel
;
1604 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1605 sas_target_priv_data
->flags
|=
1606 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1607 if (sas_device
->fast_path
)
1608 sas_target_priv_data
->flags
|=
1609 MPT_TARGET_FASTPATH_IO
;
1611 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1617 * scsih_target_destroy - target destroy routine
1618 * @starget: scsi target struct
1623 scsih_target_destroy(struct scsi_target
*starget
)
1625 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1626 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1627 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1628 struct _sas_device
*sas_device
;
1629 struct _raid_device
*raid_device
;
1630 struct _pcie_device
*pcie_device
;
1631 unsigned long flags
;
1632 struct sas_rphy
*rphy
;
1634 sas_target_priv_data
= starget
->hostdata
;
1635 if (!sas_target_priv_data
)
1638 if (starget
->channel
== RAID_CHANNEL
) {
1639 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1640 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1643 raid_device
->starget
= NULL
;
1644 raid_device
->sdev
= NULL
;
1646 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1650 if (starget
->channel
== PCIE_CHANNEL
) {
1651 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1652 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1653 sas_target_priv_data
);
1654 if (pcie_device
&& (pcie_device
->starget
== starget
) &&
1655 (pcie_device
->id
== starget
->id
) &&
1656 (pcie_device
->channel
== starget
->channel
))
1657 pcie_device
->starget
= NULL
;
1661 * Corresponding get() is in _scsih_target_alloc()
1663 sas_target_priv_data
->pcie_dev
= NULL
;
1664 pcie_device_put(pcie_device
);
1665 pcie_device_put(pcie_device
);
1667 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1671 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1672 rphy
= dev_to_rphy(starget
->dev
.parent
);
1673 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1674 if (sas_device
&& (sas_device
->starget
== starget
) &&
1675 (sas_device
->id
== starget
->id
) &&
1676 (sas_device
->channel
== starget
->channel
))
1677 sas_device
->starget
= NULL
;
1681 * Corresponding get() is in _scsih_target_alloc()
1683 sas_target_priv_data
->sas_dev
= NULL
;
1684 sas_device_put(sas_device
);
1686 sas_device_put(sas_device
);
1688 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1691 kfree(sas_target_priv_data
);
1692 starget
->hostdata
= NULL
;
1696 * scsih_slave_alloc - device add routine
1697 * @sdev: scsi device struct
1699 * Returns 0 if ok. Any other return is assumed to be an error and
1700 * the device is ignored.
1703 scsih_slave_alloc(struct scsi_device
*sdev
)
1705 struct Scsi_Host
*shost
;
1706 struct MPT3SAS_ADAPTER
*ioc
;
1707 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1708 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1709 struct scsi_target
*starget
;
1710 struct _raid_device
*raid_device
;
1711 struct _sas_device
*sas_device
;
1712 struct _pcie_device
*pcie_device
;
1713 unsigned long flags
;
1715 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1717 if (!sas_device_priv_data
)
1720 sas_device_priv_data
->lun
= sdev
->lun
;
1721 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1723 starget
= scsi_target(sdev
);
1724 sas_target_priv_data
= starget
->hostdata
;
1725 sas_target_priv_data
->num_luns
++;
1726 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1727 sdev
->hostdata
= sas_device_priv_data
;
1728 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1729 sdev
->no_uld_attach
= 1;
1731 shost
= dev_to_shost(&starget
->dev
);
1732 ioc
= shost_priv(shost
);
1733 if (starget
->channel
== RAID_CHANNEL
) {
1734 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1735 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1736 starget
->id
, starget
->channel
);
1738 raid_device
->sdev
= sdev
; /* raid is single lun */
1739 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1741 if (starget
->channel
== PCIE_CHANNEL
) {
1742 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1743 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
1744 sas_target_priv_data
->sas_address
);
1745 if (pcie_device
&& (pcie_device
->starget
== NULL
)) {
1746 sdev_printk(KERN_INFO
, sdev
,
1747 "%s : pcie_device->starget set to starget @ %d\n",
1748 __func__
, __LINE__
);
1749 pcie_device
->starget
= starget
;
1753 pcie_device_put(pcie_device
);
1754 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1756 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1757 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1758 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1759 sas_target_priv_data
->sas_address
);
1760 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1761 sdev_printk(KERN_INFO
, sdev
,
1762 "%s : sas_device->starget set to starget @ %d\n",
1763 __func__
, __LINE__
);
1764 sas_device
->starget
= starget
;
1768 sas_device_put(sas_device
);
1770 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1777 * scsih_slave_destroy - device destroy routine
1778 * @sdev: scsi device struct
1783 scsih_slave_destroy(struct scsi_device
*sdev
)
1785 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1786 struct scsi_target
*starget
;
1787 struct Scsi_Host
*shost
;
1788 struct MPT3SAS_ADAPTER
*ioc
;
1789 struct _sas_device
*sas_device
;
1790 struct _pcie_device
*pcie_device
;
1791 unsigned long flags
;
1793 if (!sdev
->hostdata
)
1796 starget
= scsi_target(sdev
);
1797 sas_target_priv_data
= starget
->hostdata
;
1798 sas_target_priv_data
->num_luns
--;
1800 shost
= dev_to_shost(&starget
->dev
);
1801 ioc
= shost_priv(shost
);
1803 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
1804 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1805 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1806 sas_target_priv_data
);
1807 if (pcie_device
&& !sas_target_priv_data
->num_luns
)
1808 pcie_device
->starget
= NULL
;
1811 pcie_device_put(pcie_device
);
1813 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1815 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1816 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1817 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1818 sas_target_priv_data
);
1819 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1820 sas_device
->starget
= NULL
;
1823 sas_device_put(sas_device
);
1824 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1827 kfree(sdev
->hostdata
);
1828 sdev
->hostdata
= NULL
;
1832 * _scsih_display_sata_capabilities - sata capabilities
1833 * @ioc: per adapter object
1834 * @handle: device handle
1835 * @sdev: scsi device struct
1838 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1839 u16 handle
, struct scsi_device
*sdev
)
1841 Mpi2ConfigReply_t mpi_reply
;
1842 Mpi2SasDevicePage0_t sas_device_pg0
;
1847 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1848 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1849 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1850 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1854 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1855 MPI2_IOCSTATUS_MASK
;
1856 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1857 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1858 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1862 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1863 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1865 sdev_printk(KERN_INFO
, sdev
,
1866 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1867 "sw_preserve(%s)\n",
1868 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1869 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1870 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1872 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1873 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1874 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1878 * raid transport support -
1879 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1880 * unloading the driver followed by a load - I believe that the subroutine
1881 * raid_class_release() is not cleaning up properly.
1885 * scsih_is_raid - return boolean indicating device is raid volume
1886 * @dev the device struct object
1889 scsih_is_raid(struct device
*dev
)
1891 struct scsi_device
*sdev
= to_scsi_device(dev
);
1892 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1894 if (ioc
->is_warpdrive
)
1896 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1900 scsih_is_nvme(struct device
*dev
)
1902 struct scsi_device
*sdev
= to_scsi_device(dev
);
1904 return (sdev
->channel
== PCIE_CHANNEL
) ? 1 : 0;
1908 * scsih_get_resync - get raid volume resync percent complete
1909 * @dev the device struct object
1912 scsih_get_resync(struct device
*dev
)
1914 struct scsi_device
*sdev
= to_scsi_device(dev
);
1915 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1916 static struct _raid_device
*raid_device
;
1917 unsigned long flags
;
1918 Mpi2RaidVolPage0_t vol_pg0
;
1919 Mpi2ConfigReply_t mpi_reply
;
1920 u32 volume_status_flags
;
1921 u8 percent_complete
;
1924 percent_complete
= 0;
1926 if (ioc
->is_warpdrive
)
1929 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1930 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1933 handle
= raid_device
->handle
;
1934 percent_complete
= raid_device
->percent_complete
;
1936 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1941 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1942 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1943 sizeof(Mpi2RaidVolPage0_t
))) {
1944 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1945 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1946 percent_complete
= 0;
1950 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1951 if (!(volume_status_flags
&
1952 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1953 percent_complete
= 0;
1957 switch (ioc
->hba_mpi_version_belonged
) {
1959 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1963 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1969 * scsih_get_state - get raid volume level
1970 * @dev the device struct object
1973 scsih_get_state(struct device
*dev
)
1975 struct scsi_device
*sdev
= to_scsi_device(dev
);
1976 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1977 static struct _raid_device
*raid_device
;
1978 unsigned long flags
;
1979 Mpi2RaidVolPage0_t vol_pg0
;
1980 Mpi2ConfigReply_t mpi_reply
;
1982 enum raid_state state
= RAID_STATE_UNKNOWN
;
1985 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1986 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1989 handle
= raid_device
->handle
;
1990 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1995 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1996 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1997 sizeof(Mpi2RaidVolPage0_t
))) {
1998 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1999 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2003 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2004 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
2005 state
= RAID_STATE_RESYNCING
;
2009 switch (vol_pg0
.VolumeState
) {
2010 case MPI2_RAID_VOL_STATE_OPTIMAL
:
2011 case MPI2_RAID_VOL_STATE_ONLINE
:
2012 state
= RAID_STATE_ACTIVE
;
2014 case MPI2_RAID_VOL_STATE_DEGRADED
:
2015 state
= RAID_STATE_DEGRADED
;
2017 case MPI2_RAID_VOL_STATE_FAILED
:
2018 case MPI2_RAID_VOL_STATE_MISSING
:
2019 state
= RAID_STATE_OFFLINE
;
2023 switch (ioc
->hba_mpi_version_belonged
) {
2025 raid_set_state(mpt2sas_raid_template
, dev
, state
);
2029 raid_set_state(mpt3sas_raid_template
, dev
, state
);
2035 * _scsih_set_level - set raid level
2036 * @sdev: scsi device struct
2037 * @volume_type: volume type
2040 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
2041 struct scsi_device
*sdev
, u8 volume_type
)
2043 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
2045 switch (volume_type
) {
2046 case MPI2_RAID_VOL_TYPE_RAID0
:
2047 level
= RAID_LEVEL_0
;
2049 case MPI2_RAID_VOL_TYPE_RAID10
:
2050 level
= RAID_LEVEL_10
;
2052 case MPI2_RAID_VOL_TYPE_RAID1E
:
2053 level
= RAID_LEVEL_1E
;
2055 case MPI2_RAID_VOL_TYPE_RAID1
:
2056 level
= RAID_LEVEL_1
;
2060 switch (ioc
->hba_mpi_version_belonged
) {
2062 raid_set_level(mpt2sas_raid_template
,
2063 &sdev
->sdev_gendev
, level
);
2067 raid_set_level(mpt3sas_raid_template
,
2068 &sdev
->sdev_gendev
, level
);
2075 * _scsih_get_volume_capabilities - volume capabilities
2076 * @ioc: per adapter object
2077 * @sas_device: the raid_device object
2079 * Returns 0 for success, else 1
2082 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
2083 struct _raid_device
*raid_device
)
2085 Mpi2RaidVolPage0_t
*vol_pg0
;
2086 Mpi2RaidPhysDiskPage0_t pd_pg0
;
2087 Mpi2SasDevicePage0_t sas_device_pg0
;
2088 Mpi2ConfigReply_t mpi_reply
;
2092 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
2093 &num_pds
)) || !num_pds
) {
2094 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2095 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2100 raid_device
->num_pds
= num_pds
;
2101 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
2102 sizeof(Mpi2RaidVol0PhysDisk_t
));
2103 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
2105 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2106 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2111 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
2112 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
2113 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2114 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2120 raid_device
->volume_type
= vol_pg0
->VolumeType
;
2122 /* figure out what the underlying devices are by
2123 * obtaining the device_info bits for the 1st device
2125 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
2126 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
2127 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
2128 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
2129 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
2130 le16_to_cpu(pd_pg0
.DevHandle
)))) {
2131 raid_device
->device_info
=
2132 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
2141 * _scsih_enable_tlr - setting TLR flags
2142 * @ioc: per adapter object
2143 * @sdev: scsi device struct
2145 * Enabling Transaction Layer Retries for tape devices when
2146 * vpd page 0x90 is present
2150 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
2154 if (sdev
->type
!= TYPE_TAPE
)
2157 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
2160 sas_enable_tlr(sdev
);
2161 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
2162 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
2168 * scsih_slave_configure - device configure routine.
2169 * @sdev: scsi device struct
2171 * Returns 0 if ok. Any other return is assumed to be an error and
2172 * the device is ignored.
2175 scsih_slave_configure(struct scsi_device
*sdev
)
2177 struct Scsi_Host
*shost
= sdev
->host
;
2178 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2179 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2180 struct MPT3SAS_TARGET
*sas_target_priv_data
;
2181 struct _sas_device
*sas_device
;
2182 struct _pcie_device
*pcie_device
;
2183 struct _raid_device
*raid_device
;
2184 unsigned long flags
;
2189 u16 handle
, volume_handle
= 0;
2190 u64 volume_wwid
= 0;
2193 sas_device_priv_data
= sdev
->hostdata
;
2194 sas_device_priv_data
->configured_lun
= 1;
2195 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2196 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2197 handle
= sas_target_priv_data
->handle
;
2199 /* raid volume handling */
2200 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2202 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2203 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
2204 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2206 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2207 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2208 __LINE__
, __func__
));
2212 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2213 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2214 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2215 __LINE__
, __func__
));
2220 * WARPDRIVE: Initialize the required data for Direct IO
2222 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
2224 /* RAID Queue Depth Support
2225 * IS volume = underlying qdepth of drive type, either
2226 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2227 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2229 if (raid_device
->device_info
&
2230 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2231 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2234 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2235 if (raid_device
->device_info
&
2236 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2242 switch (raid_device
->volume_type
) {
2243 case MPI2_RAID_VOL_TYPE_RAID0
:
2246 case MPI2_RAID_VOL_TYPE_RAID1E
:
2247 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2248 if (ioc
->manu_pg10
.OEMIdentifier
&&
2249 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2250 MFG10_GF0_R10_DISPLAY
) &&
2251 !(raid_device
->num_pds
% 2))
2256 case MPI2_RAID_VOL_TYPE_RAID1
:
2257 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2260 case MPI2_RAID_VOL_TYPE_RAID10
:
2261 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2264 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2266 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2271 if (!ioc
->hide_ir_msg
)
2272 sdev_printk(KERN_INFO
, sdev
,
2273 "%s: handle(0x%04x), wwid(0x%016llx),"
2274 " pd_count(%d), type(%s)\n",
2275 r_level
, raid_device
->handle
,
2276 (unsigned long long)raid_device
->wwid
,
2277 raid_device
->num_pds
, ds
);
2279 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
2280 blk_queue_max_hw_sectors(sdev
->request_queue
,
2281 MPT3SAS_RAID_MAX_SECTORS
);
2282 sdev_printk(KERN_INFO
, sdev
,
2283 "Set queue's max_sector to: %u\n",
2284 MPT3SAS_RAID_MAX_SECTORS
);
2287 scsih_change_queue_depth(sdev
, qdepth
);
2289 /* raid transport support */
2290 if (!ioc
->is_warpdrive
)
2291 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
2295 /* non-raid handling */
2296 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2297 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
2299 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2300 "failure at %s:%d/%s()!\n", ioc
->name
,
2301 __FILE__
, __LINE__
, __func__
));
2304 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
2305 volume_handle
, &volume_wwid
)) {
2306 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2307 "failure at %s:%d/%s()!\n", ioc
->name
,
2308 __FILE__
, __LINE__
, __func__
));
2314 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2315 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2316 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
2317 sas_device_priv_data
->sas_target
->sas_address
);
2319 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2320 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2321 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2322 __LINE__
, __func__
));
2326 qdepth
= MPT3SAS_NVME_QUEUE_DEPTH
;
2328 sdev_printk(KERN_INFO
, sdev
,
2329 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2330 ds
, handle
, (unsigned long long)pcie_device
->wwid
,
2331 pcie_device
->port_num
);
2332 if (pcie_device
->enclosure_handle
!= 0)
2333 sdev_printk(KERN_INFO
, sdev
,
2334 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2336 (unsigned long long)pcie_device
->enclosure_logical_id
,
2338 if (pcie_device
->connector_name
[0] != '\0')
2339 sdev_printk(KERN_INFO
, sdev
,
2340 "%s: enclosure level(0x%04x),"
2341 "connector name( %s)\n", ds
,
2342 pcie_device
->enclosure_level
,
2343 pcie_device
->connector_name
);
2344 pcie_device_put(pcie_device
);
2345 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2346 scsih_change_queue_depth(sdev
, qdepth
);
2348 if (pcie_device
->nvme_mdts
)
2349 blk_queue_max_hw_sectors(sdev
->request_queue
,
2350 pcie_device
->nvme_mdts
/512);
2351 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2352 ** merged and can eliminate holes created during merging
2355 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES
,
2356 sdev
->request_queue
);
2357 blk_queue_virt_boundary(sdev
->request_queue
,
2358 ioc
->page_size
- 1);
2362 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2363 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
2364 sas_device_priv_data
->sas_target
->sas_address
);
2366 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2367 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2368 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2373 sas_device
->volume_handle
= volume_handle
;
2374 sas_device
->volume_wwid
= volume_wwid
;
2375 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2376 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2378 if (sas_device
->device_info
&
2379 MPI2_SAS_DEVICE_INFO_SEP
) {
2380 sdev_printk(KERN_WARNING
, sdev
,
2381 "set ignore_delay_remove for handle(0x%04x)\n",
2382 sas_device_priv_data
->sas_target
->handle
);
2383 sas_device_priv_data
->ignore_delay_remove
= 1;
2388 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2389 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2391 else if (sas_device
->device_info
&
2392 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2396 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2397 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2398 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2399 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2401 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, sdev
, NULL
);
2403 sas_device_put(sas_device
);
2404 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2407 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2410 scsih_change_queue_depth(sdev
, qdepth
);
2413 sas_read_port_mode_page(sdev
);
2414 _scsih_enable_tlr(ioc
, sdev
);
2421 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2422 * @sdev: scsi device struct
2423 * @bdev: pointer to block device context
2424 * @capacity: device size (in 512 byte sectors)
2425 * @params: three element array to place output:
2426 * params[0] number of heads (max 255)
2427 * params[1] number of sectors (max 63)
2428 * params[2] number of cylinders
2433 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2434 sector_t capacity
, int params
[])
2444 dummy
= heads
* sectors
;
2445 cylinders
= capacity
;
2446 sector_div(cylinders
, dummy
);
2449 * Handle extended translation size for logical drives
2452 if ((ulong
)capacity
>= 0x200000) {
2455 dummy
= heads
* sectors
;
2456 cylinders
= capacity
;
2457 sector_div(cylinders
, dummy
);
2462 params
[1] = sectors
;
2463 params
[2] = cylinders
;
2469 * _scsih_response_code - translation of device response code
2470 * @ioc: per adapter object
2471 * @response_code: response code returned by the device
2476 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2480 switch (response_code
) {
2481 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2482 desc
= "task management request completed";
2484 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2485 desc
= "invalid frame";
2487 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2488 desc
= "task management request not supported";
2490 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2491 desc
= "task management request failed";
2493 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2494 desc
= "task management request succeeded";
2496 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2497 desc
= "invalid lun";
2500 desc
= "overlapped tag attempted";
2502 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2503 desc
= "task queued, however not sent to target";
2509 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2510 ioc
->name
, response_code
, desc
);
2514 * _scsih_tm_done - tm completion routine
2515 * @ioc: per adapter object
2516 * @smid: system request message index
2517 * @msix_index: MSIX table index supplied by the OS
2518 * @reply: reply message frame(lower 32bit addr)
2521 * The callback handler when using scsih_issue_tm.
2523 * Return 1 meaning mf should be freed from _base_interrupt
2524 * 0 means the mf is freed from this function.
2527 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2529 MPI2DefaultReply_t
*mpi_reply
;
2531 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2533 if (ioc
->tm_cmds
.smid
!= smid
)
2535 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2536 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2538 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2539 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2541 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2542 complete(&ioc
->tm_cmds
.done
);
2547 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2548 * @ioc: per adapter object
2549 * @handle: device handle
2551 * During taskmangement request, we need to freeze the device queue.
2554 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2556 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2557 struct scsi_device
*sdev
;
2560 shost_for_each_device(sdev
, ioc
->shost
) {
2563 sas_device_priv_data
= sdev
->hostdata
;
2564 if (!sas_device_priv_data
)
2566 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2567 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2569 ioc
->ignore_loginfos
= 1;
2575 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2576 * @ioc: per adapter object
2577 * @handle: device handle
2579 * During taskmangement request, we need to freeze the device queue.
2582 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2584 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2585 struct scsi_device
*sdev
;
2588 shost_for_each_device(sdev
, ioc
->shost
) {
2591 sas_device_priv_data
= sdev
->hostdata
;
2592 if (!sas_device_priv_data
)
2594 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2595 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2597 ioc
->ignore_loginfos
= 0;
2603 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2604 * @ioc: per adapter struct
2605 * @handle: device handle
2607 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2608 * @smid_task: smid assigned to the task
2609 * @msix_task: MSIX table index supplied by the OS
2610 * @timeout: timeout in seconds
2613 * A generic API for sending task management requests to firmware.
2615 * The callback index is set inside `ioc->tm_cb_idx`.
2616 * The caller is responsible to check for outstanding commands.
2618 * Return SUCCESS or FAILED.
2621 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2622 u64 lun
, u8 type
, u16 smid_task
, u16 msix_task
, ulong timeout
)
2624 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2625 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2630 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2632 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2633 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2634 __func__
, ioc
->name
);
2638 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2639 ioc
->pci_error_recovery
) {
2640 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2641 __func__
, ioc
->name
);
2645 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2646 if (ioc_state
& MPI2_DOORBELL_USED
) {
2647 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2648 "unexpected doorbell active!\n", ioc
->name
));
2649 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2650 return (!rc
) ? SUCCESS
: FAILED
;
2653 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2654 mpt3sas_base_fault_info(ioc
, ioc_state
&
2655 MPI2_DOORBELL_DATA_MASK
);
2656 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2657 return (!rc
) ? SUCCESS
: FAILED
;
2660 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2662 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2663 ioc
->name
, __func__
);
2667 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2668 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2669 ioc
->name
, handle
, type
, smid_task
));
2670 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2671 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2672 ioc
->tm_cmds
.smid
= smid
;
2673 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2674 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2675 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2676 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2677 mpi_request
->TaskType
= type
;
2678 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2679 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2680 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2681 init_completion(&ioc
->tm_cmds
.done
);
2682 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2683 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2684 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2685 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2686 ioc
->name
, __func__
);
2687 _debug_dump_mf(mpi_request
,
2688 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2689 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2690 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2692 rc
= (!rc
) ? SUCCESS
: FAILED
;
2697 /* sync IRQs in case those were busy during flush. */
2698 mpt3sas_base_sync_reply_irqs(ioc
);
2700 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2701 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2702 mpi_reply
= ioc
->tm_cmds
.reply
;
2703 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2704 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2705 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2706 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2707 le32_to_cpu(mpi_reply
->TerminationCount
)));
2708 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2709 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2710 if (mpi_reply
->IOCStatus
)
2711 _debug_dump_mf(mpi_request
,
2712 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2718 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2719 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2723 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2724 u64 lun
, u8 type
, u16 smid_task
, u16 msix_task
, ulong timeout
)
2728 mutex_lock(&ioc
->tm_cmds
.mutex
);
2729 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
, type
, smid_task
,
2730 msix_task
, timeout
);
2731 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2737 * _scsih_tm_display_info - displays info about the device
2738 * @ioc: per adapter struct
2739 * @scmd: pointer to scsi command object
2741 * Called by task management callback handlers.
2744 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2746 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2747 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2748 struct _sas_device
*sas_device
= NULL
;
2749 struct _pcie_device
*pcie_device
= NULL
;
2750 unsigned long flags
;
2751 char *device_str
= NULL
;
2755 if (ioc
->hide_ir_msg
)
2756 device_str
= "WarpDrive";
2758 device_str
= "volume";
2760 scsi_print_command(scmd
);
2761 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2762 starget_printk(KERN_INFO
, starget
,
2763 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2764 device_str
, priv_target
->handle
,
2765 device_str
, (unsigned long long)priv_target
->sas_address
);
2767 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2768 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2769 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
, priv_target
);
2771 starget_printk(KERN_INFO
, starget
,
2772 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2773 pcie_device
->handle
,
2774 (unsigned long long)pcie_device
->wwid
,
2775 pcie_device
->port_num
);
2776 if (pcie_device
->enclosure_handle
!= 0)
2777 starget_printk(KERN_INFO
, starget
,
2778 "enclosure logical id(0x%016llx), slot(%d)\n",
2779 (unsigned long long)
2780 pcie_device
->enclosure_logical_id
,
2782 if (pcie_device
->connector_name
[0] != '\0')
2783 starget_printk(KERN_INFO
, starget
,
2784 "enclosure level(0x%04x), connector name( %s)\n",
2785 pcie_device
->enclosure_level
,
2786 pcie_device
->connector_name
);
2787 pcie_device_put(pcie_device
);
2789 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2792 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2793 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2795 if (priv_target
->flags
&
2796 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2797 starget_printk(KERN_INFO
, starget
,
2798 "volume handle(0x%04x), "
2799 "volume wwid(0x%016llx)\n",
2800 sas_device
->volume_handle
,
2801 (unsigned long long)sas_device
->volume_wwid
);
2803 starget_printk(KERN_INFO
, starget
,
2804 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2806 (unsigned long long)sas_device
->sas_address
,
2809 _scsih_display_enclosure_chassis_info(NULL
, sas_device
,
2812 sas_device_put(sas_device
);
2814 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2819 * scsih_abort - eh threads main abort routine
2820 * @scmd: pointer to scsi command object
2822 * Returns SUCCESS if command aborted else FAILED
2825 scsih_abort(struct scsi_cmnd
*scmd
)
2827 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2828 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2829 struct scsiio_tracker
*st
= scsi_cmd_priv(scmd
);
2833 sdev_printk(KERN_INFO
, scmd
->device
,
2834 "attempting task abort! scmd(%p)\n", scmd
);
2835 _scsih_tm_display_info(ioc
, scmd
);
2837 sas_device_priv_data
= scmd
->device
->hostdata
;
2838 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2840 sdev_printk(KERN_INFO
, scmd
->device
,
2841 "device been deleted! scmd(%p)\n", scmd
);
2842 scmd
->result
= DID_NO_CONNECT
<< 16;
2843 scmd
->scsi_done(scmd
);
2848 /* check for completed command */
2849 if (st
== NULL
|| st
->cb_idx
== 0xFF) {
2850 scmd
->result
= DID_RESET
<< 16;
2855 /* for hidden raid components and volumes this is not supported */
2856 if (sas_device_priv_data
->sas_target
->flags
&
2857 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2858 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2859 scmd
->result
= DID_RESET
<< 16;
2864 mpt3sas_halt_firmware(ioc
);
2866 handle
= sas_device_priv_data
->sas_target
->handle
;
2867 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2868 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
,
2869 st
->smid
, st
->msix_io
, 30);
2870 /* Command must be cleared after abort */
2871 if (r
== SUCCESS
&& st
->cb_idx
!= 0xFF)
2874 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2875 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2880 * scsih_dev_reset - eh threads main device reset routine
2881 * @scmd: pointer to scsi command object
2883 * Returns SUCCESS if command aborted else FAILED
2886 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2888 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2889 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2890 struct _sas_device
*sas_device
= NULL
;
2894 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2895 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2897 sdev_printk(KERN_INFO
, scmd
->device
,
2898 "attempting device reset! scmd(%p)\n", scmd
);
2899 _scsih_tm_display_info(ioc
, scmd
);
2901 sas_device_priv_data
= scmd
->device
->hostdata
;
2902 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2904 sdev_printk(KERN_INFO
, scmd
->device
,
2905 "device been deleted! scmd(%p)\n", scmd
);
2906 scmd
->result
= DID_NO_CONNECT
<< 16;
2907 scmd
->scsi_done(scmd
);
2912 /* for hidden raid components obtain the volume_handle */
2914 if (sas_device_priv_data
->sas_target
->flags
&
2915 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2916 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2919 handle
= sas_device
->volume_handle
;
2921 handle
= sas_device_priv_data
->sas_target
->handle
;
2924 scmd
->result
= DID_RESET
<< 16;
2929 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2930 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 0, 30);
2931 /* Check for busy commands after reset */
2932 if (r
== SUCCESS
&& atomic_read(&scmd
->device
->device_busy
))
2935 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2936 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2939 sas_device_put(sas_device
);
2945 * scsih_target_reset - eh threads main target reset routine
2946 * @scmd: pointer to scsi command object
2948 * Returns SUCCESS if command aborted else FAILED
2951 scsih_target_reset(struct scsi_cmnd
*scmd
)
2953 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2954 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2955 struct _sas_device
*sas_device
= NULL
;
2958 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2959 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2961 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2963 _scsih_tm_display_info(ioc
, scmd
);
2965 sas_device_priv_data
= scmd
->device
->hostdata
;
2966 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2968 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2970 scmd
->result
= DID_NO_CONNECT
<< 16;
2971 scmd
->scsi_done(scmd
);
2976 /* for hidden raid components obtain the volume_handle */
2978 if (sas_device_priv_data
->sas_target
->flags
&
2979 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2980 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2983 handle
= sas_device
->volume_handle
;
2985 handle
= sas_device_priv_data
->sas_target
->handle
;
2988 scmd
->result
= DID_RESET
<< 16;
2993 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, 0,
2994 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 0, 30);
2995 /* Check for busy commands after reset */
2996 if (r
== SUCCESS
&& atomic_read(&starget
->target_busy
))
2999 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
3000 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3003 sas_device_put(sas_device
);
3010 * scsih_host_reset - eh threads main host reset routine
3011 * @scmd: pointer to scsi command object
3013 * Returns SUCCESS if command aborted else FAILED
3016 scsih_host_reset(struct scsi_cmnd
*scmd
)
3018 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3021 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
3023 scsi_print_command(scmd
);
3025 if (ioc
->is_driver_loading
|| ioc
->remove_host
) {
3026 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
3032 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
3033 r
= (retval
< 0) ? FAILED
: SUCCESS
;
3035 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
3036 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3042 * _scsih_fw_event_add - insert and queue up fw_event
3043 * @ioc: per adapter object
3044 * @fw_event: object describing the event
3045 * Context: This function will acquire ioc->fw_event_lock.
3047 * This adds the firmware event object into link list, then queues it up to
3048 * be processed from user context.
3053 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
3055 unsigned long flags
;
3057 if (ioc
->firmware_event_thread
== NULL
)
3060 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3061 fw_event_work_get(fw_event
);
3062 INIT_LIST_HEAD(&fw_event
->list
);
3063 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
3064 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
3065 fw_event_work_get(fw_event
);
3066 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
3067 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3071 * _scsih_fw_event_del_from_list - delete fw_event from the list
3072 * @ioc: per adapter object
3073 * @fw_event: object describing the event
3074 * Context: This function will acquire ioc->fw_event_lock.
3076 * If the fw_event is on the fw_event_list, remove it and do a put.
3081 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
3084 unsigned long flags
;
3086 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3087 if (!list_empty(&fw_event
->list
)) {
3088 list_del_init(&fw_event
->list
);
3089 fw_event_work_put(fw_event
);
3091 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3096 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3097 * @ioc: per adapter object
3098 * @event_data: trigger event data
3103 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
3104 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
3106 struct fw_event_work
*fw_event
;
3109 if (ioc
->is_driver_loading
)
3111 sz
= sizeof(*event_data
);
3112 fw_event
= alloc_fw_event_work(sz
);
3115 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
3116 fw_event
->ioc
= ioc
;
3117 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
3118 _scsih_fw_event_add(ioc
, fw_event
);
3119 fw_event_work_put(fw_event
);
3123 * _scsih_error_recovery_delete_devices - remove devices not responding
3124 * @ioc: per adapter object
3129 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
3131 struct fw_event_work
*fw_event
;
3133 if (ioc
->is_driver_loading
)
3135 fw_event
= alloc_fw_event_work(0);
3138 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
3139 fw_event
->ioc
= ioc
;
3140 _scsih_fw_event_add(ioc
, fw_event
);
3141 fw_event_work_put(fw_event
);
3145 * mpt3sas_port_enable_complete - port enable completed (fake event)
3146 * @ioc: per adapter object
3151 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
3153 struct fw_event_work
*fw_event
;
3155 fw_event
= alloc_fw_event_work(0);
3158 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
3159 fw_event
->ioc
= ioc
;
3160 _scsih_fw_event_add(ioc
, fw_event
);
3161 fw_event_work_put(fw_event
);
3164 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
3166 unsigned long flags
;
3167 struct fw_event_work
*fw_event
= NULL
;
3169 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3170 if (!list_empty(&ioc
->fw_event_list
)) {
3171 fw_event
= list_first_entry(&ioc
->fw_event_list
,
3172 struct fw_event_work
, list
);
3173 list_del_init(&fw_event
->list
);
3175 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3181 * _scsih_fw_event_cleanup_queue - cleanup event queue
3182 * @ioc: per adapter object
3184 * Walk the firmware event queue, either killing timers, or waiting
3185 * for outstanding events to complete
3190 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
3192 struct fw_event_work
*fw_event
;
3194 if (list_empty(&ioc
->fw_event_list
) ||
3195 !ioc
->firmware_event_thread
|| in_interrupt())
3198 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
3200 * Wait on the fw_event to complete. If this returns 1, then
3201 * the event was never executed, and we need a put for the
3202 * reference the work had on the fw_event.
3204 * If it did execute, we wait for it to finish, and the put will
3205 * happen from _firmware_event_work()
3207 if (cancel_work_sync(&fw_event
->work
))
3208 fw_event_work_put(fw_event
);
3210 fw_event_work_put(fw_event
);
3215 * _scsih_internal_device_block - block the sdev device
3216 * @sdev: per device object
3217 * @sas_device_priv_data : per device driver private data
3219 * make sure device is blocked without error, if not
3223 _scsih_internal_device_block(struct scsi_device
*sdev
,
3224 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3228 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
3229 sas_device_priv_data
->sas_target
->handle
);
3230 sas_device_priv_data
->block
= 1;
3232 r
= scsi_internal_device_block_nowait(sdev
);
3234 sdev_printk(KERN_WARNING
, sdev
,
3235 "device_block failed with return(%d) for handle(0x%04x)\n",
3236 r
, sas_device_priv_data
->sas_target
->handle
);
3240 * _scsih_internal_device_unblock - unblock the sdev device
3241 * @sdev: per device object
3242 * @sas_device_priv_data : per device driver private data
3243 * make sure device is unblocked without error, if not retry
3244 * by blocking and then unblocking
3248 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
3249 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3253 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
3254 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
3255 sas_device_priv_data
->block
= 0;
3256 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3258 /* The device has been set to SDEV_RUNNING by SD layer during
3259 * device addition but the request queue is still stopped by
3260 * our earlier block call. We need to perform a block again
3261 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3263 sdev_printk(KERN_WARNING
, sdev
,
3264 "device_unblock failed with return(%d) for handle(0x%04x) "
3265 "performing a block followed by an unblock\n",
3266 r
, sas_device_priv_data
->sas_target
->handle
);
3267 sas_device_priv_data
->block
= 1;
3268 r
= scsi_internal_device_block_nowait(sdev
);
3270 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
3271 "failed with return(%d) for handle(0x%04x)\n",
3272 r
, sas_device_priv_data
->sas_target
->handle
);
3274 sas_device_priv_data
->block
= 0;
3275 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3277 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
3278 " failed with return(%d) for handle(0x%04x)\n",
3279 r
, sas_device_priv_data
->sas_target
->handle
);
3284 * _scsih_ublock_io_all_device - unblock every device
3285 * @ioc: per adapter object
3287 * change the device state from block to running
3290 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3292 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3293 struct scsi_device
*sdev
;
3295 shost_for_each_device(sdev
, ioc
->shost
) {
3296 sas_device_priv_data
= sdev
->hostdata
;
3297 if (!sas_device_priv_data
)
3299 if (!sas_device_priv_data
->block
)
3302 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3303 "device_running, handle(0x%04x)\n",
3304 sas_device_priv_data
->sas_target
->handle
));
3305 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
3311 * _scsih_ublock_io_device - prepare device to be deleted
3312 * @ioc: per adapter object
3313 * @sas_addr: sas address
3315 * unblock then put device in offline state
3318 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
3320 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3321 struct scsi_device
*sdev
;
3323 shost_for_each_device(sdev
, ioc
->shost
) {
3324 sas_device_priv_data
= sdev
->hostdata
;
3325 if (!sas_device_priv_data
)
3327 if (sas_device_priv_data
->sas_target
->sas_address
3330 if (sas_device_priv_data
->block
)
3331 _scsih_internal_device_unblock(sdev
,
3332 sas_device_priv_data
);
3337 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3338 * @ioc: per adapter object
3339 * @handle: device handle
3341 * During device pull we need to appropriately set the sdev state.
3344 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3346 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3347 struct scsi_device
*sdev
;
3349 shost_for_each_device(sdev
, ioc
->shost
) {
3350 sas_device_priv_data
= sdev
->hostdata
;
3351 if (!sas_device_priv_data
)
3353 if (sas_device_priv_data
->block
)
3355 if (sas_device_priv_data
->ignore_delay_remove
) {
3356 sdev_printk(KERN_INFO
, sdev
,
3357 "%s skip device_block for SES handle(0x%04x)\n",
3358 __func__
, sas_device_priv_data
->sas_target
->handle
);
3361 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3366 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3367 * @ioc: per adapter object
3368 * @handle: device handle
3370 * During device pull we need to appropriately set the sdev state.
3373 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3375 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3376 struct scsi_device
*sdev
;
3377 struct _sas_device
*sas_device
;
3379 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3381 shost_for_each_device(sdev
, ioc
->shost
) {
3382 sas_device_priv_data
= sdev
->hostdata
;
3383 if (!sas_device_priv_data
)
3385 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3387 if (sas_device_priv_data
->block
)
3389 if (sas_device
&& sas_device
->pend_sas_rphy_add
)
3391 if (sas_device_priv_data
->ignore_delay_remove
) {
3392 sdev_printk(KERN_INFO
, sdev
,
3393 "%s skip device_block for SES handle(0x%04x)\n",
3394 __func__
, sas_device_priv_data
->sas_target
->handle
);
3397 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3401 sas_device_put(sas_device
);
3405 * _scsih_block_io_to_children_attached_to_ex
3406 * @ioc: per adapter object
3407 * @sas_expander: the sas_device object
3409 * This routine set sdev state to SDEV_BLOCK for all devices
3410 * attached to this expander. This function called when expander is
3414 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3415 struct _sas_node
*sas_expander
)
3417 struct _sas_port
*mpt3sas_port
;
3418 struct _sas_device
*sas_device
;
3419 struct _sas_node
*expander_sibling
;
3420 unsigned long flags
;
3425 list_for_each_entry(mpt3sas_port
,
3426 &sas_expander
->sas_port_list
, port_list
) {
3427 if (mpt3sas_port
->remote_identify
.device_type
==
3429 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3430 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3431 mpt3sas_port
->remote_identify
.sas_address
);
3433 set_bit(sas_device
->handle
,
3434 ioc
->blocking_handles
);
3435 sas_device_put(sas_device
);
3437 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3441 list_for_each_entry(mpt3sas_port
,
3442 &sas_expander
->sas_port_list
, port_list
) {
3444 if (mpt3sas_port
->remote_identify
.device_type
==
3445 SAS_EDGE_EXPANDER_DEVICE
||
3446 mpt3sas_port
->remote_identify
.device_type
==
3447 SAS_FANOUT_EXPANDER_DEVICE
) {
3449 mpt3sas_scsih_expander_find_by_sas_address(
3450 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3451 _scsih_block_io_to_children_attached_to_ex(ioc
,
3458 * _scsih_block_io_to_children_attached_directly
3459 * @ioc: per adapter object
3460 * @event_data: topology change event data
3462 * This routine set sdev state to SDEV_BLOCK for all devices
3463 * direct attached during device pull.
3466 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3467 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3473 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3474 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3477 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3478 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3479 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3480 _scsih_block_io_device(ioc
, handle
);
3485 * _scsih_block_io_to_pcie_children_attached_directly
3486 * @ioc: per adapter object
3487 * @event_data: topology change event data
3489 * This routine set sdev state to SDEV_BLOCK for all devices
3490 * direct attached during device pull/reconnect.
3493 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3494 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
3500 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3502 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
3505 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
3507 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
)
3508 _scsih_block_io_device(ioc
, handle
);
3512 * _scsih_tm_tr_send - send task management request
3513 * @ioc: per adapter object
3514 * @handle: device handle
3515 * Context: interrupt time.
3517 * This code is to initiate the device removal handshake protocol
3518 * with controller firmware. This function will issue target reset
3519 * using high priority request queue. It will send a sas iounit
3520 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3522 * This is designed to send muliple task management request at the same
3523 * time to the fifo. If the fifo is full, we will append the request,
3524 * and process it in a future completion.
3527 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3529 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3531 struct _sas_device
*sas_device
= NULL
;
3532 struct _pcie_device
*pcie_device
= NULL
;
3533 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3534 u64 sas_address
= 0;
3535 unsigned long flags
;
3536 struct _tr_list
*delayed_tr
;
3539 if (ioc
->pci_error_recovery
) {
3540 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3541 "%s: host in pci error recovery: handle(0x%04x)\n",
3542 __func__
, ioc
->name
,
3546 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3547 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3548 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3549 "%s: host is not operational: handle(0x%04x)\n",
3550 __func__
, ioc
->name
,
3555 /* if PD, then return */
3556 if (test_bit(handle
, ioc
->pd_handles
))
3559 clear_bit(handle
, ioc
->pend_os_device_add
);
3561 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3562 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3563 if (sas_device
&& sas_device
->starget
&&
3564 sas_device
->starget
->hostdata
) {
3565 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3566 sas_target_priv_data
->deleted
= 1;
3567 sas_address
= sas_device
->sas_address
;
3569 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3571 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
3572 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
3573 if (pcie_device
&& pcie_device
->starget
&&
3574 pcie_device
->starget
->hostdata
) {
3575 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
3576 sas_target_priv_data
->deleted
= 1;
3577 sas_address
= pcie_device
->wwid
;
3579 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
3581 if (sas_target_priv_data
) {
3582 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3583 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3585 (unsigned long long)sas_address
));
3587 if (sas_device
->enclosure_handle
!= 0)
3588 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3589 "setting delete flag:enclosure logical "
3590 "id(0x%016llx), slot(%d)\n", ioc
->name
,
3591 (unsigned long long)
3592 sas_device
->enclosure_logical_id
,
3594 if (sas_device
->connector_name
[0] != '\0')
3595 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3596 "setting delete flag: enclosure "
3597 "level(0x%04x), connector name( %s)\n",
3598 ioc
->name
, sas_device
->enclosure_level
,
3599 sas_device
->connector_name
));
3600 } else if (pcie_device
) {
3601 if (pcie_device
->enclosure_handle
!= 0)
3602 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3603 "setting delete flag: logical "
3604 "id(0x%016llx), slot(%d)\n", ioc
->name
,
3605 (unsigned long long)
3606 pcie_device
->enclosure_logical_id
,
3607 pcie_device
->slot
));
3608 if (pcie_device
->connector_name
[0] != '\0')
3609 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3610 "setting delete flag:, enclosure "
3612 "connector name( %s)\n", ioc
->name
,
3613 pcie_device
->enclosure_level
,
3614 pcie_device
->connector_name
));
3616 _scsih_ublock_io_device(ioc
, sas_address
);
3617 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3620 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3622 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3625 INIT_LIST_HEAD(&delayed_tr
->list
);
3626 delayed_tr
->handle
= handle
;
3627 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3628 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3629 "DELAYED:tr:handle(0x%04x), (open)\n",
3630 ioc
->name
, handle
));
3634 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3635 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3636 ioc
->name
, handle
, smid
,
3637 ioc
->tm_tr_cb_idx
));
3638 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3639 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3640 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3641 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3642 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3643 set_bit(handle
, ioc
->device_remove_in_progress
);
3644 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3645 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3649 sas_device_put(sas_device
);
3651 pcie_device_put(pcie_device
);
3655 * _scsih_tm_tr_complete -
3656 * @ioc: per adapter object
3657 * @smid: system request message index
3658 * @msix_index: MSIX table index supplied by the OS
3659 * @reply: reply message frame(lower 32bit addr)
3660 * Context: interrupt time.
3662 * This is the target reset completion routine.
3663 * This code is part of the code to initiate the device removal
3664 * handshake protocol with controller firmware.
3665 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3667 * Return 1 meaning mf should be freed from _base_interrupt
3668 * 0 means the mf is freed from this function.
3671 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3675 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3676 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3677 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3678 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3681 struct _sc_list
*delayed_sc
;
3683 if (ioc
->remove_host
) {
3684 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3685 "%s: host has been removed\n", __func__
, ioc
->name
));
3687 } else if (ioc
->pci_error_recovery
) {
3688 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3689 "%s: host in pci error recovery\n", __func__
,
3693 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3694 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3695 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3696 "%s: host is not operational\n", __func__
, ioc
->name
));
3699 if (unlikely(!mpi_reply
)) {
3700 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3701 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3704 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3705 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3706 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3707 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3708 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3710 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3714 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3715 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3716 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3717 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3718 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3719 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3720 le32_to_cpu(mpi_reply
->TerminationCount
)));
3722 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3723 if (!smid_sas_ctrl
) {
3724 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3726 return _scsih_check_for_pending_tm(ioc
, smid
);
3727 INIT_LIST_HEAD(&delayed_sc
->list
);
3728 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3729 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3730 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3731 "DELAYED:sc:handle(0x%04x), (open)\n",
3732 ioc
->name
, handle
));
3733 return _scsih_check_for_pending_tm(ioc
, smid
);
3736 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3737 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3738 ioc
->name
, handle
, smid_sas_ctrl
,
3739 ioc
->tm_sas_control_cb_idx
));
3740 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3741 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3742 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3743 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3744 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3745 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3747 return _scsih_check_for_pending_tm(ioc
, smid
);
3752 * _scsih_sas_control_complete - completion routine
3753 * @ioc: per adapter object
3754 * @smid: system request message index
3755 * @msix_index: MSIX table index supplied by the OS
3756 * @reply: reply message frame(lower 32bit addr)
3757 * Context: interrupt time.
3759 * This is the sas iounit control completion routine.
3760 * This code is part of the code to initiate the device removal
3761 * handshake protocol with controller firmware.
3763 * Return 1 meaning mf should be freed from _base_interrupt
3764 * 0 means the mf is freed from this function.
3767 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3768 u8 msix_index
, u32 reply
)
3770 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3771 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3773 if (likely(mpi_reply
)) {
3774 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3775 "sc_complete:handle(0x%04x), (open) "
3776 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3777 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3778 le16_to_cpu(mpi_reply
->IOCStatus
),
3779 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3780 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3781 MPI2_IOCSTATUS_SUCCESS
) {
3782 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3783 ioc
->device_remove_in_progress
);
3786 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3787 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3789 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3793 * _scsih_tm_tr_volume_send - send target reset request for volumes
3794 * @ioc: per adapter object
3795 * @handle: device handle
3796 * Context: interrupt time.
3798 * This is designed to send muliple task management request at the same
3799 * time to the fifo. If the fifo is full, we will append the request,
3800 * and process it in a future completion.
3803 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3805 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3807 struct _tr_list
*delayed_tr
;
3809 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3810 ioc
->pci_error_recovery
) {
3811 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3812 "%s: host reset in progress!\n",
3813 __func__
, ioc
->name
));
3817 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3819 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3822 INIT_LIST_HEAD(&delayed_tr
->list
);
3823 delayed_tr
->handle
= handle
;
3824 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3825 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3826 "DELAYED:tr:handle(0x%04x), (open)\n",
3827 ioc
->name
, handle
));
3831 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3832 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3833 ioc
->name
, handle
, smid
,
3834 ioc
->tm_tr_volume_cb_idx
));
3835 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3836 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3837 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3838 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3839 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3840 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3844 * _scsih_tm_volume_tr_complete - target reset completion
3845 * @ioc: per adapter object
3846 * @smid: system request message index
3847 * @msix_index: MSIX table index supplied by the OS
3848 * @reply: reply message frame(lower 32bit addr)
3849 * Context: interrupt time.
3851 * Return 1 meaning mf should be freed from _base_interrupt
3852 * 0 means the mf is freed from this function.
3855 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3856 u8 msix_index
, u32 reply
)
3859 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3860 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3861 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3863 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3864 ioc
->pci_error_recovery
) {
3865 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3866 "%s: host reset in progress!\n",
3867 __func__
, ioc
->name
));
3870 if (unlikely(!mpi_reply
)) {
3871 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3872 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3876 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3877 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3878 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3879 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3880 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3882 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3886 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3887 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3888 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3889 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3890 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3891 le32_to_cpu(mpi_reply
->TerminationCount
)));
3893 return _scsih_check_for_pending_tm(ioc
, smid
);
3897 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3898 * @ioc: per adapter object
3899 * @smid: system request message index
3901 * @event_context: used to track events uniquely
3903 * Context - processed in interrupt context.
3906 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
3909 Mpi2EventAckRequest_t
*ack_request
;
3910 int i
= smid
- ioc
->internal_smid
;
3911 unsigned long flags
;
3913 /* Without releasing the smid just update the
3914 * call back index and reuse the same smid for
3915 * processing this delayed request
3917 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3918 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3919 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3921 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3922 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3923 ioc
->name
, le16_to_cpu(event
), smid
,
3925 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3926 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3927 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3928 ack_request
->Event
= event
;
3929 ack_request
->EventContext
= event_context
;
3930 ack_request
->VF_ID
= 0; /* TODO */
3931 ack_request
->VP_ID
= 0;
3932 ioc
->put_smid_default(ioc
, smid
);
3936 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3937 * sas_io_unit_ctrl messages
3938 * @ioc: per adapter object
3939 * @smid: system request message index
3940 * @handle: device handle
3942 * Context - processed in interrupt context.
3945 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
3946 u16 smid
, u16 handle
)
3948 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3950 int i
= smid
- ioc
->internal_smid
;
3951 unsigned long flags
;
3953 if (ioc
->remove_host
) {
3954 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3955 "%s: host has been removed\n",
3956 __func__
, ioc
->name
));
3958 } else if (ioc
->pci_error_recovery
) {
3959 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3960 "%s: host in pci error recovery\n",
3961 __func__
, ioc
->name
));
3964 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3965 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3966 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3967 "%s: host is not operational\n",
3968 __func__
, ioc
->name
));
3972 /* Without releasing the smid just update the
3973 * call back index and reuse the same smid for
3974 * processing this delayed request
3976 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3977 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
3978 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3980 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3981 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3982 ioc
->name
, le16_to_cpu(handle
), smid
,
3983 ioc
->tm_sas_control_cb_idx
));
3984 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3985 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3986 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3987 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3988 mpi_request
->DevHandle
= handle
;
3989 ioc
->put_smid_default(ioc
, smid
);
3993 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3994 * @ioc: per adapter object
3995 * @smid: system request message index
3997 * Context: Executed in interrupt context
3999 * This will check delayed internal messages list, and process the
4002 * Return 1 meaning mf should be freed from _base_interrupt
4003 * 0 means the mf is freed from this function.
4006 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4008 struct _sc_list
*delayed_sc
;
4009 struct _event_ack_list
*delayed_event_ack
;
4011 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
4012 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
4013 struct _event_ack_list
, list
);
4014 _scsih_issue_delayed_event_ack(ioc
, smid
,
4015 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
4016 list_del(&delayed_event_ack
->list
);
4017 kfree(delayed_event_ack
);
4021 if (!list_empty(&ioc
->delayed_sc_list
)) {
4022 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
4023 struct _sc_list
, list
);
4024 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
4025 delayed_sc
->handle
);
4026 list_del(&delayed_sc
->list
);
4034 * _scsih_check_for_pending_tm - check for pending task management
4035 * @ioc: per adapter object
4036 * @smid: system request message index
4038 * This will check delayed target reset list, and feed the
4041 * Return 1 meaning mf should be freed from _base_interrupt
4042 * 0 means the mf is freed from this function.
4045 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4047 struct _tr_list
*delayed_tr
;
4049 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
4050 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
4051 struct _tr_list
, list
);
4052 mpt3sas_base_free_smid(ioc
, smid
);
4053 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
4054 list_del(&delayed_tr
->list
);
4059 if (!list_empty(&ioc
->delayed_tr_list
)) {
4060 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
4061 struct _tr_list
, list
);
4062 mpt3sas_base_free_smid(ioc
, smid
);
4063 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
4064 list_del(&delayed_tr
->list
);
4073 * _scsih_check_topo_delete_events - sanity check on topo events
4074 * @ioc: per adapter object
4075 * @event_data: the event data payload
4077 * This routine added to better handle cable breaker.
4079 * This handles the case where driver receives multiple expander
4080 * add and delete events in a single shot. When there is a delete event
4081 * the routine will void any pending add events waiting in the event queue.
4086 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4087 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4089 struct fw_event_work
*fw_event
;
4090 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
4091 u16 expander_handle
;
4092 struct _sas_node
*sas_expander
;
4093 unsigned long flags
;
4097 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
4098 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4101 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4102 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4103 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
4104 _scsih_tm_tr_send(ioc
, handle
);
4107 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4108 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
4109 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4112 if (event_data
->ExpStatus
==
4113 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
4114 /* put expander attached devices into blocking state */
4115 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4116 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
4118 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
4119 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4121 handle
= find_first_bit(ioc
->blocking_handles
,
4122 ioc
->facts
.MaxDevHandle
);
4123 if (handle
< ioc
->facts
.MaxDevHandle
)
4124 _scsih_block_io_device(ioc
, handle
);
4125 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
4126 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
4127 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4129 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4132 /* mark ignore flag for pending events */
4133 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4134 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4135 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
4138 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
4139 fw_event
->event_data
;
4140 if (local_event_data
->ExpStatus
==
4141 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4142 local_event_data
->ExpStatus
==
4143 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4144 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
4146 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4147 "setting ignoring flag\n", ioc
->name
));
4148 fw_event
->ignore
= 1;
4152 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4156 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4158 * @ioc: per adapter object
4159 * @event_data: the event data payload
4161 * This handles the case where driver receives multiple switch
4162 * or device add and delete events in a single shot. When there
4163 * is a delete event the routine will void any pending add
4164 * events waiting in the event queue.
4169 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER
*ioc
,
4170 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
4172 struct fw_event_work
*fw_event
;
4173 Mpi26EventDataPCIeTopologyChangeList_t
*local_event_data
;
4174 unsigned long flags
;
4176 u16 handle
, switch_handle
;
4178 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4180 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
4183 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
4184 if (reason_code
== MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
)
4185 _scsih_tm_tr_send(ioc
, handle
);
4188 switch_handle
= le16_to_cpu(event_data
->SwitchDevHandle
);
4189 if (!switch_handle
) {
4190 _scsih_block_io_to_pcie_children_attached_directly(
4194 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4195 if ((event_data
->SwitchStatus
4196 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
) ||
4197 (event_data
->SwitchStatus
==
4198 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
))
4199 _scsih_block_io_to_pcie_children_attached_directly(
4202 if (event_data
->SwitchStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4205 /* mark ignore flag for pending events */
4206 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4207 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4208 if (fw_event
->event
!= MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
||
4212 (Mpi26EventDataPCIeTopologyChangeList_t
*)
4213 fw_event
->event_data
;
4214 if (local_event_data
->SwitchStatus
==
4215 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4216 local_event_data
->SwitchStatus
==
4217 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4218 if (le16_to_cpu(local_event_data
->SwitchDevHandle
) ==
4220 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4221 "setting ignoring flag for switch event\n",
4223 fw_event
->ignore
= 1;
4227 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4231 * _scsih_set_volume_delete_flag - setting volume delete flag
4232 * @ioc: per adapter object
4233 * @handle: device handle
4235 * This returns nothing.
4238 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4240 struct _raid_device
*raid_device
;
4241 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4242 unsigned long flags
;
4244 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4245 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
4246 if (raid_device
&& raid_device
->starget
&&
4247 raid_device
->starget
->hostdata
) {
4248 sas_target_priv_data
=
4249 raid_device
->starget
->hostdata
;
4250 sas_target_priv_data
->deleted
= 1;
4251 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4252 "setting delete flag: handle(0x%04x), "
4253 "wwid(0x%016llx)\n", ioc
->name
, handle
,
4254 (unsigned long long) raid_device
->wwid
));
4256 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4260 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4261 * @handle: input handle
4262 * @a: handle for volume a
4263 * @b: handle for volume b
4265 * IR firmware only supports two raid volumes. The purpose of this
4266 * routine is to set the volume handle in either a or b. When the given
4267 * input handle is non-zero, or when a and b have not been set before.
4270 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
4272 if (!handle
|| handle
== *a
|| handle
== *b
)
4281 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4282 * @ioc: per adapter object
4283 * @event_data: the event data payload
4284 * Context: interrupt time.
4286 * This routine will send target reset to volume, followed by target
4287 * resets to the PDs. This is called when a PD has been removed, or
4288 * volume has been deleted or removed. When the target reset is sent
4289 * to volume, the PD target resets need to be queued to start upon
4290 * completion of the volume target reset.
4295 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
4296 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4298 Mpi2EventIrConfigElement_t
*element
;
4300 u16 handle
, volume_handle
, a
, b
;
4301 struct _tr_list
*delayed_tr
;
4306 if (ioc
->is_warpdrive
)
4309 /* Volume Resets for Deleted or Removed */
4310 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4311 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4312 if (le32_to_cpu(event_data
->Flags
) &
4313 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4315 if (element
->ReasonCode
==
4316 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
4317 element
->ReasonCode
==
4318 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
4319 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4320 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
4321 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4325 /* Volume Resets for UNHIDE events */
4326 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4327 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4328 if (le32_to_cpu(event_data
->Flags
) &
4329 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4331 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
4332 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4333 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4338 _scsih_tm_tr_volume_send(ioc
, a
);
4340 _scsih_tm_tr_volume_send(ioc
, b
);
4342 /* PD target resets */
4343 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4344 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4345 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
4347 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4348 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4349 clear_bit(handle
, ioc
->pd_handles
);
4351 _scsih_tm_tr_send(ioc
, handle
);
4352 else if (volume_handle
== a
|| volume_handle
== b
) {
4353 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
4354 BUG_ON(!delayed_tr
);
4355 INIT_LIST_HEAD(&delayed_tr
->list
);
4356 delayed_tr
->handle
= handle
;
4357 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
4358 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4359 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
4362 _scsih_tm_tr_send(ioc
, handle
);
4368 * _scsih_check_volume_delete_events - set delete flag for volumes
4369 * @ioc: per adapter object
4370 * @event_data: the event data payload
4371 * Context: interrupt time.
4373 * This will handle the case when the cable connected to entire volume is
4374 * pulled. We will take care of setting the deleted flag so normal IO will
4380 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4381 Mpi2EventDataIrVolume_t
*event_data
)
4385 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4387 state
= le32_to_cpu(event_data
->NewValue
);
4388 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
4389 MPI2_RAID_VOL_STATE_FAILED
)
4390 _scsih_set_volume_delete_flag(ioc
,
4391 le16_to_cpu(event_data
->VolDevHandle
));
4395 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4396 * @ioc: per adapter object
4397 * @event_data: the temp threshold event data
4398 * Context: interrupt time.
4403 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
4404 Mpi2EventDataTemperature_t
*event_data
)
4406 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
4407 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
4408 " exceeded for Sensor: %d !!!\n", ioc
->name
,
4409 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
4410 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
4411 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
4412 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
4413 event_data
->SensorNum
);
4414 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
4415 ioc
->name
, event_data
->CurrentTemperature
);
4419 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
4421 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
4423 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
4427 return test_and_set_bit(0, &priv
->ata_command_pending
);
4429 clear_bit(0, &priv
->ata_command_pending
);
4434 * _scsih_flush_running_cmds - completing outstanding commands.
4435 * @ioc: per adapter object
4437 * The flushing out of all pending scmd commands following host reset,
4438 * where all IO is dropped to the floor.
4443 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
4445 struct scsi_cmnd
*scmd
;
4446 struct scsiio_tracker
*st
;
4450 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4451 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
4455 _scsih_set_satl_pending(scmd
, false);
4456 st
= scsi_cmd_priv(scmd
);
4457 mpt3sas_base_clear_st(ioc
, st
);
4458 scsi_dma_unmap(scmd
);
4459 if (ioc
->pci_error_recovery
|| ioc
->remove_host
)
4460 scmd
->result
= DID_NO_CONNECT
<< 16;
4462 scmd
->result
= DID_RESET
<< 16;
4463 scmd
->scsi_done(scmd
);
4465 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
4470 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4471 * @ioc: per adapter object
4472 * @scmd: pointer to scsi command object
4473 * @mpi_request: pointer to the SCSI_IO request message frame
4475 * Supporting protection 1 and 3.
4480 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4481 Mpi25SCSIIORequest_t
*mpi_request
)
4484 unsigned char prot_op
= scsi_get_prot_op(scmd
);
4485 unsigned char prot_type
= scsi_get_prot_type(scmd
);
4486 Mpi25SCSIIORequest_t
*mpi_request_3v
=
4487 (Mpi25SCSIIORequest_t
*)mpi_request
;
4489 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
4492 if (prot_op
== SCSI_PROT_READ_STRIP
)
4493 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
4494 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
4495 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
4499 switch (prot_type
) {
4500 case SCSI_PROT_DIF_TYPE1
:
4501 case SCSI_PROT_DIF_TYPE2
:
4504 * enable ref/guard checking
4505 * auto increment ref tag
4507 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4508 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4509 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4510 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4511 cpu_to_be32(scsi_prot_ref_tag(scmd
));
4514 case SCSI_PROT_DIF_TYPE3
:
4517 * enable guard checking
4519 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4524 mpi_request_3v
->EEDPBlockSize
=
4525 cpu_to_le16(scmd
->device
->sector_size
);
4527 if (ioc
->is_gen35_ioc
)
4528 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4529 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4533 * _scsih_eedp_error_handling - return sense code for EEDP errors
4534 * @scmd: pointer to scsi command object
4535 * @ioc_status: ioc status
4540 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4544 switch (ioc_status
) {
4545 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4548 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4551 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4558 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4560 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4561 SAM_STAT_CHECK_CONDITION
;
4565 * scsih_qcmd - main scsi request entry point
4566 * @scmd: pointer to scsi command object
4567 * @done: function pointer to be invoked on completion
4569 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4571 * Returns 0 on success. If there's a failure, return either:
4572 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4573 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4576 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4578 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4579 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4580 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4581 struct _raid_device
*raid_device
;
4582 struct request
*rq
= scmd
->request
;
4584 Mpi25SCSIIORequest_t
*mpi_request
;
4585 struct _pcie_device
*pcie_device
= NULL
;
4590 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4591 scsi_print_command(scmd
);
4593 sas_device_priv_data
= scmd
->device
->hostdata
;
4594 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4595 scmd
->result
= DID_NO_CONNECT
<< 16;
4596 scmd
->scsi_done(scmd
);
4600 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
4601 scmd
->result
= DID_NO_CONNECT
<< 16;
4602 scmd
->scsi_done(scmd
);
4606 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4608 /* invalid device handle */
4609 handle
= sas_target_priv_data
->handle
;
4610 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4611 scmd
->result
= DID_NO_CONNECT
<< 16;
4612 scmd
->scsi_done(scmd
);
4617 /* host recovery or link resets sent via IOCTLs */
4618 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4619 return SCSI_MLQUEUE_HOST_BUSY
;
4621 /* device has been deleted */
4622 else if (sas_target_priv_data
->deleted
) {
4623 scmd
->result
= DID_NO_CONNECT
<< 16;
4624 scmd
->scsi_done(scmd
);
4626 /* device busy with task management */
4627 } else if (sas_target_priv_data
->tm_busy
||
4628 sas_device_priv_data
->block
)
4629 return SCSI_MLQUEUE_DEVICE_BUSY
;
4632 * Bug work around for firmware SATL handling. The loop
4633 * is based on atomic operations and ensures consistency
4634 * since we're lockless at this point
4637 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
)) {
4638 scmd
->result
= SAM_STAT_BUSY
;
4639 scmd
->scsi_done(scmd
);
4642 } while (_scsih_set_satl_pending(scmd
, true));
4644 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4645 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4646 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4647 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4649 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4652 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4653 /* NCQ Prio supported, make sure control indicated high priority */
4654 if (sas_device_priv_data
->ncq_prio_enable
) {
4655 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4656 if (class == IOPRIO_CLASS_RT
)
4657 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4659 /* Make sure Device is not raid volume.
4660 * We do not expose raid functionality to upper layer for warpdrive.
4662 if (((!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
))
4663 && !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
4664 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4665 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4667 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4669 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4670 ioc
->name
, __func__
);
4671 _scsih_set_satl_pending(scmd
, false);
4674 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4675 memset(mpi_request
, 0, ioc
->request_sz
);
4676 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4678 if (scmd
->cmd_len
== 32)
4679 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4680 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4681 if (sas_device_priv_data
->sas_target
->flags
&
4682 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4683 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4685 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4686 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4687 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4688 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4689 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4690 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4691 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4692 mpi_request
->SenseBufferLowAddress
=
4693 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4694 mpi_request
->SGLOffset0
= offsetof(Mpi25SCSIIORequest_t
, SGL
) / 4;
4695 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4697 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4699 if (mpi_request
->DataLength
) {
4700 pcie_device
= sas_target_priv_data
->pcie_dev
;
4701 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
, pcie_device
)) {
4702 mpt3sas_base_free_smid(ioc
, smid
);
4703 _scsih_set_satl_pending(scmd
, false);
4707 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4709 raid_device
= sas_target_priv_data
->raid_device
;
4710 if (raid_device
&& raid_device
->direct_io_enabled
)
4711 mpt3sas_setup_direct_io(ioc
, scmd
,
4712 raid_device
, mpi_request
);
4714 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4715 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4716 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4717 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4718 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4720 ioc
->put_smid_scsi_io(ioc
, smid
,
4721 le16_to_cpu(mpi_request
->DevHandle
));
4723 ioc
->put_smid_default(ioc
, smid
);
4727 return SCSI_MLQUEUE_HOST_BUSY
;
4731 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4732 * @sense_buffer: sense data returned by target
4733 * @data: normalized skey/asc/ascq
4738 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4740 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4741 /* descriptor format */
4742 data
->skey
= sense_buffer
[1] & 0x0F;
4743 data
->asc
= sense_buffer
[2];
4744 data
->ascq
= sense_buffer
[3];
4747 data
->skey
= sense_buffer
[2] & 0x0F;
4748 data
->asc
= sense_buffer
[12];
4749 data
->ascq
= sense_buffer
[13];
4754 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4755 * @ioc: per adapter object
4756 * @scmd: pointer to scsi command object
4757 * @mpi_reply: reply mf payload returned from firmware
4759 * scsi_status - SCSI Status code returned from target device
4760 * scsi_state - state info associated with SCSI_IO determined by ioc
4761 * ioc_status - ioc supplied status info
4766 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4767 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4771 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4772 MPI2_IOCSTATUS_MASK
;
4773 u8 scsi_state
= mpi_reply
->SCSIState
;
4774 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4775 char *desc_ioc_state
= NULL
;
4776 char *desc_scsi_status
= NULL
;
4777 char *desc_scsi_state
= ioc
->tmp_string
;
4778 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4779 struct _sas_device
*sas_device
= NULL
;
4780 struct _pcie_device
*pcie_device
= NULL
;
4781 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4782 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4783 char *device_str
= NULL
;
4787 if (ioc
->hide_ir_msg
)
4788 device_str
= "WarpDrive";
4790 device_str
= "volume";
4792 if (log_info
== 0x31170000)
4795 switch (ioc_status
) {
4796 case MPI2_IOCSTATUS_SUCCESS
:
4797 desc_ioc_state
= "success";
4799 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4800 desc_ioc_state
= "invalid function";
4802 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4803 desc_ioc_state
= "scsi recovered error";
4805 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4806 desc_ioc_state
= "scsi invalid dev handle";
4808 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4809 desc_ioc_state
= "scsi device not there";
4811 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4812 desc_ioc_state
= "scsi data overrun";
4814 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4815 desc_ioc_state
= "scsi data underrun";
4817 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4818 desc_ioc_state
= "scsi io data error";
4820 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4821 desc_ioc_state
= "scsi protocol error";
4823 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4824 desc_ioc_state
= "scsi task terminated";
4826 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4827 desc_ioc_state
= "scsi residual mismatch";
4829 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4830 desc_ioc_state
= "scsi task mgmt failed";
4832 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4833 desc_ioc_state
= "scsi ioc terminated";
4835 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4836 desc_ioc_state
= "scsi ext terminated";
4838 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4839 desc_ioc_state
= "eedp guard error";
4841 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4842 desc_ioc_state
= "eedp ref tag error";
4844 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4845 desc_ioc_state
= "eedp app tag error";
4847 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4848 desc_ioc_state
= "insufficient power";
4851 desc_ioc_state
= "unknown";
4855 switch (scsi_status
) {
4856 case MPI2_SCSI_STATUS_GOOD
:
4857 desc_scsi_status
= "good";
4859 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4860 desc_scsi_status
= "check condition";
4862 case MPI2_SCSI_STATUS_CONDITION_MET
:
4863 desc_scsi_status
= "condition met";
4865 case MPI2_SCSI_STATUS_BUSY
:
4866 desc_scsi_status
= "busy";
4868 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4869 desc_scsi_status
= "intermediate";
4871 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4872 desc_scsi_status
= "intermediate condmet";
4874 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4875 desc_scsi_status
= "reservation conflict";
4877 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4878 desc_scsi_status
= "command terminated";
4880 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4881 desc_scsi_status
= "task set full";
4883 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4884 desc_scsi_status
= "aca active";
4886 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4887 desc_scsi_status
= "task aborted";
4890 desc_scsi_status
= "unknown";
4894 desc_scsi_state
[0] = '\0';
4896 desc_scsi_state
= " ";
4897 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4898 strcat(desc_scsi_state
, "response info ");
4899 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4900 strcat(desc_scsi_state
, "state terminated ");
4901 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4902 strcat(desc_scsi_state
, "no status ");
4903 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4904 strcat(desc_scsi_state
, "autosense failed ");
4905 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4906 strcat(desc_scsi_state
, "autosense valid ");
4908 scsi_print_command(scmd
);
4910 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4911 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4912 device_str
, (unsigned long long)priv_target
->sas_address
);
4913 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
4914 pcie_device
= mpt3sas_get_pdev_from_target(ioc
, priv_target
);
4916 pr_info(MPT3SAS_FMT
"\twwid(0x%016llx), port(%d)\n",
4918 (unsigned long long)pcie_device
->wwid
,
4919 pcie_device
->port_num
);
4920 if (pcie_device
->enclosure_handle
!= 0)
4922 "\tenclosure logical id(0x%016llx), "
4923 "slot(%d)\n", ioc
->name
,
4924 (unsigned long long)
4925 pcie_device
->enclosure_logical_id
,
4927 if (pcie_device
->connector_name
[0])
4929 "\tenclosure level(0x%04x),"
4930 "connector name( %s)\n",
4931 ioc
->name
, pcie_device
->enclosure_level
,
4932 pcie_device
->connector_name
);
4933 pcie_device_put(pcie_device
);
4936 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4939 "\tsas_address(0x%016llx), phy(%d)\n",
4940 ioc
->name
, (unsigned long long)
4941 sas_device
->sas_address
, sas_device
->phy
);
4943 _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
4946 sas_device_put(sas_device
);
4951 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4952 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4953 desc_ioc_state
, ioc_status
, smid
);
4955 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4956 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4957 scsi_get_resid(scmd
));
4959 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4960 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4961 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4963 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4964 ioc
->name
, desc_scsi_status
,
4965 scsi_status
, desc_scsi_state
, scsi_state
);
4967 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4968 struct sense_info data
;
4969 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4971 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4972 ioc
->name
, data
.skey
,
4973 data
.asc
, data
.ascq
, 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
4991 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4993 Mpi2SepReply_t mpi_reply
;
4994 Mpi2SepRequest_t mpi_request
;
4995 struct _sas_device
*sas_device
;
4997 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
5001 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5002 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5003 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5004 mpi_request
.SlotStatus
=
5005 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
5006 mpi_request
.DevHandle
= cpu_to_le16(handle
);
5007 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
5008 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5009 &mpi_request
)) != 0) {
5010 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5011 __FILE__
, __LINE__
, __func__
);
5014 sas_device
->pfa_led_on
= 1;
5016 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5017 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5018 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5019 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5020 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5024 sas_device_put(sas_device
);
5028 * _scsih_turn_off_pfa_led - turn off Fault LED
5029 * @ioc: per adapter object
5030 * @sas_device: sas device whose PFA LED has to turned off
5036 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
5037 struct _sas_device
*sas_device
)
5039 Mpi2SepReply_t mpi_reply
;
5040 Mpi2SepRequest_t mpi_request
;
5042 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5043 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5044 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5045 mpi_request
.SlotStatus
= 0;
5046 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
5047 mpi_request
.DevHandle
= 0;
5048 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
5049 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
5050 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5051 &mpi_request
)) != 0) {
5052 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5053 __FILE__
, __LINE__
, __func__
);
5057 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5058 dewtprintk(ioc
, printk(MPT3SAS_FMT
5059 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5060 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5061 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5067 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5068 * @ioc: per adapter object
5069 * @handle: device handle
5070 * Context: interrupt.
5075 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5077 struct fw_event_work
*fw_event
;
5079 fw_event
= alloc_fw_event_work(0);
5082 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
5083 fw_event
->device_handle
= handle
;
5084 fw_event
->ioc
= ioc
;
5085 _scsih_fw_event_add(ioc
, fw_event
);
5086 fw_event_work_put(fw_event
);
5090 * _scsih_smart_predicted_fault - process smart errors
5091 * @ioc: per adapter object
5092 * @handle: device handle
5093 * Context: interrupt.
5098 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5100 struct scsi_target
*starget
;
5101 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5102 Mpi2EventNotificationReply_t
*event_reply
;
5103 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
5104 struct _sas_device
*sas_device
;
5106 unsigned long flags
;
5108 /* only handle non-raid devices */
5109 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5110 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
5114 starget
= sas_device
->starget
;
5115 sas_target_priv_data
= starget
->hostdata
;
5117 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
5118 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
5121 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, NULL
, starget
);
5123 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5125 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
5126 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
5128 /* insert into event log */
5129 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
5130 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
5131 event_reply
= kzalloc(sz
, GFP_KERNEL
);
5133 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5134 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5138 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
5139 event_reply
->Event
=
5140 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
5141 event_reply
->MsgLength
= sz
/4;
5142 event_reply
->EventDataLength
=
5143 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
5144 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
5145 event_reply
->EventData
;
5146 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
5147 event_data
->ASC
= 0x5D;
5148 event_data
->DevHandle
= cpu_to_le16(handle
);
5149 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
5150 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
5154 sas_device_put(sas_device
);
5158 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5163 * _scsih_io_done - scsi request callback
5164 * @ioc: per adapter object
5165 * @smid: system request message index
5166 * @msix_index: MSIX table index supplied by the OS
5167 * @reply: reply message frame(lower 32bit addr)
5169 * Callback handler when using _scsih_qcmd.
5171 * Return 1 meaning mf should be freed from _base_interrupt
5172 * 0 means the mf is freed from this function.
5175 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5177 Mpi25SCSIIORequest_t
*mpi_request
;
5178 Mpi2SCSIIOReply_t
*mpi_reply
;
5179 struct scsi_cmnd
*scmd
;
5180 struct scsiio_tracker
*st
;
5186 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5187 u32 response_code
= 0;
5189 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5191 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
5195 _scsih_set_satl_pending(scmd
, false);
5197 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5199 if (mpi_reply
== NULL
) {
5200 scmd
->result
= DID_OK
<< 16;
5204 sas_device_priv_data
= scmd
->device
->hostdata
;
5205 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
5206 sas_device_priv_data
->sas_target
->deleted
) {
5207 scmd
->result
= DID_NO_CONNECT
<< 16;
5210 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5213 * WARPDRIVE: If direct_io is set then it is directIO,
5214 * the failed direct I/O should be redirected to volume
5216 st
= scsi_cmd_priv(scmd
);
5217 if (st
->direct_io
&&
5218 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
5219 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
5221 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
5222 mpi_request
->DevHandle
=
5223 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
5224 ioc
->put_smid_scsi_io(ioc
, smid
,
5225 sas_device_priv_data
->sas_target
->handle
);
5228 /* turning off TLR */
5229 scsi_state
= mpi_reply
->SCSIState
;
5230 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
5232 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
5233 if (!sas_device_priv_data
->tlr_snoop_check
) {
5234 sas_device_priv_data
->tlr_snoop_check
++;
5235 if ((!ioc
->is_warpdrive
&&
5236 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
5237 !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
5238 && sas_is_tlr_enabled(scmd
->device
) &&
5239 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
5240 sas_disable_tlr(scmd
->device
);
5241 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
5245 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
5246 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
5247 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5248 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5251 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5252 scsi_status
= mpi_reply
->SCSIStatus
;
5254 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
5255 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
5256 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
5257 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
5258 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
5261 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5262 struct sense_info data
;
5263 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
5265 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
5266 le32_to_cpu(mpi_reply
->SenseCount
));
5267 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
5268 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5269 /* failure prediction threshold exceeded */
5270 if (data
.asc
== 0x5D)
5271 _scsih_smart_predicted_fault(ioc
,
5272 le16_to_cpu(mpi_reply
->DevHandle
));
5273 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
5275 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
5276 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
5277 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
5278 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
5279 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5281 switch (ioc_status
) {
5282 case MPI2_IOCSTATUS_BUSY
:
5283 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
5284 scmd
->result
= SAM_STAT_BUSY
;
5287 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
5288 scmd
->result
= DID_NO_CONNECT
<< 16;
5291 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
5292 if (sas_device_priv_data
->block
) {
5293 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
5296 if (log_info
== 0x31110630) {
5297 if (scmd
->retries
> 2) {
5298 scmd
->result
= DID_NO_CONNECT
<< 16;
5299 scsi_device_set_state(scmd
->device
,
5302 scmd
->result
= DID_SOFT_ERROR
<< 16;
5303 scmd
->device
->expecting_cc_ua
= 1;
5306 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
5307 scmd
->result
= DID_RESET
<< 16;
5309 } else if ((scmd
->device
->channel
== RAID_CHANNEL
) &&
5310 (scsi_state
== (MPI2_SCSI_STATE_TERMINATED
|
5311 MPI2_SCSI_STATE_NO_SCSI_STATUS
))) {
5312 scmd
->result
= DID_RESET
<< 16;
5315 scmd
->result
= DID_SOFT_ERROR
<< 16;
5317 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
5318 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
5319 scmd
->result
= DID_RESET
<< 16;
5322 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
5323 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
5324 scmd
->result
= DID_SOFT_ERROR
<< 16;
5326 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5329 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
5330 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5332 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
5335 if (xfer_cnt
< scmd
->underflow
) {
5336 if (scsi_status
== SAM_STAT_BUSY
)
5337 scmd
->result
= SAM_STAT_BUSY
;
5339 scmd
->result
= DID_SOFT_ERROR
<< 16;
5340 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5341 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
5342 scmd
->result
= DID_SOFT_ERROR
<< 16;
5343 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5344 scmd
->result
= DID_RESET
<< 16;
5345 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
5346 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
5347 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
5348 scmd
->result
= (DRIVER_SENSE
<< 24) |
5349 SAM_STAT_CHECK_CONDITION
;
5350 scmd
->sense_buffer
[0] = 0x70;
5351 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
5352 scmd
->sense_buffer
[12] = 0x20;
5353 scmd
->sense_buffer
[13] = 0;
5357 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
5358 scsi_set_resid(scmd
, 0);
5359 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
5360 case MPI2_IOCSTATUS_SUCCESS
:
5361 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5362 if (response_code
==
5363 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
5364 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5365 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
5366 scmd
->result
= DID_SOFT_ERROR
<< 16;
5367 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5368 scmd
->result
= DID_RESET
<< 16;
5371 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
5372 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
5373 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
5374 _scsih_eedp_error_handling(scmd
, ioc_status
);
5377 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
5378 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
5379 case MPI2_IOCSTATUS_INVALID_SGL
:
5380 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
5381 case MPI2_IOCSTATUS_INVALID_FIELD
:
5382 case MPI2_IOCSTATUS_INVALID_STATE
:
5383 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
5384 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
5385 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
5387 scmd
->result
= DID_SOFT_ERROR
<< 16;
5392 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
5393 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5397 scsi_dma_unmap(scmd
);
5398 mpt3sas_base_free_smid(ioc
, smid
);
5399 scmd
->scsi_done(scmd
);
5404 * _scsih_sas_host_refresh - refreshing sas host object contents
5405 * @ioc: per adapter object
5408 * During port enable, fw will send topology events for every device. Its
5409 * possible that the handles may change from the previous setting, so this
5410 * code keeping handles updating if changed.
5415 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
5420 Mpi2ConfigReply_t mpi_reply
;
5421 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5422 u16 attached_handle
;
5425 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
5426 "updating handles for sas_host(0x%016llx)\n",
5427 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
5429 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
5430 * sizeof(Mpi2SasIOUnit0PhyData_t
));
5431 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5432 if (!sas_iounit_pg0
) {
5433 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5434 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5438 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5439 sas_iounit_pg0
, sz
)) != 0)
5441 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5442 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5444 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5445 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
5447 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5448 PhyData
[0].ControllerDevHandle
);
5449 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5450 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
5452 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5453 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
5454 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
5455 attached_handle
, i
, link_rate
);
5458 kfree(sas_iounit_pg0
);
5462 * _scsih_sas_host_add - create sas host object
5463 * @ioc: per adapter object
5465 * Creating host side data object, stored in ioc->sas_hba
5470 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
5473 Mpi2ConfigReply_t mpi_reply
;
5474 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5475 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
5476 Mpi2SasPhyPage0_t phy_pg0
;
5477 Mpi2SasDevicePage0_t sas_device_pg0
;
5478 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5481 u8 device_missing_delay
;
5484 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
5486 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5487 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5490 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
5491 sizeof(struct _sas_phy
), GFP_KERNEL
);
5492 if (!ioc
->sas_hba
.phy
) {
5493 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5494 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5497 ioc
->sas_hba
.num_phys
= num_phys
;
5499 /* sas_iounit page 0 */
5500 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5501 sizeof(Mpi2SasIOUnit0PhyData_t
));
5502 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5503 if (!sas_iounit_pg0
) {
5504 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5505 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5508 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5509 sas_iounit_pg0
, sz
))) {
5510 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5511 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5514 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5515 MPI2_IOCSTATUS_MASK
;
5516 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5517 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5518 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5522 /* sas_iounit page 1 */
5523 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5524 sizeof(Mpi2SasIOUnit1PhyData_t
));
5525 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5526 if (!sas_iounit_pg1
) {
5527 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5528 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5531 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5532 sas_iounit_pg1
, sz
))) {
5533 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5534 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5537 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5538 MPI2_IOCSTATUS_MASK
;
5539 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5540 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5541 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5545 ioc
->io_missing_delay
=
5546 sas_iounit_pg1
->IODeviceMissingDelay
;
5547 device_missing_delay
=
5548 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5549 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5550 ioc
->device_missing_delay
= (device_missing_delay
&
5551 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5553 ioc
->device_missing_delay
= device_missing_delay
&
5554 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5556 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5557 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5558 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5560 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5561 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5564 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5565 MPI2_IOCSTATUS_MASK
;
5566 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5567 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5568 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5573 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5574 PhyData
[0].ControllerDevHandle
);
5575 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5576 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5577 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5578 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5580 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5581 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5582 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5583 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5586 ioc
->sas_hba
.enclosure_handle
=
5587 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5588 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5590 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5591 ioc
->name
, ioc
->sas_hba
.handle
,
5592 (unsigned long long) ioc
->sas_hba
.sas_address
,
5593 ioc
->sas_hba
.num_phys
) ;
5595 if (ioc
->sas_hba
.enclosure_handle
) {
5596 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5597 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5598 ioc
->sas_hba
.enclosure_handle
)))
5599 ioc
->sas_hba
.enclosure_logical_id
=
5600 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5604 kfree(sas_iounit_pg1
);
5605 kfree(sas_iounit_pg0
);
5609 * _scsih_expander_add - creating expander object
5610 * @ioc: per adapter object
5611 * @handle: expander handle
5613 * Creating expander object, stored in ioc->sas_expander_list.
5615 * Return 0 for success, else error.
5618 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5620 struct _sas_node
*sas_expander
;
5621 Mpi2ConfigReply_t mpi_reply
;
5622 Mpi2ExpanderPage0_t expander_pg0
;
5623 Mpi2ExpanderPage1_t expander_pg1
;
5624 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5627 u64 sas_address
, sas_address_parent
= 0;
5629 unsigned long flags
;
5630 struct _sas_port
*mpt3sas_port
= NULL
;
5637 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5640 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5641 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5642 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5643 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5647 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5648 MPI2_IOCSTATUS_MASK
;
5649 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5650 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5651 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5655 /* handle out of order topology events */
5656 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5657 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5659 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5660 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5663 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5664 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5665 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5666 sas_address_parent
);
5667 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5668 if (!sas_expander
) {
5669 rc
= _scsih_expander_add(ioc
, parent_handle
);
5675 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5676 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5677 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5679 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5684 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5686 if (!sas_expander
) {
5687 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5688 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5692 sas_expander
->handle
= handle
;
5693 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5694 sas_expander
->sas_address_parent
= sas_address_parent
;
5695 sas_expander
->sas_address
= sas_address
;
5697 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5698 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5699 handle
, parent_handle
, (unsigned long long)
5700 sas_expander
->sas_address
, sas_expander
->num_phys
);
5702 if (!sas_expander
->num_phys
)
5704 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5705 sizeof(struct _sas_phy
), GFP_KERNEL
);
5706 if (!sas_expander
->phy
) {
5707 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5708 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5713 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5714 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5715 sas_address_parent
);
5716 if (!mpt3sas_port
) {
5717 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5718 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5722 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5724 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5725 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5726 &expander_pg1
, i
, handle
))) {
5727 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5728 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5732 sas_expander
->phy
[i
].handle
= handle
;
5733 sas_expander
->phy
[i
].phy_id
= i
;
5735 if ((mpt3sas_transport_add_expander_phy(ioc
,
5736 &sas_expander
->phy
[i
], expander_pg1
,
5737 sas_expander
->parent_dev
))) {
5738 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5739 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5745 if (sas_expander
->enclosure_handle
) {
5746 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5747 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5748 sas_expander
->enclosure_handle
)))
5749 sas_expander
->enclosure_logical_id
=
5750 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5753 _scsih_expander_node_add(ioc
, sas_expander
);
5759 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5760 sas_address_parent
);
5761 kfree(sas_expander
);
5766 * mpt3sas_expander_remove - removing expander object
5767 * @ioc: per adapter object
5768 * @sas_address: expander sas_address
5773 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5775 struct _sas_node
*sas_expander
;
5776 unsigned long flags
;
5778 if (ioc
->shost_recovery
)
5781 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5782 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5784 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5786 _scsih_expander_node_remove(ioc
, sas_expander
);
5790 * _scsih_done - internal SCSI_IO callback handler.
5791 * @ioc: per adapter object
5792 * @smid: system request message index
5793 * @msix_index: MSIX table index supplied by the OS
5794 * @reply: reply message frame(lower 32bit addr)
5796 * Callback handler when sending internal generated SCSI_IO.
5797 * The callback index passed is `ioc->scsih_cb_idx`
5799 * Return 1 meaning mf should be freed from _base_interrupt
5800 * 0 means the mf is freed from this function.
5803 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5805 MPI2DefaultReply_t
*mpi_reply
;
5807 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5808 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5810 if (ioc
->scsih_cmds
.smid
!= smid
)
5812 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5814 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5815 mpi_reply
->MsgLength
*4);
5816 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5818 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5819 complete(&ioc
->scsih_cmds
.done
);
5826 #define MPT3_MAX_LUNS (255)
5830 * _scsih_check_access_status - check access flags
5831 * @ioc: per adapter object
5832 * @sas_address: sas address
5833 * @handle: sas device handle
5834 * @access_flags: errors returned during discovery of the device
5836 * Return 0 for success, else failure
5839 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5840 u16 handle
, u8 access_status
)
5845 switch (access_status
) {
5846 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5847 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5850 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5851 desc
= "sata capability failed";
5853 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5854 desc
= "sata affiliation conflict";
5856 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5857 desc
= "route not addressable";
5859 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5860 desc
= "smp error not addressable";
5862 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5863 desc
= "device blocked";
5865 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5866 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5867 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5868 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5869 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5870 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5871 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5872 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5873 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5874 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5875 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5876 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5877 desc
= "sata initialization failed";
5888 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5889 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5894 * _scsih_get_enclosure_logicalid_chassis_slot - get device's
5895 * EnclosureLogicalID and ChassisSlot information.
5896 * @ioc: per adapter object
5897 * @sas_device_pg0: SAS device page0
5898 * @sas_device: per sas device object
5903 _scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER
*ioc
,
5904 Mpi2SasDevicePage0_t
*sas_device_pg0
, struct _sas_device
*sas_device
)
5906 Mpi2ConfigReply_t mpi_reply
;
5907 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5909 if (!sas_device_pg0
|| !sas_device
)
5912 sas_device
->enclosure_handle
=
5913 le16_to_cpu(sas_device_pg0
->EnclosureHandle
);
5914 sas_device
->is_chassis_slot_valid
= 0;
5916 if (!le16_to_cpu(sas_device_pg0
->EnclosureHandle
))
5919 if (mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5920 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5921 le16_to_cpu(sas_device_pg0
->EnclosureHandle
))) {
5923 "Enclosure Pg0 read failed for handle(0x%04x)\n",
5924 ioc
->name
, le16_to_cpu(sas_device_pg0
->EnclosureHandle
));
5928 sas_device
->enclosure_logical_id
=
5929 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5931 if (le16_to_cpu(enclosure_pg0
.Flags
) &
5932 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
5933 sas_device
->is_chassis_slot_valid
= 1;
5934 sas_device
->chassis_slot
= enclosure_pg0
.ChassisSlot
;
5940 * _scsih_check_device - checking device responsiveness
5941 * @ioc: per adapter object
5942 * @parent_sas_address: sas address of parent expander or sas host
5943 * @handle: attached device handle
5944 * @phy_numberv: phy number
5945 * @link_rate: new link rate
5950 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5951 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5953 Mpi2ConfigReply_t mpi_reply
;
5954 Mpi2SasDevicePage0_t sas_device_pg0
;
5955 struct _sas_device
*sas_device
;
5957 unsigned long flags
;
5959 struct scsi_target
*starget
;
5960 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5963 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5964 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5967 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5968 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5971 /* wide port handling ~ we need only handle device once for the phy that
5972 * is matched in sas device page zero
5974 if (phy_number
!= sas_device_pg0
.PhyNum
)
5977 /* check if this is end device */
5978 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5979 if (!(_scsih_is_end_device(device_info
)))
5982 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5983 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5984 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5990 if (unlikely(sas_device
->handle
!= handle
)) {
5991 starget
= sas_device
->starget
;
5992 sas_target_priv_data
= starget
->hostdata
;
5993 starget_printk(KERN_INFO
, starget
,
5994 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5995 sas_device
->handle
, handle
);
5996 sas_target_priv_data
->handle
= handle
;
5997 sas_device
->handle
= handle
;
5998 if (le16_to_cpu(sas_device_pg0
.Flags
) &
5999 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6000 sas_device
->enclosure_level
=
6001 sas_device_pg0
.EnclosureLevel
;
6002 memcpy(sas_device
->connector_name
,
6003 sas_device_pg0
.ConnectorName
, 4);
6004 sas_device
->connector_name
[4] = '\0';
6006 sas_device
->enclosure_level
= 0;
6007 sas_device
->connector_name
[0] = '\0';
6010 _scsih_get_enclosure_logicalid_chassis_slot(ioc
,
6011 &sas_device_pg0
, sas_device
);
6014 /* check if device is present */
6015 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6016 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6018 "device is not present handle(0x%04x), flags!!!\n",
6023 /* check if there were any issues with discovery */
6024 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6025 sas_device_pg0
.AccessStatus
))
6028 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6029 _scsih_ublock_io_device(ioc
, sas_address
);
6032 sas_device_put(sas_device
);
6036 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6038 sas_device_put(sas_device
);
6042 * _scsih_add_device - creating sas device object
6043 * @ioc: per adapter object
6044 * @handle: sas device handle
6045 * @phy_num: phy number end device attached to
6046 * @is_pd: is this hidden raid component
6048 * Creating end device object, stored in ioc->sas_device_list.
6050 * Returns 0 for success, non-zero for failure.
6053 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
6056 Mpi2ConfigReply_t mpi_reply
;
6057 Mpi2SasDevicePage0_t sas_device_pg0
;
6058 Mpi2SasEnclosurePage0_t enclosure_pg0
;
6059 struct _sas_device
*sas_device
;
6063 int encl_pg0_rc
= -1;
6065 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6066 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6067 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6068 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6072 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6073 MPI2_IOCSTATUS_MASK
;
6074 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6075 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6076 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6080 /* check if this is end device */
6081 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6082 if (!(_scsih_is_end_device(device_info
)))
6084 set_bit(handle
, ioc
->pend_os_device_add
);
6085 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6087 /* check if device is present */
6088 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6089 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6090 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
6095 /* check if there were any issues with discovery */
6096 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6097 sas_device_pg0
.AccessStatus
))
6100 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
6103 clear_bit(handle
, ioc
->pend_os_device_add
);
6104 sas_device_put(sas_device
);
6108 if (sas_device_pg0
.EnclosureHandle
) {
6109 encl_pg0_rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
6110 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
6111 sas_device_pg0
.EnclosureHandle
);
6114 "Enclosure Pg0 read failed for handle(0x%04x)\n",
6115 ioc
->name
, sas_device_pg0
.EnclosureHandle
);
6118 sas_device
= kzalloc(sizeof(struct _sas_device
),
6121 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6122 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6126 kref_init(&sas_device
->refcount
);
6127 sas_device
->handle
= handle
;
6128 if (_scsih_get_sas_address(ioc
,
6129 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
6130 &sas_device
->sas_address_parent
) != 0)
6131 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6132 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6133 sas_device
->enclosure_handle
=
6134 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
6135 if (sas_device
->enclosure_handle
!= 0)
6137 le16_to_cpu(sas_device_pg0
.Slot
);
6138 sas_device
->device_info
= device_info
;
6139 sas_device
->sas_address
= sas_address
;
6140 sas_device
->phy
= sas_device_pg0
.PhyNum
;
6141 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
6142 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6144 if (le16_to_cpu(sas_device_pg0
.Flags
)
6145 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6146 sas_device
->enclosure_level
=
6147 sas_device_pg0
.EnclosureLevel
;
6148 memcpy(sas_device
->connector_name
,
6149 sas_device_pg0
.ConnectorName
, 4);
6150 sas_device
->connector_name
[4] = '\0';
6152 sas_device
->enclosure_level
= 0;
6153 sas_device
->connector_name
[0] = '\0';
6156 /* get enclosure_logical_id & chassis_slot */
6157 sas_device
->is_chassis_slot_valid
= 0;
6158 if (encl_pg0_rc
== 0) {
6159 sas_device
->enclosure_logical_id
=
6160 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
6162 if (le16_to_cpu(enclosure_pg0
.Flags
) &
6163 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6164 sas_device
->is_chassis_slot_valid
= 1;
6165 sas_device
->chassis_slot
=
6166 enclosure_pg0
.ChassisSlot
;
6170 /* get device name */
6171 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
6173 if (ioc
->wait_for_discovery_to_complete
)
6174 _scsih_sas_device_init_add(ioc
, sas_device
);
6176 _scsih_sas_device_add(ioc
, sas_device
);
6178 sas_device_put(sas_device
);
6183 * _scsih_remove_device - removing sas device object
6184 * @ioc: per adapter object
6185 * @sas_device_delete: the sas_device object
6190 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
6191 struct _sas_device
*sas_device
)
6193 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6195 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
6196 (sas_device
->pfa_led_on
)) {
6197 _scsih_turn_off_pfa_led(ioc
, sas_device
);
6198 sas_device
->pfa_led_on
= 0;
6201 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6202 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6203 ioc
->name
, __func__
,
6204 sas_device
->handle
, (unsigned long long)
6205 sas_device
->sas_address
));
6207 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6210 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6211 sas_target_priv_data
= sas_device
->starget
->hostdata
;
6212 sas_target_priv_data
->deleted
= 1;
6213 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
6214 sas_target_priv_data
->handle
=
6215 MPT3SAS_INVALID_DEVICE_HANDLE
;
6218 if (!ioc
->hide_drives
)
6219 mpt3sas_transport_port_remove(ioc
,
6220 sas_device
->sas_address
,
6221 sas_device
->sas_address_parent
);
6224 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6225 ioc
->name
, sas_device
->handle
,
6226 (unsigned long long) sas_device
->sas_address
);
6228 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
6230 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6231 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6232 ioc
->name
, __func__
,
6233 sas_device
->handle
, (unsigned long long)
6234 sas_device
->sas_address
));
6235 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6240 * _scsih_sas_topology_change_event_debug - debug for topology event
6241 * @ioc: per adapter object
6242 * @event_data: event data payload
6246 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6247 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
6253 char *status_str
= NULL
;
6254 u8 link_rate
, prev_link_rate
;
6256 switch (event_data
->ExpStatus
) {
6257 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
6260 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
6261 status_str
= "remove";
6263 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
6265 status_str
= "responding";
6267 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
6268 status_str
= "remove delay";
6271 status_str
= "unknown status";
6274 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
6275 ioc
->name
, status_str
);
6276 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6277 "start_phy(%02d), count(%d)\n",
6278 le16_to_cpu(event_data
->ExpanderDevHandle
),
6279 le16_to_cpu(event_data
->EnclosureHandle
),
6280 event_data
->StartPhyNum
, event_data
->NumEntries
);
6281 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6282 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6285 phy_number
= event_data
->StartPhyNum
+ i
;
6286 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6287 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6288 switch (reason_code
) {
6289 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6290 status_str
= "target add";
6292 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6293 status_str
= "target remove";
6295 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
6296 status_str
= "delay target remove";
6298 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6299 status_str
= "link rate change";
6301 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
6302 status_str
= "target responding";
6305 status_str
= "unknown";
6308 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6309 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6310 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6311 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
6312 handle
, status_str
, link_rate
, prev_link_rate
);
6318 * _scsih_sas_topology_change_event - handle topology changes
6319 * @ioc: per adapter object
6320 * @fw_event: The fw_event_work object
6325 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6326 struct fw_event_work
*fw_event
)
6329 u16 parent_handle
, handle
;
6331 u8 phy_number
, max_phys
;
6332 struct _sas_node
*sas_expander
;
6334 unsigned long flags
;
6335 u8 link_rate
, prev_link_rate
;
6336 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
6337 (Mpi2EventDataSasTopologyChangeList_t
*)
6338 fw_event
->event_data
;
6340 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6341 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
6343 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
6346 if (!ioc
->sas_hba
.num_phys
)
6347 _scsih_sas_host_add(ioc
);
6349 _scsih_sas_host_refresh(ioc
);
6351 if (fw_event
->ignore
) {
6352 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6353 "ignoring expander event\n", ioc
->name
));
6357 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
6359 /* handle expander add */
6360 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
6361 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
6364 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6365 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
6368 sas_address
= sas_expander
->sas_address
;
6369 max_phys
= sas_expander
->num_phys
;
6370 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
6371 sas_address
= ioc
->sas_hba
.sas_address
;
6372 max_phys
= ioc
->sas_hba
.num_phys
;
6374 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6377 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6379 /* handle siblings events */
6380 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6381 if (fw_event
->ignore
) {
6382 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6383 "ignoring expander event\n", ioc
->name
));
6386 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6388 phy_number
= event_data
->StartPhyNum
+ i
;
6389 if (phy_number
>= max_phys
)
6391 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6392 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6393 if ((event_data
->PHY
[i
].PhyStatus
&
6394 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
6395 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
6397 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6400 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6401 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6402 switch (reason_code
) {
6403 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6405 if (ioc
->shost_recovery
)
6408 if (link_rate
== prev_link_rate
)
6411 mpt3sas_transport_update_links(ioc
, sas_address
,
6412 handle
, phy_number
, link_rate
);
6414 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
6417 _scsih_check_device(ioc
, sas_address
, handle
,
6418 phy_number
, link_rate
);
6420 if (!test_bit(handle
, ioc
->pend_os_device_add
))
6424 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6426 if (ioc
->shost_recovery
)
6429 mpt3sas_transport_update_links(ioc
, sas_address
,
6430 handle
, phy_number
, link_rate
);
6432 _scsih_add_device(ioc
, handle
, phy_number
, 0);
6435 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6437 _scsih_device_remove_by_handle(ioc
, handle
);
6442 /* handle expander removal */
6443 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
6445 mpt3sas_expander_remove(ioc
, sas_address
);
6451 * _scsih_sas_device_status_change_event_debug - debug for device event
6452 * @event_data: event data payload
6458 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6459 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
6461 char *reason_str
= NULL
;
6463 switch (event_data
->ReasonCode
) {
6464 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
6465 reason_str
= "smart data";
6467 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
6468 reason_str
= "unsupported device discovered";
6470 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
6471 reason_str
= "internal device reset";
6473 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
6474 reason_str
= "internal task abort";
6476 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
6477 reason_str
= "internal task abort set";
6479 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
6480 reason_str
= "internal clear task set";
6482 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
6483 reason_str
= "internal query task";
6485 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
6486 reason_str
= "sata init failure";
6488 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
6489 reason_str
= "internal device reset complete";
6491 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
6492 reason_str
= "internal task abort complete";
6494 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
6495 reason_str
= "internal async notification";
6497 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
6498 reason_str
= "expander reduced functionality";
6500 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
6501 reason_str
= "expander reduced functionality complete";
6504 reason_str
= "unknown reason";
6507 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
6508 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6509 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
6510 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
6511 le16_to_cpu(event_data
->TaskTag
));
6512 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
6513 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
6514 event_data
->ASC
, event_data
->ASCQ
);
6519 * _scsih_sas_device_status_change_event - handle device status change
6520 * @ioc: per adapter object
6521 * @fw_event: The fw_event_work object
6527 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6528 struct fw_event_work
*fw_event
)
6530 struct MPT3SAS_TARGET
*target_priv_data
;
6531 struct _sas_device
*sas_device
;
6533 unsigned long flags
;
6534 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
6535 (Mpi2EventDataSasDeviceStatusChange_t
*)
6536 fw_event
->event_data
;
6538 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6539 _scsih_sas_device_status_change_event_debug(ioc
,
6542 /* In MPI Revision K (0xC), the internal device reset complete was
6543 * implemented, so avoid setting tm_busy flag for older firmware.
6545 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
6548 if (event_data
->ReasonCode
!=
6549 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
6550 event_data
->ReasonCode
!=
6551 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
6554 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6555 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6556 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6559 if (!sas_device
|| !sas_device
->starget
)
6562 target_priv_data
= sas_device
->starget
->hostdata
;
6563 if (!target_priv_data
)
6566 if (event_data
->ReasonCode
==
6567 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6568 target_priv_data
->tm_busy
= 1;
6570 target_priv_data
->tm_busy
= 0;
6574 sas_device_put(sas_device
);
6576 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6581 * _scsih_check_pcie_access_status - check access flags
6582 * @ioc: per adapter object
6584 * @handle: sas device handle
6585 * @access_flags: errors returned during discovery of the device
6587 * Return 0 for success, else failure
6590 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6591 u16 handle
, u8 access_status
)
6596 switch (access_status
) {
6597 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS
:
6598 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION
:
6601 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED
:
6602 desc
= "PCIe device capability failed";
6604 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
:
6605 desc
= "PCIe device blocked";
6607 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED
:
6608 desc
= "PCIe device mem space access failed";
6610 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE
:
6611 desc
= "PCIe device unsupported";
6613 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED
:
6614 desc
= "PCIe device MSIx Required";
6616 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX
:
6617 desc
= "PCIe device init fail max";
6619 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN
:
6620 desc
= "PCIe device status unknown";
6622 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT
:
6623 desc
= "nvme ready timeout";
6625 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED
:
6626 desc
= "nvme device configuration unsupported";
6628 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED
:
6629 desc
= "nvme identify failed";
6631 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED
:
6632 desc
= "nvme qconfig failed";
6634 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED
:
6635 desc
= "nvme qcreation failed";
6637 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED
:
6638 desc
= "nvme eventcfg failed";
6640 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED
:
6641 desc
= "nvme get feature stat failed";
6643 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT
:
6644 desc
= "nvme idle timeout";
6646 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS
:
6647 desc
= "nvme failure status";
6651 " NVMe discovery error(0x%02x): wwid(0x%016llx),"
6652 "handle(0x%04x)\n", ioc
->name
, access_status
,
6653 (unsigned long long)wwid
, handle
);
6661 "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6663 (unsigned long long)wwid
, handle
);
6668 * _scsih_pcie_device_remove_from_sml - removing pcie device
6669 * from SML and free up associated memory
6670 * @ioc: per adapter object
6671 * @pcie_device: the pcie_device object
6676 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
6677 struct _pcie_device
*pcie_device
)
6679 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6681 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6682 "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6683 pcie_device
->handle
, (unsigned long long)
6684 pcie_device
->wwid
));
6685 if (pcie_device
->enclosure_handle
!= 0)
6686 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6687 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6688 ioc
->name
, __func__
,
6689 (unsigned long long)pcie_device
->enclosure_logical_id
,
6690 pcie_device
->slot
));
6691 if (pcie_device
->connector_name
[0] != '\0')
6692 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6693 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
6694 ioc
->name
, __func__
,
6695 pcie_device
->enclosure_level
,
6696 pcie_device
->connector_name
));
6698 if (pcie_device
->starget
&& pcie_device
->starget
->hostdata
) {
6699 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
6700 sas_target_priv_data
->deleted
= 1;
6701 _scsih_ublock_io_device(ioc
, pcie_device
->wwid
);
6702 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
6706 "removing handle(0x%04x), wwid (0x%016llx)\n",
6707 ioc
->name
, pcie_device
->handle
,
6708 (unsigned long long) pcie_device
->wwid
);
6709 if (pcie_device
->enclosure_handle
!= 0)
6711 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6713 (unsigned long long)pcie_device
->enclosure_logical_id
,
6715 if (pcie_device
->connector_name
[0] != '\0')
6717 "removing: enclosure level(0x%04x), connector name( %s)\n",
6718 ioc
->name
, pcie_device
->enclosure_level
,
6719 pcie_device
->connector_name
);
6721 if (pcie_device
->starget
)
6722 scsi_remove_target(&pcie_device
->starget
->dev
);
6723 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6724 "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6725 pcie_device
->handle
, (unsigned long long)
6726 pcie_device
->wwid
));
6727 if (pcie_device
->enclosure_handle
!= 0)
6728 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6729 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6730 ioc
->name
, __func__
,
6731 (unsigned long long)pcie_device
->enclosure_logical_id
,
6732 pcie_device
->slot
));
6733 if (pcie_device
->connector_name
[0] != '\0')
6734 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6735 "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6736 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
6737 pcie_device
->connector_name
));
6739 kfree(pcie_device
->serial_number
);
6744 * _scsih_pcie_check_device - checking device responsiveness
6745 * @ioc: per adapter object
6746 * @handle: attached device handle
6751 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6753 Mpi2ConfigReply_t mpi_reply
;
6754 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6756 struct _pcie_device
*pcie_device
;
6758 unsigned long flags
;
6759 struct scsi_target
*starget
;
6760 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6763 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6764 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6767 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6768 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6771 /* check if this is end device */
6772 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6773 if (!(_scsih_is_nvme_device(device_info
)))
6776 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6777 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
6778 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6781 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6785 if (unlikely(pcie_device
->handle
!= handle
)) {
6786 starget
= pcie_device
->starget
;
6787 sas_target_priv_data
= starget
->hostdata
;
6788 starget_printk(KERN_INFO
, starget
,
6789 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6790 pcie_device
->handle
, handle
);
6791 sas_target_priv_data
->handle
= handle
;
6792 pcie_device
->handle
= handle
;
6794 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6795 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6796 pcie_device
->enclosure_level
=
6797 pcie_device_pg0
.EnclosureLevel
;
6798 memcpy(&pcie_device
->connector_name
[0],
6799 &pcie_device_pg0
.ConnectorName
[0], 4);
6801 pcie_device
->enclosure_level
= 0;
6802 pcie_device
->connector_name
[0] = '\0';
6806 /* check if device is present */
6807 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6808 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6810 "device is not present handle(0x%04x), flags!!!\n",
6812 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6813 pcie_device_put(pcie_device
);
6817 /* check if there were any issues with discovery */
6818 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6819 pcie_device_pg0
.AccessStatus
)) {
6820 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6821 pcie_device_put(pcie_device
);
6825 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6826 pcie_device_put(pcie_device
);
6828 _scsih_ublock_io_device(ioc
, wwid
);
6834 * _scsih_pcie_add_device - creating pcie device object
6835 * @ioc: per adapter object
6836 * @handle: pcie device handle
6838 * Creating end device object, stored in ioc->pcie_device_list.
6840 * Return 1 means queue the event later, 0 means complete the event
6843 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6845 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6846 Mpi26PCIeDevicePage2_t pcie_device_pg2
;
6847 Mpi2ConfigReply_t mpi_reply
;
6848 Mpi2SasEnclosurePage0_t enclosure_pg0
;
6849 struct _pcie_device
*pcie_device
;
6850 u32 pcie_device_type
;
6854 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6855 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6856 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6857 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6860 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6861 MPI2_IOCSTATUS_MASK
;
6862 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6864 "failure at %s:%d/%s()!\n",
6865 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6869 set_bit(handle
, ioc
->pend_os_device_add
);
6870 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6872 /* check if device is present */
6873 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6874 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6876 "device is not present handle(0x04%x)!!!\n",
6881 /* check if there were any issues with discovery */
6882 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6883 pcie_device_pg0
.AccessStatus
))
6886 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
6889 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6891 clear_bit(handle
, ioc
->pend_os_device_add
);
6892 pcie_device_put(pcie_device
);
6896 pcie_device
= kzalloc(sizeof(struct _pcie_device
), GFP_KERNEL
);
6898 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6899 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6903 kref_init(&pcie_device
->refcount
);
6904 pcie_device
->id
= ioc
->pcie_target_id
++;
6905 pcie_device
->channel
= PCIE_CHANNEL
;
6906 pcie_device
->handle
= handle
;
6907 pcie_device
->device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6908 pcie_device
->wwid
= wwid
;
6909 pcie_device
->port_num
= pcie_device_pg0
.PortNum
;
6910 pcie_device
->fast_path
= (le32_to_cpu(pcie_device_pg0
.Flags
) &
6911 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6912 pcie_device_type
= pcie_device
->device_info
&
6913 MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
;
6915 pcie_device
->enclosure_handle
=
6916 le16_to_cpu(pcie_device_pg0
.EnclosureHandle
);
6917 if (pcie_device
->enclosure_handle
!= 0)
6918 pcie_device
->slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
6920 if (le16_to_cpu(pcie_device_pg0
.Flags
) &
6921 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6922 pcie_device
->enclosure_level
= pcie_device_pg0
.EnclosureLevel
;
6923 memcpy(&pcie_device
->connector_name
[0],
6924 &pcie_device_pg0
.ConnectorName
[0], 4);
6926 pcie_device
->enclosure_level
= 0;
6927 pcie_device
->connector_name
[0] = '\0';
6930 /* get enclosure_logical_id */
6931 if (pcie_device
->enclosure_handle
&&
6932 !(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
6933 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
6934 pcie_device
->enclosure_handle
)))
6935 pcie_device
->enclosure_logical_id
=
6936 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
6938 /* TODO -- Add device name once FW supports it */
6939 if (mpt3sas_config_get_pcie_device_pg2(ioc
, &mpi_reply
,
6940 &pcie_device_pg2
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)) {
6941 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6942 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6947 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6948 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6949 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6950 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6954 pcie_device
->nvme_mdts
=
6955 le32_to_cpu(pcie_device_pg2
.MaximumDataTransferSize
);
6957 if (ioc
->wait_for_discovery_to_complete
)
6958 _scsih_pcie_device_init_add(ioc
, pcie_device
);
6960 _scsih_pcie_device_add(ioc
, pcie_device
);
6962 pcie_device_put(pcie_device
);
6967 * _scsih_pcie_topology_change_event_debug - debug for topology
6969 * @ioc: per adapter object
6970 * @event_data: event data payload
6974 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6975 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
6981 char *status_str
= NULL
;
6982 u8 link_rate
, prev_link_rate
;
6984 switch (event_data
->SwitchStatus
) {
6985 case MPI26_EVENT_PCIE_TOPO_SS_ADDED
:
6988 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING
:
6989 status_str
= "remove";
6991 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
:
6993 status_str
= "responding";
6995 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
:
6996 status_str
= "remove delay";
6999 status_str
= "unknown status";
7002 pr_info(MPT3SAS_FMT
"pcie topology change: (%s)\n",
7003 ioc
->name
, status_str
);
7004 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
7005 "start_port(%02d), count(%d)\n",
7006 le16_to_cpu(event_data
->SwitchDevHandle
),
7007 le16_to_cpu(event_data
->EnclosureHandle
),
7008 event_data
->StartPortNum
, event_data
->NumEntries
);
7009 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7011 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7014 port_number
= event_data
->StartPortNum
+ i
;
7015 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7016 switch (reason_code
) {
7017 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7018 status_str
= "target add";
7020 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7021 status_str
= "target remove";
7023 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
:
7024 status_str
= "delay target remove";
7026 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7027 status_str
= "link rate change";
7029 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
:
7030 status_str
= "target responding";
7033 status_str
= "unknown";
7036 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
&
7037 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7038 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
&
7039 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7040 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
7041 " link rate: new(0x%02x), old(0x%02x)\n", port_number
,
7042 handle
, status_str
, link_rate
, prev_link_rate
);
7047 * _scsih_pcie_topology_change_event - handle PCIe topology
7049 * @ioc: per adapter object
7050 * @fw_event: The fw_event_work object
7055 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7056 struct fw_event_work
*fw_event
)
7061 u8 link_rate
, prev_link_rate
;
7062 unsigned long flags
;
7064 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
=
7065 (Mpi26EventDataPCIeTopologyChangeList_t
*) fw_event
->event_data
;
7066 struct _pcie_device
*pcie_device
;
7068 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7069 _scsih_pcie_topology_change_event_debug(ioc
, event_data
);
7071 if (ioc
->shost_recovery
|| ioc
->remove_host
||
7072 ioc
->pci_error_recovery
)
7075 if (fw_event
->ignore
) {
7076 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"ignoring switch event\n",
7081 /* handle siblings events */
7082 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7083 if (fw_event
->ignore
) {
7084 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7085 "ignoring switch event\n", ioc
->name
));
7088 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7090 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7092 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7096 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
7097 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7098 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
7099 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7101 switch (reason_code
) {
7102 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7103 if (ioc
->shost_recovery
)
7105 if (link_rate
== prev_link_rate
)
7107 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7110 _scsih_pcie_check_device(ioc
, handle
);
7112 /* This code after this point handles the test case
7113 * where a device has been added, however its returning
7114 * BUSY for sometime. Then before the Device Missing
7115 * Delay expires and the device becomes READY, the
7116 * device is removed and added back.
7118 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7119 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
7120 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7123 pcie_device_put(pcie_device
);
7127 if (!test_bit(handle
, ioc
->pend_os_device_add
))
7130 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7131 "handle(0x%04x) device not found: convert "
7132 "event to a device add\n", ioc
->name
, handle
));
7133 event_data
->PortEntry
[i
].PortStatus
&= 0xF0;
7134 event_data
->PortEntry
[i
].PortStatus
|=
7135 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
;
7136 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7137 if (ioc
->shost_recovery
)
7139 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7142 rc
= _scsih_pcie_add_device(ioc
, handle
);
7144 /* mark entry vacant */
7145 /* TODO This needs to be reviewed and fixed,
7146 * we dont have an entry
7147 * to make an event void like vacant
7149 event_data
->PortEntry
[i
].PortStatus
|=
7150 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
;
7153 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7154 _scsih_pcie_device_remove_by_handle(ioc
, handle
);
7161 * _scsih_pcie_device_status_change_event_debug - debug for
7163 * @event_data: event data payload
7169 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7170 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
)
7172 char *reason_str
= NULL
;
7174 switch (event_data
->ReasonCode
) {
7175 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
:
7176 reason_str
= "smart data";
7178 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED
:
7179 reason_str
= "unsupported device discovered";
7181 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
:
7182 reason_str
= "internal device reset";
7184 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL
:
7185 reason_str
= "internal task abort";
7187 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
7188 reason_str
= "internal task abort set";
7190 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
7191 reason_str
= "internal clear task set";
7193 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL
:
7194 reason_str
= "internal query task";
7196 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE
:
7197 reason_str
= "device init failure";
7199 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
7200 reason_str
= "internal device reset complete";
7202 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
7203 reason_str
= "internal task abort complete";
7205 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION
:
7206 reason_str
= "internal async notification";
7209 reason_str
= "unknown reason";
7213 pr_info(MPT3SAS_FMT
"PCIE device status change: (%s)\n"
7214 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7215 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
7216 (unsigned long long)le64_to_cpu(event_data
->WWID
),
7217 le16_to_cpu(event_data
->TaskTag
));
7218 if (event_data
->ReasonCode
== MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
)
7219 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
7220 event_data
->ASC
, event_data
->ASCQ
);
7225 * _scsih_pcie_device_status_change_event - handle device status
7227 * @ioc: per adapter object
7228 * @fw_event: The fw_event_work object
7234 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7235 struct fw_event_work
*fw_event
)
7237 struct MPT3SAS_TARGET
*target_priv_data
;
7238 struct _pcie_device
*pcie_device
;
7240 unsigned long flags
;
7241 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
=
7242 (Mpi26EventDataPCIeDeviceStatusChange_t
*)fw_event
->event_data
;
7243 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7244 _scsih_pcie_device_status_change_event_debug(ioc
,
7247 if (event_data
->ReasonCode
!=
7248 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
7249 event_data
->ReasonCode
!=
7250 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
7253 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7254 wwid
= le64_to_cpu(event_data
->WWID
);
7255 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
7257 if (!pcie_device
|| !pcie_device
->starget
)
7260 target_priv_data
= pcie_device
->starget
->hostdata
;
7261 if (!target_priv_data
)
7264 if (event_data
->ReasonCode
==
7265 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
)
7266 target_priv_data
->tm_busy
= 1;
7268 target_priv_data
->tm_busy
= 0;
7271 pcie_device_put(pcie_device
);
7273 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7277 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7279 * @ioc: per adapter object
7280 * @event_data: event data payload
7286 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7287 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
7289 char *reason_str
= NULL
;
7291 switch (event_data
->ReasonCode
) {
7292 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7293 reason_str
= "enclosure add";
7295 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7296 reason_str
= "enclosure remove";
7299 reason_str
= "unknown reason";
7303 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
7304 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
7305 " number slots(%d)\n", ioc
->name
, reason_str
,
7306 le16_to_cpu(event_data
->EnclosureHandle
),
7307 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
7308 le16_to_cpu(event_data
->StartSlot
));
7312 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7313 * @ioc: per adapter object
7314 * @fw_event: The fw_event_work object
7320 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7321 struct fw_event_work
*fw_event
)
7323 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7324 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
7325 (Mpi2EventDataSasEnclDevStatusChange_t
*)
7326 fw_event
->event_data
);
7330 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7331 * @ioc: per adapter object
7332 * @fw_event: The fw_event_work object
7338 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
7339 struct fw_event_work
*fw_event
)
7341 struct scsi_cmnd
*scmd
;
7342 struct scsi_device
*sdev
;
7343 struct scsiio_tracker
*st
;
7346 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7347 u32 termination_count
;
7349 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
7350 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
7351 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7352 fw_event
->event_data
;
7354 unsigned long flags
;
7357 u8 task_abort_retries
;
7359 mutex_lock(&ioc
->tm_cmds
.mutex
);
7361 "%s: enter: phy number(%d), width(%d)\n",
7362 ioc
->name
, __func__
, event_data
->PhyNum
,
7363 event_data
->PortWidth
);
7365 _scsih_block_io_all_device(ioc
);
7367 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7368 mpi_reply
= ioc
->tm_cmds
.reply
;
7369 broadcast_aen_retry
:
7371 /* sanity checks for retrying this loop */
7372 if (max_retries
++ == 5) {
7373 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
7374 ioc
->name
, __func__
));
7376 } else if (max_retries
> 1)
7377 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
7378 ioc
->name
, __func__
, max_retries
- 1));
7380 termination_count
= 0;
7382 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
7383 if (ioc
->shost_recovery
)
7385 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
7388 st
= scsi_cmd_priv(scmd
);
7389 sdev
= scmd
->device
;
7390 sas_device_priv_data
= sdev
->hostdata
;
7391 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
7393 /* skip hidden raid components */
7394 if (sas_device_priv_data
->sas_target
->flags
&
7395 MPT_TARGET_FLAGS_RAID_COMPONENT
)
7398 if (sas_device_priv_data
->sas_target
->flags
&
7399 MPT_TARGET_FLAGS_VOLUME
)
7402 handle
= sas_device_priv_data
->sas_target
->handle
;
7403 lun
= sas_device_priv_data
->lun
;
7406 if (ioc
->shost_recovery
)
7409 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7410 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
,
7411 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, st
->smid
,
7414 sdev_printk(KERN_WARNING
, sdev
,
7415 "mpt3sas_scsih_issue_tm: FAILED when sending "
7416 "QUERY_TASK: scmd(%p)\n", scmd
);
7417 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7418 goto broadcast_aen_retry
;
7420 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
7421 & MPI2_IOCSTATUS_MASK
;
7422 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7423 sdev_printk(KERN_WARNING
, sdev
,
7424 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7426 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7427 goto broadcast_aen_retry
;
7430 /* see if IO is still owned by IOC and target */
7431 if (mpi_reply
->ResponseCode
==
7432 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
7433 mpi_reply
->ResponseCode
==
7434 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
7435 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7438 task_abort_retries
= 0;
7440 if (task_abort_retries
++ == 60) {
7441 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7442 "%s: ABORT_TASK: giving up\n", ioc
->name
,
7444 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7445 goto broadcast_aen_retry
;
7448 if (ioc
->shost_recovery
)
7451 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->lun
,
7452 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, st
->smid
,
7454 if (r
== FAILED
|| st
->cb_idx
!= 0xFF) {
7455 sdev_printk(KERN_WARNING
, sdev
,
7456 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7457 "scmd(%p)\n", scmd
);
7461 if (task_abort_retries
> 1)
7462 sdev_printk(KERN_WARNING
, sdev
,
7463 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7465 task_abort_retries
- 1, scmd
);
7467 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
7468 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7471 if (ioc
->broadcast_aen_pending
) {
7472 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7473 "%s: loop back due to pending AEN\n",
7474 ioc
->name
, __func__
));
7475 ioc
->broadcast_aen_pending
= 0;
7476 goto broadcast_aen_retry
;
7480 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7483 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7484 "%s - exit, query_count = %d termination_count = %d\n",
7485 ioc
->name
, __func__
, query_count
, termination_count
));
7487 ioc
->broadcast_aen_busy
= 0;
7488 if (!ioc
->shost_recovery
)
7489 _scsih_ublock_io_all_device(ioc
);
7490 mutex_unlock(&ioc
->tm_cmds
.mutex
);
7494 * _scsih_sas_discovery_event - handle discovery events
7495 * @ioc: per adapter object
7496 * @fw_event: The fw_event_work object
7502 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
7503 struct fw_event_work
*fw_event
)
7505 Mpi2EventDataSasDiscovery_t
*event_data
=
7506 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
7508 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
7509 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
7510 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
7512 if (event_data
->DiscoveryStatus
)
7513 pr_info("discovery_status(0x%08x)",
7514 le32_to_cpu(event_data
->DiscoveryStatus
));
7518 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
7519 !ioc
->sas_hba
.num_phys
) {
7520 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
7521 /* Wait for the reset to complete */
7522 while (ioc
->shost_recovery
)
7525 _scsih_sas_host_add(ioc
);
7530 * _scsih_pcie_enumeration_event - handle enumeration events
7531 * @ioc: per adapter object
7532 * @fw_event: The fw_event_work object
7538 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER
*ioc
,
7539 struct fw_event_work
*fw_event
)
7541 Mpi26EventDataPCIeEnumeration_t
*event_data
=
7542 (Mpi26EventDataPCIeEnumeration_t
*)fw_event
->event_data
;
7544 if (!(ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
))
7547 pr_info(MPT3SAS_FMT
"pcie enumeration event: (%s) Flag 0x%02x",
7549 (event_data
->ReasonCode
== MPI26_EVENT_PCIE_ENUM_RC_STARTED
) ?
7550 "started" : "completed",
7552 if (event_data
->EnumerationStatus
)
7553 pr_cont("enumeration_status(0x%08x)",
7554 le32_to_cpu(event_data
->EnumerationStatus
));
7559 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7560 * @ioc: per adapter object
7561 * @handle: device handle for physical disk
7562 * @phys_disk_num: physical disk number
7564 * Return 0 for success, else failure.
7567 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
7569 Mpi2RaidActionRequest_t
*mpi_request
;
7570 Mpi2RaidActionReply_t
*mpi_reply
;
7577 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
7580 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7582 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7583 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7584 ioc
->name
, __func__
);
7588 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7590 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7592 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7593 ioc
->name
, __func__
);
7594 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7599 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7600 ioc
->scsih_cmds
.smid
= smid
;
7601 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7603 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7604 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
7605 mpi_request
->PhysDiskNum
= phys_disk_num
;
7607 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
7608 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
7609 handle
, phys_disk_num
));
7611 init_completion(&ioc
->scsih_cmds
.done
);
7612 ioc
->put_smid_default(ioc
, smid
);
7613 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7615 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7616 pr_err(MPT3SAS_FMT
"%s: timeout\n",
7617 ioc
->name
, __func__
);
7618 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
7624 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7626 mpi_reply
= ioc
->scsih_cmds
.reply
;
7627 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
7628 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
7629 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
7632 ioc_status
&= MPI2_IOCSTATUS_MASK
;
7633 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7634 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7635 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
7636 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
7640 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7641 "IR RAID_ACTION: completed successfully\n",
7646 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7647 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7650 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
7655 * _scsih_reprobe_lun - reprobing lun
7656 * @sdev: scsi device struct
7657 * @no_uld_attach: sdev->no_uld_attach flag setting
7661 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
7663 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
7664 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
7665 sdev
->no_uld_attach
? "hiding" : "exposing");
7666 WARN_ON(scsi_device_reprobe(sdev
));
7670 * _scsih_sas_volume_add - add new volume
7671 * @ioc: per adapter object
7672 * @element: IR config element data
7678 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
7679 Mpi2EventIrConfigElement_t
*element
)
7681 struct _raid_device
*raid_device
;
7682 unsigned long flags
;
7684 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
7687 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
7690 "failure at %s:%d/%s()!\n", ioc
->name
,
7691 __FILE__
, __LINE__
, __func__
);
7695 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7696 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
7697 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7702 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
7705 "failure at %s:%d/%s()!\n", ioc
->name
,
7706 __FILE__
, __LINE__
, __func__
);
7710 raid_device
->id
= ioc
->sas_id
++;
7711 raid_device
->channel
= RAID_CHANNEL
;
7712 raid_device
->handle
= handle
;
7713 raid_device
->wwid
= wwid
;
7714 _scsih_raid_device_add(ioc
, raid_device
);
7715 if (!ioc
->wait_for_discovery_to_complete
) {
7716 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7717 raid_device
->id
, 0);
7719 _scsih_raid_device_remove(ioc
, raid_device
);
7721 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7722 _scsih_determine_boot_device(ioc
, raid_device
, 1);
7723 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7728 * _scsih_sas_volume_delete - delete volume
7729 * @ioc: per adapter object
7730 * @handle: volume device handle
7736 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
7738 struct _raid_device
*raid_device
;
7739 unsigned long flags
;
7740 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7741 struct scsi_target
*starget
= NULL
;
7743 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7744 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7746 if (raid_device
->starget
) {
7747 starget
= raid_device
->starget
;
7748 sas_target_priv_data
= starget
->hostdata
;
7749 sas_target_priv_data
->deleted
= 1;
7751 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7752 ioc
->name
, raid_device
->handle
,
7753 (unsigned long long) raid_device
->wwid
);
7754 list_del(&raid_device
->list
);
7757 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7759 scsi_remove_target(&starget
->dev
);
7763 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7764 * @ioc: per adapter object
7765 * @element: IR config element data
7771 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
7772 Mpi2EventIrConfigElement_t
*element
)
7774 struct _sas_device
*sas_device
;
7775 struct scsi_target
*starget
= NULL
;
7776 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7777 unsigned long flags
;
7778 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7780 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7781 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7783 sas_device
->volume_handle
= 0;
7784 sas_device
->volume_wwid
= 0;
7785 clear_bit(handle
, ioc
->pd_handles
);
7786 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7787 starget
= sas_device
->starget
;
7788 sas_target_priv_data
= starget
->hostdata
;
7789 sas_target_priv_data
->flags
&=
7790 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
7793 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7797 /* exposing raid component */
7799 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
7801 sas_device_put(sas_device
);
7805 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7806 * @ioc: per adapter object
7807 * @element: IR config element data
7813 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
7814 Mpi2EventIrConfigElement_t
*element
)
7816 struct _sas_device
*sas_device
;
7817 struct scsi_target
*starget
= NULL
;
7818 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7819 unsigned long flags
;
7820 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7821 u16 volume_handle
= 0;
7822 u64 volume_wwid
= 0;
7824 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
7826 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
7829 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7830 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7832 set_bit(handle
, ioc
->pd_handles
);
7833 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7834 starget
= sas_device
->starget
;
7835 sas_target_priv_data
= starget
->hostdata
;
7836 sas_target_priv_data
->flags
|=
7837 MPT_TARGET_FLAGS_RAID_COMPONENT
;
7838 sas_device
->volume_handle
= volume_handle
;
7839 sas_device
->volume_wwid
= volume_wwid
;
7842 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7846 /* hiding raid component */
7847 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7850 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
7852 sas_device_put(sas_device
);
7856 * _scsih_sas_pd_delete - delete pd component
7857 * @ioc: per adapter object
7858 * @element: IR config element data
7864 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
7865 Mpi2EventIrConfigElement_t
*element
)
7867 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7869 _scsih_device_remove_by_handle(ioc
, handle
);
7873 * _scsih_sas_pd_add - remove pd component
7874 * @ioc: per adapter object
7875 * @element: IR config element data
7881 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
7882 Mpi2EventIrConfigElement_t
*element
)
7884 struct _sas_device
*sas_device
;
7885 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7886 Mpi2ConfigReply_t mpi_reply
;
7887 Mpi2SasDevicePage0_t sas_device_pg0
;
7892 set_bit(handle
, ioc
->pd_handles
);
7894 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7896 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7897 sas_device_put(sas_device
);
7901 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
7902 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
7903 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7904 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7908 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7909 MPI2_IOCSTATUS_MASK
;
7910 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7911 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7912 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7916 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7917 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
7918 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7919 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7921 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7922 _scsih_add_device(ioc
, handle
, 0, 1);
7926 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
7927 * @ioc: per adapter object
7928 * @event_data: event data payload
7934 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7935 Mpi2EventDataIrConfigChangeList_t
*event_data
)
7937 Mpi2EventIrConfigElement_t
*element
;
7940 char *reason_str
= NULL
, *element_str
= NULL
;
7942 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
7944 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
7945 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
7946 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
7947 "foreign" : "native", event_data
->NumElements
);
7948 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
7949 switch (element
->ReasonCode
) {
7950 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
7953 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
7954 reason_str
= "remove";
7956 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
7957 reason_str
= "no change";
7959 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
7960 reason_str
= "hide";
7962 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
7963 reason_str
= "unhide";
7965 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
7966 reason_str
= "volume_created";
7968 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
7969 reason_str
= "volume_deleted";
7971 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
7972 reason_str
= "pd_created";
7974 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
7975 reason_str
= "pd_deleted";
7978 reason_str
= "unknown reason";
7981 element_type
= le16_to_cpu(element
->ElementFlags
) &
7982 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
7983 switch (element_type
) {
7984 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
7985 element_str
= "volume";
7987 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
7988 element_str
= "phys disk";
7990 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
7991 element_str
= "hot spare";
7994 element_str
= "unknown element";
7997 pr_info("\t(%s:%s), vol handle(0x%04x), " \
7998 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
7999 reason_str
, le16_to_cpu(element
->VolDevHandle
),
8000 le16_to_cpu(element
->PhysDiskDevHandle
),
8001 element
->PhysDiskNum
);
8006 * _scsih_sas_ir_config_change_event - handle ir configuration change events
8007 * @ioc: per adapter object
8008 * @fw_event: The fw_event_work object
8014 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
8015 struct fw_event_work
*fw_event
)
8017 Mpi2EventIrConfigElement_t
*element
;
8020 Mpi2EventDataIrConfigChangeList_t
*event_data
=
8021 (Mpi2EventDataIrConfigChangeList_t
*)
8022 fw_event
->event_data
;
8024 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8025 (!ioc
->hide_ir_msg
))
8026 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
8028 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
8029 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
8031 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8032 if (ioc
->shost_recovery
&&
8033 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
8034 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8035 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
8036 _scsih_ir_fastpath(ioc
,
8037 le16_to_cpu(element
->PhysDiskDevHandle
),
8038 element
->PhysDiskNum
);
8043 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8045 switch (element
->ReasonCode
) {
8046 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8047 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8048 if (!foreign_config
)
8049 _scsih_sas_volume_add(ioc
, element
);
8051 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8052 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8053 if (!foreign_config
)
8054 _scsih_sas_volume_delete(ioc
,
8055 le16_to_cpu(element
->VolDevHandle
));
8057 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8058 if (!ioc
->is_warpdrive
)
8059 _scsih_sas_pd_hide(ioc
, element
);
8061 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8062 if (!ioc
->is_warpdrive
)
8063 _scsih_sas_pd_expose(ioc
, element
);
8065 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8066 if (!ioc
->is_warpdrive
)
8067 _scsih_sas_pd_add(ioc
, element
);
8069 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8070 if (!ioc
->is_warpdrive
)
8071 _scsih_sas_pd_delete(ioc
, element
);
8078 * _scsih_sas_ir_volume_event - IR volume event
8079 * @ioc: per adapter object
8080 * @fw_event: The fw_event_work object
8086 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
8087 struct fw_event_work
*fw_event
)
8090 unsigned long flags
;
8091 struct _raid_device
*raid_device
;
8095 Mpi2EventDataIrVolume_t
*event_data
=
8096 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
8098 if (ioc
->shost_recovery
)
8101 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
8104 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8105 state
= le32_to_cpu(event_data
->NewValue
);
8106 if (!ioc
->hide_ir_msg
)
8107 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8108 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8109 ioc
->name
, __func__
, handle
,
8110 le32_to_cpu(event_data
->PreviousValue
), state
));
8112 case MPI2_RAID_VOL_STATE_MISSING
:
8113 case MPI2_RAID_VOL_STATE_FAILED
:
8114 _scsih_sas_volume_delete(ioc
, handle
);
8117 case MPI2_RAID_VOL_STATE_ONLINE
:
8118 case MPI2_RAID_VOL_STATE_DEGRADED
:
8119 case MPI2_RAID_VOL_STATE_OPTIMAL
:
8121 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8122 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8123 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8128 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
8131 "failure at %s:%d/%s()!\n", ioc
->name
,
8132 __FILE__
, __LINE__
, __func__
);
8136 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
8139 "failure at %s:%d/%s()!\n", ioc
->name
,
8140 __FILE__
, __LINE__
, __func__
);
8144 raid_device
->id
= ioc
->sas_id
++;
8145 raid_device
->channel
= RAID_CHANNEL
;
8146 raid_device
->handle
= handle
;
8147 raid_device
->wwid
= wwid
;
8148 _scsih_raid_device_add(ioc
, raid_device
);
8149 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8150 raid_device
->id
, 0);
8152 _scsih_raid_device_remove(ioc
, raid_device
);
8155 case MPI2_RAID_VOL_STATE_INITIALIZING
:
8162 * _scsih_sas_ir_physical_disk_event - PD event
8163 * @ioc: per adapter object
8164 * @fw_event: The fw_event_work object
8170 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
8171 struct fw_event_work
*fw_event
)
8173 u16 handle
, parent_handle
;
8175 struct _sas_device
*sas_device
;
8176 Mpi2ConfigReply_t mpi_reply
;
8177 Mpi2SasDevicePage0_t sas_device_pg0
;
8179 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
8180 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
8183 if (ioc
->shost_recovery
)
8186 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
8189 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
8190 state
= le32_to_cpu(event_data
->NewValue
);
8192 if (!ioc
->hide_ir_msg
)
8193 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8194 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8195 ioc
->name
, __func__
, handle
,
8196 le32_to_cpu(event_data
->PreviousValue
), state
));
8199 case MPI2_RAID_PD_STATE_ONLINE
:
8200 case MPI2_RAID_PD_STATE_DEGRADED
:
8201 case MPI2_RAID_PD_STATE_REBUILDING
:
8202 case MPI2_RAID_PD_STATE_OPTIMAL
:
8203 case MPI2_RAID_PD_STATE_HOT_SPARE
:
8205 if (!ioc
->is_warpdrive
)
8206 set_bit(handle
, ioc
->pd_handles
);
8208 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8210 sas_device_put(sas_device
);
8214 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8215 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
8217 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8218 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8222 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8223 MPI2_IOCSTATUS_MASK
;
8224 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8225 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8226 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8230 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8231 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
8232 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
8233 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
8235 _scsih_add_device(ioc
, handle
, 0, 1);
8239 case MPI2_RAID_PD_STATE_OFFLINE
:
8240 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
8241 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
8248 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8249 * @ioc: per adapter object
8250 * @event_data: event data payload
8256 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8257 Mpi2EventDataIrOperationStatus_t
*event_data
)
8259 char *reason_str
= NULL
;
8261 switch (event_data
->RAIDOperation
) {
8262 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
8263 reason_str
= "resync";
8265 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
8266 reason_str
= "online capacity expansion";
8268 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
8269 reason_str
= "consistency check";
8271 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
8272 reason_str
= "background init";
8274 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
8275 reason_str
= "make data consistent";
8282 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
8283 "\thandle(0x%04x), percent complete(%d)\n",
8284 ioc
->name
, reason_str
,
8285 le16_to_cpu(event_data
->VolDevHandle
),
8286 event_data
->PercentComplete
);
8290 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8291 * @ioc: per adapter object
8292 * @fw_event: The fw_event_work object
8298 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
8299 struct fw_event_work
*fw_event
)
8301 Mpi2EventDataIrOperationStatus_t
*event_data
=
8302 (Mpi2EventDataIrOperationStatus_t
*)
8303 fw_event
->event_data
;
8304 static struct _raid_device
*raid_device
;
8305 unsigned long flags
;
8308 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8309 (!ioc
->hide_ir_msg
))
8310 _scsih_sas_ir_operation_status_event_debug(ioc
,
8313 /* code added for raid transport support */
8314 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
8316 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8317 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8318 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8320 raid_device
->percent_complete
=
8321 event_data
->PercentComplete
;
8322 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8327 * _scsih_prep_device_scan - initialize parameters prior to device scan
8328 * @ioc: per adapter object
8330 * Set the deleted flag prior to device scan. If the device is found during
8331 * the scan, then we clear the deleted flag.
8334 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
8336 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
8337 struct scsi_device
*sdev
;
8339 shost_for_each_device(sdev
, ioc
->shost
) {
8340 sas_device_priv_data
= sdev
->hostdata
;
8341 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
8342 sas_device_priv_data
->sas_target
->deleted
= 1;
8347 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8348 * @ioc: per adapter object
8349 * @sas_device_pg0: SAS Device page 0
8351 * After host reset, find out whether devices are still responding.
8352 * Used in _scsih_remove_unresponsive_sas_devices.
8357 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
8358 Mpi2SasDevicePage0_t
*sas_device_pg0
)
8360 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8361 struct scsi_target
*starget
;
8362 struct _sas_device
*sas_device
= NULL
;
8363 unsigned long flags
;
8365 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8366 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
8367 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
8368 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
8369 sas_device
->responding
= 1;
8370 starget
= sas_device
->starget
;
8371 if (starget
&& starget
->hostdata
) {
8372 sas_target_priv_data
= starget
->hostdata
;
8373 sas_target_priv_data
->tm_busy
= 0;
8374 sas_target_priv_data
->deleted
= 0;
8376 sas_target_priv_data
= NULL
;
8378 starget_printk(KERN_INFO
, starget
,
8379 "handle(0x%04x), sas_addr(0x%016llx)\n",
8380 sas_device_pg0
->DevHandle
,
8381 (unsigned long long)
8382 sas_device
->sas_address
);
8384 if (sas_device
->enclosure_handle
!= 0)
8385 starget_printk(KERN_INFO
, starget
,
8386 "enclosure logical id(0x%016llx),"
8388 (unsigned long long)
8389 sas_device
->enclosure_logical_id
,
8392 if (sas_device_pg0
->Flags
&
8393 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
8394 sas_device
->enclosure_level
=
8395 sas_device_pg0
->EnclosureLevel
;
8396 memcpy(&sas_device
->connector_name
[0],
8397 &sas_device_pg0
->ConnectorName
[0], 4);
8399 sas_device
->enclosure_level
= 0;
8400 sas_device
->connector_name
[0] = '\0';
8403 _scsih_get_enclosure_logicalid_chassis_slot(ioc
,
8404 sas_device_pg0
, sas_device
);
8406 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
8408 pr_info("\thandle changed from(0x%04x)!!!\n",
8409 sas_device
->handle
);
8410 sas_device
->handle
= sas_device_pg0
->DevHandle
;
8411 if (sas_target_priv_data
)
8412 sas_target_priv_data
->handle
=
8413 sas_device_pg0
->DevHandle
;
8418 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8422 * _scsih_search_responding_sas_devices -
8423 * @ioc: per adapter object
8425 * After host reset, find out whether devices are still responding.
8431 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
8433 Mpi2SasDevicePage0_t sas_device_pg0
;
8434 Mpi2ConfigReply_t mpi_reply
;
8439 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
8441 if (list_empty(&ioc
->sas_device_list
))
8445 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8446 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8448 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8449 MPI2_IOCSTATUS_MASK
;
8450 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8452 handle
= sas_device_pg0
.DevHandle
=
8453 le16_to_cpu(sas_device_pg0
.DevHandle
);
8454 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
8455 if (!(_scsih_is_end_device(device_info
)))
8457 sas_device_pg0
.SASAddress
=
8458 le64_to_cpu(sas_device_pg0
.SASAddress
);
8459 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
8460 sas_device_pg0
.Flags
= le16_to_cpu(sas_device_pg0
.Flags
);
8461 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
8465 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
8470 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8471 * @ioc: per adapter object
8472 * @pcie_device_pg0: PCIe Device page 0
8474 * After host reset, find out whether devices are still responding.
8475 * Used in _scsih_remove_unresponding_devices.
8480 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER
*ioc
,
8481 Mpi26PCIeDevicePage0_t
*pcie_device_pg0
)
8483 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8484 struct scsi_target
*starget
;
8485 struct _pcie_device
*pcie_device
;
8486 unsigned long flags
;
8488 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8489 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
) {
8490 if ((pcie_device
->wwid
== pcie_device_pg0
->WWID
) &&
8491 (pcie_device
->slot
== pcie_device_pg0
->Slot
)) {
8492 pcie_device
->responding
= 1;
8493 starget
= pcie_device
->starget
;
8494 if (starget
&& starget
->hostdata
) {
8495 sas_target_priv_data
= starget
->hostdata
;
8496 sas_target_priv_data
->tm_busy
= 0;
8497 sas_target_priv_data
->deleted
= 0;
8499 sas_target_priv_data
= NULL
;
8501 starget_printk(KERN_INFO
, starget
,
8502 "handle(0x%04x), wwid(0x%016llx) ",
8503 pcie_device
->handle
,
8504 (unsigned long long)pcie_device
->wwid
);
8505 if (pcie_device
->enclosure_handle
!= 0)
8506 starget_printk(KERN_INFO
, starget
,
8507 "enclosure logical id(0x%016llx), "
8509 (unsigned long long)
8510 pcie_device
->enclosure_logical_id
,
8514 if (((le32_to_cpu(pcie_device_pg0
->Flags
)) &
8515 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) &&
8516 (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
)) {
8517 pcie_device
->enclosure_level
=
8518 pcie_device_pg0
->EnclosureLevel
;
8519 memcpy(&pcie_device
->connector_name
[0],
8520 &pcie_device_pg0
->ConnectorName
[0], 4);
8522 pcie_device
->enclosure_level
= 0;
8523 pcie_device
->connector_name
[0] = '\0';
8526 if (pcie_device
->handle
== pcie_device_pg0
->DevHandle
)
8528 pr_info("\thandle changed from(0x%04x)!!!\n",
8529 pcie_device
->handle
);
8530 pcie_device
->handle
= pcie_device_pg0
->DevHandle
;
8531 if (sas_target_priv_data
)
8532 sas_target_priv_data
->handle
=
8533 pcie_device_pg0
->DevHandle
;
8539 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8543 * _scsih_search_responding_pcie_devices -
8544 * @ioc: per adapter object
8546 * After host reset, find out whether devices are still responding.
8552 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER
*ioc
)
8554 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
8555 Mpi2ConfigReply_t mpi_reply
;
8560 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
8562 if (list_empty(&ioc
->pcie_device_list
))
8566 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
8567 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8569 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8570 MPI2_IOCSTATUS_MASK
;
8571 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8572 pr_info(MPT3SAS_FMT
"\tbreak from %s: "
8573 "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
8574 __func__
, ioc_status
,
8575 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8578 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
8579 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
8580 if (!(_scsih_is_nvme_device(device_info
)))
8582 pcie_device_pg0
.WWID
= le64_to_cpu(pcie_device_pg0
.WWID
),
8583 pcie_device_pg0
.Slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
8584 pcie_device_pg0
.Flags
= le32_to_cpu(pcie_device_pg0
.Flags
);
8585 pcie_device_pg0
.DevHandle
= handle
;
8586 _scsih_mark_responding_pcie_device(ioc
, &pcie_device_pg0
);
8589 pr_info(MPT3SAS_FMT
"search for PCIe end-devices: complete\n",
8594 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8595 * @ioc: per adapter object
8596 * @wwid: world wide identifier for raid volume
8597 * @handle: device handle
8599 * After host reset, find out whether devices are still responding.
8600 * Used in _scsih_remove_unresponsive_raid_devices.
8605 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
8608 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8609 struct scsi_target
*starget
;
8610 struct _raid_device
*raid_device
;
8611 unsigned long flags
;
8613 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8614 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
8615 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
8616 starget
= raid_device
->starget
;
8617 if (starget
&& starget
->hostdata
) {
8618 sas_target_priv_data
= starget
->hostdata
;
8619 sas_target_priv_data
->deleted
= 0;
8621 sas_target_priv_data
= NULL
;
8622 raid_device
->responding
= 1;
8623 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8624 starget_printk(KERN_INFO
, raid_device
->starget
,
8625 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
8626 (unsigned long long)raid_device
->wwid
);
8629 * WARPDRIVE: The handles of the PDs might have changed
8630 * across the host reset so re-initialize the
8631 * required data for Direct IO
8633 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
8634 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8635 if (raid_device
->handle
== handle
) {
8636 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
8640 pr_info("\thandle changed from(0x%04x)!!!\n",
8641 raid_device
->handle
);
8642 raid_device
->handle
= handle
;
8643 if (sas_target_priv_data
)
8644 sas_target_priv_data
->handle
= handle
;
8645 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8649 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8653 * _scsih_search_responding_raid_devices -
8654 * @ioc: per adapter object
8656 * After host reset, find out whether devices are still responding.
8662 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
8664 Mpi2RaidVolPage1_t volume_pg1
;
8665 Mpi2RaidVolPage0_t volume_pg0
;
8666 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8667 Mpi2ConfigReply_t mpi_reply
;
8672 if (!ioc
->ir_firmware
)
8675 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
8678 if (list_empty(&ioc
->raid_device_list
))
8682 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
8683 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
8684 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8685 MPI2_IOCSTATUS_MASK
;
8686 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8688 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
8690 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
8691 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
8692 sizeof(Mpi2RaidVolPage0_t
)))
8695 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
8696 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
8697 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
8698 _scsih_mark_responding_raid_device(ioc
,
8699 le64_to_cpu(volume_pg1
.WWID
), handle
);
8702 /* refresh the pd_handles */
8703 if (!ioc
->is_warpdrive
) {
8704 phys_disk_num
= 0xFF;
8705 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
8706 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
8707 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
8709 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8710 MPI2_IOCSTATUS_MASK
;
8711 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8713 phys_disk_num
= pd_pg0
.PhysDiskNum
;
8714 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
8715 set_bit(handle
, ioc
->pd_handles
);
8719 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
8724 * _scsih_mark_responding_expander - mark a expander as responding
8725 * @ioc: per adapter object
8726 * @expander_pg0:SAS Expander Config Page0
8728 * After host reset, find out whether devices are still responding.
8729 * Used in _scsih_remove_unresponsive_expanders.
8734 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
,
8735 Mpi2ExpanderPage0_t
*expander_pg0
)
8737 struct _sas_node
*sas_expander
= NULL
;
8738 unsigned long flags
;
8739 int i
, encl_pg0_rc
= -1;
8740 Mpi2ConfigReply_t mpi_reply
;
8741 Mpi2SasEnclosurePage0_t enclosure_pg0
;
8742 u16 handle
= le16_to_cpu(expander_pg0
->DevHandle
);
8743 u64 sas_address
= le64_to_cpu(expander_pg0
->SASAddress
);
8745 if (le16_to_cpu(expander_pg0
->EnclosureHandle
)) {
8746 encl_pg0_rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
8747 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
8748 le16_to_cpu(expander_pg0
->EnclosureHandle
));
8751 "Enclosure Pg0 read failed for handle(0x%04x)\n",
8753 le16_to_cpu(expander_pg0
->EnclosureHandle
));
8756 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8757 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
8758 if (sas_expander
->sas_address
!= sas_address
)
8760 sas_expander
->responding
= 1;
8763 sas_expander
->enclosure_logical_id
=
8764 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
8766 sas_expander
->enclosure_handle
=
8767 le16_to_cpu(expander_pg0
->EnclosureHandle
);
8769 if (sas_expander
->handle
== handle
)
8771 pr_info("\texpander(0x%016llx): handle changed" \
8772 " from(0x%04x) to (0x%04x)!!!\n",
8773 (unsigned long long)sas_expander
->sas_address
,
8774 sas_expander
->handle
, handle
);
8775 sas_expander
->handle
= handle
;
8776 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
8777 sas_expander
->phy
[i
].handle
= handle
;
8781 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8785 * _scsih_search_responding_expanders -
8786 * @ioc: per adapter object
8788 * After host reset, find out whether devices are still responding.
8794 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
8796 Mpi2ExpanderPage0_t expander_pg0
;
8797 Mpi2ConfigReply_t mpi_reply
;
8802 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
8804 if (list_empty(&ioc
->sas_expander_list
))
8808 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8809 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8811 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8812 MPI2_IOCSTATUS_MASK
;
8813 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8816 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
8817 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
8818 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8820 (unsigned long long)sas_address
);
8821 _scsih_mark_responding_expander(ioc
, &expander_pg0
);
8825 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
8829 * _scsih_remove_unresponding_devices - removing unresponding devices
8830 * @ioc: per adapter object
8835 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER
*ioc
)
8837 struct _sas_device
*sas_device
, *sas_device_next
;
8838 struct _sas_node
*sas_expander
, *sas_expander_next
;
8839 struct _raid_device
*raid_device
, *raid_device_next
;
8840 struct _pcie_device
*pcie_device
, *pcie_device_next
;
8841 struct list_head tmp_list
;
8842 unsigned long flags
;
8845 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
8848 /* removing unresponding end devices */
8849 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
8852 * Iterate, pulling off devices marked as non-responding. We become the
8853 * owner for the reference the list had on any object we prune.
8855 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8856 list_for_each_entry_safe(sas_device
, sas_device_next
,
8857 &ioc
->sas_device_list
, list
) {
8858 if (!sas_device
->responding
)
8859 list_move_tail(&sas_device
->list
, &head
);
8861 sas_device
->responding
= 0;
8863 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8866 * Now, uninitialize and remove the unresponding devices we pruned.
8868 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
8869 _scsih_remove_device(ioc
, sas_device
);
8870 list_del_init(&sas_device
->list
);
8871 sas_device_put(sas_device
);
8875 " Removing unresponding devices: pcie end-devices\n"
8877 INIT_LIST_HEAD(&head
);
8878 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8879 list_for_each_entry_safe(pcie_device
, pcie_device_next
,
8880 &ioc
->pcie_device_list
, list
) {
8881 if (!pcie_device
->responding
)
8882 list_move_tail(&pcie_device
->list
, &head
);
8884 pcie_device
->responding
= 0;
8886 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8888 list_for_each_entry_safe(pcie_device
, pcie_device_next
, &head
, list
) {
8889 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
8890 list_del_init(&pcie_device
->list
);
8891 pcie_device_put(pcie_device
);
8894 /* removing unresponding volumes */
8895 if (ioc
->ir_firmware
) {
8896 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
8898 list_for_each_entry_safe(raid_device
, raid_device_next
,
8899 &ioc
->raid_device_list
, list
) {
8900 if (!raid_device
->responding
)
8901 _scsih_sas_volume_delete(ioc
,
8902 raid_device
->handle
);
8904 raid_device
->responding
= 0;
8908 /* removing unresponding expanders */
8909 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
8911 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8912 INIT_LIST_HEAD(&tmp_list
);
8913 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
8914 &ioc
->sas_expander_list
, list
) {
8915 if (!sas_expander
->responding
)
8916 list_move_tail(&sas_expander
->list
, &tmp_list
);
8918 sas_expander
->responding
= 0;
8920 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8921 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
8923 _scsih_expander_node_remove(ioc
, sas_expander
);
8926 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
8929 /* unblock devices */
8930 _scsih_ublock_io_all_device(ioc
);
8934 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
8935 struct _sas_node
*sas_expander
, u16 handle
)
8937 Mpi2ExpanderPage1_t expander_pg1
;
8938 Mpi2ConfigReply_t mpi_reply
;
8941 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
8942 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
8943 &expander_pg1
, i
, handle
))) {
8944 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8945 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8949 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
8950 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
8951 expander_pg1
.NegotiatedLinkRate
>> 4);
8956 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
8957 * @ioc: per adapter object
8962 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
8964 Mpi2ExpanderPage0_t expander_pg0
;
8965 Mpi2SasDevicePage0_t sas_device_pg0
;
8966 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
8967 Mpi2RaidVolPage1_t volume_pg1
;
8968 Mpi2RaidVolPage0_t volume_pg0
;
8969 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8970 Mpi2EventIrConfigElement_t element
;
8971 Mpi2ConfigReply_t mpi_reply
;
8974 u16 handle
, parent_handle
;
8976 struct _sas_device
*sas_device
;
8977 struct _pcie_device
*pcie_device
;
8978 struct _sas_node
*expander_device
;
8979 static struct _raid_device
*raid_device
;
8981 unsigned long flags
;
8983 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
8985 _scsih_sas_host_refresh(ioc
);
8987 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
8991 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8992 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8993 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8994 MPI2_IOCSTATUS_MASK
;
8995 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8996 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
8997 "ioc_status(0x%04x), loginfo(0x%08x)\n",
8998 ioc
->name
, ioc_status
,
8999 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9002 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
9003 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9004 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
9005 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
9006 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9007 if (expander_device
)
9008 _scsih_refresh_expander_links(ioc
, expander_device
,
9011 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
9012 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9013 handle
, (unsigned long long)
9014 le64_to_cpu(expander_pg0
.SASAddress
));
9015 _scsih_expander_add(ioc
, handle
);
9016 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
9017 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9018 handle
, (unsigned long long)
9019 le64_to_cpu(expander_pg0
.SASAddress
));
9023 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
9026 if (!ioc
->ir_firmware
)
9029 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
9032 phys_disk_num
= 0xFF;
9033 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
9034 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
9036 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9037 MPI2_IOCSTATUS_MASK
;
9038 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9039 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
9040 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9041 ioc
->name
, ioc_status
,
9042 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9045 phys_disk_num
= pd_pg0
.PhysDiskNum
;
9046 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
9047 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
9049 sas_device_put(sas_device
);
9052 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9053 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
9056 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9057 MPI2_IOCSTATUS_MASK
;
9058 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9059 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
9060 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9061 ioc
->name
, ioc_status
,
9062 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9065 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9066 if (!_scsih_get_sas_address(ioc
, parent_handle
,
9068 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
9069 " handle (0x%04x), sas_addr(0x%016llx)\n",
9070 ioc
->name
, handle
, (unsigned long long)
9071 le64_to_cpu(sas_device_pg0
.SASAddress
));
9072 mpt3sas_transport_update_links(ioc
, sas_address
,
9073 handle
, sas_device_pg0
.PhyNum
,
9074 MPI2_SAS_NEG_LINK_RATE_1_5
);
9075 set_bit(handle
, ioc
->pd_handles
);
9077 /* This will retry adding the end device.
9078 * _scsih_add_device() will decide on retries and
9079 * return "1" when it should be retried
9081 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9085 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
9086 " handle (0x%04x), sas_addr(0x%016llx)\n",
9087 ioc
->name
, handle
, (unsigned long long)
9088 le64_to_cpu(sas_device_pg0
.SASAddress
));
9092 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
9095 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
9099 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
9100 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
9101 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9102 MPI2_IOCSTATUS_MASK
;
9103 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9104 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9105 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9106 ioc
->name
, ioc_status
,
9107 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9110 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
9111 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
9112 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
9113 le64_to_cpu(volume_pg1
.WWID
));
9114 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
9117 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
9118 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
9119 sizeof(Mpi2RaidVolPage0_t
)))
9121 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9122 MPI2_IOCSTATUS_MASK
;
9123 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9124 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9125 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9126 ioc
->name
, ioc_status
,
9127 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9130 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
9131 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
9132 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
9133 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
9134 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
9135 element
.VolDevHandle
= volume_pg1
.DevHandle
;
9137 "\tBEFORE adding volume: handle (0x%04x)\n",
9138 ioc
->name
, volume_pg1
.DevHandle
);
9139 _scsih_sas_volume_add(ioc
, &element
);
9141 "\tAFTER adding volume: handle (0x%04x)\n",
9142 ioc
->name
, volume_pg1
.DevHandle
);
9146 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
9151 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
9156 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9157 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9159 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9160 MPI2_IOCSTATUS_MASK
;
9161 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9162 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
9163 " ioc_status(0x%04x), loginfo(0x%08x)\n",
9164 ioc
->name
, ioc_status
,
9165 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9168 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
9169 if (!(_scsih_is_end_device(
9170 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
9172 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
9173 le64_to_cpu(sas_device_pg0
.SASAddress
));
9175 sas_device_put(sas_device
);
9178 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9179 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
9180 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
9181 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9182 handle
, (unsigned long long)
9183 le64_to_cpu(sas_device_pg0
.SASAddress
));
9184 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
9185 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
9187 /* This will retry adding the end device.
9188 * _scsih_add_device() will decide on retries and
9189 * return "1" when it should be retried
9191 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9195 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
9196 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9197 handle
, (unsigned long long)
9198 le64_to_cpu(sas_device_pg0
.SASAddress
));
9201 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
9203 pr_info(MPT3SAS_FMT
"\tscan devices: pcie end devices start\n",
9208 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
9209 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9211 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
)
9212 & MPI2_IOCSTATUS_MASK
;
9213 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9214 pr_info(MPT3SAS_FMT
"\tbreak from pcie end device"
9215 " scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9216 ioc
->name
, ioc_status
,
9217 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9220 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
9221 if (!(_scsih_is_nvme_device(
9222 le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
9224 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
,
9225 le64_to_cpu(pcie_device_pg0
.WWID
));
9227 pcie_device_put(pcie_device
);
9231 parent_handle
= le16_to_cpu(pcie_device_pg0
.ParentDevHandle
);
9232 _scsih_pcie_add_device(ioc
, handle
);
9234 pr_info(MPT3SAS_FMT
"\tAFTER adding pcie end device: "
9235 "handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
,
9237 (unsigned long long) le64_to_cpu(pcie_device_pg0
.WWID
));
9239 pr_info(MPT3SAS_FMT
"\tpcie devices: pcie end devices complete\n",
9241 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
9244 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9245 * @ioc: per adapter object
9246 * @reset_phase: phase
9248 * The handler for doing any required cleanup or initialization.
9250 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
9251 * MPT3_IOC_DONE_RESET
9256 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
9258 switch (reset_phase
) {
9259 case MPT3_IOC_PRE_RESET
:
9260 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9261 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
9263 case MPT3_IOC_AFTER_RESET
:
9264 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9265 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
9266 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
9267 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
9268 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
9269 complete(&ioc
->scsih_cmds
.done
);
9271 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
9272 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
9273 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
9274 complete(&ioc
->tm_cmds
.done
);
9277 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
9278 memset(ioc
->device_remove_in_progress
, 0,
9279 ioc
->device_remove_in_progress_sz
);
9280 _scsih_fw_event_cleanup_queue(ioc
);
9281 _scsih_flush_running_cmds(ioc
);
9283 case MPT3_IOC_DONE_RESET
:
9284 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9285 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
9286 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
9287 !ioc
->sas_hba
.num_phys
)) {
9288 _scsih_prep_device_scan(ioc
);
9289 _scsih_search_responding_sas_devices(ioc
);
9290 _scsih_search_responding_pcie_devices(ioc
);
9291 _scsih_search_responding_raid_devices(ioc
);
9292 _scsih_search_responding_expanders(ioc
);
9293 _scsih_error_recovery_delete_devices(ioc
);
9300 * _mpt3sas_fw_work - delayed task for processing firmware events
9301 * @ioc: per adapter object
9302 * @fw_event: The fw_event_work object
9308 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
9310 _scsih_fw_event_del_from_list(ioc
, fw_event
);
9312 /* the queue is being flushed so ignore this event */
9313 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
9314 fw_event_work_put(fw_event
);
9318 switch (fw_event
->event
) {
9319 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
9320 mpt3sas_process_trigger_data(ioc
,
9321 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
9322 fw_event
->event_data
);
9324 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
9325 while (scsi_host_in_recovery(ioc
->shost
) ||
9326 ioc
->shost_recovery
) {
9328 * If we're unloading, bail. Otherwise, this can become
9331 if (ioc
->remove_host
)
9335 _scsih_remove_unresponding_devices(ioc
);
9336 _scsih_scan_for_devices_after_reset(ioc
);
9338 case MPT3SAS_PORT_ENABLE_COMPLETE
:
9339 ioc
->start_scan
= 0;
9340 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
9341 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
9343 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
9344 "port enable: complete from worker thread\n",
9347 case MPT3SAS_TURN_ON_PFA_LED
:
9348 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
9350 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9351 _scsih_sas_topology_change_event(ioc
, fw_event
);
9353 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9354 _scsih_sas_device_status_change_event(ioc
, fw_event
);
9356 case MPI2_EVENT_SAS_DISCOVERY
:
9357 _scsih_sas_discovery_event(ioc
, fw_event
);
9359 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9360 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
9362 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9363 _scsih_sas_enclosure_dev_status_change_event(ioc
,
9366 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9367 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
9369 case MPI2_EVENT_IR_VOLUME
:
9370 _scsih_sas_ir_volume_event(ioc
, fw_event
);
9372 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9373 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
9375 case MPI2_EVENT_IR_OPERATION_STATUS
:
9376 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
9378 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9379 _scsih_pcie_device_status_change_event(ioc
, fw_event
);
9381 case MPI2_EVENT_PCIE_ENUMERATION
:
9382 _scsih_pcie_enumeration_event(ioc
, fw_event
);
9384 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9385 _scsih_pcie_topology_change_event(ioc
, fw_event
);
9390 fw_event_work_put(fw_event
);
9394 * _firmware_event_work
9395 * @ioc: per adapter object
9396 * @work: The fw_event_work object
9399 * wrappers for the work thread handling firmware events
9405 _firmware_event_work(struct work_struct
*work
)
9407 struct fw_event_work
*fw_event
= container_of(work
,
9408 struct fw_event_work
, work
);
9410 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
9414 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9415 * @ioc: per adapter object
9416 * @msix_index: MSIX table index supplied by the OS
9417 * @reply: reply message frame(lower 32bit addr)
9418 * Context: interrupt.
9420 * This function merely adds a new work task into ioc->firmware_event_thread.
9421 * The tasks are worked from _firmware_event_work in user context.
9423 * Return 1 meaning mf should be freed from _base_interrupt
9424 * 0 means the mf is freed from this function.
9427 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
9430 struct fw_event_work
*fw_event
;
9431 Mpi2EventNotificationReply_t
*mpi_reply
;
9434 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
9436 /* events turned off due to host reset or driver unloading */
9437 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
9440 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
9442 if (unlikely(!mpi_reply
)) {
9443 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
9444 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9448 event
= le16_to_cpu(mpi_reply
->Event
);
9450 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
9451 mpt3sas_trigger_event(ioc
, event
, 0);
9455 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9457 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
9458 (Mpi2EventDataSasBroadcastPrimitive_t
*)
9459 mpi_reply
->EventData
;
9461 if (baen_data
->Primitive
!=
9462 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
9465 if (ioc
->broadcast_aen_busy
) {
9466 ioc
->broadcast_aen_pending
++;
9469 ioc
->broadcast_aen_busy
= 1;
9473 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9474 _scsih_check_topo_delete_events(ioc
,
9475 (Mpi2EventDataSasTopologyChangeList_t
*)
9476 mpi_reply
->EventData
);
9478 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9479 _scsih_check_pcie_topo_remove_events(ioc
,
9480 (Mpi26EventDataPCIeTopologyChangeList_t
*)
9481 mpi_reply
->EventData
);
9483 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9484 _scsih_check_ir_config_unhide_events(ioc
,
9485 (Mpi2EventDataIrConfigChangeList_t
*)
9486 mpi_reply
->EventData
);
9488 case MPI2_EVENT_IR_VOLUME
:
9489 _scsih_check_volume_delete_events(ioc
,
9490 (Mpi2EventDataIrVolume_t
*)
9491 mpi_reply
->EventData
);
9493 case MPI2_EVENT_LOG_ENTRY_ADDED
:
9495 Mpi2EventDataLogEntryAdded_t
*log_entry
;
9498 if (!ioc
->is_warpdrive
)
9501 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
9502 mpi_reply
->EventData
;
9503 log_code
= (u32
*)log_entry
->LogData
;
9505 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
9506 != MPT2_WARPDRIVE_LOGENTRY
)
9509 switch (le32_to_cpu(*log_code
)) {
9510 case MPT2_WARPDRIVE_LC_SSDT
:
9511 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9512 "IO Throttling has occurred in the WarpDrive "
9513 "subsystem. Check WarpDrive documentation for "
9514 "additional details.\n", ioc
->name
);
9516 case MPT2_WARPDRIVE_LC_SSDLW
:
9517 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9518 "Program/Erase Cycles for the WarpDrive subsystem "
9519 "in degraded range. Check WarpDrive documentation "
9520 "for additional details.\n", ioc
->name
);
9522 case MPT2_WARPDRIVE_LC_SSDLF
:
9523 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9524 "There are no Program/Erase Cycles for the "
9525 "WarpDrive subsystem. The storage device will be "
9526 "in read-only mode. Check WarpDrive documentation "
9527 "for additional details.\n", ioc
->name
);
9529 case MPT2_WARPDRIVE_LC_BRMF
:
9530 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9531 "The Backup Rail Monitor has failed on the "
9532 "WarpDrive subsystem. Check WarpDrive "
9533 "documentation for additional details.\n",
9540 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9541 case MPI2_EVENT_IR_OPERATION_STATUS
:
9542 case MPI2_EVENT_SAS_DISCOVERY
:
9543 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9544 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9545 case MPI2_EVENT_PCIE_ENUMERATION
:
9546 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9549 case MPI2_EVENT_TEMP_THRESHOLD
:
9550 _scsih_temp_threshold_events(ioc
,
9551 (Mpi2EventDataTemperature_t
*)
9552 mpi_reply
->EventData
);
9554 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
9555 ActiveCableEventData
=
9556 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
9557 switch (ActiveCableEventData
->ReasonCode
) {
9558 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
9559 pr_notice(MPT3SAS_FMT
9560 "Currently an active cable with ReceptacleID %d\n",
9561 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9562 pr_notice("cannot be powered and devices connected\n");
9563 pr_notice("to this active cable will not be seen\n");
9564 pr_notice("This active cable requires %d mW of power\n",
9565 ActiveCableEventData
->ActiveCablePowerRequirement
);
9568 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
9569 pr_notice(MPT3SAS_FMT
9570 "Currently a cable with ReceptacleID %d\n",
9571 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9573 "is not running at optimal speed(12 Gb/s rate)\n");
9579 default: /* ignore the rest */
9583 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
9584 fw_event
= alloc_fw_event_work(sz
);
9586 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
9587 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9591 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
9592 fw_event
->ioc
= ioc
;
9593 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
9594 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
9595 fw_event
->event
= event
;
9596 _scsih_fw_event_add(ioc
, fw_event
);
9597 fw_event_work_put(fw_event
);
9602 * _scsih_expander_node_remove - removing expander device from list.
9603 * @ioc: per adapter object
9604 * @sas_expander: the sas_device object
9606 * Removing object and freeing associated memory from the
9607 * ioc->sas_expander_list.
9612 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
9613 struct _sas_node
*sas_expander
)
9615 struct _sas_port
*mpt3sas_port
, *next
;
9616 unsigned long flags
;
9618 /* remove sibling ports attached to this expander */
9619 list_for_each_entry_safe(mpt3sas_port
, next
,
9620 &sas_expander
->sas_port_list
, port_list
) {
9621 if (ioc
->shost_recovery
)
9623 if (mpt3sas_port
->remote_identify
.device_type
==
9625 mpt3sas_device_remove_by_sas_address(ioc
,
9626 mpt3sas_port
->remote_identify
.sas_address
);
9627 else if (mpt3sas_port
->remote_identify
.device_type
==
9628 SAS_EDGE_EXPANDER_DEVICE
||
9629 mpt3sas_port
->remote_identify
.device_type
==
9630 SAS_FANOUT_EXPANDER_DEVICE
)
9631 mpt3sas_expander_remove(ioc
,
9632 mpt3sas_port
->remote_identify
.sas_address
);
9635 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
9636 sas_expander
->sas_address_parent
);
9639 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9641 sas_expander
->handle
, (unsigned long long)
9642 sas_expander
->sas_address
);
9644 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9645 list_del(&sas_expander
->list
);
9646 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9648 kfree(sas_expander
->phy
);
9649 kfree(sas_expander
);
9653 * _scsih_ir_shutdown - IR shutdown notification
9654 * @ioc: per adapter object
9656 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9657 * the host system is shutting down.
9662 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
9664 Mpi2RaidActionRequest_t
*mpi_request
;
9665 Mpi2RaidActionReply_t
*mpi_reply
;
9668 /* is IR firmware build loaded ? */
9669 if (!ioc
->ir_firmware
)
9672 /* are there any volumes ? */
9673 if (list_empty(&ioc
->raid_device_list
))
9676 mutex_lock(&ioc
->scsih_cmds
.mutex
);
9678 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
9679 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
9680 ioc
->name
, __func__
);
9683 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
9685 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
9687 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
9688 ioc
->name
, __func__
);
9689 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9693 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
9694 ioc
->scsih_cmds
.smid
= smid
;
9695 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
9697 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
9698 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
9700 if (!ioc
->hide_ir_msg
)
9701 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
9702 init_completion(&ioc
->scsih_cmds
.done
);
9703 ioc
->put_smid_default(ioc
, smid
);
9704 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
9706 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
9707 pr_err(MPT3SAS_FMT
"%s: timeout\n",
9708 ioc
->name
, __func__
);
9712 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
9713 mpi_reply
= ioc
->scsih_cmds
.reply
;
9714 if (!ioc
->hide_ir_msg
)
9715 pr_info(MPT3SAS_FMT
"IR shutdown "
9716 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9717 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
9718 le32_to_cpu(mpi_reply
->IOCLogInfo
));
9722 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9723 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
9727 * scsih_remove - detach and remove add host
9728 * @pdev: PCI device struct
9730 * Routine called when unloading the driver.
9733 static void scsih_remove(struct pci_dev
*pdev
)
9735 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9736 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9737 struct _sas_port
*mpt3sas_port
, *next_port
;
9738 struct _raid_device
*raid_device
, *next
;
9739 struct MPT3SAS_TARGET
*sas_target_priv_data
;
9740 struct _pcie_device
*pcie_device
, *pcienext
;
9741 struct workqueue_struct
*wq
;
9742 unsigned long flags
;
9744 ioc
->remove_host
= 1;
9746 mpt3sas_wait_for_commands_to_complete(ioc
);
9747 _scsih_flush_running_cmds(ioc
);
9749 _scsih_fw_event_cleanup_queue(ioc
);
9751 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9752 wq
= ioc
->firmware_event_thread
;
9753 ioc
->firmware_event_thread
= NULL
;
9754 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9756 destroy_workqueue(wq
);
9758 /* release all the volumes */
9759 _scsih_ir_shutdown(ioc
);
9760 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
9762 if (raid_device
->starget
) {
9763 sas_target_priv_data
=
9764 raid_device
->starget
->hostdata
;
9765 sas_target_priv_data
->deleted
= 1;
9766 scsi_remove_target(&raid_device
->starget
->dev
);
9768 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
9769 ioc
->name
, raid_device
->handle
,
9770 (unsigned long long) raid_device
->wwid
);
9771 _scsih_raid_device_remove(ioc
, raid_device
);
9773 list_for_each_entry_safe(pcie_device
, pcienext
, &ioc
->pcie_device_list
,
9775 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
9776 list_del_init(&pcie_device
->list
);
9777 pcie_device_put(pcie_device
);
9780 /* free ports attached to the sas_host */
9781 list_for_each_entry_safe(mpt3sas_port
, next_port
,
9782 &ioc
->sas_hba
.sas_port_list
, port_list
) {
9783 if (mpt3sas_port
->remote_identify
.device_type
==
9785 mpt3sas_device_remove_by_sas_address(ioc
,
9786 mpt3sas_port
->remote_identify
.sas_address
);
9787 else if (mpt3sas_port
->remote_identify
.device_type
==
9788 SAS_EDGE_EXPANDER_DEVICE
||
9789 mpt3sas_port
->remote_identify
.device_type
==
9790 SAS_FANOUT_EXPANDER_DEVICE
)
9791 mpt3sas_expander_remove(ioc
,
9792 mpt3sas_port
->remote_identify
.sas_address
);
9795 /* free phys attached to the sas_host */
9796 if (ioc
->sas_hba
.num_phys
) {
9797 kfree(ioc
->sas_hba
.phy
);
9798 ioc
->sas_hba
.phy
= NULL
;
9799 ioc
->sas_hba
.num_phys
= 0;
9802 sas_remove_host(shost
);
9803 mpt3sas_base_detach(ioc
);
9804 spin_lock(&gioc_lock
);
9805 list_del(&ioc
->list
);
9806 spin_unlock(&gioc_lock
);
9807 scsi_host_put(shost
);
9811 * scsih_shutdown - routine call during system shutdown
9812 * @pdev: PCI device struct
9817 scsih_shutdown(struct pci_dev
*pdev
)
9819 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9820 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9821 struct workqueue_struct
*wq
;
9822 unsigned long flags
;
9824 ioc
->remove_host
= 1;
9826 mpt3sas_wait_for_commands_to_complete(ioc
);
9827 _scsih_flush_running_cmds(ioc
);
9829 _scsih_fw_event_cleanup_queue(ioc
);
9831 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9832 wq
= ioc
->firmware_event_thread
;
9833 ioc
->firmware_event_thread
= NULL
;
9834 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9836 destroy_workqueue(wq
);
9838 _scsih_ir_shutdown(ioc
);
9839 mpt3sas_base_detach(ioc
);
9844 * _scsih_probe_boot_devices - reports 1st device
9845 * @ioc: per adapter object
9847 * If specified in bios page 2, this routine reports the 1st
9848 * device scsi-ml or sas transport for persistent boot device
9849 * purposes. Please refer to function _scsih_determine_boot_device()
9852 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
9856 struct _sas_device
*sas_device
;
9857 struct _raid_device
*raid_device
;
9858 struct _pcie_device
*pcie_device
;
9860 u64 sas_address_parent
;
9862 unsigned long flags
;
9866 /* no Bios, return immediately */
9867 if (!ioc
->bios_pg3
.BiosVersion
)
9871 if (ioc
->req_boot_device
.device
) {
9872 device
= ioc
->req_boot_device
.device
;
9873 channel
= ioc
->req_boot_device
.channel
;
9874 } else if (ioc
->req_alt_boot_device
.device
) {
9875 device
= ioc
->req_alt_boot_device
.device
;
9876 channel
= ioc
->req_alt_boot_device
.channel
;
9877 } else if (ioc
->current_boot_device
.device
) {
9878 device
= ioc
->current_boot_device
.device
;
9879 channel
= ioc
->current_boot_device
.channel
;
9885 if (channel
== RAID_CHANNEL
) {
9886 raid_device
= device
;
9887 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9888 raid_device
->id
, 0);
9890 _scsih_raid_device_remove(ioc
, raid_device
);
9891 } else if (channel
== PCIE_CHANNEL
) {
9892 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9893 pcie_device
= device
;
9894 tid
= pcie_device
->id
;
9895 list_move_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
9896 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9897 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, tid
, 0);
9899 _scsih_pcie_device_remove(ioc
, pcie_device
);
9901 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9902 sas_device
= device
;
9903 handle
= sas_device
->handle
;
9904 sas_address_parent
= sas_device
->sas_address_parent
;
9905 sas_address
= sas_device
->sas_address
;
9906 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
9907 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9909 if (ioc
->hide_drives
)
9911 if (!mpt3sas_transport_port_add(ioc
, handle
,
9912 sas_address_parent
)) {
9913 _scsih_sas_device_remove(ioc
, sas_device
);
9914 } else if (!sas_device
->starget
) {
9915 if (!ioc
->is_driver_loading
) {
9916 mpt3sas_transport_port_remove(ioc
,
9918 sas_address_parent
);
9919 _scsih_sas_device_remove(ioc
, sas_device
);
9926 * _scsih_probe_raid - reporting raid volumes to scsi-ml
9927 * @ioc: per adapter object
9929 * Called during initial loading of the driver.
9932 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
9934 struct _raid_device
*raid_device
, *raid_next
;
9937 list_for_each_entry_safe(raid_device
, raid_next
,
9938 &ioc
->raid_device_list
, list
) {
9939 if (raid_device
->starget
)
9941 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9942 raid_device
->id
, 0);
9944 _scsih_raid_device_remove(ioc
, raid_device
);
9948 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
9950 struct _sas_device
*sas_device
= NULL
;
9951 unsigned long flags
;
9953 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9954 if (!list_empty(&ioc
->sas_device_init_list
)) {
9955 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
9956 struct _sas_device
, list
);
9957 sas_device_get(sas_device
);
9959 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9964 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
9965 struct _sas_device
*sas_device
)
9967 unsigned long flags
;
9969 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9972 * Since we dropped the lock during the call to port_add(), we need to
9973 * be careful here that somebody else didn't move or delete this item
9974 * while we were busy with other things.
9976 * If it was on the list, we need a put() for the reference the list
9977 * had. Either way, we need a get() for the destination list.
9979 if (!list_empty(&sas_device
->list
)) {
9980 list_del_init(&sas_device
->list
);
9981 sas_device_put(sas_device
);
9984 sas_device_get(sas_device
);
9985 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
9987 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9991 * _scsih_probe_sas - reporting sas devices to sas transport
9992 * @ioc: per adapter object
9994 * Called during initial loading of the driver.
9997 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
9999 struct _sas_device
*sas_device
;
10001 if (ioc
->hide_drives
)
10004 while ((sas_device
= get_next_sas_device(ioc
))) {
10005 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
10006 sas_device
->sas_address_parent
)) {
10007 _scsih_sas_device_remove(ioc
, sas_device
);
10008 sas_device_put(sas_device
);
10010 } else if (!sas_device
->starget
) {
10012 * When asyn scanning is enabled, its not possible to
10013 * remove devices while scanning is turned on due to an
10014 * oops in scsi_sysfs_add_sdev()->add_device()->
10015 * sysfs_addrm_start()
10017 if (!ioc
->is_driver_loading
) {
10018 mpt3sas_transport_port_remove(ioc
,
10019 sas_device
->sas_address
,
10020 sas_device
->sas_address_parent
);
10021 _scsih_sas_device_remove(ioc
, sas_device
);
10022 sas_device_put(sas_device
);
10026 sas_device_make_active(ioc
, sas_device
);
10027 sas_device_put(sas_device
);
10032 * get_next_pcie_device - Get the next pcie device
10033 * @ioc: per adapter object
10035 * Get the next pcie device from pcie_device_init_list list.
10037 * Returns pcie device structure if pcie_device_init_list list is not empty
10038 * otherwise returns NULL
10040 static struct _pcie_device
*get_next_pcie_device(struct MPT3SAS_ADAPTER
*ioc
)
10042 struct _pcie_device
*pcie_device
= NULL
;
10043 unsigned long flags
;
10045 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10046 if (!list_empty(&ioc
->pcie_device_init_list
)) {
10047 pcie_device
= list_first_entry(&ioc
->pcie_device_init_list
,
10048 struct _pcie_device
, list
);
10049 pcie_device_get(pcie_device
);
10051 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10053 return pcie_device
;
10057 * pcie_device_make_active - Add pcie device to pcie_device_list list
10058 * @ioc: per adapter object
10059 * @pcie_device: pcie device object
10061 * Add the pcie device which has registered with SCSI Transport Later to
10062 * pcie_device_list list
10064 static void pcie_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
10065 struct _pcie_device
*pcie_device
)
10067 unsigned long flags
;
10069 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10071 if (!list_empty(&pcie_device
->list
)) {
10072 list_del_init(&pcie_device
->list
);
10073 pcie_device_put(pcie_device
);
10075 pcie_device_get(pcie_device
);
10076 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
10078 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10082 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
10083 * @ioc: per adapter object
10085 * Called during initial loading of the driver.
10088 _scsih_probe_pcie(struct MPT3SAS_ADAPTER
*ioc
)
10090 struct _pcie_device
*pcie_device
;
10093 /* PCIe Device List */
10094 while ((pcie_device
= get_next_pcie_device(ioc
))) {
10095 if (pcie_device
->starget
) {
10096 pcie_device_put(pcie_device
);
10099 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
,
10100 pcie_device
->id
, 0);
10102 _scsih_pcie_device_remove(ioc
, pcie_device
);
10103 pcie_device_put(pcie_device
);
10105 } else if (!pcie_device
->starget
) {
10107 * When async scanning is enabled, its not possible to
10108 * remove devices while scanning is turned on due to an
10109 * oops in scsi_sysfs_add_sdev()->add_device()->
10110 * sysfs_addrm_start()
10112 if (!ioc
->is_driver_loading
) {
10113 /* TODO-- Need to find out whether this condition will
10116 _scsih_pcie_device_remove(ioc
, pcie_device
);
10117 pcie_device_put(pcie_device
);
10121 pcie_device_make_active(ioc
, pcie_device
);
10122 pcie_device_put(pcie_device
);
10127 * _scsih_probe_devices - probing for devices
10128 * @ioc: per adapter object
10130 * Called during initial loading of the driver.
10133 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
10135 u16 volume_mapping_flags
;
10137 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
10138 return; /* return when IOC doesn't support initiator mode */
10140 _scsih_probe_boot_devices(ioc
);
10142 if (ioc
->ir_firmware
) {
10143 volume_mapping_flags
=
10144 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
10145 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
10146 if (volume_mapping_flags
==
10147 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
10148 _scsih_probe_raid(ioc
);
10149 _scsih_probe_sas(ioc
);
10151 _scsih_probe_sas(ioc
);
10152 _scsih_probe_raid(ioc
);
10155 _scsih_probe_sas(ioc
);
10156 _scsih_probe_pcie(ioc
);
10161 * scsih_scan_start - scsi lld callback for .scan_start
10162 * @shost: SCSI host pointer
10164 * The shost has the ability to discover targets on its own instead
10165 * of scanning the entire bus. In our implemention, we will kick off
10166 * firmware discovery.
10169 scsih_scan_start(struct Scsi_Host
*shost
)
10171 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10173 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
10174 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
10176 if (disable_discovery
> 0)
10179 ioc
->start_scan
= 1;
10180 rc
= mpt3sas_port_enable(ioc
);
10183 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
10187 * scsih_scan_finished - scsi lld callback for .scan_finished
10188 * @shost: SCSI host pointer
10189 * @time: elapsed time of the scan in jiffies
10191 * This function will be called periodicallyn until it returns 1 with the
10192 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10193 * we wait for firmware discovery to complete, then return 1.
10196 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
10198 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10200 if (disable_discovery
> 0) {
10201 ioc
->is_driver_loading
= 0;
10202 ioc
->wait_for_discovery_to_complete
= 0;
10206 if (time
>= (300 * HZ
)) {
10207 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
10208 pr_info(MPT3SAS_FMT
10209 "port enable: FAILED with timeout (timeout=300s)\n",
10211 ioc
->is_driver_loading
= 0;
10215 if (ioc
->start_scan
)
10218 if (ioc
->start_scan_failed
) {
10219 pr_info(MPT3SAS_FMT
10220 "port enable: FAILED with (ioc_status=0x%08x)\n",
10221 ioc
->name
, ioc
->start_scan_failed
);
10222 ioc
->is_driver_loading
= 0;
10223 ioc
->wait_for_discovery_to_complete
= 0;
10224 ioc
->remove_host
= 1;
10228 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
10229 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
10231 if (ioc
->wait_for_discovery_to_complete
) {
10232 ioc
->wait_for_discovery_to_complete
= 0;
10233 _scsih_probe_devices(ioc
);
10235 mpt3sas_base_start_watchdog(ioc
);
10236 ioc
->is_driver_loading
= 0;
10240 /* shost template for SAS 2.0 HBA devices */
10241 static struct scsi_host_template mpt2sas_driver_template
= {
10242 .module
= THIS_MODULE
,
10243 .name
= "Fusion MPT SAS Host",
10244 .proc_name
= MPT2SAS_DRIVER_NAME
,
10245 .queuecommand
= scsih_qcmd
,
10246 .target_alloc
= scsih_target_alloc
,
10247 .slave_alloc
= scsih_slave_alloc
,
10248 .slave_configure
= scsih_slave_configure
,
10249 .target_destroy
= scsih_target_destroy
,
10250 .slave_destroy
= scsih_slave_destroy
,
10251 .scan_finished
= scsih_scan_finished
,
10252 .scan_start
= scsih_scan_start
,
10253 .change_queue_depth
= scsih_change_queue_depth
,
10254 .eh_abort_handler
= scsih_abort
,
10255 .eh_device_reset_handler
= scsih_dev_reset
,
10256 .eh_target_reset_handler
= scsih_target_reset
,
10257 .eh_host_reset_handler
= scsih_host_reset
,
10258 .bios_param
= scsih_bios_param
,
10261 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
10262 .max_sectors
= 32767,
10264 .use_clustering
= ENABLE_CLUSTERING
,
10265 .shost_attrs
= mpt3sas_host_attrs
,
10266 .sdev_attrs
= mpt3sas_dev_attrs
,
10267 .track_queue_depth
= 1,
10268 .cmd_size
= sizeof(struct scsiio_tracker
),
10271 /* raid transport support for SAS 2.0 HBA devices */
10272 static struct raid_function_template mpt2sas_raid_functions
= {
10273 .cookie
= &mpt2sas_driver_template
,
10274 .is_raid
= scsih_is_raid
,
10275 .get_resync
= scsih_get_resync
,
10276 .get_state
= scsih_get_state
,
10279 /* shost template for SAS 3.0 HBA devices */
10280 static struct scsi_host_template mpt3sas_driver_template
= {
10281 .module
= THIS_MODULE
,
10282 .name
= "Fusion MPT SAS Host",
10283 .proc_name
= MPT3SAS_DRIVER_NAME
,
10284 .queuecommand
= scsih_qcmd
,
10285 .target_alloc
= scsih_target_alloc
,
10286 .slave_alloc
= scsih_slave_alloc
,
10287 .slave_configure
= scsih_slave_configure
,
10288 .target_destroy
= scsih_target_destroy
,
10289 .slave_destroy
= scsih_slave_destroy
,
10290 .scan_finished
= scsih_scan_finished
,
10291 .scan_start
= scsih_scan_start
,
10292 .change_queue_depth
= scsih_change_queue_depth
,
10293 .eh_abort_handler
= scsih_abort
,
10294 .eh_device_reset_handler
= scsih_dev_reset
,
10295 .eh_target_reset_handler
= scsih_target_reset
,
10296 .eh_host_reset_handler
= scsih_host_reset
,
10297 .bios_param
= scsih_bios_param
,
10300 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
10301 .max_sectors
= 32767,
10303 .use_clustering
= ENABLE_CLUSTERING
,
10304 .shost_attrs
= mpt3sas_host_attrs
,
10305 .sdev_attrs
= mpt3sas_dev_attrs
,
10306 .track_queue_depth
= 1,
10307 .cmd_size
= sizeof(struct scsiio_tracker
),
10310 /* raid transport support for SAS 3.0 HBA devices */
10311 static struct raid_function_template mpt3sas_raid_functions
= {
10312 .cookie
= &mpt3sas_driver_template
,
10313 .is_raid
= scsih_is_raid
,
10314 .get_resync
= scsih_get_resync
,
10315 .get_state
= scsih_get_state
,
10319 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10320 * this device belongs to.
10321 * @pdev: PCI device struct
10323 * return MPI2_VERSION for SAS 2.0 HBA devices,
10324 * MPI25_VERSION for SAS 3.0 HBA devices, and
10325 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10328 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
10331 switch (pdev
->device
) {
10332 case MPI2_MFGPAGE_DEVID_SSS6200
:
10333 case MPI2_MFGPAGE_DEVID_SAS2004
:
10334 case MPI2_MFGPAGE_DEVID_SAS2008
:
10335 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
10336 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
10337 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
10338 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
10339 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
10340 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
10341 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
10342 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
10343 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
10344 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
10345 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
10346 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
10347 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
10348 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
10349 return MPI2_VERSION
;
10350 case MPI25_MFGPAGE_DEVID_SAS3004
:
10351 case MPI25_MFGPAGE_DEVID_SAS3008
:
10352 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
10353 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
10354 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
10355 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
10356 return MPI25_VERSION
;
10357 case MPI26_MFGPAGE_DEVID_SAS3216
:
10358 case MPI26_MFGPAGE_DEVID_SAS3224
:
10359 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
10360 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
10361 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
10362 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
10363 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
10364 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
10365 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
10366 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
10367 case MPI26_MFGPAGE_DEVID_SAS3508
:
10368 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10369 case MPI26_MFGPAGE_DEVID_SAS3408
:
10370 case MPI26_MFGPAGE_DEVID_SAS3516
:
10371 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10372 case MPI26_MFGPAGE_DEVID_SAS3416
:
10373 case MPI26_MFGPAGE_DEVID_SAS3616
:
10374 return MPI26_VERSION
;
10380 * _scsih_probe - attach and add scsi host
10381 * @pdev: PCI device struct
10382 * @id: pci device id
10384 * Returns 0 success, anything else error.
10387 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
10389 struct MPT3SAS_ADAPTER
*ioc
;
10390 struct Scsi_Host
*shost
= NULL
;
10392 u16 hba_mpi_version
;
10394 /* Determine in which MPI version class this pci device belongs */
10395 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
10396 if (hba_mpi_version
== 0)
10399 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10400 * for other generation HBA's return with -ENODEV
10402 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
10405 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10406 * for other generation HBA's return with -ENODEV
10408 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
10409 || hba_mpi_version
== MPI26_VERSION
)))
10412 switch (hba_mpi_version
) {
10414 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
10415 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
10416 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10417 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
10418 sizeof(struct MPT3SAS_ADAPTER
));
10421 ioc
= shost_priv(shost
);
10422 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10423 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10424 ioc
->id
= mpt2_ids
++;
10425 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
10426 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
10427 ioc
->is_warpdrive
= 1;
10428 ioc
->hide_ir_msg
= 1;
10430 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
10432 case MPI25_VERSION
:
10433 case MPI26_VERSION
:
10434 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10435 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
10436 sizeof(struct MPT3SAS_ADAPTER
));
10439 ioc
= shost_priv(shost
);
10440 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10441 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10442 ioc
->id
= mpt3_ids
++;
10443 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
10444 switch (pdev
->device
) {
10445 case MPI26_MFGPAGE_DEVID_SAS3508
:
10446 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10447 case MPI26_MFGPAGE_DEVID_SAS3408
:
10448 case MPI26_MFGPAGE_DEVID_SAS3516
:
10449 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10450 case MPI26_MFGPAGE_DEVID_SAS3416
:
10451 case MPI26_MFGPAGE_DEVID_SAS3616
:
10452 ioc
->is_gen35_ioc
= 1;
10455 ioc
->is_gen35_ioc
= 0;
10457 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
10458 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
10459 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
10460 ioc
->combined_reply_queue
= 1;
10461 if (ioc
->is_gen35_ioc
)
10462 ioc
->combined_reply_index_count
=
10463 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
10465 ioc
->combined_reply_index_count
=
10466 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
10473 INIT_LIST_HEAD(&ioc
->list
);
10474 spin_lock(&gioc_lock
);
10475 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
10476 spin_unlock(&gioc_lock
);
10477 ioc
->shost
= shost
;
10479 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
10480 ioc
->tm_cb_idx
= tm_cb_idx
;
10481 ioc
->ctl_cb_idx
= ctl_cb_idx
;
10482 ioc
->base_cb_idx
= base_cb_idx
;
10483 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
10484 ioc
->transport_cb_idx
= transport_cb_idx
;
10485 ioc
->scsih_cb_idx
= scsih_cb_idx
;
10486 ioc
->config_cb_idx
= config_cb_idx
;
10487 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
10488 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
10489 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
10490 ioc
->logging_level
= logging_level
;
10491 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
10492 /* misc semaphores and spin locks */
10493 mutex_init(&ioc
->reset_in_progress_mutex
);
10494 /* initializing pci_access_mutex lock */
10495 mutex_init(&ioc
->pci_access_mutex
);
10496 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
10497 spin_lock_init(&ioc
->scsi_lookup_lock
);
10498 spin_lock_init(&ioc
->sas_device_lock
);
10499 spin_lock_init(&ioc
->sas_node_lock
);
10500 spin_lock_init(&ioc
->fw_event_lock
);
10501 spin_lock_init(&ioc
->raid_device_lock
);
10502 spin_lock_init(&ioc
->pcie_device_lock
);
10503 spin_lock_init(&ioc
->diag_trigger_lock
);
10505 INIT_LIST_HEAD(&ioc
->sas_device_list
);
10506 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
10507 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
10508 INIT_LIST_HEAD(&ioc
->pcie_device_list
);
10509 INIT_LIST_HEAD(&ioc
->pcie_device_init_list
);
10510 INIT_LIST_HEAD(&ioc
->fw_event_list
);
10511 INIT_LIST_HEAD(&ioc
->raid_device_list
);
10512 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
10513 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
10514 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
10515 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
10516 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
10517 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
10519 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
10521 /* init shost parameters */
10522 shost
->max_cmd_len
= 32;
10523 shost
->max_lun
= max_lun
;
10524 shost
->transportt
= mpt3sas_transport_template
;
10525 shost
->unique_id
= ioc
->id
;
10527 if (max_sectors
!= 0xFFFF) {
10528 if (max_sectors
< 64) {
10529 shost
->max_sectors
= 64;
10530 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10531 "for max_sectors, range is 64 to 32767. Assigning "
10532 "value of 64.\n", ioc
->name
, max_sectors
);
10533 } else if (max_sectors
> 32767) {
10534 shost
->max_sectors
= 32767;
10535 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10536 "for max_sectors, range is 64 to 32767. Assigning "
10537 "default value of 32767.\n", ioc
->name
,
10540 shost
->max_sectors
= max_sectors
& 0xFFFE;
10541 pr_info(MPT3SAS_FMT
10542 "The max_sectors value is set to %d\n",
10543 ioc
->name
, shost
->max_sectors
);
10547 /* register EEDP capabilities with SCSI layer */
10549 scsi_host_set_prot(shost
, prot_mask
);
10551 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
10552 | SHOST_DIF_TYPE2_PROTECTION
10553 | SHOST_DIF_TYPE3_PROTECTION
);
10555 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
10558 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
10559 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
10560 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
10561 ioc
->firmware_event_name
, 0);
10562 if (!ioc
->firmware_event_thread
) {
10563 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10564 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10566 goto out_thread_fail
;
10569 ioc
->is_driver_loading
= 1;
10570 if ((mpt3sas_base_attach(ioc
))) {
10571 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10572 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10574 goto out_attach_fail
;
10577 if (ioc
->is_warpdrive
) {
10578 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
10579 ioc
->hide_drives
= 0;
10580 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
10581 ioc
->hide_drives
= 1;
10583 if (mpt3sas_get_num_volumes(ioc
))
10584 ioc
->hide_drives
= 1;
10586 ioc
->hide_drives
= 0;
10589 ioc
->hide_drives
= 0;
10591 rv
= scsi_add_host(shost
, &pdev
->dev
);
10593 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10594 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10595 goto out_add_shost_fail
;
10598 scsi_scan_host(shost
);
10600 out_add_shost_fail
:
10601 mpt3sas_base_detach(ioc
);
10603 destroy_workqueue(ioc
->firmware_event_thread
);
10605 spin_lock(&gioc_lock
);
10606 list_del(&ioc
->list
);
10607 spin_unlock(&gioc_lock
);
10608 scsi_host_put(shost
);
10614 * scsih_suspend - power management suspend main entry point
10615 * @pdev: PCI device struct
10616 * @state: PM state change to (usually PCI_D3)
10618 * Returns 0 success, anything else error.
10621 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10623 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10624 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10625 pci_power_t device_state
;
10627 mpt3sas_base_stop_watchdog(ioc
);
10628 flush_scheduled_work();
10629 scsi_block_requests(shost
);
10630 device_state
= pci_choose_state(pdev
, state
);
10631 pr_info(MPT3SAS_FMT
10632 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10633 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10635 pci_save_state(pdev
);
10636 mpt3sas_base_free_resources(ioc
);
10637 pci_set_power_state(pdev
, device_state
);
10642 * scsih_resume - power management resume main entry point
10643 * @pdev: PCI device struct
10645 * Returns 0 success, anything else error.
10648 scsih_resume(struct pci_dev
*pdev
)
10650 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10651 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10652 pci_power_t device_state
= pdev
->current_state
;
10655 pr_info(MPT3SAS_FMT
10656 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10657 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10659 pci_set_power_state(pdev
, PCI_D0
);
10660 pci_enable_wake(pdev
, PCI_D0
, 0);
10661 pci_restore_state(pdev
);
10663 r
= mpt3sas_base_map_resources(ioc
);
10667 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
10668 scsi_unblock_requests(shost
);
10669 mpt3sas_base_start_watchdog(ioc
);
10672 #endif /* CONFIG_PM */
10675 * scsih_pci_error_detected - Called when a PCI error is detected.
10676 * @pdev: PCI device struct
10677 * @state: PCI channel state
10679 * Description: Called when a PCI error is detected.
10682 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
10684 static pci_ers_result_t
10685 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10687 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10688 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10690 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
10694 case pci_channel_io_normal
:
10695 return PCI_ERS_RESULT_CAN_RECOVER
;
10696 case pci_channel_io_frozen
:
10697 /* Fatal error, prepare for slot reset */
10698 ioc
->pci_error_recovery
= 1;
10699 scsi_block_requests(ioc
->shost
);
10700 mpt3sas_base_stop_watchdog(ioc
);
10701 mpt3sas_base_free_resources(ioc
);
10702 return PCI_ERS_RESULT_NEED_RESET
;
10703 case pci_channel_io_perm_failure
:
10704 /* Permanent error, prepare for device removal */
10705 ioc
->pci_error_recovery
= 1;
10706 mpt3sas_base_stop_watchdog(ioc
);
10707 _scsih_flush_running_cmds(ioc
);
10708 return PCI_ERS_RESULT_DISCONNECT
;
10710 return PCI_ERS_RESULT_NEED_RESET
;
10714 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10715 * @pdev: PCI device struct
10717 * Description: This routine is called by the pci error recovery
10718 * code after the PCI slot has been reset, just before we
10719 * should resume normal operations.
10721 static pci_ers_result_t
10722 scsih_pci_slot_reset(struct pci_dev
*pdev
)
10724 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10725 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10728 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
10731 ioc
->pci_error_recovery
= 0;
10733 pci_restore_state(pdev
);
10734 rc
= mpt3sas_base_map_resources(ioc
);
10736 return PCI_ERS_RESULT_DISCONNECT
;
10738 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
10740 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
10741 (rc
== 0) ? "success" : "failed");
10744 return PCI_ERS_RESULT_RECOVERED
;
10746 return PCI_ERS_RESULT_DISCONNECT
;
10750 * scsih_pci_resume() - resume normal ops after PCI reset
10751 * @pdev: pointer to PCI device
10753 * Called when the error recovery driver tells us that its
10754 * OK to resume normal operation. Use completion to allow
10755 * halted scsi ops to resume.
10758 scsih_pci_resume(struct pci_dev
*pdev
)
10760 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10761 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10763 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
10765 pci_cleanup_aer_uncorrect_error_status(pdev
);
10766 mpt3sas_base_start_watchdog(ioc
);
10767 scsi_unblock_requests(ioc
->shost
);
10771 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10772 * @pdev: pointer to PCI device
10774 static pci_ers_result_t
10775 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
10777 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10778 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10780 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
10783 /* TODO - dump whatever for debugging purposes */
10785 /* This called only if scsih_pci_error_detected returns
10786 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10787 * works, no need to reset slot.
10789 return PCI_ERS_RESULT_RECOVERED
;
10793 * scsih__ncq_prio_supp - Check for NCQ command priority support
10794 * @sdev: scsi device struct
10796 * This is called when a user indicates they would like to enable
10797 * ncq command priorities. This works only on SATA devices.
10799 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
10801 unsigned char *buf
;
10802 bool ncq_prio_supp
= false;
10804 if (!scsi_device_supports_vpd(sdev
))
10805 return ncq_prio_supp
;
10807 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
10809 return ncq_prio_supp
;
10811 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
10812 ncq_prio_supp
= (buf
[213] >> 4) & 1;
10815 return ncq_prio_supp
;
10818 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10820 static const struct pci_device_id mpt3sas_pci_table
[] = {
10821 /* Spitfire ~ 2004 */
10822 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
10823 PCI_ANY_ID
, PCI_ANY_ID
},
10824 /* Falcon ~ 2008 */
10825 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
10826 PCI_ANY_ID
, PCI_ANY_ID
},
10827 /* Liberator ~ 2108 */
10828 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
10829 PCI_ANY_ID
, PCI_ANY_ID
},
10830 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
10831 PCI_ANY_ID
, PCI_ANY_ID
},
10832 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
10833 PCI_ANY_ID
, PCI_ANY_ID
},
10834 /* Meteor ~ 2116 */
10835 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
10836 PCI_ANY_ID
, PCI_ANY_ID
},
10837 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
10838 PCI_ANY_ID
, PCI_ANY_ID
},
10839 /* Thunderbolt ~ 2208 */
10840 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
10841 PCI_ANY_ID
, PCI_ANY_ID
},
10842 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
10843 PCI_ANY_ID
, PCI_ANY_ID
},
10844 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
10845 PCI_ANY_ID
, PCI_ANY_ID
},
10846 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
10847 PCI_ANY_ID
, PCI_ANY_ID
},
10848 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
10849 PCI_ANY_ID
, PCI_ANY_ID
},
10850 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
10851 PCI_ANY_ID
, PCI_ANY_ID
},
10852 /* Mustang ~ 2308 */
10853 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
10854 PCI_ANY_ID
, PCI_ANY_ID
},
10855 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
10856 PCI_ANY_ID
, PCI_ANY_ID
},
10857 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
10858 PCI_ANY_ID
, PCI_ANY_ID
},
10860 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
10861 PCI_ANY_ID
, PCI_ANY_ID
},
10862 /* Fury ~ 3004 and 3008 */
10863 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
10864 PCI_ANY_ID
, PCI_ANY_ID
},
10865 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
10866 PCI_ANY_ID
, PCI_ANY_ID
},
10867 /* Invader ~ 3108 */
10868 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
10869 PCI_ANY_ID
, PCI_ANY_ID
},
10870 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
10871 PCI_ANY_ID
, PCI_ANY_ID
},
10872 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
10873 PCI_ANY_ID
, PCI_ANY_ID
},
10874 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
10875 PCI_ANY_ID
, PCI_ANY_ID
},
10876 /* Cutlass ~ 3216 and 3224 */
10877 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
10878 PCI_ANY_ID
, PCI_ANY_ID
},
10879 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
10880 PCI_ANY_ID
, PCI_ANY_ID
},
10881 /* Intruder ~ 3316 and 3324 */
10882 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
10883 PCI_ANY_ID
, PCI_ANY_ID
},
10884 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
10885 PCI_ANY_ID
, PCI_ANY_ID
},
10886 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
10887 PCI_ANY_ID
, PCI_ANY_ID
},
10888 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
10889 PCI_ANY_ID
, PCI_ANY_ID
},
10890 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
10891 PCI_ANY_ID
, PCI_ANY_ID
},
10892 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
10893 PCI_ANY_ID
, PCI_ANY_ID
},
10894 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
10895 PCI_ANY_ID
, PCI_ANY_ID
},
10896 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
10897 PCI_ANY_ID
, PCI_ANY_ID
},
10898 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
10899 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
10900 PCI_ANY_ID
, PCI_ANY_ID
},
10901 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
10902 PCI_ANY_ID
, PCI_ANY_ID
},
10903 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
10904 PCI_ANY_ID
, PCI_ANY_ID
},
10905 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
10906 PCI_ANY_ID
, PCI_ANY_ID
},
10907 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
10908 PCI_ANY_ID
, PCI_ANY_ID
},
10909 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
10910 PCI_ANY_ID
, PCI_ANY_ID
},
10911 /* Mercator ~ 3616*/
10912 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3616
,
10913 PCI_ANY_ID
, PCI_ANY_ID
},
10914 {0} /* Terminating entry */
10916 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
10918 static struct pci_error_handlers _mpt3sas_err_handler
= {
10919 .error_detected
= scsih_pci_error_detected
,
10920 .mmio_enabled
= scsih_pci_mmio_enabled
,
10921 .slot_reset
= scsih_pci_slot_reset
,
10922 .resume
= scsih_pci_resume
,
10925 static struct pci_driver mpt3sas_driver
= {
10926 .name
= MPT3SAS_DRIVER_NAME
,
10927 .id_table
= mpt3sas_pci_table
,
10928 .probe
= _scsih_probe
,
10929 .remove
= scsih_remove
,
10930 .shutdown
= scsih_shutdown
,
10931 .err_handler
= &_mpt3sas_err_handler
,
10933 .suspend
= scsih_suspend
,
10934 .resume
= scsih_resume
,
10939 * scsih_init - main entry point for this driver.
10941 * Returns 0 success, anything else error.
10949 mpt3sas_base_initialize_callback_handler();
10951 /* queuecommand callback hander */
10952 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
10954 /* task management callback handler */
10955 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
10957 /* base internal commands callback handler */
10958 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
10959 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
10960 mpt3sas_port_enable_done
);
10962 /* transport internal commands callback handler */
10963 transport_cb_idx
= mpt3sas_base_register_callback_handler(
10964 mpt3sas_transport_done
);
10966 /* scsih internal commands callback handler */
10967 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
10969 /* configuration page API internal commands callback handler */
10970 config_cb_idx
= mpt3sas_base_register_callback_handler(
10971 mpt3sas_config_done
);
10973 /* ctl module callback handler */
10974 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
10976 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
10977 _scsih_tm_tr_complete
);
10979 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
10980 _scsih_tm_volume_tr_complete
);
10982 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
10983 _scsih_sas_control_complete
);
10989 * scsih_exit - exit point for this driver (when it is a module).
10991 * Returns 0 success, anything else error.
10997 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
10998 mpt3sas_base_release_callback_handler(tm_cb_idx
);
10999 mpt3sas_base_release_callback_handler(base_cb_idx
);
11000 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
11001 mpt3sas_base_release_callback_handler(transport_cb_idx
);
11002 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
11003 mpt3sas_base_release_callback_handler(config_cb_idx
);
11004 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
11006 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
11007 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
11008 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
11010 /* raid transport support */
11011 if (hbas_to_enumerate
!= 1)
11012 raid_class_release(mpt3sas_raid_template
);
11013 if (hbas_to_enumerate
!= 2)
11014 raid_class_release(mpt2sas_raid_template
);
11015 sas_release_transport(mpt3sas_transport_template
);
11019 * _mpt3sas_init - main entry point for this driver.
11021 * Returns 0 success, anything else error.
11024 _mpt3sas_init(void)
11028 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
11029 MPT3SAS_DRIVER_VERSION
);
11031 mpt3sas_transport_template
=
11032 sas_attach_transport(&mpt3sas_transport_functions
);
11033 if (!mpt3sas_transport_template
)
11036 /* No need attach mpt3sas raid functions template
11037 * if hbas_to_enumarate value is one.
11039 if (hbas_to_enumerate
!= 1) {
11040 mpt3sas_raid_template
=
11041 raid_class_attach(&mpt3sas_raid_functions
);
11042 if (!mpt3sas_raid_template
) {
11043 sas_release_transport(mpt3sas_transport_template
);
11048 /* No need to attach mpt2sas raid functions template
11049 * if hbas_to_enumarate value is two
11051 if (hbas_to_enumerate
!= 2) {
11052 mpt2sas_raid_template
=
11053 raid_class_attach(&mpt2sas_raid_functions
);
11054 if (!mpt2sas_raid_template
) {
11055 sas_release_transport(mpt3sas_transport_template
);
11060 error
= scsih_init();
11066 mpt3sas_ctl_init(hbas_to_enumerate
);
11068 error
= pci_register_driver(&mpt3sas_driver
);
11076 * _mpt3sas_exit - exit point for this driver (when it is a module).
11080 _mpt3sas_exit(void)
11082 pr_info("mpt3sas version %s unloading\n",
11083 MPT3SAS_DRIVER_VERSION
);
11085 pci_unregister_driver(&mpt3sas_driver
);
11087 mpt3sas_ctl_exit(hbas_to_enumerate
);
11092 module_init(_mpt3sas_init
);
11093 module_exit(_mpt3sas_exit
);