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 * _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.
1454 static struct scsi_cmnd
*
1455 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1457 return ioc
->scsi_lookup
[smid
- 1].scmd
;
1461 * __scsih_scsi_lookup_get_clear - returns scmd entry without
1463 * @ioc: per adapter object
1464 * @smid: system request message index
1466 * Returns the smid stored scmd pointer.
1467 * Then will dereference the stored scmd pointer.
1469 static inline struct scsi_cmnd
*
1470 __scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
,
1473 struct scsi_cmnd
*scmd
= NULL
;
1475 swap(scmd
, ioc
->scsi_lookup
[smid
- 1].scmd
);
1481 * _scsih_scsi_lookup_get_clear - returns scmd entry
1482 * @ioc: per adapter object
1483 * @smid: system request message index
1485 * Returns the smid stored scmd pointer.
1486 * Then will derefrence the stored scmd pointer.
1488 static inline struct scsi_cmnd
*
1489 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1491 unsigned long flags
;
1492 struct scsi_cmnd
*scmd
;
1494 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1495 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
1496 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1502 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1503 * @ioc: per adapter object
1504 * @smid: system request message index
1505 * @scmd: pointer to scsi command object
1506 * Context: This function will acquire ioc->scsi_lookup_lock.
1508 * This will search for a scmd pointer in the scsi_lookup array,
1509 * returning the revelent smid. A returned value of zero means invalid.
1512 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1516 unsigned long flags
;
1519 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1521 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1522 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1523 smid
= ioc
->scsi_lookup
[i
].smid
;
1528 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1533 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1534 * @ioc: per adapter object
1537 * Context: This function will acquire ioc->scsi_lookup_lock.
1539 * This will search for a matching channel:id in the scsi_lookup array,
1540 * returning 1 if found.
1543 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1547 unsigned long flags
;
1550 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1552 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1553 if (ioc
->scsi_lookup
[i
].scmd
&&
1554 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1555 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1561 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1566 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1567 * @ioc: per adapter object
1571 * Context: This function will acquire ioc->scsi_lookup_lock.
1573 * This will search for a matching channel:id:lun in the scsi_lookup array,
1574 * returning 1 if found.
1577 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1578 unsigned int lun
, int channel
)
1581 unsigned long flags
;
1584 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1586 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1587 if (ioc
->scsi_lookup
[i
].scmd
&&
1588 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1589 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1590 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1596 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1601 * scsih_change_queue_depth - setting device queue depth
1602 * @sdev: scsi device struct
1603 * @qdepth: requested queue depth
1605 * Returns queue depth.
1608 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1610 struct Scsi_Host
*shost
= sdev
->host
;
1612 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1613 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1614 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1615 struct _sas_device
*sas_device
;
1616 unsigned long flags
;
1618 max_depth
= shost
->can_queue
;
1620 /* limit max device queue for SATA to 32 */
1621 sas_device_priv_data
= sdev
->hostdata
;
1622 if (!sas_device_priv_data
)
1624 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1625 if (!sas_target_priv_data
)
1627 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1630 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1631 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1633 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1634 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1636 sas_device_put(sas_device
);
1638 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1642 if (!sdev
->tagged_supported
)
1644 if (qdepth
> max_depth
)
1646 return scsi_change_queue_depth(sdev
, qdepth
);
1650 * scsih_target_alloc - target add routine
1651 * @starget: scsi target struct
1653 * Returns 0 if ok. Any other return is assumed to be an error and
1654 * the device is ignored.
1657 scsih_target_alloc(struct scsi_target
*starget
)
1659 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1660 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1661 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1662 struct _sas_device
*sas_device
;
1663 struct _raid_device
*raid_device
;
1664 struct _pcie_device
*pcie_device
;
1665 unsigned long flags
;
1666 struct sas_rphy
*rphy
;
1668 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1670 if (!sas_target_priv_data
)
1673 starget
->hostdata
= sas_target_priv_data
;
1674 sas_target_priv_data
->starget
= starget
;
1675 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1678 if (starget
->channel
== RAID_CHANNEL
) {
1679 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1680 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1683 sas_target_priv_data
->handle
= raid_device
->handle
;
1684 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1685 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1686 if (ioc
->is_warpdrive
)
1687 sas_target_priv_data
->raid_device
= raid_device
;
1688 raid_device
->starget
= starget
;
1690 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1695 if (starget
->channel
== PCIE_CHANNEL
) {
1696 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1697 pcie_device
= __mpt3sas_get_pdev_by_idchannel(ioc
, starget
->id
,
1700 sas_target_priv_data
->handle
= pcie_device
->handle
;
1701 sas_target_priv_data
->sas_address
= pcie_device
->wwid
;
1702 sas_target_priv_data
->pcie_dev
= pcie_device
;
1703 pcie_device
->starget
= starget
;
1704 pcie_device
->id
= starget
->id
;
1705 pcie_device
->channel
= starget
->channel
;
1706 sas_target_priv_data
->flags
|=
1707 MPT_TARGET_FLAGS_PCIE_DEVICE
;
1708 if (pcie_device
->fast_path
)
1709 sas_target_priv_data
->flags
|=
1710 MPT_TARGET_FASTPATH_IO
;
1712 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1716 /* sas/sata devices */
1717 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1718 rphy
= dev_to_rphy(starget
->dev
.parent
);
1719 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1720 rphy
->identify
.sas_address
);
1723 sas_target_priv_data
->handle
= sas_device
->handle
;
1724 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1725 sas_target_priv_data
->sas_dev
= sas_device
;
1726 sas_device
->starget
= starget
;
1727 sas_device
->id
= starget
->id
;
1728 sas_device
->channel
= starget
->channel
;
1729 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1730 sas_target_priv_data
->flags
|=
1731 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1732 if (sas_device
->fast_path
)
1733 sas_target_priv_data
->flags
|=
1734 MPT_TARGET_FASTPATH_IO
;
1736 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1742 * scsih_target_destroy - target destroy routine
1743 * @starget: scsi target struct
1748 scsih_target_destroy(struct scsi_target
*starget
)
1750 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1751 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1752 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1753 struct _sas_device
*sas_device
;
1754 struct _raid_device
*raid_device
;
1755 struct _pcie_device
*pcie_device
;
1756 unsigned long flags
;
1757 struct sas_rphy
*rphy
;
1759 sas_target_priv_data
= starget
->hostdata
;
1760 if (!sas_target_priv_data
)
1763 if (starget
->channel
== RAID_CHANNEL
) {
1764 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1765 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1768 raid_device
->starget
= NULL
;
1769 raid_device
->sdev
= NULL
;
1771 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1775 if (starget
->channel
== PCIE_CHANNEL
) {
1776 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1777 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1778 sas_target_priv_data
);
1779 if (pcie_device
&& (pcie_device
->starget
== starget
) &&
1780 (pcie_device
->id
== starget
->id
) &&
1781 (pcie_device
->channel
== starget
->channel
))
1782 pcie_device
->starget
= NULL
;
1786 * Corresponding get() is in _scsih_target_alloc()
1788 sas_target_priv_data
->pcie_dev
= NULL
;
1789 pcie_device_put(pcie_device
);
1790 pcie_device_put(pcie_device
);
1792 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1796 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1797 rphy
= dev_to_rphy(starget
->dev
.parent
);
1798 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1799 if (sas_device
&& (sas_device
->starget
== starget
) &&
1800 (sas_device
->id
== starget
->id
) &&
1801 (sas_device
->channel
== starget
->channel
))
1802 sas_device
->starget
= NULL
;
1806 * Corresponding get() is in _scsih_target_alloc()
1808 sas_target_priv_data
->sas_dev
= NULL
;
1809 sas_device_put(sas_device
);
1811 sas_device_put(sas_device
);
1813 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1816 kfree(sas_target_priv_data
);
1817 starget
->hostdata
= NULL
;
1821 * scsih_slave_alloc - device add routine
1822 * @sdev: scsi device struct
1824 * Returns 0 if ok. Any other return is assumed to be an error and
1825 * the device is ignored.
1828 scsih_slave_alloc(struct scsi_device
*sdev
)
1830 struct Scsi_Host
*shost
;
1831 struct MPT3SAS_ADAPTER
*ioc
;
1832 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1833 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1834 struct scsi_target
*starget
;
1835 struct _raid_device
*raid_device
;
1836 struct _sas_device
*sas_device
;
1837 struct _pcie_device
*pcie_device
;
1838 unsigned long flags
;
1840 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1842 if (!sas_device_priv_data
)
1845 sas_device_priv_data
->lun
= sdev
->lun
;
1846 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1848 starget
= scsi_target(sdev
);
1849 sas_target_priv_data
= starget
->hostdata
;
1850 sas_target_priv_data
->num_luns
++;
1851 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1852 sdev
->hostdata
= sas_device_priv_data
;
1853 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1854 sdev
->no_uld_attach
= 1;
1856 shost
= dev_to_shost(&starget
->dev
);
1857 ioc
= shost_priv(shost
);
1858 if (starget
->channel
== RAID_CHANNEL
) {
1859 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1860 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1861 starget
->id
, starget
->channel
);
1863 raid_device
->sdev
= sdev
; /* raid is single lun */
1864 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1866 if (starget
->channel
== PCIE_CHANNEL
) {
1867 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1868 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
1869 sas_target_priv_data
->sas_address
);
1870 if (pcie_device
&& (pcie_device
->starget
== NULL
)) {
1871 sdev_printk(KERN_INFO
, sdev
,
1872 "%s : pcie_device->starget set to starget @ %d\n",
1873 __func__
, __LINE__
);
1874 pcie_device
->starget
= starget
;
1878 pcie_device_put(pcie_device
);
1879 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1881 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1882 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1883 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1884 sas_target_priv_data
->sas_address
);
1885 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1886 sdev_printk(KERN_INFO
, sdev
,
1887 "%s : sas_device->starget set to starget @ %d\n",
1888 __func__
, __LINE__
);
1889 sas_device
->starget
= starget
;
1893 sas_device_put(sas_device
);
1895 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1902 * scsih_slave_destroy - device destroy routine
1903 * @sdev: scsi device struct
1908 scsih_slave_destroy(struct scsi_device
*sdev
)
1910 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1911 struct scsi_target
*starget
;
1912 struct Scsi_Host
*shost
;
1913 struct MPT3SAS_ADAPTER
*ioc
;
1914 struct _sas_device
*sas_device
;
1915 struct _pcie_device
*pcie_device
;
1916 unsigned long flags
;
1918 if (!sdev
->hostdata
)
1921 starget
= scsi_target(sdev
);
1922 sas_target_priv_data
= starget
->hostdata
;
1923 sas_target_priv_data
->num_luns
--;
1925 shost
= dev_to_shost(&starget
->dev
);
1926 ioc
= shost_priv(shost
);
1928 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
1929 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1930 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1931 sas_target_priv_data
);
1932 if (pcie_device
&& !sas_target_priv_data
->num_luns
)
1933 pcie_device
->starget
= NULL
;
1936 pcie_device_put(pcie_device
);
1938 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1940 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1941 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1942 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1943 sas_target_priv_data
);
1944 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1945 sas_device
->starget
= NULL
;
1948 sas_device_put(sas_device
);
1949 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1952 kfree(sdev
->hostdata
);
1953 sdev
->hostdata
= NULL
;
1957 * _scsih_display_sata_capabilities - sata capabilities
1958 * @ioc: per adapter object
1959 * @handle: device handle
1960 * @sdev: scsi device struct
1963 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1964 u16 handle
, struct scsi_device
*sdev
)
1966 Mpi2ConfigReply_t mpi_reply
;
1967 Mpi2SasDevicePage0_t sas_device_pg0
;
1972 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1973 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1974 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1975 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1979 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1980 MPI2_IOCSTATUS_MASK
;
1981 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1982 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1983 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1987 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1988 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1990 sdev_printk(KERN_INFO
, sdev
,
1991 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1992 "sw_preserve(%s)\n",
1993 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1994 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1995 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1997 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1998 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1999 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
2003 * raid transport support -
2004 * Enabled for SLES11 and newer, in older kernels the driver will panic when
2005 * unloading the driver followed by a load - I believe that the subroutine
2006 * raid_class_release() is not cleaning up properly.
2010 * scsih_is_raid - return boolean indicating device is raid volume
2011 * @dev the device struct object
2014 scsih_is_raid(struct device
*dev
)
2016 struct scsi_device
*sdev
= to_scsi_device(dev
);
2017 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2019 if (ioc
->is_warpdrive
)
2021 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
2025 scsih_is_nvme(struct device
*dev
)
2027 struct scsi_device
*sdev
= to_scsi_device(dev
);
2029 return (sdev
->channel
== PCIE_CHANNEL
) ? 1 : 0;
2033 * scsih_get_resync - get raid volume resync percent complete
2034 * @dev the device struct object
2037 scsih_get_resync(struct device
*dev
)
2039 struct scsi_device
*sdev
= to_scsi_device(dev
);
2040 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2041 static struct _raid_device
*raid_device
;
2042 unsigned long flags
;
2043 Mpi2RaidVolPage0_t vol_pg0
;
2044 Mpi2ConfigReply_t mpi_reply
;
2045 u32 volume_status_flags
;
2046 u8 percent_complete
;
2049 percent_complete
= 0;
2051 if (ioc
->is_warpdrive
)
2054 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2055 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
2058 handle
= raid_device
->handle
;
2059 percent_complete
= raid_device
->percent_complete
;
2061 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2066 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
2067 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
2068 sizeof(Mpi2RaidVolPage0_t
))) {
2069 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2070 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2071 percent_complete
= 0;
2075 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2076 if (!(volume_status_flags
&
2077 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
2078 percent_complete
= 0;
2082 switch (ioc
->hba_mpi_version_belonged
) {
2084 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
2088 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
2094 * scsih_get_state - get raid volume level
2095 * @dev the device struct object
2098 scsih_get_state(struct device
*dev
)
2100 struct scsi_device
*sdev
= to_scsi_device(dev
);
2101 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2102 static struct _raid_device
*raid_device
;
2103 unsigned long flags
;
2104 Mpi2RaidVolPage0_t vol_pg0
;
2105 Mpi2ConfigReply_t mpi_reply
;
2107 enum raid_state state
= RAID_STATE_UNKNOWN
;
2110 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2111 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
2114 handle
= raid_device
->handle
;
2115 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2120 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
2121 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
2122 sizeof(Mpi2RaidVolPage0_t
))) {
2123 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2124 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2128 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2129 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
2130 state
= RAID_STATE_RESYNCING
;
2134 switch (vol_pg0
.VolumeState
) {
2135 case MPI2_RAID_VOL_STATE_OPTIMAL
:
2136 case MPI2_RAID_VOL_STATE_ONLINE
:
2137 state
= RAID_STATE_ACTIVE
;
2139 case MPI2_RAID_VOL_STATE_DEGRADED
:
2140 state
= RAID_STATE_DEGRADED
;
2142 case MPI2_RAID_VOL_STATE_FAILED
:
2143 case MPI2_RAID_VOL_STATE_MISSING
:
2144 state
= RAID_STATE_OFFLINE
;
2148 switch (ioc
->hba_mpi_version_belonged
) {
2150 raid_set_state(mpt2sas_raid_template
, dev
, state
);
2154 raid_set_state(mpt3sas_raid_template
, dev
, state
);
2160 * _scsih_set_level - set raid level
2161 * @sdev: scsi device struct
2162 * @volume_type: volume type
2165 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
2166 struct scsi_device
*sdev
, u8 volume_type
)
2168 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
2170 switch (volume_type
) {
2171 case MPI2_RAID_VOL_TYPE_RAID0
:
2172 level
= RAID_LEVEL_0
;
2174 case MPI2_RAID_VOL_TYPE_RAID10
:
2175 level
= RAID_LEVEL_10
;
2177 case MPI2_RAID_VOL_TYPE_RAID1E
:
2178 level
= RAID_LEVEL_1E
;
2180 case MPI2_RAID_VOL_TYPE_RAID1
:
2181 level
= RAID_LEVEL_1
;
2185 switch (ioc
->hba_mpi_version_belonged
) {
2187 raid_set_level(mpt2sas_raid_template
,
2188 &sdev
->sdev_gendev
, level
);
2192 raid_set_level(mpt3sas_raid_template
,
2193 &sdev
->sdev_gendev
, level
);
2200 * _scsih_get_volume_capabilities - volume capabilities
2201 * @ioc: per adapter object
2202 * @sas_device: the raid_device object
2204 * Returns 0 for success, else 1
2207 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
2208 struct _raid_device
*raid_device
)
2210 Mpi2RaidVolPage0_t
*vol_pg0
;
2211 Mpi2RaidPhysDiskPage0_t pd_pg0
;
2212 Mpi2SasDevicePage0_t sas_device_pg0
;
2213 Mpi2ConfigReply_t mpi_reply
;
2217 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
2218 &num_pds
)) || !num_pds
) {
2219 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2220 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2225 raid_device
->num_pds
= num_pds
;
2226 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
2227 sizeof(Mpi2RaidVol0PhysDisk_t
));
2228 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
2230 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2231 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2236 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
2237 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
2238 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2239 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2245 raid_device
->volume_type
= vol_pg0
->VolumeType
;
2247 /* figure out what the underlying devices are by
2248 * obtaining the device_info bits for the 1st device
2250 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
2251 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
2252 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
2253 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
2254 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
2255 le16_to_cpu(pd_pg0
.DevHandle
)))) {
2256 raid_device
->device_info
=
2257 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
2266 * _scsih_enable_tlr - setting TLR flags
2267 * @ioc: per adapter object
2268 * @sdev: scsi device struct
2270 * Enabling Transaction Layer Retries for tape devices when
2271 * vpd page 0x90 is present
2275 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
2279 if (sdev
->type
!= TYPE_TAPE
)
2282 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
2285 sas_enable_tlr(sdev
);
2286 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
2287 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
2293 * scsih_slave_configure - device configure routine.
2294 * @sdev: scsi device struct
2296 * Returns 0 if ok. Any other return is assumed to be an error and
2297 * the device is ignored.
2300 scsih_slave_configure(struct scsi_device
*sdev
)
2302 struct Scsi_Host
*shost
= sdev
->host
;
2303 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2304 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2305 struct MPT3SAS_TARGET
*sas_target_priv_data
;
2306 struct _sas_device
*sas_device
;
2307 struct _pcie_device
*pcie_device
;
2308 struct _raid_device
*raid_device
;
2309 unsigned long flags
;
2314 u16 handle
, volume_handle
= 0;
2315 u64 volume_wwid
= 0;
2318 sas_device_priv_data
= sdev
->hostdata
;
2319 sas_device_priv_data
->configured_lun
= 1;
2320 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2321 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2322 handle
= sas_target_priv_data
->handle
;
2324 /* raid volume handling */
2325 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2327 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2328 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
2329 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2331 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2332 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2333 __LINE__
, __func__
));
2337 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2338 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2339 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2340 __LINE__
, __func__
));
2345 * WARPDRIVE: Initialize the required data for Direct IO
2347 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
2349 /* RAID Queue Depth Support
2350 * IS volume = underlying qdepth of drive type, either
2351 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2352 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2354 if (raid_device
->device_info
&
2355 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2356 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2359 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2360 if (raid_device
->device_info
&
2361 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2367 switch (raid_device
->volume_type
) {
2368 case MPI2_RAID_VOL_TYPE_RAID0
:
2371 case MPI2_RAID_VOL_TYPE_RAID1E
:
2372 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2373 if (ioc
->manu_pg10
.OEMIdentifier
&&
2374 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2375 MFG10_GF0_R10_DISPLAY
) &&
2376 !(raid_device
->num_pds
% 2))
2381 case MPI2_RAID_VOL_TYPE_RAID1
:
2382 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2385 case MPI2_RAID_VOL_TYPE_RAID10
:
2386 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2389 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2391 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2396 if (!ioc
->hide_ir_msg
)
2397 sdev_printk(KERN_INFO
, sdev
,
2398 "%s: handle(0x%04x), wwid(0x%016llx),"
2399 " pd_count(%d), type(%s)\n",
2400 r_level
, raid_device
->handle
,
2401 (unsigned long long)raid_device
->wwid
,
2402 raid_device
->num_pds
, ds
);
2404 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
2405 blk_queue_max_hw_sectors(sdev
->request_queue
,
2406 MPT3SAS_RAID_MAX_SECTORS
);
2407 sdev_printk(KERN_INFO
, sdev
,
2408 "Set queue's max_sector to: %u\n",
2409 MPT3SAS_RAID_MAX_SECTORS
);
2412 scsih_change_queue_depth(sdev
, qdepth
);
2414 /* raid transport support */
2415 if (!ioc
->is_warpdrive
)
2416 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
2420 /* non-raid handling */
2421 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2422 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
2424 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2425 "failure at %s:%d/%s()!\n", ioc
->name
,
2426 __FILE__
, __LINE__
, __func__
));
2429 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
2430 volume_handle
, &volume_wwid
)) {
2431 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2432 "failure at %s:%d/%s()!\n", ioc
->name
,
2433 __FILE__
, __LINE__
, __func__
));
2439 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2440 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2441 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
2442 sas_device_priv_data
->sas_target
->sas_address
);
2444 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2445 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2446 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2447 __LINE__
, __func__
));
2451 qdepth
= MPT3SAS_NVME_QUEUE_DEPTH
;
2453 sdev_printk(KERN_INFO
, sdev
,
2454 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2455 ds
, handle
, (unsigned long long)pcie_device
->wwid
,
2456 pcie_device
->port_num
);
2457 if (pcie_device
->enclosure_handle
!= 0)
2458 sdev_printk(KERN_INFO
, sdev
,
2459 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2461 (unsigned long long)pcie_device
->enclosure_logical_id
,
2463 if (pcie_device
->connector_name
[0] != '\0')
2464 sdev_printk(KERN_INFO
, sdev
,
2465 "%s: enclosure level(0x%04x),"
2466 "connector name( %s)\n", ds
,
2467 pcie_device
->enclosure_level
,
2468 pcie_device
->connector_name
);
2469 pcie_device_put(pcie_device
);
2470 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2471 scsih_change_queue_depth(sdev
, qdepth
);
2473 if (pcie_device
->nvme_mdts
)
2474 blk_queue_max_hw_sectors(sdev
->request_queue
,
2475 pcie_device
->nvme_mdts
/512);
2476 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2477 ** merged and can eliminate holes created during merging
2480 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES
,
2481 sdev
->request_queue
);
2482 blk_queue_virt_boundary(sdev
->request_queue
,
2483 ioc
->page_size
- 1);
2487 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2488 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
2489 sas_device_priv_data
->sas_target
->sas_address
);
2491 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2492 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2493 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2498 sas_device
->volume_handle
= volume_handle
;
2499 sas_device
->volume_wwid
= volume_wwid
;
2500 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2501 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2503 if (sas_device
->device_info
&
2504 MPI2_SAS_DEVICE_INFO_SEP
) {
2505 sdev_printk(KERN_WARNING
, sdev
,
2506 "set ignore_delay_remove for handle(0x%04x)\n",
2507 sas_device_priv_data
->sas_target
->handle
);
2508 sas_device_priv_data
->ignore_delay_remove
= 1;
2513 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2514 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2516 else if (sas_device
->device_info
&
2517 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2521 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2522 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2523 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2524 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2526 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, sdev
, NULL
);
2528 sas_device_put(sas_device
);
2529 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2532 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2535 scsih_change_queue_depth(sdev
, qdepth
);
2538 sas_read_port_mode_page(sdev
);
2539 _scsih_enable_tlr(ioc
, sdev
);
2546 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2547 * @sdev: scsi device struct
2548 * @bdev: pointer to block device context
2549 * @capacity: device size (in 512 byte sectors)
2550 * @params: three element array to place output:
2551 * params[0] number of heads (max 255)
2552 * params[1] number of sectors (max 63)
2553 * params[2] number of cylinders
2558 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2559 sector_t capacity
, int params
[])
2569 dummy
= heads
* sectors
;
2570 cylinders
= capacity
;
2571 sector_div(cylinders
, dummy
);
2574 * Handle extended translation size for logical drives
2577 if ((ulong
)capacity
>= 0x200000) {
2580 dummy
= heads
* sectors
;
2581 cylinders
= capacity
;
2582 sector_div(cylinders
, dummy
);
2587 params
[1] = sectors
;
2588 params
[2] = cylinders
;
2594 * _scsih_response_code - translation of device response code
2595 * @ioc: per adapter object
2596 * @response_code: response code returned by the device
2601 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2605 switch (response_code
) {
2606 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2607 desc
= "task management request completed";
2609 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2610 desc
= "invalid frame";
2612 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2613 desc
= "task management request not supported";
2615 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2616 desc
= "task management request failed";
2618 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2619 desc
= "task management request succeeded";
2621 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2622 desc
= "invalid lun";
2625 desc
= "overlapped tag attempted";
2627 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2628 desc
= "task queued, however not sent to target";
2634 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2635 ioc
->name
, response_code
, desc
);
2639 * _scsih_tm_done - tm completion routine
2640 * @ioc: per adapter object
2641 * @smid: system request message index
2642 * @msix_index: MSIX table index supplied by the OS
2643 * @reply: reply message frame(lower 32bit addr)
2646 * The callback handler when using scsih_issue_tm.
2648 * Return 1 meaning mf should be freed from _base_interrupt
2649 * 0 means the mf is freed from this function.
2652 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2654 MPI2DefaultReply_t
*mpi_reply
;
2656 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2658 if (ioc
->tm_cmds
.smid
!= smid
)
2660 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2661 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2663 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2664 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2666 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2667 complete(&ioc
->tm_cmds
.done
);
2672 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2673 * @ioc: per adapter object
2674 * @handle: device handle
2676 * During taskmangement request, we need to freeze the device queue.
2679 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2681 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2682 struct scsi_device
*sdev
;
2685 shost_for_each_device(sdev
, ioc
->shost
) {
2688 sas_device_priv_data
= sdev
->hostdata
;
2689 if (!sas_device_priv_data
)
2691 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2692 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2694 ioc
->ignore_loginfos
= 1;
2700 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2701 * @ioc: per adapter object
2702 * @handle: device handle
2704 * During taskmangement request, we need to freeze the device queue.
2707 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2709 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2710 struct scsi_device
*sdev
;
2713 shost_for_each_device(sdev
, ioc
->shost
) {
2716 sas_device_priv_data
= sdev
->hostdata
;
2717 if (!sas_device_priv_data
)
2719 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2720 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2722 ioc
->ignore_loginfos
= 0;
2728 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2729 * @ioc: per adapter struct
2730 * @device_handle: device handle
2731 * @channel: the channel assigned by the OS
2732 * @id: the id assigned by the OS
2734 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2735 * @smid_task: smid assigned to the task
2736 * @timeout: timeout in seconds
2739 * A generic API for sending task management requests to firmware.
2741 * The callback index is set inside `ioc->tm_cb_idx`.
2743 * Return SUCCESS or FAILED.
2746 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2747 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2749 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2750 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2753 struct scsiio_tracker
*scsi_lookup
= NULL
;
2757 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2759 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2760 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2761 __func__
, ioc
->name
);
2765 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2766 ioc
->pci_error_recovery
) {
2767 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2768 __func__
, ioc
->name
);
2772 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2773 if (ioc_state
& MPI2_DOORBELL_USED
) {
2774 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2775 "unexpected doorbell active!\n", ioc
->name
));
2776 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2777 return (!rc
) ? SUCCESS
: FAILED
;
2780 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2781 mpt3sas_base_fault_info(ioc
, ioc_state
&
2782 MPI2_DOORBELL_DATA_MASK
);
2783 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2784 return (!rc
) ? SUCCESS
: FAILED
;
2787 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2789 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2790 ioc
->name
, __func__
);
2794 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2795 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2797 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2798 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2799 ioc
->name
, handle
, type
, smid_task
));
2800 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2801 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2802 ioc
->tm_cmds
.smid
= smid
;
2803 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2804 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2805 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2806 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2807 mpi_request
->TaskType
= type
;
2808 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2809 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2810 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2811 init_completion(&ioc
->tm_cmds
.done
);
2812 if ((type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) &&
2813 (scsi_lookup
->msix_io
< ioc
->reply_queue_count
))
2814 msix_task
= scsi_lookup
->msix_io
;
2817 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2818 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2819 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2820 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2821 ioc
->name
, __func__
);
2822 _debug_dump_mf(mpi_request
,
2823 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2824 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2825 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2827 rc
= (!rc
) ? SUCCESS
: FAILED
;
2832 /* sync IRQs in case those were busy during flush. */
2833 mpt3sas_base_sync_reply_irqs(ioc
);
2835 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2836 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2837 mpi_reply
= ioc
->tm_cmds
.reply
;
2838 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2839 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2840 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2841 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2842 le32_to_cpu(mpi_reply
->TerminationCount
)));
2843 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2844 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2845 if (mpi_reply
->IOCStatus
)
2846 _debug_dump_mf(mpi_request
,
2847 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2852 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2854 if (scsi_lookup
->scmd
== NULL
)
2859 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2860 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2865 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2866 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2867 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2872 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2881 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2882 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2886 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2887 uint channel
, uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2891 mutex_lock(&ioc
->tm_cmds
.mutex
);
2892 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, channel
, id
, lun
, type
,
2893 smid_task
, timeout
);
2894 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2900 * _scsih_tm_display_info - displays info about the device
2901 * @ioc: per adapter struct
2902 * @scmd: pointer to scsi command object
2904 * Called by task management callback handlers.
2907 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2909 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2910 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2911 struct _sas_device
*sas_device
= NULL
;
2912 struct _pcie_device
*pcie_device
= NULL
;
2913 unsigned long flags
;
2914 char *device_str
= NULL
;
2918 if (ioc
->hide_ir_msg
)
2919 device_str
= "WarpDrive";
2921 device_str
= "volume";
2923 scsi_print_command(scmd
);
2924 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2925 starget_printk(KERN_INFO
, starget
,
2926 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2927 device_str
, priv_target
->handle
,
2928 device_str
, (unsigned long long)priv_target
->sas_address
);
2930 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2931 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2932 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
, priv_target
);
2934 starget_printk(KERN_INFO
, starget
,
2935 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2936 pcie_device
->handle
,
2937 (unsigned long long)pcie_device
->wwid
,
2938 pcie_device
->port_num
);
2939 if (pcie_device
->enclosure_handle
!= 0)
2940 starget_printk(KERN_INFO
, starget
,
2941 "enclosure logical id(0x%016llx), slot(%d)\n",
2942 (unsigned long long)
2943 pcie_device
->enclosure_logical_id
,
2945 if (pcie_device
->connector_name
[0] != '\0')
2946 starget_printk(KERN_INFO
, starget
,
2947 "enclosure level(0x%04x), connector name( %s)\n",
2948 pcie_device
->enclosure_level
,
2949 pcie_device
->connector_name
);
2950 pcie_device_put(pcie_device
);
2952 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2955 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2956 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2958 if (priv_target
->flags
&
2959 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2960 starget_printk(KERN_INFO
, starget
,
2961 "volume handle(0x%04x), "
2962 "volume wwid(0x%016llx)\n",
2963 sas_device
->volume_handle
,
2964 (unsigned long long)sas_device
->volume_wwid
);
2966 starget_printk(KERN_INFO
, starget
,
2967 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2969 (unsigned long long)sas_device
->sas_address
,
2972 _scsih_display_enclosure_chassis_info(NULL
, sas_device
,
2975 sas_device_put(sas_device
);
2977 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2982 * scsih_abort - eh threads main abort routine
2983 * @scmd: pointer to scsi command object
2985 * Returns SUCCESS if command aborted else FAILED
2988 scsih_abort(struct scsi_cmnd
*scmd
)
2990 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2991 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2996 sdev_printk(KERN_INFO
, scmd
->device
,
2997 "attempting task abort! scmd(%p)\n", scmd
);
2998 _scsih_tm_display_info(ioc
, scmd
);
3000 sas_device_priv_data
= scmd
->device
->hostdata
;
3001 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3003 sdev_printk(KERN_INFO
, scmd
->device
,
3004 "device been deleted! scmd(%p)\n", scmd
);
3005 scmd
->result
= DID_NO_CONNECT
<< 16;
3006 scmd
->scsi_done(scmd
);
3011 /* search for the command */
3012 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
3014 scmd
->result
= DID_RESET
<< 16;
3019 /* for hidden raid components and volumes this is not supported */
3020 if (sas_device_priv_data
->sas_target
->flags
&
3021 MPT_TARGET_FLAGS_RAID_COMPONENT
||
3022 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3023 scmd
->result
= DID_RESET
<< 16;
3028 mpt3sas_halt_firmware(ioc
);
3030 handle
= sas_device_priv_data
->sas_target
->handle
;
3031 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
3032 scmd
->device
->id
, scmd
->device
->lun
,
3033 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
3036 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
3037 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3042 * scsih_dev_reset - eh threads main device reset routine
3043 * @scmd: pointer to scsi command object
3045 * Returns SUCCESS if command aborted else FAILED
3048 scsih_dev_reset(struct scsi_cmnd
*scmd
)
3050 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3051 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3052 struct _sas_device
*sas_device
= NULL
;
3056 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3057 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
3059 sdev_printk(KERN_INFO
, scmd
->device
,
3060 "attempting device reset! scmd(%p)\n", scmd
);
3061 _scsih_tm_display_info(ioc
, scmd
);
3063 sas_device_priv_data
= scmd
->device
->hostdata
;
3064 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3066 sdev_printk(KERN_INFO
, scmd
->device
,
3067 "device been deleted! scmd(%p)\n", scmd
);
3068 scmd
->result
= DID_NO_CONNECT
<< 16;
3069 scmd
->scsi_done(scmd
);
3074 /* for hidden raid components obtain the volume_handle */
3076 if (sas_device_priv_data
->sas_target
->flags
&
3077 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
3078 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
3081 handle
= sas_device
->volume_handle
;
3083 handle
= sas_device_priv_data
->sas_target
->handle
;
3086 scmd
->result
= DID_RESET
<< 16;
3091 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
3092 scmd
->device
->id
, scmd
->device
->lun
,
3093 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30);
3096 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
3097 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3100 sas_device_put(sas_device
);
3106 * scsih_target_reset - eh threads main target reset routine
3107 * @scmd: pointer to scsi command object
3109 * Returns SUCCESS if command aborted else FAILED
3112 scsih_target_reset(struct scsi_cmnd
*scmd
)
3114 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3115 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3116 struct _sas_device
*sas_device
= NULL
;
3119 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3120 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
3122 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
3124 _scsih_tm_display_info(ioc
, scmd
);
3126 sas_device_priv_data
= scmd
->device
->hostdata
;
3127 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3129 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
3131 scmd
->result
= DID_NO_CONNECT
<< 16;
3132 scmd
->scsi_done(scmd
);
3137 /* for hidden raid components obtain the volume_handle */
3139 if (sas_device_priv_data
->sas_target
->flags
&
3140 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
3141 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
3144 handle
= sas_device
->volume_handle
;
3146 handle
= sas_device_priv_data
->sas_target
->handle
;
3149 scmd
->result
= DID_RESET
<< 16;
3154 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
3155 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
3159 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
3160 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3163 sas_device_put(sas_device
);
3170 * scsih_host_reset - eh threads main host reset routine
3171 * @scmd: pointer to scsi command object
3173 * Returns SUCCESS if command aborted else FAILED
3176 scsih_host_reset(struct scsi_cmnd
*scmd
)
3178 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3181 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
3183 scsi_print_command(scmd
);
3185 if (ioc
->is_driver_loading
|| ioc
->remove_host
) {
3186 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
3192 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
3193 r
= (retval
< 0) ? FAILED
: SUCCESS
;
3195 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
3196 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3202 * _scsih_fw_event_add - insert and queue up fw_event
3203 * @ioc: per adapter object
3204 * @fw_event: object describing the event
3205 * Context: This function will acquire ioc->fw_event_lock.
3207 * This adds the firmware event object into link list, then queues it up to
3208 * be processed from user context.
3213 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
3215 unsigned long flags
;
3217 if (ioc
->firmware_event_thread
== NULL
)
3220 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3221 fw_event_work_get(fw_event
);
3222 INIT_LIST_HEAD(&fw_event
->list
);
3223 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
3224 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
3225 fw_event_work_get(fw_event
);
3226 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
3227 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3231 * _scsih_fw_event_del_from_list - delete fw_event from the list
3232 * @ioc: per adapter object
3233 * @fw_event: object describing the event
3234 * Context: This function will acquire ioc->fw_event_lock.
3236 * If the fw_event is on the fw_event_list, remove it and do a put.
3241 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
3244 unsigned long flags
;
3246 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3247 if (!list_empty(&fw_event
->list
)) {
3248 list_del_init(&fw_event
->list
);
3249 fw_event_work_put(fw_event
);
3251 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3256 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3257 * @ioc: per adapter object
3258 * @event_data: trigger event data
3263 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
3264 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
3266 struct fw_event_work
*fw_event
;
3269 if (ioc
->is_driver_loading
)
3271 sz
= sizeof(*event_data
);
3272 fw_event
= alloc_fw_event_work(sz
);
3275 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
3276 fw_event
->ioc
= ioc
;
3277 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
3278 _scsih_fw_event_add(ioc
, fw_event
);
3279 fw_event_work_put(fw_event
);
3283 * _scsih_error_recovery_delete_devices - remove devices not responding
3284 * @ioc: per adapter object
3289 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
3291 struct fw_event_work
*fw_event
;
3293 if (ioc
->is_driver_loading
)
3295 fw_event
= alloc_fw_event_work(0);
3298 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
3299 fw_event
->ioc
= ioc
;
3300 _scsih_fw_event_add(ioc
, fw_event
);
3301 fw_event_work_put(fw_event
);
3305 * mpt3sas_port_enable_complete - port enable completed (fake event)
3306 * @ioc: per adapter object
3311 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
3313 struct fw_event_work
*fw_event
;
3315 fw_event
= alloc_fw_event_work(0);
3318 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
3319 fw_event
->ioc
= ioc
;
3320 _scsih_fw_event_add(ioc
, fw_event
);
3321 fw_event_work_put(fw_event
);
3324 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
3326 unsigned long flags
;
3327 struct fw_event_work
*fw_event
= NULL
;
3329 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3330 if (!list_empty(&ioc
->fw_event_list
)) {
3331 fw_event
= list_first_entry(&ioc
->fw_event_list
,
3332 struct fw_event_work
, list
);
3333 list_del_init(&fw_event
->list
);
3335 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3341 * _scsih_fw_event_cleanup_queue - cleanup event queue
3342 * @ioc: per adapter object
3344 * Walk the firmware event queue, either killing timers, or waiting
3345 * for outstanding events to complete
3350 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
3352 struct fw_event_work
*fw_event
;
3354 if (list_empty(&ioc
->fw_event_list
) ||
3355 !ioc
->firmware_event_thread
|| in_interrupt())
3358 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
3360 * Wait on the fw_event to complete. If this returns 1, then
3361 * the event was never executed, and we need a put for the
3362 * reference the work had on the fw_event.
3364 * If it did execute, we wait for it to finish, and the put will
3365 * happen from _firmware_event_work()
3367 if (cancel_work_sync(&fw_event
->work
))
3368 fw_event_work_put(fw_event
);
3370 fw_event_work_put(fw_event
);
3375 * _scsih_internal_device_block - block the sdev device
3376 * @sdev: per device object
3377 * @sas_device_priv_data : per device driver private data
3379 * make sure device is blocked without error, if not
3383 _scsih_internal_device_block(struct scsi_device
*sdev
,
3384 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3388 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
3389 sas_device_priv_data
->sas_target
->handle
);
3390 sas_device_priv_data
->block
= 1;
3392 r
= scsi_internal_device_block_nowait(sdev
);
3394 sdev_printk(KERN_WARNING
, sdev
,
3395 "device_block failed with return(%d) for handle(0x%04x)\n",
3396 r
, sas_device_priv_data
->sas_target
->handle
);
3400 * _scsih_internal_device_unblock - unblock the sdev device
3401 * @sdev: per device object
3402 * @sas_device_priv_data : per device driver private data
3403 * make sure device is unblocked without error, if not retry
3404 * by blocking and then unblocking
3408 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
3409 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3413 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
3414 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
3415 sas_device_priv_data
->block
= 0;
3416 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3418 /* The device has been set to SDEV_RUNNING by SD layer during
3419 * device addition but the request queue is still stopped by
3420 * our earlier block call. We need to perform a block again
3421 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3423 sdev_printk(KERN_WARNING
, sdev
,
3424 "device_unblock failed with return(%d) for handle(0x%04x) "
3425 "performing a block followed by an unblock\n",
3426 r
, sas_device_priv_data
->sas_target
->handle
);
3427 sas_device_priv_data
->block
= 1;
3428 r
= scsi_internal_device_block_nowait(sdev
);
3430 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
3431 "failed with return(%d) for handle(0x%04x)\n",
3432 r
, sas_device_priv_data
->sas_target
->handle
);
3434 sas_device_priv_data
->block
= 0;
3435 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3437 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
3438 " failed with return(%d) for handle(0x%04x)\n",
3439 r
, sas_device_priv_data
->sas_target
->handle
);
3444 * _scsih_ublock_io_all_device - unblock every device
3445 * @ioc: per adapter object
3447 * change the device state from block to running
3450 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3452 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3453 struct scsi_device
*sdev
;
3455 shost_for_each_device(sdev
, ioc
->shost
) {
3456 sas_device_priv_data
= sdev
->hostdata
;
3457 if (!sas_device_priv_data
)
3459 if (!sas_device_priv_data
->block
)
3462 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3463 "device_running, handle(0x%04x)\n",
3464 sas_device_priv_data
->sas_target
->handle
));
3465 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
3471 * _scsih_ublock_io_device - prepare device to be deleted
3472 * @ioc: per adapter object
3473 * @sas_addr: sas address
3475 * unblock then put device in offline state
3478 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
3480 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3481 struct scsi_device
*sdev
;
3483 shost_for_each_device(sdev
, ioc
->shost
) {
3484 sas_device_priv_data
= sdev
->hostdata
;
3485 if (!sas_device_priv_data
)
3487 if (sas_device_priv_data
->sas_target
->sas_address
3490 if (sas_device_priv_data
->block
)
3491 _scsih_internal_device_unblock(sdev
,
3492 sas_device_priv_data
);
3497 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3498 * @ioc: per adapter object
3499 * @handle: device handle
3501 * During device pull we need to appropriately set the sdev state.
3504 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3506 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3507 struct scsi_device
*sdev
;
3509 shost_for_each_device(sdev
, ioc
->shost
) {
3510 sas_device_priv_data
= sdev
->hostdata
;
3511 if (!sas_device_priv_data
)
3513 if (sas_device_priv_data
->block
)
3515 if (sas_device_priv_data
->ignore_delay_remove
) {
3516 sdev_printk(KERN_INFO
, sdev
,
3517 "%s skip device_block for SES handle(0x%04x)\n",
3518 __func__
, sas_device_priv_data
->sas_target
->handle
);
3521 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3526 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3527 * @ioc: per adapter object
3528 * @handle: device handle
3530 * During device pull we need to appropriately set the sdev state.
3533 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3535 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3536 struct scsi_device
*sdev
;
3537 struct _sas_device
*sas_device
;
3539 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3541 shost_for_each_device(sdev
, ioc
->shost
) {
3542 sas_device_priv_data
= sdev
->hostdata
;
3543 if (!sas_device_priv_data
)
3545 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3547 if (sas_device_priv_data
->block
)
3549 if (sas_device
&& sas_device
->pend_sas_rphy_add
)
3551 if (sas_device_priv_data
->ignore_delay_remove
) {
3552 sdev_printk(KERN_INFO
, sdev
,
3553 "%s skip device_block for SES handle(0x%04x)\n",
3554 __func__
, sas_device_priv_data
->sas_target
->handle
);
3557 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3561 sas_device_put(sas_device
);
3565 * _scsih_block_io_to_children_attached_to_ex
3566 * @ioc: per adapter object
3567 * @sas_expander: the sas_device object
3569 * This routine set sdev state to SDEV_BLOCK for all devices
3570 * attached to this expander. This function called when expander is
3574 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3575 struct _sas_node
*sas_expander
)
3577 struct _sas_port
*mpt3sas_port
;
3578 struct _sas_device
*sas_device
;
3579 struct _sas_node
*expander_sibling
;
3580 unsigned long flags
;
3585 list_for_each_entry(mpt3sas_port
,
3586 &sas_expander
->sas_port_list
, port_list
) {
3587 if (mpt3sas_port
->remote_identify
.device_type
==
3589 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3590 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3591 mpt3sas_port
->remote_identify
.sas_address
);
3593 set_bit(sas_device
->handle
,
3594 ioc
->blocking_handles
);
3595 sas_device_put(sas_device
);
3597 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3601 list_for_each_entry(mpt3sas_port
,
3602 &sas_expander
->sas_port_list
, port_list
) {
3604 if (mpt3sas_port
->remote_identify
.device_type
==
3605 SAS_EDGE_EXPANDER_DEVICE
||
3606 mpt3sas_port
->remote_identify
.device_type
==
3607 SAS_FANOUT_EXPANDER_DEVICE
) {
3609 mpt3sas_scsih_expander_find_by_sas_address(
3610 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3611 _scsih_block_io_to_children_attached_to_ex(ioc
,
3618 * _scsih_block_io_to_children_attached_directly
3619 * @ioc: per adapter object
3620 * @event_data: topology change event data
3622 * This routine set sdev state to SDEV_BLOCK for all devices
3623 * direct attached during device pull.
3626 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3627 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3633 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3634 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3637 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3638 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3639 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3640 _scsih_block_io_device(ioc
, handle
);
3645 * _scsih_block_io_to_pcie_children_attached_directly
3646 * @ioc: per adapter object
3647 * @event_data: topology change event data
3649 * This routine set sdev state to SDEV_BLOCK for all devices
3650 * direct attached during device pull/reconnect.
3653 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3654 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
3660 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3662 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
3665 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
3667 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
)
3668 _scsih_block_io_device(ioc
, handle
);
3672 * _scsih_tm_tr_send - send task management request
3673 * @ioc: per adapter object
3674 * @handle: device handle
3675 * Context: interrupt time.
3677 * This code is to initiate the device removal handshake protocol
3678 * with controller firmware. This function will issue target reset
3679 * using high priority request queue. It will send a sas iounit
3680 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3682 * This is designed to send muliple task management request at the same
3683 * time to the fifo. If the fifo is full, we will append the request,
3684 * and process it in a future completion.
3687 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3689 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3691 struct _sas_device
*sas_device
= NULL
;
3692 struct _pcie_device
*pcie_device
= NULL
;
3693 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3694 u64 sas_address
= 0;
3695 unsigned long flags
;
3696 struct _tr_list
*delayed_tr
;
3699 if (ioc
->pci_error_recovery
) {
3700 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3701 "%s: host in pci error recovery: handle(0x%04x)\n",
3702 __func__
, ioc
->name
,
3706 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3707 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3708 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3709 "%s: host is not operational: handle(0x%04x)\n",
3710 __func__
, ioc
->name
,
3715 /* if PD, then return */
3716 if (test_bit(handle
, ioc
->pd_handles
))
3719 clear_bit(handle
, ioc
->pend_os_device_add
);
3721 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3722 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3723 if (sas_device
&& sas_device
->starget
&&
3724 sas_device
->starget
->hostdata
) {
3725 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3726 sas_target_priv_data
->deleted
= 1;
3727 sas_address
= sas_device
->sas_address
;
3729 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3731 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
3732 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
3733 if (pcie_device
&& pcie_device
->starget
&&
3734 pcie_device
->starget
->hostdata
) {
3735 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
3736 sas_target_priv_data
->deleted
= 1;
3737 sas_address
= pcie_device
->wwid
;
3739 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
3741 if (sas_target_priv_data
) {
3742 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3743 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3745 (unsigned long long)sas_address
));
3747 if (sas_device
->enclosure_handle
!= 0)
3748 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3749 "setting delete flag:enclosure logical "
3750 "id(0x%016llx), slot(%d)\n", ioc
->name
,
3751 (unsigned long long)
3752 sas_device
->enclosure_logical_id
,
3754 if (sas_device
->connector_name
[0] != '\0')
3755 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3756 "setting delete flag: enclosure "
3757 "level(0x%04x), connector name( %s)\n",
3758 ioc
->name
, sas_device
->enclosure_level
,
3759 sas_device
->connector_name
));
3760 } else if (pcie_device
) {
3761 if (pcie_device
->enclosure_handle
!= 0)
3762 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3763 "setting delete flag: logical "
3764 "id(0x%016llx), slot(%d)\n", ioc
->name
,
3765 (unsigned long long)
3766 pcie_device
->enclosure_logical_id
,
3767 pcie_device
->slot
));
3768 if (pcie_device
->connector_name
[0] != '\0')
3769 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3770 "setting delete flag:, enclosure "
3772 "connector name( %s)\n", ioc
->name
,
3773 pcie_device
->enclosure_level
,
3774 pcie_device
->connector_name
));
3776 _scsih_ublock_io_device(ioc
, sas_address
);
3777 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3780 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3782 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3785 INIT_LIST_HEAD(&delayed_tr
->list
);
3786 delayed_tr
->handle
= handle
;
3787 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3788 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3789 "DELAYED:tr:handle(0x%04x), (open)\n",
3790 ioc
->name
, handle
));
3794 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3795 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3796 ioc
->name
, handle
, smid
,
3797 ioc
->tm_tr_cb_idx
));
3798 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3799 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3800 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3801 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3802 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3803 set_bit(handle
, ioc
->device_remove_in_progress
);
3804 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3805 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3809 sas_device_put(sas_device
);
3811 pcie_device_put(pcie_device
);
3815 * _scsih_tm_tr_complete -
3816 * @ioc: per adapter object
3817 * @smid: system request message index
3818 * @msix_index: MSIX table index supplied by the OS
3819 * @reply: reply message frame(lower 32bit addr)
3820 * Context: interrupt time.
3822 * This is the target reset completion routine.
3823 * This code is part of the code to initiate the device removal
3824 * handshake protocol with controller firmware.
3825 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3827 * Return 1 meaning mf should be freed from _base_interrupt
3828 * 0 means the mf is freed from this function.
3831 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3835 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3836 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3837 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3838 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3841 struct _sc_list
*delayed_sc
;
3843 if (ioc
->remove_host
) {
3844 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3845 "%s: host has been removed\n", __func__
, ioc
->name
));
3847 } else if (ioc
->pci_error_recovery
) {
3848 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3849 "%s: host in pci error recovery\n", __func__
,
3853 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3854 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3855 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3856 "%s: host is not operational\n", __func__
, ioc
->name
));
3859 if (unlikely(!mpi_reply
)) {
3860 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3861 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3864 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3865 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3866 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3867 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3868 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3870 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3874 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3875 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3876 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3877 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3878 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3879 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3880 le32_to_cpu(mpi_reply
->TerminationCount
)));
3882 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3883 if (!smid_sas_ctrl
) {
3884 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3886 return _scsih_check_for_pending_tm(ioc
, smid
);
3887 INIT_LIST_HEAD(&delayed_sc
->list
);
3888 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3889 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3890 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3891 "DELAYED:sc:handle(0x%04x), (open)\n",
3892 ioc
->name
, handle
));
3893 return _scsih_check_for_pending_tm(ioc
, smid
);
3896 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3897 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3898 ioc
->name
, handle
, smid_sas_ctrl
,
3899 ioc
->tm_sas_control_cb_idx
));
3900 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3901 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3902 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3903 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3904 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3905 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3907 return _scsih_check_for_pending_tm(ioc
, smid
);
3910 /** _scsih_allow_scmd_to_device - check whether scmd needs to
3911 * issue to IOC or not.
3912 * @ioc: per adapter object
3913 * @scmd: pointer to scsi command object
3915 * Returns true if scmd can be issued to IOC otherwise returns false.
3917 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER
*ioc
,
3918 struct scsi_cmnd
*scmd
)
3921 if (ioc
->pci_error_recovery
)
3924 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
) {
3925 if (ioc
->remove_host
)
3931 if (ioc
->remove_host
) {
3933 switch (scmd
->cmnd
[0]) {
3934 case SYNCHRONIZE_CACHE
:
3946 * _scsih_sas_control_complete - completion routine
3947 * @ioc: per adapter object
3948 * @smid: system request message index
3949 * @msix_index: MSIX table index supplied by the OS
3950 * @reply: reply message frame(lower 32bit addr)
3951 * Context: interrupt time.
3953 * This is the sas iounit control completion routine.
3954 * This code is part of the code to initiate the device removal
3955 * handshake protocol with controller firmware.
3957 * Return 1 meaning mf should be freed from _base_interrupt
3958 * 0 means the mf is freed from this function.
3961 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3962 u8 msix_index
, u32 reply
)
3964 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3965 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3967 if (likely(mpi_reply
)) {
3968 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3969 "sc_complete:handle(0x%04x), (open) "
3970 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3971 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3972 le16_to_cpu(mpi_reply
->IOCStatus
),
3973 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3974 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3975 MPI2_IOCSTATUS_SUCCESS
) {
3976 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3977 ioc
->device_remove_in_progress
);
3980 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3981 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3983 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3987 * _scsih_tm_tr_volume_send - send target reset request for volumes
3988 * @ioc: per adapter object
3989 * @handle: device handle
3990 * Context: interrupt time.
3992 * This is designed to send muliple task management request at the same
3993 * time to the fifo. If the fifo is full, we will append the request,
3994 * and process it in a future completion.
3997 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3999 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
4001 struct _tr_list
*delayed_tr
;
4003 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4004 ioc
->pci_error_recovery
) {
4005 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4006 "%s: host reset in progress!\n",
4007 __func__
, ioc
->name
));
4011 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
4013 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
4016 INIT_LIST_HEAD(&delayed_tr
->list
);
4017 delayed_tr
->handle
= handle
;
4018 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
4019 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4020 "DELAYED:tr:handle(0x%04x), (open)\n",
4021 ioc
->name
, handle
));
4025 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4026 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4027 ioc
->name
, handle
, smid
,
4028 ioc
->tm_tr_volume_cb_idx
));
4029 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4030 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
4031 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
4032 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4033 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
4034 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
4038 * _scsih_tm_volume_tr_complete - target reset completion
4039 * @ioc: per adapter object
4040 * @smid: system request message index
4041 * @msix_index: MSIX table index supplied by the OS
4042 * @reply: reply message frame(lower 32bit addr)
4043 * Context: interrupt time.
4045 * Return 1 meaning mf should be freed from _base_interrupt
4046 * 0 means the mf is freed from this function.
4049 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
4050 u8 msix_index
, u32 reply
)
4053 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
4054 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
4055 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4057 if (ioc
->shost_recovery
|| ioc
->remove_host
||
4058 ioc
->pci_error_recovery
) {
4059 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4060 "%s: host reset in progress!\n",
4061 __func__
, ioc
->name
));
4064 if (unlikely(!mpi_reply
)) {
4065 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
4066 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4070 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4071 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
4072 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
4073 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
4074 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
4076 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
4080 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4081 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
4082 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
4083 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
4084 le32_to_cpu(mpi_reply
->IOCLogInfo
),
4085 le32_to_cpu(mpi_reply
->TerminationCount
)));
4087 return _scsih_check_for_pending_tm(ioc
, smid
);
4091 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
4092 * @ioc: per adapter object
4093 * @smid: system request message index
4095 * @event_context: used to track events uniquely
4097 * Context - processed in interrupt context.
4100 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
4103 Mpi2EventAckRequest_t
*ack_request
;
4104 int i
= smid
- ioc
->internal_smid
;
4105 unsigned long flags
;
4107 /* Without releasing the smid just update the
4108 * call back index and reuse the same smid for
4109 * processing this delayed request
4111 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4112 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
4113 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4115 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4116 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
4117 ioc
->name
, le16_to_cpu(event
), smid
,
4119 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4120 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
4121 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
4122 ack_request
->Event
= event
;
4123 ack_request
->EventContext
= event_context
;
4124 ack_request
->VF_ID
= 0; /* TODO */
4125 ack_request
->VP_ID
= 0;
4126 ioc
->put_smid_default(ioc
, smid
);
4130 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
4131 * sas_io_unit_ctrl messages
4132 * @ioc: per adapter object
4133 * @smid: system request message index
4134 * @handle: device handle
4136 * Context - processed in interrupt context.
4139 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
4140 u16 smid
, u16 handle
)
4142 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
4144 int i
= smid
- ioc
->internal_smid
;
4145 unsigned long flags
;
4147 if (ioc
->remove_host
) {
4148 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4149 "%s: host has been removed\n",
4150 __func__
, ioc
->name
));
4152 } else if (ioc
->pci_error_recovery
) {
4153 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4154 "%s: host in pci error recovery\n",
4155 __func__
, ioc
->name
));
4158 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4159 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4160 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4161 "%s: host is not operational\n",
4162 __func__
, ioc
->name
));
4166 /* Without releasing the smid just update the
4167 * call back index and reuse the same smid for
4168 * processing this delayed request
4170 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4171 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
4172 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4174 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4175 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4176 ioc
->name
, le16_to_cpu(handle
), smid
,
4177 ioc
->tm_sas_control_cb_idx
));
4178 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4179 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4180 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4181 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4182 mpi_request
->DevHandle
= handle
;
4183 ioc
->put_smid_default(ioc
, smid
);
4187 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
4188 * @ioc: per adapter object
4189 * @smid: system request message index
4191 * Context: Executed in interrupt context
4193 * This will check delayed internal messages list, and process the
4196 * Return 1 meaning mf should be freed from _base_interrupt
4197 * 0 means the mf is freed from this function.
4200 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4202 struct _sc_list
*delayed_sc
;
4203 struct _event_ack_list
*delayed_event_ack
;
4205 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
4206 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
4207 struct _event_ack_list
, list
);
4208 _scsih_issue_delayed_event_ack(ioc
, smid
,
4209 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
4210 list_del(&delayed_event_ack
->list
);
4211 kfree(delayed_event_ack
);
4215 if (!list_empty(&ioc
->delayed_sc_list
)) {
4216 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
4217 struct _sc_list
, list
);
4218 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
4219 delayed_sc
->handle
);
4220 list_del(&delayed_sc
->list
);
4228 * _scsih_check_for_pending_tm - check for pending task management
4229 * @ioc: per adapter object
4230 * @smid: system request message index
4232 * This will check delayed target reset list, and feed the
4235 * Return 1 meaning mf should be freed from _base_interrupt
4236 * 0 means the mf is freed from this function.
4239 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4241 struct _tr_list
*delayed_tr
;
4243 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
4244 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
4245 struct _tr_list
, list
);
4246 mpt3sas_base_free_smid(ioc
, smid
);
4247 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
4248 list_del(&delayed_tr
->list
);
4253 if (!list_empty(&ioc
->delayed_tr_list
)) {
4254 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
4255 struct _tr_list
, list
);
4256 mpt3sas_base_free_smid(ioc
, smid
);
4257 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
4258 list_del(&delayed_tr
->list
);
4267 * _scsih_check_topo_delete_events - sanity check on topo events
4268 * @ioc: per adapter object
4269 * @event_data: the event data payload
4271 * This routine added to better handle cable breaker.
4273 * This handles the case where driver receives multiple expander
4274 * add and delete events in a single shot. When there is a delete event
4275 * the routine will void any pending add events waiting in the event queue.
4280 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4281 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4283 struct fw_event_work
*fw_event
;
4284 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
4285 u16 expander_handle
;
4286 struct _sas_node
*sas_expander
;
4287 unsigned long flags
;
4291 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
4292 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4295 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4296 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4297 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
4298 _scsih_tm_tr_send(ioc
, handle
);
4301 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4302 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
4303 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4306 if (event_data
->ExpStatus
==
4307 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
4308 /* put expander attached devices into blocking state */
4309 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4310 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
4312 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
4313 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4315 handle
= find_first_bit(ioc
->blocking_handles
,
4316 ioc
->facts
.MaxDevHandle
);
4317 if (handle
< ioc
->facts
.MaxDevHandle
)
4318 _scsih_block_io_device(ioc
, handle
);
4319 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
4320 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
4321 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4323 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4326 /* mark ignore flag for pending events */
4327 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4328 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4329 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
4332 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
4333 fw_event
->event_data
;
4334 if (local_event_data
->ExpStatus
==
4335 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4336 local_event_data
->ExpStatus
==
4337 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4338 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
4340 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4341 "setting ignoring flag\n", ioc
->name
));
4342 fw_event
->ignore
= 1;
4346 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4350 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4352 * @ioc: per adapter object
4353 * @event_data: the event data payload
4355 * This handles the case where driver receives multiple switch
4356 * or device add and delete events in a single shot. When there
4357 * is a delete event the routine will void any pending add
4358 * events waiting in the event queue.
4363 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER
*ioc
,
4364 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
4366 struct fw_event_work
*fw_event
;
4367 Mpi26EventDataPCIeTopologyChangeList_t
*local_event_data
;
4368 unsigned long flags
;
4370 u16 handle
, switch_handle
;
4372 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4374 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
4377 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
4378 if (reason_code
== MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
)
4379 _scsih_tm_tr_send(ioc
, handle
);
4382 switch_handle
= le16_to_cpu(event_data
->SwitchDevHandle
);
4383 if (!switch_handle
) {
4384 _scsih_block_io_to_pcie_children_attached_directly(
4388 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4389 if ((event_data
->SwitchStatus
4390 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
) ||
4391 (event_data
->SwitchStatus
==
4392 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
))
4393 _scsih_block_io_to_pcie_children_attached_directly(
4396 if (event_data
->SwitchStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4399 /* mark ignore flag for pending events */
4400 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4401 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4402 if (fw_event
->event
!= MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
||
4406 (Mpi26EventDataPCIeTopologyChangeList_t
*)
4407 fw_event
->event_data
;
4408 if (local_event_data
->SwitchStatus
==
4409 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4410 local_event_data
->SwitchStatus
==
4411 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4412 if (le16_to_cpu(local_event_data
->SwitchDevHandle
) ==
4414 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4415 "setting ignoring flag for switch event\n",
4417 fw_event
->ignore
= 1;
4421 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4425 * _scsih_set_volume_delete_flag - setting volume delete flag
4426 * @ioc: per adapter object
4427 * @handle: device handle
4429 * This returns nothing.
4432 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4434 struct _raid_device
*raid_device
;
4435 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4436 unsigned long flags
;
4438 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4439 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
4440 if (raid_device
&& raid_device
->starget
&&
4441 raid_device
->starget
->hostdata
) {
4442 sas_target_priv_data
=
4443 raid_device
->starget
->hostdata
;
4444 sas_target_priv_data
->deleted
= 1;
4445 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4446 "setting delete flag: handle(0x%04x), "
4447 "wwid(0x%016llx)\n", ioc
->name
, handle
,
4448 (unsigned long long) raid_device
->wwid
));
4450 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4454 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4455 * @handle: input handle
4456 * @a: handle for volume a
4457 * @b: handle for volume b
4459 * IR firmware only supports two raid volumes. The purpose of this
4460 * routine is to set the volume handle in either a or b. When the given
4461 * input handle is non-zero, or when a and b have not been set before.
4464 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
4466 if (!handle
|| handle
== *a
|| handle
== *b
)
4475 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4476 * @ioc: per adapter object
4477 * @event_data: the event data payload
4478 * Context: interrupt time.
4480 * This routine will send target reset to volume, followed by target
4481 * resets to the PDs. This is called when a PD has been removed, or
4482 * volume has been deleted or removed. When the target reset is sent
4483 * to volume, the PD target resets need to be queued to start upon
4484 * completion of the volume target reset.
4489 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
4490 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4492 Mpi2EventIrConfigElement_t
*element
;
4494 u16 handle
, volume_handle
, a
, b
;
4495 struct _tr_list
*delayed_tr
;
4500 if (ioc
->is_warpdrive
)
4503 /* Volume Resets for Deleted or Removed */
4504 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4505 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4506 if (le32_to_cpu(event_data
->Flags
) &
4507 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4509 if (element
->ReasonCode
==
4510 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
4511 element
->ReasonCode
==
4512 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
4513 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4514 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
4515 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4519 /* Volume Resets for UNHIDE events */
4520 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4521 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4522 if (le32_to_cpu(event_data
->Flags
) &
4523 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4525 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
4526 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4527 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4532 _scsih_tm_tr_volume_send(ioc
, a
);
4534 _scsih_tm_tr_volume_send(ioc
, b
);
4536 /* PD target resets */
4537 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4538 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4539 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
4541 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4542 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4543 clear_bit(handle
, ioc
->pd_handles
);
4545 _scsih_tm_tr_send(ioc
, handle
);
4546 else if (volume_handle
== a
|| volume_handle
== b
) {
4547 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
4548 BUG_ON(!delayed_tr
);
4549 INIT_LIST_HEAD(&delayed_tr
->list
);
4550 delayed_tr
->handle
= handle
;
4551 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
4552 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4553 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
4556 _scsih_tm_tr_send(ioc
, handle
);
4562 * _scsih_check_volume_delete_events - set delete flag for volumes
4563 * @ioc: per adapter object
4564 * @event_data: the event data payload
4565 * Context: interrupt time.
4567 * This will handle the case when the cable connected to entire volume is
4568 * pulled. We will take care of setting the deleted flag so normal IO will
4574 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4575 Mpi2EventDataIrVolume_t
*event_data
)
4579 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4581 state
= le32_to_cpu(event_data
->NewValue
);
4582 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
4583 MPI2_RAID_VOL_STATE_FAILED
)
4584 _scsih_set_volume_delete_flag(ioc
,
4585 le16_to_cpu(event_data
->VolDevHandle
));
4589 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4590 * @ioc: per adapter object
4591 * @event_data: the temp threshold event data
4592 * Context: interrupt time.
4597 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
4598 Mpi2EventDataTemperature_t
*event_data
)
4600 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
4601 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
4602 " exceeded for Sensor: %d !!!\n", ioc
->name
,
4603 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
4604 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
4605 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
4606 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
4607 event_data
->SensorNum
);
4608 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
4609 ioc
->name
, event_data
->CurrentTemperature
);
4613 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
4615 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
4617 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
4621 return test_and_set_bit(0, &priv
->ata_command_pending
);
4623 clear_bit(0, &priv
->ata_command_pending
);
4628 * _scsih_flush_running_cmds - completing outstanding commands.
4629 * @ioc: per adapter object
4631 * The flushing out of all pending scmd commands following host reset,
4632 * where all IO is dropped to the floor.
4637 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
4639 struct scsi_cmnd
*scmd
;
4643 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4644 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4648 _scsih_set_satl_pending(scmd
, false);
4649 mpt3sas_base_free_smid(ioc
, smid
);
4650 scsi_dma_unmap(scmd
);
4651 if (ioc
->pci_error_recovery
|| ioc
->remove_host
)
4652 scmd
->result
= DID_NO_CONNECT
<< 16;
4654 scmd
->result
= DID_RESET
<< 16;
4655 scmd
->scsi_done(scmd
);
4657 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
4662 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4663 * @ioc: per adapter object
4664 * @scmd: pointer to scsi command object
4665 * @mpi_request: pointer to the SCSI_IO request message frame
4667 * Supporting protection 1 and 3.
4672 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4673 Mpi25SCSIIORequest_t
*mpi_request
)
4676 unsigned char prot_op
= scsi_get_prot_op(scmd
);
4677 unsigned char prot_type
= scsi_get_prot_type(scmd
);
4678 Mpi25SCSIIORequest_t
*mpi_request_3v
=
4679 (Mpi25SCSIIORequest_t
*)mpi_request
;
4681 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
4684 if (prot_op
== SCSI_PROT_READ_STRIP
)
4685 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
4686 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
4687 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
4691 switch (prot_type
) {
4692 case SCSI_PROT_DIF_TYPE1
:
4693 case SCSI_PROT_DIF_TYPE2
:
4696 * enable ref/guard checking
4697 * auto increment ref tag
4699 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4700 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4701 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4702 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4703 cpu_to_be32(scsi_prot_ref_tag(scmd
));
4706 case SCSI_PROT_DIF_TYPE3
:
4709 * enable guard checking
4711 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4716 mpi_request_3v
->EEDPBlockSize
=
4717 cpu_to_le16(scmd
->device
->sector_size
);
4719 if (ioc
->is_gen35_ioc
)
4720 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4721 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4725 * _scsih_eedp_error_handling - return sense code for EEDP errors
4726 * @scmd: pointer to scsi command object
4727 * @ioc_status: ioc status
4732 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4736 switch (ioc_status
) {
4737 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4740 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4743 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4750 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4752 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4753 SAM_STAT_CHECK_CONDITION
;
4757 * scsih_qcmd - main scsi request entry point
4758 * @scmd: pointer to scsi command object
4759 * @done: function pointer to be invoked on completion
4761 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4763 * Returns 0 on success. If there's a failure, return either:
4764 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4765 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4768 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4770 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4771 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4772 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4773 struct _raid_device
*raid_device
;
4774 struct request
*rq
= scmd
->request
;
4776 Mpi25SCSIIORequest_t
*mpi_request
;
4777 struct _pcie_device
*pcie_device
= NULL
;
4782 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4783 scsi_print_command(scmd
);
4785 sas_device_priv_data
= scmd
->device
->hostdata
;
4786 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4787 scmd
->result
= DID_NO_CONNECT
<< 16;
4788 scmd
->scsi_done(scmd
);
4792 if (!(_scsih_allow_scmd_to_device(ioc
, scmd
))) {
4793 scmd
->result
= DID_NO_CONNECT
<< 16;
4794 scmd
->scsi_done(scmd
);
4798 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4800 /* invalid device handle */
4801 handle
= sas_target_priv_data
->handle
;
4802 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4803 scmd
->result
= DID_NO_CONNECT
<< 16;
4804 scmd
->scsi_done(scmd
);
4809 /* host recovery or link resets sent via IOCTLs */
4810 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4811 return SCSI_MLQUEUE_HOST_BUSY
;
4813 /* device has been deleted */
4814 else if (sas_target_priv_data
->deleted
) {
4815 scmd
->result
= DID_NO_CONNECT
<< 16;
4816 scmd
->scsi_done(scmd
);
4818 /* device busy with task management */
4819 } else if (sas_target_priv_data
->tm_busy
||
4820 sas_device_priv_data
->block
)
4821 return SCSI_MLQUEUE_DEVICE_BUSY
;
4824 * Bug work around for firmware SATL handling. The loop
4825 * is based on atomic operations and ensures consistency
4826 * since we're lockless at this point
4829 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
)) {
4830 scmd
->result
= SAM_STAT_BUSY
;
4831 scmd
->scsi_done(scmd
);
4834 } while (_scsih_set_satl_pending(scmd
, true));
4836 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4837 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4838 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4839 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4841 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4844 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4845 /* NCQ Prio supported, make sure control indicated high priority */
4846 if (sas_device_priv_data
->ncq_prio_enable
) {
4847 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4848 if (class == IOPRIO_CLASS_RT
)
4849 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4851 /* Make sure Device is not raid volume.
4852 * We do not expose raid functionality to upper layer for warpdrive.
4854 if (((!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
))
4855 && !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
4856 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4857 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4859 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4861 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4862 ioc
->name
, __func__
);
4863 _scsih_set_satl_pending(scmd
, false);
4866 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4867 memset(mpi_request
, 0, ioc
->request_sz
);
4868 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4870 if (scmd
->cmd_len
== 32)
4871 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4872 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4873 if (sas_device_priv_data
->sas_target
->flags
&
4874 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4875 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4877 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4878 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4879 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4880 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4881 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4882 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4883 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4884 mpi_request
->SenseBufferLowAddress
=
4885 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4886 mpi_request
->SGLOffset0
= offsetof(Mpi25SCSIIORequest_t
, SGL
) / 4;
4887 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4889 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4891 if (mpi_request
->DataLength
) {
4892 pcie_device
= sas_target_priv_data
->pcie_dev
;
4893 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
, pcie_device
)) {
4894 mpt3sas_base_free_smid(ioc
, smid
);
4895 _scsih_set_satl_pending(scmd
, false);
4899 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4901 raid_device
= sas_target_priv_data
->raid_device
;
4902 if (raid_device
&& raid_device
->direct_io_enabled
)
4903 mpt3sas_setup_direct_io(ioc
, scmd
,
4904 raid_device
, mpi_request
, smid
);
4906 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4907 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4908 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4909 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4910 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4912 ioc
->put_smid_scsi_io(ioc
, smid
,
4913 le16_to_cpu(mpi_request
->DevHandle
));
4915 ioc
->put_smid_default(ioc
, smid
);
4919 return SCSI_MLQUEUE_HOST_BUSY
;
4923 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4924 * @sense_buffer: sense data returned by target
4925 * @data: normalized skey/asc/ascq
4930 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4932 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4933 /* descriptor format */
4934 data
->skey
= sense_buffer
[1] & 0x0F;
4935 data
->asc
= sense_buffer
[2];
4936 data
->ascq
= sense_buffer
[3];
4939 data
->skey
= sense_buffer
[2] & 0x0F;
4940 data
->asc
= sense_buffer
[12];
4941 data
->ascq
= sense_buffer
[13];
4946 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4947 * @ioc: per adapter object
4948 * @scmd: pointer to scsi command object
4949 * @mpi_reply: reply mf payload returned from firmware
4951 * scsi_status - SCSI Status code returned from target device
4952 * scsi_state - state info associated with SCSI_IO determined by ioc
4953 * ioc_status - ioc supplied status info
4958 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4959 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4963 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4964 MPI2_IOCSTATUS_MASK
;
4965 u8 scsi_state
= mpi_reply
->SCSIState
;
4966 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4967 char *desc_ioc_state
= NULL
;
4968 char *desc_scsi_status
= NULL
;
4969 char *desc_scsi_state
= ioc
->tmp_string
;
4970 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4971 struct _sas_device
*sas_device
= NULL
;
4972 struct _pcie_device
*pcie_device
= NULL
;
4973 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4974 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4975 char *device_str
= NULL
;
4979 if (ioc
->hide_ir_msg
)
4980 device_str
= "WarpDrive";
4982 device_str
= "volume";
4984 if (log_info
== 0x31170000)
4987 switch (ioc_status
) {
4988 case MPI2_IOCSTATUS_SUCCESS
:
4989 desc_ioc_state
= "success";
4991 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4992 desc_ioc_state
= "invalid function";
4994 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4995 desc_ioc_state
= "scsi recovered error";
4997 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4998 desc_ioc_state
= "scsi invalid dev handle";
5000 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
5001 desc_ioc_state
= "scsi device not there";
5003 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
5004 desc_ioc_state
= "scsi data overrun";
5006 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
5007 desc_ioc_state
= "scsi data underrun";
5009 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
5010 desc_ioc_state
= "scsi io data error";
5012 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
5013 desc_ioc_state
= "scsi protocol error";
5015 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
5016 desc_ioc_state
= "scsi task terminated";
5018 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
5019 desc_ioc_state
= "scsi residual mismatch";
5021 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
5022 desc_ioc_state
= "scsi task mgmt failed";
5024 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
5025 desc_ioc_state
= "scsi ioc terminated";
5027 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
5028 desc_ioc_state
= "scsi ext terminated";
5030 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
5031 desc_ioc_state
= "eedp guard error";
5033 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
5034 desc_ioc_state
= "eedp ref tag error";
5036 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
5037 desc_ioc_state
= "eedp app tag error";
5039 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
5040 desc_ioc_state
= "insufficient power";
5043 desc_ioc_state
= "unknown";
5047 switch (scsi_status
) {
5048 case MPI2_SCSI_STATUS_GOOD
:
5049 desc_scsi_status
= "good";
5051 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
5052 desc_scsi_status
= "check condition";
5054 case MPI2_SCSI_STATUS_CONDITION_MET
:
5055 desc_scsi_status
= "condition met";
5057 case MPI2_SCSI_STATUS_BUSY
:
5058 desc_scsi_status
= "busy";
5060 case MPI2_SCSI_STATUS_INTERMEDIATE
:
5061 desc_scsi_status
= "intermediate";
5063 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
5064 desc_scsi_status
= "intermediate condmet";
5066 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
5067 desc_scsi_status
= "reservation conflict";
5069 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
5070 desc_scsi_status
= "command terminated";
5072 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
5073 desc_scsi_status
= "task set full";
5075 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
5076 desc_scsi_status
= "aca active";
5078 case MPI2_SCSI_STATUS_TASK_ABORTED
:
5079 desc_scsi_status
= "task aborted";
5082 desc_scsi_status
= "unknown";
5086 desc_scsi_state
[0] = '\0';
5088 desc_scsi_state
= " ";
5089 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
5090 strcat(desc_scsi_state
, "response info ");
5091 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5092 strcat(desc_scsi_state
, "state terminated ");
5093 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
5094 strcat(desc_scsi_state
, "no status ");
5095 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
5096 strcat(desc_scsi_state
, "autosense failed ");
5097 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
5098 strcat(desc_scsi_state
, "autosense valid ");
5100 scsi_print_command(scmd
);
5102 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
5103 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
5104 device_str
, (unsigned long long)priv_target
->sas_address
);
5105 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
5106 pcie_device
= mpt3sas_get_pdev_from_target(ioc
, priv_target
);
5108 pr_info(MPT3SAS_FMT
"\twwid(0x%016llx), port(%d)\n",
5110 (unsigned long long)pcie_device
->wwid
,
5111 pcie_device
->port_num
);
5112 if (pcie_device
->enclosure_handle
!= 0)
5114 "\tenclosure logical id(0x%016llx), "
5115 "slot(%d)\n", ioc
->name
,
5116 (unsigned long long)
5117 pcie_device
->enclosure_logical_id
,
5119 if (pcie_device
->connector_name
[0])
5121 "\tenclosure level(0x%04x),"
5122 "connector name( %s)\n",
5123 ioc
->name
, pcie_device
->enclosure_level
,
5124 pcie_device
->connector_name
);
5125 pcie_device_put(pcie_device
);
5128 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
5131 "\tsas_address(0x%016llx), phy(%d)\n",
5132 ioc
->name
, (unsigned long long)
5133 sas_device
->sas_address
, sas_device
->phy
);
5135 _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
5138 sas_device_put(sas_device
);
5143 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
5144 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
5145 desc_ioc_state
, ioc_status
, smid
);
5147 "\trequest_len(%d), underflow(%d), resid(%d)\n",
5148 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
5149 scsi_get_resid(scmd
));
5151 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
5152 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
5153 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
5155 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
5156 ioc
->name
, desc_scsi_status
,
5157 scsi_status
, desc_scsi_state
, scsi_state
);
5159 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5160 struct sense_info data
;
5161 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5163 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
5164 ioc
->name
, data
.skey
,
5165 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
5167 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
5168 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
5169 response_bytes
= (u8
*)&response_info
;
5170 _scsih_response_code(ioc
, response_bytes
[0]);
5175 * _scsih_turn_on_pfa_led - illuminate PFA LED
5176 * @ioc: per adapter object
5177 * @handle: device handle
5183 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5185 Mpi2SepReply_t mpi_reply
;
5186 Mpi2SepRequest_t mpi_request
;
5187 struct _sas_device
*sas_device
;
5189 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
5193 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5194 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5195 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5196 mpi_request
.SlotStatus
=
5197 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
5198 mpi_request
.DevHandle
= cpu_to_le16(handle
);
5199 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
5200 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5201 &mpi_request
)) != 0) {
5202 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5203 __FILE__
, __LINE__
, __func__
);
5206 sas_device
->pfa_led_on
= 1;
5208 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5209 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5210 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5211 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5212 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5216 sas_device_put(sas_device
);
5220 * _scsih_turn_off_pfa_led - turn off Fault LED
5221 * @ioc: per adapter object
5222 * @sas_device: sas device whose PFA LED has to turned off
5228 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
5229 struct _sas_device
*sas_device
)
5231 Mpi2SepReply_t mpi_reply
;
5232 Mpi2SepRequest_t mpi_request
;
5234 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5235 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5236 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5237 mpi_request
.SlotStatus
= 0;
5238 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
5239 mpi_request
.DevHandle
= 0;
5240 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
5241 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
5242 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5243 &mpi_request
)) != 0) {
5244 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5245 __FILE__
, __LINE__
, __func__
);
5249 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5250 dewtprintk(ioc
, printk(MPT3SAS_FMT
5251 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5252 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5253 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5259 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5260 * @ioc: per adapter object
5261 * @handle: device handle
5262 * Context: interrupt.
5267 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5269 struct fw_event_work
*fw_event
;
5271 fw_event
= alloc_fw_event_work(0);
5274 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
5275 fw_event
->device_handle
= handle
;
5276 fw_event
->ioc
= ioc
;
5277 _scsih_fw_event_add(ioc
, fw_event
);
5278 fw_event_work_put(fw_event
);
5282 * _scsih_smart_predicted_fault - process smart errors
5283 * @ioc: per adapter object
5284 * @handle: device handle
5285 * Context: interrupt.
5290 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5292 struct scsi_target
*starget
;
5293 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5294 Mpi2EventNotificationReply_t
*event_reply
;
5295 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
5296 struct _sas_device
*sas_device
;
5298 unsigned long flags
;
5300 /* only handle non-raid devices */
5301 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5302 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
5306 starget
= sas_device
->starget
;
5307 sas_target_priv_data
= starget
->hostdata
;
5309 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
5310 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
5313 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, NULL
, starget
);
5315 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5317 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
5318 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
5320 /* insert into event log */
5321 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
5322 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
5323 event_reply
= kzalloc(sz
, GFP_KERNEL
);
5325 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5326 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5330 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
5331 event_reply
->Event
=
5332 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
5333 event_reply
->MsgLength
= sz
/4;
5334 event_reply
->EventDataLength
=
5335 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
5336 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
5337 event_reply
->EventData
;
5338 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
5339 event_data
->ASC
= 0x5D;
5340 event_data
->DevHandle
= cpu_to_le16(handle
);
5341 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
5342 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
5346 sas_device_put(sas_device
);
5350 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5355 * _scsih_io_done - scsi request callback
5356 * @ioc: per adapter object
5357 * @smid: system request message index
5358 * @msix_index: MSIX table index supplied by the OS
5359 * @reply: reply message frame(lower 32bit addr)
5361 * Callback handler when using _scsih_qcmd.
5363 * Return 1 meaning mf should be freed from _base_interrupt
5364 * 0 means the mf is freed from this function.
5367 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5369 Mpi25SCSIIORequest_t
*mpi_request
;
5370 Mpi2SCSIIOReply_t
*mpi_reply
;
5371 struct scsi_cmnd
*scmd
;
5377 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5378 u32 response_code
= 0;
5379 unsigned long flags
;
5381 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5383 if (ioc
->broadcast_aen_busy
|| ioc
->pci_error_recovery
||
5384 ioc
->got_task_abort_from_ioctl
)
5385 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
5387 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
5392 _scsih_set_satl_pending(scmd
, false);
5394 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5396 if (mpi_reply
== NULL
) {
5397 scmd
->result
= DID_OK
<< 16;
5401 sas_device_priv_data
= scmd
->device
->hostdata
;
5402 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
5403 sas_device_priv_data
->sas_target
->deleted
) {
5404 scmd
->result
= DID_NO_CONNECT
<< 16;
5407 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5410 * WARPDRIVE: If direct_io is set then it is directIO,
5411 * the failed direct I/O should be redirected to volume
5413 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
5414 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
5415 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
5416 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5417 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
5418 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5419 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
5420 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
5421 mpi_request
->DevHandle
=
5422 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
5423 ioc
->put_smid_scsi_io(ioc
, smid
,
5424 sas_device_priv_data
->sas_target
->handle
);
5427 /* turning off TLR */
5428 scsi_state
= mpi_reply
->SCSIState
;
5429 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
5431 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
5432 if (!sas_device_priv_data
->tlr_snoop_check
) {
5433 sas_device_priv_data
->tlr_snoop_check
++;
5434 if ((!ioc
->is_warpdrive
&&
5435 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
5436 !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
5437 && sas_is_tlr_enabled(scmd
->device
) &&
5438 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
5439 sas_disable_tlr(scmd
->device
);
5440 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
5444 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
5445 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
5446 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5447 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5450 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5451 scsi_status
= mpi_reply
->SCSIStatus
;
5453 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
5454 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
5455 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
5456 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
5457 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
5460 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5461 struct sense_info data
;
5462 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
5464 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
5465 le32_to_cpu(mpi_reply
->SenseCount
));
5466 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
5467 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5468 /* failure prediction threshold exceeded */
5469 if (data
.asc
== 0x5D)
5470 _scsih_smart_predicted_fault(ioc
,
5471 le16_to_cpu(mpi_reply
->DevHandle
));
5472 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
5474 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
5475 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
5476 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
5477 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
5478 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5480 switch (ioc_status
) {
5481 case MPI2_IOCSTATUS_BUSY
:
5482 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
5483 scmd
->result
= SAM_STAT_BUSY
;
5486 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
5487 scmd
->result
= DID_NO_CONNECT
<< 16;
5490 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
5491 if (sas_device_priv_data
->block
) {
5492 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
5495 if (log_info
== 0x31110630) {
5496 if (scmd
->retries
> 2) {
5497 scmd
->result
= DID_NO_CONNECT
<< 16;
5498 scsi_device_set_state(scmd
->device
,
5501 scmd
->result
= DID_SOFT_ERROR
<< 16;
5502 scmd
->device
->expecting_cc_ua
= 1;
5505 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
5506 scmd
->result
= DID_RESET
<< 16;
5508 } else if ((scmd
->device
->channel
== RAID_CHANNEL
) &&
5509 (scsi_state
== (MPI2_SCSI_STATE_TERMINATED
|
5510 MPI2_SCSI_STATE_NO_SCSI_STATUS
))) {
5511 scmd
->result
= DID_RESET
<< 16;
5514 scmd
->result
= DID_SOFT_ERROR
<< 16;
5516 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
5517 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
5518 scmd
->result
= DID_RESET
<< 16;
5521 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
5522 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
5523 scmd
->result
= DID_SOFT_ERROR
<< 16;
5525 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5528 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
5529 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5531 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
5534 if (xfer_cnt
< scmd
->underflow
) {
5535 if (scsi_status
== SAM_STAT_BUSY
)
5536 scmd
->result
= SAM_STAT_BUSY
;
5538 scmd
->result
= DID_SOFT_ERROR
<< 16;
5539 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5540 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
5541 scmd
->result
= DID_SOFT_ERROR
<< 16;
5542 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5543 scmd
->result
= DID_RESET
<< 16;
5544 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
5545 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
5546 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
5547 scmd
->result
= (DRIVER_SENSE
<< 24) |
5548 SAM_STAT_CHECK_CONDITION
;
5549 scmd
->sense_buffer
[0] = 0x70;
5550 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
5551 scmd
->sense_buffer
[12] = 0x20;
5552 scmd
->sense_buffer
[13] = 0;
5556 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
5557 scsi_set_resid(scmd
, 0);
5558 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
5559 case MPI2_IOCSTATUS_SUCCESS
:
5560 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5561 if (response_code
==
5562 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
5563 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5564 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
5565 scmd
->result
= DID_SOFT_ERROR
<< 16;
5566 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5567 scmd
->result
= DID_RESET
<< 16;
5570 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
5571 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
5572 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
5573 _scsih_eedp_error_handling(scmd
, ioc_status
);
5576 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
5577 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
5578 case MPI2_IOCSTATUS_INVALID_SGL
:
5579 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
5580 case MPI2_IOCSTATUS_INVALID_FIELD
:
5581 case MPI2_IOCSTATUS_INVALID_STATE
:
5582 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
5583 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
5584 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
5586 scmd
->result
= DID_SOFT_ERROR
<< 16;
5591 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
5592 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5596 scsi_dma_unmap(scmd
);
5598 scmd
->scsi_done(scmd
);
5603 * _scsih_sas_host_refresh - refreshing sas host object contents
5604 * @ioc: per adapter object
5607 * During port enable, fw will send topology events for every device. Its
5608 * possible that the handles may change from the previous setting, so this
5609 * code keeping handles updating if changed.
5614 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
5619 Mpi2ConfigReply_t mpi_reply
;
5620 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5621 u16 attached_handle
;
5624 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
5625 "updating handles for sas_host(0x%016llx)\n",
5626 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
5628 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
5629 * sizeof(Mpi2SasIOUnit0PhyData_t
));
5630 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5631 if (!sas_iounit_pg0
) {
5632 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5633 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5637 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5638 sas_iounit_pg0
, sz
)) != 0)
5640 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5641 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5643 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5644 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
5646 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5647 PhyData
[0].ControllerDevHandle
);
5648 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5649 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
5651 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5652 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
5653 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
5654 attached_handle
, i
, link_rate
);
5657 kfree(sas_iounit_pg0
);
5661 * _scsih_sas_host_add - create sas host object
5662 * @ioc: per adapter object
5664 * Creating host side data object, stored in ioc->sas_hba
5669 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
5672 Mpi2ConfigReply_t mpi_reply
;
5673 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5674 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
5675 Mpi2SasPhyPage0_t phy_pg0
;
5676 Mpi2SasDevicePage0_t sas_device_pg0
;
5677 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5680 u8 device_missing_delay
;
5683 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
5685 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5686 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5689 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
5690 sizeof(struct _sas_phy
), GFP_KERNEL
);
5691 if (!ioc
->sas_hba
.phy
) {
5692 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5693 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5696 ioc
->sas_hba
.num_phys
= num_phys
;
5698 /* sas_iounit page 0 */
5699 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5700 sizeof(Mpi2SasIOUnit0PhyData_t
));
5701 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5702 if (!sas_iounit_pg0
) {
5703 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5704 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5707 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5708 sas_iounit_pg0
, sz
))) {
5709 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5710 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5713 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5714 MPI2_IOCSTATUS_MASK
;
5715 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5716 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5717 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5721 /* sas_iounit page 1 */
5722 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5723 sizeof(Mpi2SasIOUnit1PhyData_t
));
5724 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5725 if (!sas_iounit_pg1
) {
5726 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5727 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5730 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5731 sas_iounit_pg1
, sz
))) {
5732 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5733 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5736 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5737 MPI2_IOCSTATUS_MASK
;
5738 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5739 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5740 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5744 ioc
->io_missing_delay
=
5745 sas_iounit_pg1
->IODeviceMissingDelay
;
5746 device_missing_delay
=
5747 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5748 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5749 ioc
->device_missing_delay
= (device_missing_delay
&
5750 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5752 ioc
->device_missing_delay
= device_missing_delay
&
5753 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5755 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5756 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5757 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5759 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5760 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5763 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5764 MPI2_IOCSTATUS_MASK
;
5765 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5766 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5767 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5772 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5773 PhyData
[0].ControllerDevHandle
);
5774 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5775 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5776 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5777 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5779 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5780 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5781 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5782 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5785 ioc
->sas_hba
.enclosure_handle
=
5786 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5787 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5789 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5790 ioc
->name
, ioc
->sas_hba
.handle
,
5791 (unsigned long long) ioc
->sas_hba
.sas_address
,
5792 ioc
->sas_hba
.num_phys
) ;
5794 if (ioc
->sas_hba
.enclosure_handle
) {
5795 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5796 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5797 ioc
->sas_hba
.enclosure_handle
)))
5798 ioc
->sas_hba
.enclosure_logical_id
=
5799 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5803 kfree(sas_iounit_pg1
);
5804 kfree(sas_iounit_pg0
);
5808 * _scsih_expander_add - creating expander object
5809 * @ioc: per adapter object
5810 * @handle: expander handle
5812 * Creating expander object, stored in ioc->sas_expander_list.
5814 * Return 0 for success, else error.
5817 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5819 struct _sas_node
*sas_expander
;
5820 Mpi2ConfigReply_t mpi_reply
;
5821 Mpi2ExpanderPage0_t expander_pg0
;
5822 Mpi2ExpanderPage1_t expander_pg1
;
5823 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5826 u64 sas_address
, sas_address_parent
= 0;
5828 unsigned long flags
;
5829 struct _sas_port
*mpt3sas_port
= NULL
;
5836 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5839 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5840 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5841 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5842 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5846 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5847 MPI2_IOCSTATUS_MASK
;
5848 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5849 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5850 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5854 /* handle out of order topology events */
5855 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5856 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5858 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5859 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5862 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5863 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5864 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5865 sas_address_parent
);
5866 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5867 if (!sas_expander
) {
5868 rc
= _scsih_expander_add(ioc
, parent_handle
);
5874 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5875 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5876 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5878 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5883 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5885 if (!sas_expander
) {
5886 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5887 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5891 sas_expander
->handle
= handle
;
5892 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5893 sas_expander
->sas_address_parent
= sas_address_parent
;
5894 sas_expander
->sas_address
= sas_address
;
5896 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5897 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5898 handle
, parent_handle
, (unsigned long long)
5899 sas_expander
->sas_address
, sas_expander
->num_phys
);
5901 if (!sas_expander
->num_phys
)
5903 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5904 sizeof(struct _sas_phy
), GFP_KERNEL
);
5905 if (!sas_expander
->phy
) {
5906 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5907 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5912 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5913 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5914 sas_address_parent
);
5915 if (!mpt3sas_port
) {
5916 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5917 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5921 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5923 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5924 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5925 &expander_pg1
, i
, handle
))) {
5926 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5927 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5931 sas_expander
->phy
[i
].handle
= handle
;
5932 sas_expander
->phy
[i
].phy_id
= i
;
5934 if ((mpt3sas_transport_add_expander_phy(ioc
,
5935 &sas_expander
->phy
[i
], expander_pg1
,
5936 sas_expander
->parent_dev
))) {
5937 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5938 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5944 if (sas_expander
->enclosure_handle
) {
5945 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5946 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5947 sas_expander
->enclosure_handle
)))
5948 sas_expander
->enclosure_logical_id
=
5949 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5952 _scsih_expander_node_add(ioc
, sas_expander
);
5958 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5959 sas_address_parent
);
5960 kfree(sas_expander
);
5965 * mpt3sas_expander_remove - removing expander object
5966 * @ioc: per adapter object
5967 * @sas_address: expander sas_address
5972 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5974 struct _sas_node
*sas_expander
;
5975 unsigned long flags
;
5977 if (ioc
->shost_recovery
)
5980 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5981 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5983 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5985 _scsih_expander_node_remove(ioc
, sas_expander
);
5989 * _scsih_done - internal SCSI_IO callback handler.
5990 * @ioc: per adapter object
5991 * @smid: system request message index
5992 * @msix_index: MSIX table index supplied by the OS
5993 * @reply: reply message frame(lower 32bit addr)
5995 * Callback handler when sending internal generated SCSI_IO.
5996 * The callback index passed is `ioc->scsih_cb_idx`
5998 * Return 1 meaning mf should be freed from _base_interrupt
5999 * 0 means the mf is freed from this function.
6002 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
6004 MPI2DefaultReply_t
*mpi_reply
;
6006 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
6007 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
6009 if (ioc
->scsih_cmds
.smid
!= smid
)
6011 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
6013 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
6014 mpi_reply
->MsgLength
*4);
6015 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
6017 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
6018 complete(&ioc
->scsih_cmds
.done
);
6025 #define MPT3_MAX_LUNS (255)
6029 * _scsih_check_access_status - check access flags
6030 * @ioc: per adapter object
6031 * @sas_address: sas address
6032 * @handle: sas device handle
6033 * @access_flags: errors returned during discovery of the device
6035 * Return 0 for success, else failure
6038 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
6039 u16 handle
, u8 access_status
)
6044 switch (access_status
) {
6045 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
6046 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
6049 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
6050 desc
= "sata capability failed";
6052 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
6053 desc
= "sata affiliation conflict";
6055 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
6056 desc
= "route not addressable";
6058 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
6059 desc
= "smp error not addressable";
6061 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
6062 desc
= "device blocked";
6064 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
6065 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
6066 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
6067 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
6068 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
6069 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
6070 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
6071 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
6072 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
6073 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
6074 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
6075 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
6076 desc
= "sata initialization failed";
6087 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
6088 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
6093 * _scsih_get_enclosure_logicalid_chassis_slot - get device's
6094 * EnclosureLogicalID and ChassisSlot information.
6095 * @ioc: per adapter object
6096 * @sas_device_pg0: SAS device page0
6097 * @sas_device: per sas device object
6102 _scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER
*ioc
,
6103 Mpi2SasDevicePage0_t
*sas_device_pg0
, struct _sas_device
*sas_device
)
6105 Mpi2ConfigReply_t mpi_reply
;
6106 Mpi2SasEnclosurePage0_t enclosure_pg0
;
6108 if (!sas_device_pg0
|| !sas_device
)
6111 sas_device
->enclosure_handle
=
6112 le16_to_cpu(sas_device_pg0
->EnclosureHandle
);
6113 sas_device
->is_chassis_slot_valid
= 0;
6115 if (!le16_to_cpu(sas_device_pg0
->EnclosureHandle
))
6118 if (mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
6119 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
6120 le16_to_cpu(sas_device_pg0
->EnclosureHandle
))) {
6122 "Enclosure Pg0 read failed for handle(0x%04x)\n",
6123 ioc
->name
, le16_to_cpu(sas_device_pg0
->EnclosureHandle
));
6127 sas_device
->enclosure_logical_id
=
6128 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
6130 if (le16_to_cpu(enclosure_pg0
.Flags
) &
6131 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6132 sas_device
->is_chassis_slot_valid
= 1;
6133 sas_device
->chassis_slot
= enclosure_pg0
.ChassisSlot
;
6139 * _scsih_check_device - checking device responsiveness
6140 * @ioc: per adapter object
6141 * @parent_sas_address: sas address of parent expander or sas host
6142 * @handle: attached device handle
6143 * @phy_numberv: phy number
6144 * @link_rate: new link rate
6149 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
6150 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
6152 Mpi2ConfigReply_t mpi_reply
;
6153 Mpi2SasDevicePage0_t sas_device_pg0
;
6154 struct _sas_device
*sas_device
;
6156 unsigned long flags
;
6158 struct scsi_target
*starget
;
6159 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6162 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6163 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6166 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6167 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6170 /* wide port handling ~ we need only handle device once for the phy that
6171 * is matched in sas device page zero
6173 if (phy_number
!= sas_device_pg0
.PhyNum
)
6176 /* check if this is end device */
6177 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6178 if (!(_scsih_is_end_device(device_info
)))
6181 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6182 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6183 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6189 if (unlikely(sas_device
->handle
!= handle
)) {
6190 starget
= sas_device
->starget
;
6191 sas_target_priv_data
= starget
->hostdata
;
6192 starget_printk(KERN_INFO
, starget
,
6193 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6194 sas_device
->handle
, handle
);
6195 sas_target_priv_data
->handle
= handle
;
6196 sas_device
->handle
= handle
;
6197 if (le16_to_cpu(sas_device_pg0
.Flags
) &
6198 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6199 sas_device
->enclosure_level
=
6200 sas_device_pg0
.EnclosureLevel
;
6201 memcpy(sas_device
->connector_name
,
6202 sas_device_pg0
.ConnectorName
, 4);
6203 sas_device
->connector_name
[4] = '\0';
6205 sas_device
->enclosure_level
= 0;
6206 sas_device
->connector_name
[0] = '\0';
6209 _scsih_get_enclosure_logicalid_chassis_slot(ioc
,
6210 &sas_device_pg0
, sas_device
);
6213 /* check if device is present */
6214 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6215 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6217 "device is not present handle(0x%04x), flags!!!\n",
6222 /* check if there were any issues with discovery */
6223 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6224 sas_device_pg0
.AccessStatus
))
6227 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6228 _scsih_ublock_io_device(ioc
, sas_address
);
6231 sas_device_put(sas_device
);
6235 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6237 sas_device_put(sas_device
);
6241 * _scsih_add_device - creating sas device object
6242 * @ioc: per adapter object
6243 * @handle: sas device handle
6244 * @phy_num: phy number end device attached to
6245 * @is_pd: is this hidden raid component
6247 * Creating end device object, stored in ioc->sas_device_list.
6249 * Returns 0 for success, non-zero for failure.
6252 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
6255 Mpi2ConfigReply_t mpi_reply
;
6256 Mpi2SasDevicePage0_t sas_device_pg0
;
6257 Mpi2SasEnclosurePage0_t enclosure_pg0
;
6258 struct _sas_device
*sas_device
;
6262 int encl_pg0_rc
= -1;
6264 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6265 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6266 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6267 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6271 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6272 MPI2_IOCSTATUS_MASK
;
6273 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6274 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6275 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6279 /* check if this is end device */
6280 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6281 if (!(_scsih_is_end_device(device_info
)))
6283 set_bit(handle
, ioc
->pend_os_device_add
);
6284 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6286 /* check if device is present */
6287 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6288 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6289 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
6294 /* check if there were any issues with discovery */
6295 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6296 sas_device_pg0
.AccessStatus
))
6299 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
6302 clear_bit(handle
, ioc
->pend_os_device_add
);
6303 sas_device_put(sas_device
);
6307 if (sas_device_pg0
.EnclosureHandle
) {
6308 encl_pg0_rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
6309 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
6310 sas_device_pg0
.EnclosureHandle
);
6313 "Enclosure Pg0 read failed for handle(0x%04x)\n",
6314 ioc
->name
, sas_device_pg0
.EnclosureHandle
);
6317 sas_device
= kzalloc(sizeof(struct _sas_device
),
6320 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6321 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6325 kref_init(&sas_device
->refcount
);
6326 sas_device
->handle
= handle
;
6327 if (_scsih_get_sas_address(ioc
,
6328 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
6329 &sas_device
->sas_address_parent
) != 0)
6330 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6331 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6332 sas_device
->enclosure_handle
=
6333 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
6334 if (sas_device
->enclosure_handle
!= 0)
6336 le16_to_cpu(sas_device_pg0
.Slot
);
6337 sas_device
->device_info
= device_info
;
6338 sas_device
->sas_address
= sas_address
;
6339 sas_device
->phy
= sas_device_pg0
.PhyNum
;
6340 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
6341 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6343 if (le16_to_cpu(sas_device_pg0
.Flags
)
6344 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6345 sas_device
->enclosure_level
=
6346 sas_device_pg0
.EnclosureLevel
;
6347 memcpy(sas_device
->connector_name
,
6348 sas_device_pg0
.ConnectorName
, 4);
6349 sas_device
->connector_name
[4] = '\0';
6351 sas_device
->enclosure_level
= 0;
6352 sas_device
->connector_name
[0] = '\0';
6355 /* get enclosure_logical_id & chassis_slot */
6356 sas_device
->is_chassis_slot_valid
= 0;
6357 if (encl_pg0_rc
== 0) {
6358 sas_device
->enclosure_logical_id
=
6359 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
6361 if (le16_to_cpu(enclosure_pg0
.Flags
) &
6362 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6363 sas_device
->is_chassis_slot_valid
= 1;
6364 sas_device
->chassis_slot
=
6365 enclosure_pg0
.ChassisSlot
;
6369 /* get device name */
6370 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
6372 if (ioc
->wait_for_discovery_to_complete
)
6373 _scsih_sas_device_init_add(ioc
, sas_device
);
6375 _scsih_sas_device_add(ioc
, sas_device
);
6377 sas_device_put(sas_device
);
6382 * _scsih_remove_device - removing sas device object
6383 * @ioc: per adapter object
6384 * @sas_device_delete: the sas_device object
6389 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
6390 struct _sas_device
*sas_device
)
6392 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6394 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
6395 (sas_device
->pfa_led_on
)) {
6396 _scsih_turn_off_pfa_led(ioc
, sas_device
);
6397 sas_device
->pfa_led_on
= 0;
6400 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6401 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6402 ioc
->name
, __func__
,
6403 sas_device
->handle
, (unsigned long long)
6404 sas_device
->sas_address
));
6406 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6409 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6410 sas_target_priv_data
= sas_device
->starget
->hostdata
;
6411 sas_target_priv_data
->deleted
= 1;
6412 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
6413 sas_target_priv_data
->handle
=
6414 MPT3SAS_INVALID_DEVICE_HANDLE
;
6417 if (!ioc
->hide_drives
)
6418 mpt3sas_transport_port_remove(ioc
,
6419 sas_device
->sas_address
,
6420 sas_device
->sas_address_parent
);
6423 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6424 ioc
->name
, sas_device
->handle
,
6425 (unsigned long long) sas_device
->sas_address
);
6427 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
6429 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6430 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6431 ioc
->name
, __func__
,
6432 sas_device
->handle
, (unsigned long long)
6433 sas_device
->sas_address
));
6434 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6439 * _scsih_sas_topology_change_event_debug - debug for topology event
6440 * @ioc: per adapter object
6441 * @event_data: event data payload
6445 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6446 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
6452 char *status_str
= NULL
;
6453 u8 link_rate
, prev_link_rate
;
6455 switch (event_data
->ExpStatus
) {
6456 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
6459 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
6460 status_str
= "remove";
6462 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
6464 status_str
= "responding";
6466 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
6467 status_str
= "remove delay";
6470 status_str
= "unknown status";
6473 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
6474 ioc
->name
, status_str
);
6475 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6476 "start_phy(%02d), count(%d)\n",
6477 le16_to_cpu(event_data
->ExpanderDevHandle
),
6478 le16_to_cpu(event_data
->EnclosureHandle
),
6479 event_data
->StartPhyNum
, event_data
->NumEntries
);
6480 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6481 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6484 phy_number
= event_data
->StartPhyNum
+ i
;
6485 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6486 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6487 switch (reason_code
) {
6488 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6489 status_str
= "target add";
6491 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6492 status_str
= "target remove";
6494 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
6495 status_str
= "delay target remove";
6497 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6498 status_str
= "link rate change";
6500 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
6501 status_str
= "target responding";
6504 status_str
= "unknown";
6507 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6508 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6509 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6510 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
6511 handle
, status_str
, link_rate
, prev_link_rate
);
6517 * _scsih_sas_topology_change_event - handle topology changes
6518 * @ioc: per adapter object
6519 * @fw_event: The fw_event_work object
6524 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6525 struct fw_event_work
*fw_event
)
6528 u16 parent_handle
, handle
;
6530 u8 phy_number
, max_phys
;
6531 struct _sas_node
*sas_expander
;
6533 unsigned long flags
;
6534 u8 link_rate
, prev_link_rate
;
6535 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
6536 (Mpi2EventDataSasTopologyChangeList_t
*)
6537 fw_event
->event_data
;
6539 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6540 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
6542 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
6545 if (!ioc
->sas_hba
.num_phys
)
6546 _scsih_sas_host_add(ioc
);
6548 _scsih_sas_host_refresh(ioc
);
6550 if (fw_event
->ignore
) {
6551 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6552 "ignoring expander event\n", ioc
->name
));
6556 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
6558 /* handle expander add */
6559 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
6560 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
6563 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6564 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
6567 sas_address
= sas_expander
->sas_address
;
6568 max_phys
= sas_expander
->num_phys
;
6569 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
6570 sas_address
= ioc
->sas_hba
.sas_address
;
6571 max_phys
= ioc
->sas_hba
.num_phys
;
6573 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6576 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6578 /* handle siblings events */
6579 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6580 if (fw_event
->ignore
) {
6581 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6582 "ignoring expander event\n", ioc
->name
));
6585 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6587 phy_number
= event_data
->StartPhyNum
+ i
;
6588 if (phy_number
>= max_phys
)
6590 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6591 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6592 if ((event_data
->PHY
[i
].PhyStatus
&
6593 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
6594 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
6596 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6599 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6600 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6601 switch (reason_code
) {
6602 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6604 if (ioc
->shost_recovery
)
6607 if (link_rate
== prev_link_rate
)
6610 mpt3sas_transport_update_links(ioc
, sas_address
,
6611 handle
, phy_number
, link_rate
);
6613 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
6616 _scsih_check_device(ioc
, sas_address
, handle
,
6617 phy_number
, link_rate
);
6619 if (!test_bit(handle
, ioc
->pend_os_device_add
))
6623 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6625 if (ioc
->shost_recovery
)
6628 mpt3sas_transport_update_links(ioc
, sas_address
,
6629 handle
, phy_number
, link_rate
);
6631 _scsih_add_device(ioc
, handle
, phy_number
, 0);
6634 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6636 _scsih_device_remove_by_handle(ioc
, handle
);
6641 /* handle expander removal */
6642 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
6644 mpt3sas_expander_remove(ioc
, sas_address
);
6650 * _scsih_sas_device_status_change_event_debug - debug for device event
6651 * @event_data: event data payload
6657 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6658 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
6660 char *reason_str
= NULL
;
6662 switch (event_data
->ReasonCode
) {
6663 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
6664 reason_str
= "smart data";
6666 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
6667 reason_str
= "unsupported device discovered";
6669 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
6670 reason_str
= "internal device reset";
6672 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
6673 reason_str
= "internal task abort";
6675 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
6676 reason_str
= "internal task abort set";
6678 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
6679 reason_str
= "internal clear task set";
6681 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
6682 reason_str
= "internal query task";
6684 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
6685 reason_str
= "sata init failure";
6687 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
6688 reason_str
= "internal device reset complete";
6690 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
6691 reason_str
= "internal task abort complete";
6693 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
6694 reason_str
= "internal async notification";
6696 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
6697 reason_str
= "expander reduced functionality";
6699 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
6700 reason_str
= "expander reduced functionality complete";
6703 reason_str
= "unknown reason";
6706 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
6707 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6708 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
6709 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
6710 le16_to_cpu(event_data
->TaskTag
));
6711 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
6712 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
6713 event_data
->ASC
, event_data
->ASCQ
);
6718 * _scsih_sas_device_status_change_event - handle device status change
6719 * @ioc: per adapter object
6720 * @fw_event: The fw_event_work object
6726 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6727 struct fw_event_work
*fw_event
)
6729 struct MPT3SAS_TARGET
*target_priv_data
;
6730 struct _sas_device
*sas_device
;
6732 unsigned long flags
;
6733 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
6734 (Mpi2EventDataSasDeviceStatusChange_t
*)
6735 fw_event
->event_data
;
6737 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6738 _scsih_sas_device_status_change_event_debug(ioc
,
6741 /* In MPI Revision K (0xC), the internal device reset complete was
6742 * implemented, so avoid setting tm_busy flag for older firmware.
6744 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
6747 if (event_data
->ReasonCode
!=
6748 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
6749 event_data
->ReasonCode
!=
6750 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
6753 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6754 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6755 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6758 if (!sas_device
|| !sas_device
->starget
)
6761 target_priv_data
= sas_device
->starget
->hostdata
;
6762 if (!target_priv_data
)
6765 if (event_data
->ReasonCode
==
6766 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6767 target_priv_data
->tm_busy
= 1;
6769 target_priv_data
->tm_busy
= 0;
6773 sas_device_put(sas_device
);
6775 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6780 * _scsih_check_pcie_access_status - check access flags
6781 * @ioc: per adapter object
6783 * @handle: sas device handle
6784 * @access_flags: errors returned during discovery of the device
6786 * Return 0 for success, else failure
6789 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6790 u16 handle
, u8 access_status
)
6795 switch (access_status
) {
6796 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS
:
6797 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION
:
6800 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED
:
6801 desc
= "PCIe device capability failed";
6803 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
:
6804 desc
= "PCIe device blocked";
6806 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED
:
6807 desc
= "PCIe device mem space access failed";
6809 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE
:
6810 desc
= "PCIe device unsupported";
6812 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED
:
6813 desc
= "PCIe device MSIx Required";
6815 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX
:
6816 desc
= "PCIe device init fail max";
6818 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN
:
6819 desc
= "PCIe device status unknown";
6821 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT
:
6822 desc
= "nvme ready timeout";
6824 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED
:
6825 desc
= "nvme device configuration unsupported";
6827 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED
:
6828 desc
= "nvme identify failed";
6830 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED
:
6831 desc
= "nvme qconfig failed";
6833 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED
:
6834 desc
= "nvme qcreation failed";
6836 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED
:
6837 desc
= "nvme eventcfg failed";
6839 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED
:
6840 desc
= "nvme get feature stat failed";
6842 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT
:
6843 desc
= "nvme idle timeout";
6845 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS
:
6846 desc
= "nvme failure status";
6850 " NVMe discovery error(0x%02x): wwid(0x%016llx),"
6851 "handle(0x%04x)\n", ioc
->name
, access_status
,
6852 (unsigned long long)wwid
, handle
);
6860 "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6862 (unsigned long long)wwid
, handle
);
6867 * _scsih_pcie_device_remove_from_sml - removing pcie device
6868 * from SML and free up associated memory
6869 * @ioc: per adapter object
6870 * @pcie_device: the pcie_device object
6875 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
6876 struct _pcie_device
*pcie_device
)
6878 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6880 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6881 "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6882 pcie_device
->handle
, (unsigned long long)
6883 pcie_device
->wwid
));
6884 if (pcie_device
->enclosure_handle
!= 0)
6885 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6886 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6887 ioc
->name
, __func__
,
6888 (unsigned long long)pcie_device
->enclosure_logical_id
,
6889 pcie_device
->slot
));
6890 if (pcie_device
->connector_name
[0] != '\0')
6891 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6892 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
6893 ioc
->name
, __func__
,
6894 pcie_device
->enclosure_level
,
6895 pcie_device
->connector_name
));
6897 if (pcie_device
->starget
&& pcie_device
->starget
->hostdata
) {
6898 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
6899 sas_target_priv_data
->deleted
= 1;
6900 _scsih_ublock_io_device(ioc
, pcie_device
->wwid
);
6901 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
6905 "removing handle(0x%04x), wwid (0x%016llx)\n",
6906 ioc
->name
, pcie_device
->handle
,
6907 (unsigned long long) pcie_device
->wwid
);
6908 if (pcie_device
->enclosure_handle
!= 0)
6910 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6912 (unsigned long long)pcie_device
->enclosure_logical_id
,
6914 if (pcie_device
->connector_name
[0] != '\0')
6916 "removing: enclosure level(0x%04x), connector name( %s)\n",
6917 ioc
->name
, pcie_device
->enclosure_level
,
6918 pcie_device
->connector_name
);
6920 if (pcie_device
->starget
)
6921 scsi_remove_target(&pcie_device
->starget
->dev
);
6922 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6923 "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6924 pcie_device
->handle
, (unsigned long long)
6925 pcie_device
->wwid
));
6926 if (pcie_device
->enclosure_handle
!= 0)
6927 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6928 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6929 ioc
->name
, __func__
,
6930 (unsigned long long)pcie_device
->enclosure_logical_id
,
6931 pcie_device
->slot
));
6932 if (pcie_device
->connector_name
[0] != '\0')
6933 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6934 "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6935 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
6936 pcie_device
->connector_name
));
6938 kfree(pcie_device
->serial_number
);
6943 * _scsih_pcie_check_device - checking device responsiveness
6944 * @ioc: per adapter object
6945 * @handle: attached device handle
6950 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6952 Mpi2ConfigReply_t mpi_reply
;
6953 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6955 struct _pcie_device
*pcie_device
;
6957 unsigned long flags
;
6958 struct scsi_target
*starget
;
6959 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6962 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6963 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6966 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6967 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6970 /* check if this is end device */
6971 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6972 if (!(_scsih_is_nvme_device(device_info
)))
6975 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6976 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
6977 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6980 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6984 if (unlikely(pcie_device
->handle
!= handle
)) {
6985 starget
= pcie_device
->starget
;
6986 sas_target_priv_data
= starget
->hostdata
;
6987 starget_printk(KERN_INFO
, starget
,
6988 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6989 pcie_device
->handle
, handle
);
6990 sas_target_priv_data
->handle
= handle
;
6991 pcie_device
->handle
= handle
;
6993 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6994 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6995 pcie_device
->enclosure_level
=
6996 pcie_device_pg0
.EnclosureLevel
;
6997 memcpy(&pcie_device
->connector_name
[0],
6998 &pcie_device_pg0
.ConnectorName
[0], 4);
7000 pcie_device
->enclosure_level
= 0;
7001 pcie_device
->connector_name
[0] = '\0';
7005 /* check if device is present */
7006 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
7007 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
7009 "device is not present handle(0x%04x), flags!!!\n",
7011 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7012 pcie_device_put(pcie_device
);
7016 /* check if there were any issues with discovery */
7017 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
7018 pcie_device_pg0
.AccessStatus
)) {
7019 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7020 pcie_device_put(pcie_device
);
7024 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7025 pcie_device_put(pcie_device
);
7027 _scsih_ublock_io_device(ioc
, wwid
);
7033 * _scsih_pcie_add_device - creating pcie device object
7034 * @ioc: per adapter object
7035 * @handle: pcie device handle
7037 * Creating end device object, stored in ioc->pcie_device_list.
7039 * Return 1 means queue the event later, 0 means complete the event
7042 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
7044 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
7045 Mpi26PCIeDevicePage2_t pcie_device_pg2
;
7046 Mpi2ConfigReply_t mpi_reply
;
7047 Mpi2SasEnclosurePage0_t enclosure_pg0
;
7048 struct _pcie_device
*pcie_device
;
7049 u32 pcie_device_type
;
7053 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
7054 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
7055 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7056 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7059 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7060 MPI2_IOCSTATUS_MASK
;
7061 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7063 "failure at %s:%d/%s()!\n",
7064 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7068 set_bit(handle
, ioc
->pend_os_device_add
);
7069 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
7071 /* check if device is present */
7072 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
7073 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
7075 "device is not present handle(0x04%x)!!!\n",
7080 /* check if there were any issues with discovery */
7081 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
7082 pcie_device_pg0
.AccessStatus
))
7085 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
7088 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
7090 clear_bit(handle
, ioc
->pend_os_device_add
);
7091 pcie_device_put(pcie_device
);
7095 pcie_device
= kzalloc(sizeof(struct _pcie_device
), GFP_KERNEL
);
7097 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7098 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7102 kref_init(&pcie_device
->refcount
);
7103 pcie_device
->id
= ioc
->pcie_target_id
++;
7104 pcie_device
->channel
= PCIE_CHANNEL
;
7105 pcie_device
->handle
= handle
;
7106 pcie_device
->device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
7107 pcie_device
->wwid
= wwid
;
7108 pcie_device
->port_num
= pcie_device_pg0
.PortNum
;
7109 pcie_device
->fast_path
= (le32_to_cpu(pcie_device_pg0
.Flags
) &
7110 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
7111 pcie_device_type
= pcie_device
->device_info
&
7112 MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
;
7114 pcie_device
->enclosure_handle
=
7115 le16_to_cpu(pcie_device_pg0
.EnclosureHandle
);
7116 if (pcie_device
->enclosure_handle
!= 0)
7117 pcie_device
->slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
7119 if (le16_to_cpu(pcie_device_pg0
.Flags
) &
7120 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
7121 pcie_device
->enclosure_level
= pcie_device_pg0
.EnclosureLevel
;
7122 memcpy(&pcie_device
->connector_name
[0],
7123 &pcie_device_pg0
.ConnectorName
[0], 4);
7125 pcie_device
->enclosure_level
= 0;
7126 pcie_device
->connector_name
[0] = '\0';
7129 /* get enclosure_logical_id */
7130 if (pcie_device
->enclosure_handle
&&
7131 !(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
7132 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
7133 pcie_device
->enclosure_handle
)))
7134 pcie_device
->enclosure_logical_id
=
7135 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
7137 /* TODO -- Add device name once FW supports it */
7138 if (mpt3sas_config_get_pcie_device_pg2(ioc
, &mpi_reply
,
7139 &pcie_device_pg2
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)) {
7140 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7141 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7146 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
7147 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7148 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7149 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7153 pcie_device
->nvme_mdts
=
7154 le32_to_cpu(pcie_device_pg2
.MaximumDataTransferSize
);
7156 if (ioc
->wait_for_discovery_to_complete
)
7157 _scsih_pcie_device_init_add(ioc
, pcie_device
);
7159 _scsih_pcie_device_add(ioc
, pcie_device
);
7161 pcie_device_put(pcie_device
);
7166 * _scsih_pcie_topology_change_event_debug - debug for topology
7168 * @ioc: per adapter object
7169 * @event_data: event data payload
7173 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7174 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
7180 char *status_str
= NULL
;
7181 u8 link_rate
, prev_link_rate
;
7183 switch (event_data
->SwitchStatus
) {
7184 case MPI26_EVENT_PCIE_TOPO_SS_ADDED
:
7187 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING
:
7188 status_str
= "remove";
7190 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
:
7192 status_str
= "responding";
7194 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
:
7195 status_str
= "remove delay";
7198 status_str
= "unknown status";
7201 pr_info(MPT3SAS_FMT
"pcie topology change: (%s)\n",
7202 ioc
->name
, status_str
);
7203 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
7204 "start_port(%02d), count(%d)\n",
7205 le16_to_cpu(event_data
->SwitchDevHandle
),
7206 le16_to_cpu(event_data
->EnclosureHandle
),
7207 event_data
->StartPortNum
, event_data
->NumEntries
);
7208 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7210 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7213 port_number
= event_data
->StartPortNum
+ i
;
7214 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7215 switch (reason_code
) {
7216 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7217 status_str
= "target add";
7219 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7220 status_str
= "target remove";
7222 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
:
7223 status_str
= "delay target remove";
7225 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7226 status_str
= "link rate change";
7228 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
:
7229 status_str
= "target responding";
7232 status_str
= "unknown";
7235 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
&
7236 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7237 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
&
7238 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7239 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
7240 " link rate: new(0x%02x), old(0x%02x)\n", port_number
,
7241 handle
, status_str
, link_rate
, prev_link_rate
);
7246 * _scsih_pcie_topology_change_event - handle PCIe topology
7248 * @ioc: per adapter object
7249 * @fw_event: The fw_event_work object
7254 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7255 struct fw_event_work
*fw_event
)
7260 u8 link_rate
, prev_link_rate
;
7261 unsigned long flags
;
7264 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
=
7265 (Mpi26EventDataPCIeTopologyChangeList_t
*) fw_event
->event_data
;
7266 struct _pcie_device
*pcie_device
;
7268 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7269 _scsih_pcie_topology_change_event_debug(ioc
, event_data
);
7271 if (ioc
->shost_recovery
|| ioc
->remove_host
||
7272 ioc
->pci_error_recovery
)
7275 if (fw_event
->ignore
) {
7276 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"ignoring switch event\n",
7281 /* handle siblings events */
7282 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7283 if (fw_event
->ignore
) {
7284 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7285 "ignoring switch event\n", ioc
->name
));
7288 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7290 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7292 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7296 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
7297 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7298 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
7299 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7301 switch (reason_code
) {
7302 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7303 if (ioc
->shost_recovery
)
7305 if (link_rate
== prev_link_rate
)
7307 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7310 _scsih_pcie_check_device(ioc
, handle
);
7312 /* This code after this point handles the test case
7313 * where a device has been added, however its returning
7314 * BUSY for sometime. Then before the Device Missing
7315 * Delay expires and the device becomes READY, the
7316 * device is removed and added back.
7318 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7319 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
7320 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7323 pcie_device_put(pcie_device
);
7327 if (!test_bit(handle
, ioc
->pend_os_device_add
))
7330 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7331 "handle(0x%04x) device not found: convert "
7332 "event to a device add\n", ioc
->name
, handle
));
7333 event_data
->PortEntry
[i
].PortStatus
&= 0xF0;
7334 event_data
->PortEntry
[i
].PortStatus
|=
7335 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
;
7336 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7337 if (ioc
->shost_recovery
)
7339 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7342 rc
= _scsih_pcie_add_device(ioc
, handle
);
7344 /* mark entry vacant */
7345 /* TODO This needs to be reviewed and fixed,
7346 * we dont have an entry
7347 * to make an event void like vacant
7349 event_data
->PortEntry
[i
].PortStatus
|=
7350 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
;
7353 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7354 _scsih_pcie_device_remove_by_handle(ioc
, handle
);
7358 return requeue_event
;
7362 * _scsih_pcie_device_status_change_event_debug - debug for
7364 * @event_data: event data payload
7370 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7371 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
)
7373 char *reason_str
= NULL
;
7375 switch (event_data
->ReasonCode
) {
7376 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
:
7377 reason_str
= "smart data";
7379 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED
:
7380 reason_str
= "unsupported device discovered";
7382 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
:
7383 reason_str
= "internal device reset";
7385 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL
:
7386 reason_str
= "internal task abort";
7388 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
7389 reason_str
= "internal task abort set";
7391 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
7392 reason_str
= "internal clear task set";
7394 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL
:
7395 reason_str
= "internal query task";
7397 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE
:
7398 reason_str
= "device init failure";
7400 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
7401 reason_str
= "internal device reset complete";
7403 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
7404 reason_str
= "internal task abort complete";
7406 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION
:
7407 reason_str
= "internal async notification";
7410 reason_str
= "unknown reason";
7414 pr_info(MPT3SAS_FMT
"PCIE device status change: (%s)\n"
7415 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7416 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
7417 (unsigned long long)le64_to_cpu(event_data
->WWID
),
7418 le16_to_cpu(event_data
->TaskTag
));
7419 if (event_data
->ReasonCode
== MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
)
7420 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
7421 event_data
->ASC
, event_data
->ASCQ
);
7426 * _scsih_pcie_device_status_change_event - handle device status
7428 * @ioc: per adapter object
7429 * @fw_event: The fw_event_work object
7435 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7436 struct fw_event_work
*fw_event
)
7438 struct MPT3SAS_TARGET
*target_priv_data
;
7439 struct _pcie_device
*pcie_device
;
7441 unsigned long flags
;
7442 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
=
7443 (Mpi26EventDataPCIeDeviceStatusChange_t
*)fw_event
->event_data
;
7444 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7445 _scsih_pcie_device_status_change_event_debug(ioc
,
7448 if (event_data
->ReasonCode
!=
7449 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
7450 event_data
->ReasonCode
!=
7451 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
7454 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7455 wwid
= le64_to_cpu(event_data
->WWID
);
7456 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
7458 if (!pcie_device
|| !pcie_device
->starget
)
7461 target_priv_data
= pcie_device
->starget
->hostdata
;
7462 if (!target_priv_data
)
7465 if (event_data
->ReasonCode
==
7466 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
)
7467 target_priv_data
->tm_busy
= 1;
7469 target_priv_data
->tm_busy
= 0;
7472 pcie_device_put(pcie_device
);
7474 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7478 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7480 * @ioc: per adapter object
7481 * @event_data: event data payload
7487 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7488 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
7490 char *reason_str
= NULL
;
7492 switch (event_data
->ReasonCode
) {
7493 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7494 reason_str
= "enclosure add";
7496 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7497 reason_str
= "enclosure remove";
7500 reason_str
= "unknown reason";
7504 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
7505 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
7506 " number slots(%d)\n", ioc
->name
, reason_str
,
7507 le16_to_cpu(event_data
->EnclosureHandle
),
7508 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
7509 le16_to_cpu(event_data
->StartSlot
));
7513 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7514 * @ioc: per adapter object
7515 * @fw_event: The fw_event_work object
7521 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7522 struct fw_event_work
*fw_event
)
7524 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7525 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
7526 (Mpi2EventDataSasEnclDevStatusChange_t
*)
7527 fw_event
->event_data
);
7531 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7532 * @ioc: per adapter object
7533 * @fw_event: The fw_event_work object
7539 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
7540 struct fw_event_work
*fw_event
)
7542 struct scsi_cmnd
*scmd
;
7543 struct scsi_device
*sdev
;
7546 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7547 u32 termination_count
;
7549 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
7550 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
7551 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7552 fw_event
->event_data
;
7554 unsigned long flags
;
7557 u8 task_abort_retries
;
7559 mutex_lock(&ioc
->tm_cmds
.mutex
);
7561 "%s: enter: phy number(%d), width(%d)\n",
7562 ioc
->name
, __func__
, event_data
->PhyNum
,
7563 event_data
->PortWidth
);
7565 _scsih_block_io_all_device(ioc
);
7567 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7568 mpi_reply
= ioc
->tm_cmds
.reply
;
7569 broadcast_aen_retry
:
7571 /* sanity checks for retrying this loop */
7572 if (max_retries
++ == 5) {
7573 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
7574 ioc
->name
, __func__
));
7576 } else if (max_retries
> 1)
7577 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
7578 ioc
->name
, __func__
, max_retries
- 1));
7580 termination_count
= 0;
7582 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
7583 if (ioc
->shost_recovery
)
7585 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
7588 sdev
= scmd
->device
;
7589 sas_device_priv_data
= sdev
->hostdata
;
7590 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
7592 /* skip hidden raid components */
7593 if (sas_device_priv_data
->sas_target
->flags
&
7594 MPT_TARGET_FLAGS_RAID_COMPONENT
)
7597 if (sas_device_priv_data
->sas_target
->flags
&
7598 MPT_TARGET_FLAGS_VOLUME
)
7601 handle
= sas_device_priv_data
->sas_target
->handle
;
7602 lun
= sas_device_priv_data
->lun
;
7605 if (ioc
->shost_recovery
)
7608 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7609 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
7610 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
7612 sdev_printk(KERN_WARNING
, sdev
,
7613 "mpt3sas_scsih_issue_tm: FAILED when sending "
7614 "QUERY_TASK: scmd(%p)\n", scmd
);
7615 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7616 goto broadcast_aen_retry
;
7618 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
7619 & MPI2_IOCSTATUS_MASK
;
7620 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7621 sdev_printk(KERN_WARNING
, sdev
,
7622 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7624 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7625 goto broadcast_aen_retry
;
7628 /* see if IO is still owned by IOC and target */
7629 if (mpi_reply
->ResponseCode
==
7630 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
7631 mpi_reply
->ResponseCode
==
7632 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
7633 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7636 task_abort_retries
= 0;
7638 if (task_abort_retries
++ == 60) {
7639 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7640 "%s: ABORT_TASK: giving up\n", ioc
->name
,
7642 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7643 goto broadcast_aen_retry
;
7646 if (ioc
->shost_recovery
)
7649 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
7650 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
,
7653 sdev_printk(KERN_WARNING
, sdev
,
7654 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7655 "scmd(%p)\n", scmd
);
7659 if (task_abort_retries
> 1)
7660 sdev_printk(KERN_WARNING
, sdev
,
7661 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7663 task_abort_retries
- 1, scmd
);
7665 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
7666 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7669 if (ioc
->broadcast_aen_pending
) {
7670 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7671 "%s: loop back due to pending AEN\n",
7672 ioc
->name
, __func__
));
7673 ioc
->broadcast_aen_pending
= 0;
7674 goto broadcast_aen_retry
;
7678 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7681 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7682 "%s - exit, query_count = %d termination_count = %d\n",
7683 ioc
->name
, __func__
, query_count
, termination_count
));
7685 ioc
->broadcast_aen_busy
= 0;
7686 if (!ioc
->shost_recovery
)
7687 _scsih_ublock_io_all_device(ioc
);
7688 mutex_unlock(&ioc
->tm_cmds
.mutex
);
7692 * _scsih_sas_discovery_event - handle discovery events
7693 * @ioc: per adapter object
7694 * @fw_event: The fw_event_work object
7700 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
7701 struct fw_event_work
*fw_event
)
7703 Mpi2EventDataSasDiscovery_t
*event_data
=
7704 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
7706 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
7707 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
7708 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
7710 if (event_data
->DiscoveryStatus
)
7711 pr_info("discovery_status(0x%08x)",
7712 le32_to_cpu(event_data
->DiscoveryStatus
));
7716 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
7717 !ioc
->sas_hba
.num_phys
) {
7718 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
7719 /* Wait for the reset to complete */
7720 while (ioc
->shost_recovery
)
7723 _scsih_sas_host_add(ioc
);
7728 * _scsih_pcie_enumeration_event - handle enumeration events
7729 * @ioc: per adapter object
7730 * @fw_event: The fw_event_work object
7736 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER
*ioc
,
7737 struct fw_event_work
*fw_event
)
7739 Mpi26EventDataPCIeEnumeration_t
*event_data
=
7740 (Mpi26EventDataPCIeEnumeration_t
*)fw_event
->event_data
;
7742 if (!(ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
))
7745 pr_info(MPT3SAS_FMT
"pcie enumeration event: (%s) Flag 0x%02x",
7747 (event_data
->ReasonCode
== MPI26_EVENT_PCIE_ENUM_RC_STARTED
) ?
7748 "started" : "completed",
7750 if (event_data
->EnumerationStatus
)
7751 pr_cont("enumeration_status(0x%08x)",
7752 le32_to_cpu(event_data
->EnumerationStatus
));
7757 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7758 * @ioc: per adapter object
7759 * @handle: device handle for physical disk
7760 * @phys_disk_num: physical disk number
7762 * Return 0 for success, else failure.
7765 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
7767 Mpi2RaidActionRequest_t
*mpi_request
;
7768 Mpi2RaidActionReply_t
*mpi_reply
;
7775 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
7778 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7780 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7781 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7782 ioc
->name
, __func__
);
7786 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7788 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7790 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7791 ioc
->name
, __func__
);
7792 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7797 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7798 ioc
->scsih_cmds
.smid
= smid
;
7799 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7801 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7802 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
7803 mpi_request
->PhysDiskNum
= phys_disk_num
;
7805 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
7806 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
7807 handle
, phys_disk_num
));
7809 init_completion(&ioc
->scsih_cmds
.done
);
7810 ioc
->put_smid_default(ioc
, smid
);
7811 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7813 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7814 pr_err(MPT3SAS_FMT
"%s: timeout\n",
7815 ioc
->name
, __func__
);
7816 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
7822 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7824 mpi_reply
= ioc
->scsih_cmds
.reply
;
7825 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
7826 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
7827 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
7830 ioc_status
&= MPI2_IOCSTATUS_MASK
;
7831 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7832 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7833 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
7834 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
7838 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7839 "IR RAID_ACTION: completed successfully\n",
7844 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7845 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7848 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
7853 * _scsih_reprobe_lun - reprobing lun
7854 * @sdev: scsi device struct
7855 * @no_uld_attach: sdev->no_uld_attach flag setting
7859 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
7861 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
7862 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
7863 sdev
->no_uld_attach
? "hiding" : "exposing");
7864 WARN_ON(scsi_device_reprobe(sdev
));
7868 * _scsih_sas_volume_add - add new volume
7869 * @ioc: per adapter object
7870 * @element: IR config element data
7876 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
7877 Mpi2EventIrConfigElement_t
*element
)
7879 struct _raid_device
*raid_device
;
7880 unsigned long flags
;
7882 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
7885 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
7888 "failure at %s:%d/%s()!\n", ioc
->name
,
7889 __FILE__
, __LINE__
, __func__
);
7893 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7894 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
7895 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7900 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
7903 "failure at %s:%d/%s()!\n", ioc
->name
,
7904 __FILE__
, __LINE__
, __func__
);
7908 raid_device
->id
= ioc
->sas_id
++;
7909 raid_device
->channel
= RAID_CHANNEL
;
7910 raid_device
->handle
= handle
;
7911 raid_device
->wwid
= wwid
;
7912 _scsih_raid_device_add(ioc
, raid_device
);
7913 if (!ioc
->wait_for_discovery_to_complete
) {
7914 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7915 raid_device
->id
, 0);
7917 _scsih_raid_device_remove(ioc
, raid_device
);
7919 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7920 _scsih_determine_boot_device(ioc
, raid_device
, 1);
7921 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7926 * _scsih_sas_volume_delete - delete volume
7927 * @ioc: per adapter object
7928 * @handle: volume device handle
7934 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
7936 struct _raid_device
*raid_device
;
7937 unsigned long flags
;
7938 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7939 struct scsi_target
*starget
= NULL
;
7941 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7942 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7944 if (raid_device
->starget
) {
7945 starget
= raid_device
->starget
;
7946 sas_target_priv_data
= starget
->hostdata
;
7947 sas_target_priv_data
->deleted
= 1;
7949 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7950 ioc
->name
, raid_device
->handle
,
7951 (unsigned long long) raid_device
->wwid
);
7952 list_del(&raid_device
->list
);
7955 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7957 scsi_remove_target(&starget
->dev
);
7961 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7962 * @ioc: per adapter object
7963 * @element: IR config element data
7969 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
7970 Mpi2EventIrConfigElement_t
*element
)
7972 struct _sas_device
*sas_device
;
7973 struct scsi_target
*starget
= NULL
;
7974 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7975 unsigned long flags
;
7976 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7978 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7979 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7981 sas_device
->volume_handle
= 0;
7982 sas_device
->volume_wwid
= 0;
7983 clear_bit(handle
, ioc
->pd_handles
);
7984 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7985 starget
= sas_device
->starget
;
7986 sas_target_priv_data
= starget
->hostdata
;
7987 sas_target_priv_data
->flags
&=
7988 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
7991 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7995 /* exposing raid component */
7997 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
7999 sas_device_put(sas_device
);
8003 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
8004 * @ioc: per adapter object
8005 * @element: IR config element data
8011 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
8012 Mpi2EventIrConfigElement_t
*element
)
8014 struct _sas_device
*sas_device
;
8015 struct scsi_target
*starget
= NULL
;
8016 struct MPT3SAS_TARGET
*sas_target_priv_data
;
8017 unsigned long flags
;
8018 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
8019 u16 volume_handle
= 0;
8020 u64 volume_wwid
= 0;
8022 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
8024 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
8027 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8028 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
8030 set_bit(handle
, ioc
->pd_handles
);
8031 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
8032 starget
= sas_device
->starget
;
8033 sas_target_priv_data
= starget
->hostdata
;
8034 sas_target_priv_data
->flags
|=
8035 MPT_TARGET_FLAGS_RAID_COMPONENT
;
8036 sas_device
->volume_handle
= volume_handle
;
8037 sas_device
->volume_wwid
= volume_wwid
;
8040 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8044 /* hiding raid component */
8045 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
8048 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
8050 sas_device_put(sas_device
);
8054 * _scsih_sas_pd_delete - delete pd component
8055 * @ioc: per adapter object
8056 * @element: IR config element data
8062 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
8063 Mpi2EventIrConfigElement_t
*element
)
8065 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
8067 _scsih_device_remove_by_handle(ioc
, handle
);
8071 * _scsih_sas_pd_add - remove pd component
8072 * @ioc: per adapter object
8073 * @element: IR config element data
8079 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
8080 Mpi2EventIrConfigElement_t
*element
)
8082 struct _sas_device
*sas_device
;
8083 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
8084 Mpi2ConfigReply_t mpi_reply
;
8085 Mpi2SasDevicePage0_t sas_device_pg0
;
8090 set_bit(handle
, ioc
->pd_handles
);
8092 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8094 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
8095 sas_device_put(sas_device
);
8099 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
8100 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
8101 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8102 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8106 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8107 MPI2_IOCSTATUS_MASK
;
8108 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8109 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8110 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8114 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8115 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
8116 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
8117 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
8119 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
8120 _scsih_add_device(ioc
, handle
, 0, 1);
8124 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
8125 * @ioc: per adapter object
8126 * @event_data: event data payload
8132 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8133 Mpi2EventDataIrConfigChangeList_t
*event_data
)
8135 Mpi2EventIrConfigElement_t
*element
;
8138 char *reason_str
= NULL
, *element_str
= NULL
;
8140 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8142 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
8143 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
8144 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
8145 "foreign" : "native", event_data
->NumElements
);
8146 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8147 switch (element
->ReasonCode
) {
8148 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8151 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8152 reason_str
= "remove";
8154 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
8155 reason_str
= "no change";
8157 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8158 reason_str
= "hide";
8160 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8161 reason_str
= "unhide";
8163 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8164 reason_str
= "volume_created";
8166 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8167 reason_str
= "volume_deleted";
8169 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8170 reason_str
= "pd_created";
8172 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8173 reason_str
= "pd_deleted";
8176 reason_str
= "unknown reason";
8179 element_type
= le16_to_cpu(element
->ElementFlags
) &
8180 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
8181 switch (element_type
) {
8182 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
8183 element_str
= "volume";
8185 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
8186 element_str
= "phys disk";
8188 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
8189 element_str
= "hot spare";
8192 element_str
= "unknown element";
8195 pr_info("\t(%s:%s), vol handle(0x%04x), " \
8196 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
8197 reason_str
, le16_to_cpu(element
->VolDevHandle
),
8198 le16_to_cpu(element
->PhysDiskDevHandle
),
8199 element
->PhysDiskNum
);
8204 * _scsih_sas_ir_config_change_event - handle ir configuration change events
8205 * @ioc: per adapter object
8206 * @fw_event: The fw_event_work object
8212 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
8213 struct fw_event_work
*fw_event
)
8215 Mpi2EventIrConfigElement_t
*element
;
8218 Mpi2EventDataIrConfigChangeList_t
*event_data
=
8219 (Mpi2EventDataIrConfigChangeList_t
*)
8220 fw_event
->event_data
;
8222 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8223 (!ioc
->hide_ir_msg
))
8224 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
8226 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
8227 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
8229 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8230 if (ioc
->shost_recovery
&&
8231 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
8232 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8233 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
8234 _scsih_ir_fastpath(ioc
,
8235 le16_to_cpu(element
->PhysDiskDevHandle
),
8236 element
->PhysDiskNum
);
8241 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8243 switch (element
->ReasonCode
) {
8244 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8245 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8246 if (!foreign_config
)
8247 _scsih_sas_volume_add(ioc
, element
);
8249 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8250 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8251 if (!foreign_config
)
8252 _scsih_sas_volume_delete(ioc
,
8253 le16_to_cpu(element
->VolDevHandle
));
8255 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8256 if (!ioc
->is_warpdrive
)
8257 _scsih_sas_pd_hide(ioc
, element
);
8259 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8260 if (!ioc
->is_warpdrive
)
8261 _scsih_sas_pd_expose(ioc
, element
);
8263 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8264 if (!ioc
->is_warpdrive
)
8265 _scsih_sas_pd_add(ioc
, element
);
8267 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8268 if (!ioc
->is_warpdrive
)
8269 _scsih_sas_pd_delete(ioc
, element
);
8276 * _scsih_sas_ir_volume_event - IR volume event
8277 * @ioc: per adapter object
8278 * @fw_event: The fw_event_work object
8284 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
8285 struct fw_event_work
*fw_event
)
8288 unsigned long flags
;
8289 struct _raid_device
*raid_device
;
8293 Mpi2EventDataIrVolume_t
*event_data
=
8294 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
8296 if (ioc
->shost_recovery
)
8299 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
8302 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8303 state
= le32_to_cpu(event_data
->NewValue
);
8304 if (!ioc
->hide_ir_msg
)
8305 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8306 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8307 ioc
->name
, __func__
, handle
,
8308 le32_to_cpu(event_data
->PreviousValue
), state
));
8310 case MPI2_RAID_VOL_STATE_MISSING
:
8311 case MPI2_RAID_VOL_STATE_FAILED
:
8312 _scsih_sas_volume_delete(ioc
, handle
);
8315 case MPI2_RAID_VOL_STATE_ONLINE
:
8316 case MPI2_RAID_VOL_STATE_DEGRADED
:
8317 case MPI2_RAID_VOL_STATE_OPTIMAL
:
8319 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8320 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8321 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8326 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
8329 "failure at %s:%d/%s()!\n", ioc
->name
,
8330 __FILE__
, __LINE__
, __func__
);
8334 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
8337 "failure at %s:%d/%s()!\n", ioc
->name
,
8338 __FILE__
, __LINE__
, __func__
);
8342 raid_device
->id
= ioc
->sas_id
++;
8343 raid_device
->channel
= RAID_CHANNEL
;
8344 raid_device
->handle
= handle
;
8345 raid_device
->wwid
= wwid
;
8346 _scsih_raid_device_add(ioc
, raid_device
);
8347 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8348 raid_device
->id
, 0);
8350 _scsih_raid_device_remove(ioc
, raid_device
);
8353 case MPI2_RAID_VOL_STATE_INITIALIZING
:
8360 * _scsih_sas_ir_physical_disk_event - PD event
8361 * @ioc: per adapter object
8362 * @fw_event: The fw_event_work object
8368 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
8369 struct fw_event_work
*fw_event
)
8371 u16 handle
, parent_handle
;
8373 struct _sas_device
*sas_device
;
8374 Mpi2ConfigReply_t mpi_reply
;
8375 Mpi2SasDevicePage0_t sas_device_pg0
;
8377 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
8378 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
8381 if (ioc
->shost_recovery
)
8384 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
8387 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
8388 state
= le32_to_cpu(event_data
->NewValue
);
8390 if (!ioc
->hide_ir_msg
)
8391 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8392 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8393 ioc
->name
, __func__
, handle
,
8394 le32_to_cpu(event_data
->PreviousValue
), state
));
8397 case MPI2_RAID_PD_STATE_ONLINE
:
8398 case MPI2_RAID_PD_STATE_DEGRADED
:
8399 case MPI2_RAID_PD_STATE_REBUILDING
:
8400 case MPI2_RAID_PD_STATE_OPTIMAL
:
8401 case MPI2_RAID_PD_STATE_HOT_SPARE
:
8403 if (!ioc
->is_warpdrive
)
8404 set_bit(handle
, ioc
->pd_handles
);
8406 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8408 sas_device_put(sas_device
);
8412 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8413 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
8415 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8416 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8420 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8421 MPI2_IOCSTATUS_MASK
;
8422 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8423 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8424 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8428 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8429 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
8430 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
8431 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
8433 _scsih_add_device(ioc
, handle
, 0, 1);
8437 case MPI2_RAID_PD_STATE_OFFLINE
:
8438 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
8439 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
8446 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8447 * @ioc: per adapter object
8448 * @event_data: event data payload
8454 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8455 Mpi2EventDataIrOperationStatus_t
*event_data
)
8457 char *reason_str
= NULL
;
8459 switch (event_data
->RAIDOperation
) {
8460 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
8461 reason_str
= "resync";
8463 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
8464 reason_str
= "online capacity expansion";
8466 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
8467 reason_str
= "consistency check";
8469 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
8470 reason_str
= "background init";
8472 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
8473 reason_str
= "make data consistent";
8480 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
8481 "\thandle(0x%04x), percent complete(%d)\n",
8482 ioc
->name
, reason_str
,
8483 le16_to_cpu(event_data
->VolDevHandle
),
8484 event_data
->PercentComplete
);
8488 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8489 * @ioc: per adapter object
8490 * @fw_event: The fw_event_work object
8496 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
8497 struct fw_event_work
*fw_event
)
8499 Mpi2EventDataIrOperationStatus_t
*event_data
=
8500 (Mpi2EventDataIrOperationStatus_t
*)
8501 fw_event
->event_data
;
8502 static struct _raid_device
*raid_device
;
8503 unsigned long flags
;
8506 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8507 (!ioc
->hide_ir_msg
))
8508 _scsih_sas_ir_operation_status_event_debug(ioc
,
8511 /* code added for raid transport support */
8512 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
8514 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8515 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8516 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8518 raid_device
->percent_complete
=
8519 event_data
->PercentComplete
;
8520 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8525 * _scsih_prep_device_scan - initialize parameters prior to device scan
8526 * @ioc: per adapter object
8528 * Set the deleted flag prior to device scan. If the device is found during
8529 * the scan, then we clear the deleted flag.
8532 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
8534 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
8535 struct scsi_device
*sdev
;
8537 shost_for_each_device(sdev
, ioc
->shost
) {
8538 sas_device_priv_data
= sdev
->hostdata
;
8539 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
8540 sas_device_priv_data
->sas_target
->deleted
= 1;
8545 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8546 * @ioc: per adapter object
8547 * @sas_device_pg0: SAS Device page 0
8549 * After host reset, find out whether devices are still responding.
8550 * Used in _scsih_remove_unresponsive_sas_devices.
8555 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
8556 Mpi2SasDevicePage0_t
*sas_device_pg0
)
8558 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8559 struct scsi_target
*starget
;
8560 struct _sas_device
*sas_device
= NULL
;
8561 unsigned long flags
;
8563 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8564 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
8565 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
8566 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
8567 sas_device
->responding
= 1;
8568 starget
= sas_device
->starget
;
8569 if (starget
&& starget
->hostdata
) {
8570 sas_target_priv_data
= starget
->hostdata
;
8571 sas_target_priv_data
->tm_busy
= 0;
8572 sas_target_priv_data
->deleted
= 0;
8574 sas_target_priv_data
= NULL
;
8576 starget_printk(KERN_INFO
, starget
,
8577 "handle(0x%04x), sas_addr(0x%016llx)\n",
8578 sas_device_pg0
->DevHandle
,
8579 (unsigned long long)
8580 sas_device
->sas_address
);
8582 if (sas_device
->enclosure_handle
!= 0)
8583 starget_printk(KERN_INFO
, starget
,
8584 "enclosure logical id(0x%016llx),"
8586 (unsigned long long)
8587 sas_device
->enclosure_logical_id
,
8590 if (sas_device_pg0
->Flags
&
8591 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
8592 sas_device
->enclosure_level
=
8593 sas_device_pg0
->EnclosureLevel
;
8594 memcpy(&sas_device
->connector_name
[0],
8595 &sas_device_pg0
->ConnectorName
[0], 4);
8597 sas_device
->enclosure_level
= 0;
8598 sas_device
->connector_name
[0] = '\0';
8601 _scsih_get_enclosure_logicalid_chassis_slot(ioc
,
8602 sas_device_pg0
, sas_device
);
8604 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
8606 pr_info("\thandle changed from(0x%04x)!!!\n",
8607 sas_device
->handle
);
8608 sas_device
->handle
= sas_device_pg0
->DevHandle
;
8609 if (sas_target_priv_data
)
8610 sas_target_priv_data
->handle
=
8611 sas_device_pg0
->DevHandle
;
8616 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8620 * _scsih_search_responding_sas_devices -
8621 * @ioc: per adapter object
8623 * After host reset, find out whether devices are still responding.
8629 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
8631 Mpi2SasDevicePage0_t sas_device_pg0
;
8632 Mpi2ConfigReply_t mpi_reply
;
8637 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
8639 if (list_empty(&ioc
->sas_device_list
))
8643 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8644 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8646 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8647 MPI2_IOCSTATUS_MASK
;
8648 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8650 handle
= sas_device_pg0
.DevHandle
=
8651 le16_to_cpu(sas_device_pg0
.DevHandle
);
8652 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
8653 if (!(_scsih_is_end_device(device_info
)))
8655 sas_device_pg0
.SASAddress
=
8656 le64_to_cpu(sas_device_pg0
.SASAddress
);
8657 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
8658 sas_device_pg0
.Flags
= le16_to_cpu(sas_device_pg0
.Flags
);
8659 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
8663 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
8668 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8669 * @ioc: per adapter object
8670 * @pcie_device_pg0: PCIe Device page 0
8672 * After host reset, find out whether devices are still responding.
8673 * Used in _scsih_remove_unresponding_devices.
8678 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER
*ioc
,
8679 Mpi26PCIeDevicePage0_t
*pcie_device_pg0
)
8681 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8682 struct scsi_target
*starget
;
8683 struct _pcie_device
*pcie_device
;
8684 unsigned long flags
;
8686 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8687 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
) {
8688 if ((pcie_device
->wwid
== pcie_device_pg0
->WWID
) &&
8689 (pcie_device
->slot
== pcie_device_pg0
->Slot
)) {
8690 pcie_device
->responding
= 1;
8691 starget
= pcie_device
->starget
;
8692 if (starget
&& starget
->hostdata
) {
8693 sas_target_priv_data
= starget
->hostdata
;
8694 sas_target_priv_data
->tm_busy
= 0;
8695 sas_target_priv_data
->deleted
= 0;
8697 sas_target_priv_data
= NULL
;
8699 starget_printk(KERN_INFO
, starget
,
8700 "handle(0x%04x), wwid(0x%016llx) ",
8701 pcie_device
->handle
,
8702 (unsigned long long)pcie_device
->wwid
);
8703 if (pcie_device
->enclosure_handle
!= 0)
8704 starget_printk(KERN_INFO
, starget
,
8705 "enclosure logical id(0x%016llx), "
8707 (unsigned long long)
8708 pcie_device
->enclosure_logical_id
,
8712 if (((le32_to_cpu(pcie_device_pg0
->Flags
)) &
8713 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) &&
8714 (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
)) {
8715 pcie_device
->enclosure_level
=
8716 pcie_device_pg0
->EnclosureLevel
;
8717 memcpy(&pcie_device
->connector_name
[0],
8718 &pcie_device_pg0
->ConnectorName
[0], 4);
8720 pcie_device
->enclosure_level
= 0;
8721 pcie_device
->connector_name
[0] = '\0';
8724 if (pcie_device
->handle
== pcie_device_pg0
->DevHandle
)
8726 pr_info("\thandle changed from(0x%04x)!!!\n",
8727 pcie_device
->handle
);
8728 pcie_device
->handle
= pcie_device_pg0
->DevHandle
;
8729 if (sas_target_priv_data
)
8730 sas_target_priv_data
->handle
=
8731 pcie_device_pg0
->DevHandle
;
8737 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8741 * _scsih_search_responding_pcie_devices -
8742 * @ioc: per adapter object
8744 * After host reset, find out whether devices are still responding.
8750 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER
*ioc
)
8752 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
8753 Mpi2ConfigReply_t mpi_reply
;
8758 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
8760 if (list_empty(&ioc
->pcie_device_list
))
8764 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
8765 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8767 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8768 MPI2_IOCSTATUS_MASK
;
8769 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8770 pr_info(MPT3SAS_FMT
"\tbreak from %s: "
8771 "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc
->name
,
8772 __func__
, ioc_status
,
8773 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8776 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
8777 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
8778 if (!(_scsih_is_nvme_device(device_info
)))
8780 pcie_device_pg0
.WWID
= le64_to_cpu(pcie_device_pg0
.WWID
),
8781 pcie_device_pg0
.Slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
8782 pcie_device_pg0
.Flags
= le32_to_cpu(pcie_device_pg0
.Flags
);
8783 pcie_device_pg0
.DevHandle
= handle
;
8784 _scsih_mark_responding_pcie_device(ioc
, &pcie_device_pg0
);
8787 pr_info(MPT3SAS_FMT
"search for PCIe end-devices: complete\n",
8792 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8793 * @ioc: per adapter object
8794 * @wwid: world wide identifier for raid volume
8795 * @handle: device handle
8797 * After host reset, find out whether devices are still responding.
8798 * Used in _scsih_remove_unresponsive_raid_devices.
8803 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
8806 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8807 struct scsi_target
*starget
;
8808 struct _raid_device
*raid_device
;
8809 unsigned long flags
;
8811 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8812 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
8813 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
8814 starget
= raid_device
->starget
;
8815 if (starget
&& starget
->hostdata
) {
8816 sas_target_priv_data
= starget
->hostdata
;
8817 sas_target_priv_data
->deleted
= 0;
8819 sas_target_priv_data
= NULL
;
8820 raid_device
->responding
= 1;
8821 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8822 starget_printk(KERN_INFO
, raid_device
->starget
,
8823 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
8824 (unsigned long long)raid_device
->wwid
);
8827 * WARPDRIVE: The handles of the PDs might have changed
8828 * across the host reset so re-initialize the
8829 * required data for Direct IO
8831 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
8832 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8833 if (raid_device
->handle
== handle
) {
8834 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
8838 pr_info("\thandle changed from(0x%04x)!!!\n",
8839 raid_device
->handle
);
8840 raid_device
->handle
= handle
;
8841 if (sas_target_priv_data
)
8842 sas_target_priv_data
->handle
= handle
;
8843 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8847 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8851 * _scsih_search_responding_raid_devices -
8852 * @ioc: per adapter object
8854 * After host reset, find out whether devices are still responding.
8860 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
8862 Mpi2RaidVolPage1_t volume_pg1
;
8863 Mpi2RaidVolPage0_t volume_pg0
;
8864 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8865 Mpi2ConfigReply_t mpi_reply
;
8870 if (!ioc
->ir_firmware
)
8873 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
8876 if (list_empty(&ioc
->raid_device_list
))
8880 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
8881 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
8882 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8883 MPI2_IOCSTATUS_MASK
;
8884 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8886 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
8888 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
8889 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
8890 sizeof(Mpi2RaidVolPage0_t
)))
8893 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
8894 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
8895 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
8896 _scsih_mark_responding_raid_device(ioc
,
8897 le64_to_cpu(volume_pg1
.WWID
), handle
);
8900 /* refresh the pd_handles */
8901 if (!ioc
->is_warpdrive
) {
8902 phys_disk_num
= 0xFF;
8903 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
8904 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
8905 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
8907 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8908 MPI2_IOCSTATUS_MASK
;
8909 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8911 phys_disk_num
= pd_pg0
.PhysDiskNum
;
8912 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
8913 set_bit(handle
, ioc
->pd_handles
);
8917 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
8922 * _scsih_mark_responding_expander - mark a expander as responding
8923 * @ioc: per adapter object
8924 * @expander_pg0:SAS Expander Config Page0
8926 * After host reset, find out whether devices are still responding.
8927 * Used in _scsih_remove_unresponsive_expanders.
8932 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
,
8933 Mpi2ExpanderPage0_t
*expander_pg0
)
8935 struct _sas_node
*sas_expander
= NULL
;
8936 unsigned long flags
;
8937 int i
, encl_pg0_rc
= -1;
8938 Mpi2ConfigReply_t mpi_reply
;
8939 Mpi2SasEnclosurePage0_t enclosure_pg0
;
8940 u16 handle
= le16_to_cpu(expander_pg0
->DevHandle
);
8941 u64 sas_address
= le64_to_cpu(expander_pg0
->SASAddress
);
8943 if (le16_to_cpu(expander_pg0
->EnclosureHandle
)) {
8944 encl_pg0_rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
8945 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
8946 le16_to_cpu(expander_pg0
->EnclosureHandle
));
8949 "Enclosure Pg0 read failed for handle(0x%04x)\n",
8951 le16_to_cpu(expander_pg0
->EnclosureHandle
));
8954 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8955 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
8956 if (sas_expander
->sas_address
!= sas_address
)
8958 sas_expander
->responding
= 1;
8961 sas_expander
->enclosure_logical_id
=
8962 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
8964 sas_expander
->enclosure_handle
=
8965 le16_to_cpu(expander_pg0
->EnclosureHandle
);
8967 if (sas_expander
->handle
== handle
)
8969 pr_info("\texpander(0x%016llx): handle changed" \
8970 " from(0x%04x) to (0x%04x)!!!\n",
8971 (unsigned long long)sas_expander
->sas_address
,
8972 sas_expander
->handle
, handle
);
8973 sas_expander
->handle
= handle
;
8974 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
8975 sas_expander
->phy
[i
].handle
= handle
;
8979 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8983 * _scsih_search_responding_expanders -
8984 * @ioc: per adapter object
8986 * After host reset, find out whether devices are still responding.
8992 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
8994 Mpi2ExpanderPage0_t expander_pg0
;
8995 Mpi2ConfigReply_t mpi_reply
;
9000 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
9002 if (list_empty(&ioc
->sas_expander_list
))
9006 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
9007 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
9009 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9010 MPI2_IOCSTATUS_MASK
;
9011 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
9014 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
9015 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
9016 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
9018 (unsigned long long)sas_address
);
9019 _scsih_mark_responding_expander(ioc
, &expander_pg0
);
9023 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
9027 * _scsih_remove_unresponding_devices - removing unresponding devices
9028 * @ioc: per adapter object
9033 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER
*ioc
)
9035 struct _sas_device
*sas_device
, *sas_device_next
;
9036 struct _sas_node
*sas_expander
, *sas_expander_next
;
9037 struct _raid_device
*raid_device
, *raid_device_next
;
9038 struct _pcie_device
*pcie_device
, *pcie_device_next
;
9039 struct list_head tmp_list
;
9040 unsigned long flags
;
9043 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
9046 /* removing unresponding end devices */
9047 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
9050 * Iterate, pulling off devices marked as non-responding. We become the
9051 * owner for the reference the list had on any object we prune.
9053 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9054 list_for_each_entry_safe(sas_device
, sas_device_next
,
9055 &ioc
->sas_device_list
, list
) {
9056 if (!sas_device
->responding
)
9057 list_move_tail(&sas_device
->list
, &head
);
9059 sas_device
->responding
= 0;
9061 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9064 * Now, uninitialize and remove the unresponding devices we pruned.
9066 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
9067 _scsih_remove_device(ioc
, sas_device
);
9068 list_del_init(&sas_device
->list
);
9069 sas_device_put(sas_device
);
9073 " Removing unresponding devices: pcie end-devices\n"
9075 INIT_LIST_HEAD(&head
);
9076 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9077 list_for_each_entry_safe(pcie_device
, pcie_device_next
,
9078 &ioc
->pcie_device_list
, list
) {
9079 if (!pcie_device
->responding
)
9080 list_move_tail(&pcie_device
->list
, &head
);
9082 pcie_device
->responding
= 0;
9084 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9086 list_for_each_entry_safe(pcie_device
, pcie_device_next
, &head
, list
) {
9087 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
9088 list_del_init(&pcie_device
->list
);
9089 pcie_device_put(pcie_device
);
9092 /* removing unresponding volumes */
9093 if (ioc
->ir_firmware
) {
9094 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
9096 list_for_each_entry_safe(raid_device
, raid_device_next
,
9097 &ioc
->raid_device_list
, list
) {
9098 if (!raid_device
->responding
)
9099 _scsih_sas_volume_delete(ioc
,
9100 raid_device
->handle
);
9102 raid_device
->responding
= 0;
9106 /* removing unresponding expanders */
9107 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
9109 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9110 INIT_LIST_HEAD(&tmp_list
);
9111 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
9112 &ioc
->sas_expander_list
, list
) {
9113 if (!sas_expander
->responding
)
9114 list_move_tail(&sas_expander
->list
, &tmp_list
);
9116 sas_expander
->responding
= 0;
9118 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9119 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
9121 _scsih_expander_node_remove(ioc
, sas_expander
);
9124 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
9127 /* unblock devices */
9128 _scsih_ublock_io_all_device(ioc
);
9132 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
9133 struct _sas_node
*sas_expander
, u16 handle
)
9135 Mpi2ExpanderPage1_t expander_pg1
;
9136 Mpi2ConfigReply_t mpi_reply
;
9139 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
9140 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
9141 &expander_pg1
, i
, handle
))) {
9142 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
9143 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9147 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
9148 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
9149 expander_pg1
.NegotiatedLinkRate
>> 4);
9154 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
9155 * @ioc: per adapter object
9160 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
9162 Mpi2ExpanderPage0_t expander_pg0
;
9163 Mpi2SasDevicePage0_t sas_device_pg0
;
9164 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
9165 Mpi2RaidVolPage1_t volume_pg1
;
9166 Mpi2RaidVolPage0_t volume_pg0
;
9167 Mpi2RaidPhysDiskPage0_t pd_pg0
;
9168 Mpi2EventIrConfigElement_t element
;
9169 Mpi2ConfigReply_t mpi_reply
;
9172 u16 handle
, parent_handle
;
9174 struct _sas_device
*sas_device
;
9175 struct _pcie_device
*pcie_device
;
9176 struct _sas_node
*expander_device
;
9177 static struct _raid_device
*raid_device
;
9179 unsigned long flags
;
9181 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
9183 _scsih_sas_host_refresh(ioc
);
9185 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
9189 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
9190 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
9191 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9192 MPI2_IOCSTATUS_MASK
;
9193 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9194 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
9195 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9196 ioc
->name
, ioc_status
,
9197 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9200 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
9201 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9202 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
9203 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
9204 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9205 if (expander_device
)
9206 _scsih_refresh_expander_links(ioc
, expander_device
,
9209 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
9210 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9211 handle
, (unsigned long long)
9212 le64_to_cpu(expander_pg0
.SASAddress
));
9213 _scsih_expander_add(ioc
, handle
);
9214 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
9215 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9216 handle
, (unsigned long long)
9217 le64_to_cpu(expander_pg0
.SASAddress
));
9221 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
9224 if (!ioc
->ir_firmware
)
9227 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
9230 phys_disk_num
= 0xFF;
9231 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
9232 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
9234 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9235 MPI2_IOCSTATUS_MASK
;
9236 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9237 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
9238 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9239 ioc
->name
, ioc_status
,
9240 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9243 phys_disk_num
= pd_pg0
.PhysDiskNum
;
9244 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
9245 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
9247 sas_device_put(sas_device
);
9250 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9251 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
9254 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9255 MPI2_IOCSTATUS_MASK
;
9256 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9257 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
9258 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9259 ioc
->name
, ioc_status
,
9260 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9263 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9264 if (!_scsih_get_sas_address(ioc
, parent_handle
,
9266 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
9267 " handle (0x%04x), sas_addr(0x%016llx)\n",
9268 ioc
->name
, handle
, (unsigned long long)
9269 le64_to_cpu(sas_device_pg0
.SASAddress
));
9270 mpt3sas_transport_update_links(ioc
, sas_address
,
9271 handle
, sas_device_pg0
.PhyNum
,
9272 MPI2_SAS_NEG_LINK_RATE_1_5
);
9273 set_bit(handle
, ioc
->pd_handles
);
9275 /* This will retry adding the end device.
9276 * _scsih_add_device() will decide on retries and
9277 * return "1" when it should be retried
9279 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9283 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
9284 " handle (0x%04x), sas_addr(0x%016llx)\n",
9285 ioc
->name
, handle
, (unsigned long long)
9286 le64_to_cpu(sas_device_pg0
.SASAddress
));
9290 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
9293 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
9297 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
9298 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
9299 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9300 MPI2_IOCSTATUS_MASK
;
9301 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9302 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9303 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9304 ioc
->name
, ioc_status
,
9305 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9308 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
9309 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
9310 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
9311 le64_to_cpu(volume_pg1
.WWID
));
9312 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
9315 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
9316 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
9317 sizeof(Mpi2RaidVolPage0_t
)))
9319 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9320 MPI2_IOCSTATUS_MASK
;
9321 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9322 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9323 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9324 ioc
->name
, ioc_status
,
9325 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9328 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
9329 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
9330 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
9331 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
9332 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
9333 element
.VolDevHandle
= volume_pg1
.DevHandle
;
9335 "\tBEFORE adding volume: handle (0x%04x)\n",
9336 ioc
->name
, volume_pg1
.DevHandle
);
9337 _scsih_sas_volume_add(ioc
, &element
);
9339 "\tAFTER adding volume: handle (0x%04x)\n",
9340 ioc
->name
, volume_pg1
.DevHandle
);
9344 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
9349 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
9354 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9355 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9357 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9358 MPI2_IOCSTATUS_MASK
;
9359 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9360 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
9361 " ioc_status(0x%04x), loginfo(0x%08x)\n",
9362 ioc
->name
, ioc_status
,
9363 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9366 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
9367 if (!(_scsih_is_end_device(
9368 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
9370 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
9371 le64_to_cpu(sas_device_pg0
.SASAddress
));
9373 sas_device_put(sas_device
);
9376 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9377 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
9378 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
9379 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9380 handle
, (unsigned long long)
9381 le64_to_cpu(sas_device_pg0
.SASAddress
));
9382 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
9383 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
9385 /* This will retry adding the end device.
9386 * _scsih_add_device() will decide on retries and
9387 * return "1" when it should be retried
9389 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9393 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
9394 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9395 handle
, (unsigned long long)
9396 le64_to_cpu(sas_device_pg0
.SASAddress
));
9399 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
9401 pr_info(MPT3SAS_FMT
"\tscan devices: pcie end devices start\n",
9406 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
9407 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9409 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
)
9410 & MPI2_IOCSTATUS_MASK
;
9411 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9412 pr_info(MPT3SAS_FMT
"\tbreak from pcie end device"
9413 " scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9414 ioc
->name
, ioc_status
,
9415 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9418 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
9419 if (!(_scsih_is_nvme_device(
9420 le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
9422 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
,
9423 le64_to_cpu(pcie_device_pg0
.WWID
));
9425 pcie_device_put(pcie_device
);
9429 parent_handle
= le16_to_cpu(pcie_device_pg0
.ParentDevHandle
);
9430 _scsih_pcie_add_device(ioc
, handle
);
9432 pr_info(MPT3SAS_FMT
"\tAFTER adding pcie end device: "
9433 "handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
,
9435 (unsigned long long) le64_to_cpu(pcie_device_pg0
.WWID
));
9437 pr_info(MPT3SAS_FMT
"\tpcie devices: pcie end devices complete\n",
9439 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
9442 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9443 * @ioc: per adapter object
9444 * @reset_phase: phase
9446 * The handler for doing any required cleanup or initialization.
9448 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
9449 * MPT3_IOC_DONE_RESET
9454 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
9456 switch (reset_phase
) {
9457 case MPT3_IOC_PRE_RESET
:
9458 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9459 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
9461 case MPT3_IOC_AFTER_RESET
:
9462 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9463 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
9464 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
9465 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
9466 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
9467 complete(&ioc
->scsih_cmds
.done
);
9469 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
9470 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
9471 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
9472 complete(&ioc
->tm_cmds
.done
);
9475 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
9476 memset(ioc
->device_remove_in_progress
, 0,
9477 ioc
->device_remove_in_progress_sz
);
9478 _scsih_fw_event_cleanup_queue(ioc
);
9479 _scsih_flush_running_cmds(ioc
);
9481 case MPT3_IOC_DONE_RESET
:
9482 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9483 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
9484 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
9485 !ioc
->sas_hba
.num_phys
)) {
9486 _scsih_prep_device_scan(ioc
);
9487 _scsih_search_responding_sas_devices(ioc
);
9488 _scsih_search_responding_pcie_devices(ioc
);
9489 _scsih_search_responding_raid_devices(ioc
);
9490 _scsih_search_responding_expanders(ioc
);
9491 _scsih_error_recovery_delete_devices(ioc
);
9498 * _mpt3sas_fw_work - delayed task for processing firmware events
9499 * @ioc: per adapter object
9500 * @fw_event: The fw_event_work object
9506 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
9508 _scsih_fw_event_del_from_list(ioc
, fw_event
);
9510 /* the queue is being flushed so ignore this event */
9511 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
9512 fw_event_work_put(fw_event
);
9516 switch (fw_event
->event
) {
9517 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
9518 mpt3sas_process_trigger_data(ioc
,
9519 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
9520 fw_event
->event_data
);
9522 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
9523 while (scsi_host_in_recovery(ioc
->shost
) ||
9524 ioc
->shost_recovery
) {
9526 * If we're unloading, bail. Otherwise, this can become
9529 if (ioc
->remove_host
)
9533 _scsih_remove_unresponding_devices(ioc
);
9534 _scsih_scan_for_devices_after_reset(ioc
);
9536 case MPT3SAS_PORT_ENABLE_COMPLETE
:
9537 ioc
->start_scan
= 0;
9538 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
9539 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
9541 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
9542 "port enable: complete from worker thread\n",
9545 case MPT3SAS_TURN_ON_PFA_LED
:
9546 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
9548 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9549 _scsih_sas_topology_change_event(ioc
, fw_event
);
9551 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9552 _scsih_sas_device_status_change_event(ioc
, fw_event
);
9554 case MPI2_EVENT_SAS_DISCOVERY
:
9555 _scsih_sas_discovery_event(ioc
, fw_event
);
9557 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9558 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
9560 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9561 _scsih_sas_enclosure_dev_status_change_event(ioc
,
9564 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9565 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
9567 case MPI2_EVENT_IR_VOLUME
:
9568 _scsih_sas_ir_volume_event(ioc
, fw_event
);
9570 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9571 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
9573 case MPI2_EVENT_IR_OPERATION_STATUS
:
9574 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
9576 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9577 _scsih_pcie_device_status_change_event(ioc
, fw_event
);
9579 case MPI2_EVENT_PCIE_ENUMERATION
:
9580 _scsih_pcie_enumeration_event(ioc
, fw_event
);
9582 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9583 _scsih_pcie_topology_change_event(ioc
, fw_event
);
9588 fw_event_work_put(fw_event
);
9592 * _firmware_event_work
9593 * @ioc: per adapter object
9594 * @work: The fw_event_work object
9597 * wrappers for the work thread handling firmware events
9603 _firmware_event_work(struct work_struct
*work
)
9605 struct fw_event_work
*fw_event
= container_of(work
,
9606 struct fw_event_work
, work
);
9608 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
9612 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9613 * @ioc: per adapter object
9614 * @msix_index: MSIX table index supplied by the OS
9615 * @reply: reply message frame(lower 32bit addr)
9616 * Context: interrupt.
9618 * This function merely adds a new work task into ioc->firmware_event_thread.
9619 * The tasks are worked from _firmware_event_work in user context.
9621 * Return 1 meaning mf should be freed from _base_interrupt
9622 * 0 means the mf is freed from this function.
9625 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
9628 struct fw_event_work
*fw_event
;
9629 Mpi2EventNotificationReply_t
*mpi_reply
;
9632 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
9634 /* events turned off due to host reset or driver unloading */
9635 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
9638 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
9640 if (unlikely(!mpi_reply
)) {
9641 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
9642 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9646 event
= le16_to_cpu(mpi_reply
->Event
);
9648 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
9649 mpt3sas_trigger_event(ioc
, event
, 0);
9653 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9655 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
9656 (Mpi2EventDataSasBroadcastPrimitive_t
*)
9657 mpi_reply
->EventData
;
9659 if (baen_data
->Primitive
!=
9660 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
9663 if (ioc
->broadcast_aen_busy
) {
9664 ioc
->broadcast_aen_pending
++;
9667 ioc
->broadcast_aen_busy
= 1;
9671 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9672 _scsih_check_topo_delete_events(ioc
,
9673 (Mpi2EventDataSasTopologyChangeList_t
*)
9674 mpi_reply
->EventData
);
9676 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9677 _scsih_check_pcie_topo_remove_events(ioc
,
9678 (Mpi26EventDataPCIeTopologyChangeList_t
*)
9679 mpi_reply
->EventData
);
9681 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9682 _scsih_check_ir_config_unhide_events(ioc
,
9683 (Mpi2EventDataIrConfigChangeList_t
*)
9684 mpi_reply
->EventData
);
9686 case MPI2_EVENT_IR_VOLUME
:
9687 _scsih_check_volume_delete_events(ioc
,
9688 (Mpi2EventDataIrVolume_t
*)
9689 mpi_reply
->EventData
);
9691 case MPI2_EVENT_LOG_ENTRY_ADDED
:
9693 Mpi2EventDataLogEntryAdded_t
*log_entry
;
9696 if (!ioc
->is_warpdrive
)
9699 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
9700 mpi_reply
->EventData
;
9701 log_code
= (u32
*)log_entry
->LogData
;
9703 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
9704 != MPT2_WARPDRIVE_LOGENTRY
)
9707 switch (le32_to_cpu(*log_code
)) {
9708 case MPT2_WARPDRIVE_LC_SSDT
:
9709 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9710 "IO Throttling has occurred in the WarpDrive "
9711 "subsystem. Check WarpDrive documentation for "
9712 "additional details.\n", ioc
->name
);
9714 case MPT2_WARPDRIVE_LC_SSDLW
:
9715 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9716 "Program/Erase Cycles for the WarpDrive subsystem "
9717 "in degraded range. Check WarpDrive documentation "
9718 "for additional details.\n", ioc
->name
);
9720 case MPT2_WARPDRIVE_LC_SSDLF
:
9721 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9722 "There are no Program/Erase Cycles for the "
9723 "WarpDrive subsystem. The storage device will be "
9724 "in read-only mode. Check WarpDrive documentation "
9725 "for additional details.\n", ioc
->name
);
9727 case MPT2_WARPDRIVE_LC_BRMF
:
9728 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9729 "The Backup Rail Monitor has failed on the "
9730 "WarpDrive subsystem. Check WarpDrive "
9731 "documentation for additional details.\n",
9738 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9739 case MPI2_EVENT_IR_OPERATION_STATUS
:
9740 case MPI2_EVENT_SAS_DISCOVERY
:
9741 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9742 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9743 case MPI2_EVENT_PCIE_ENUMERATION
:
9744 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9747 case MPI2_EVENT_TEMP_THRESHOLD
:
9748 _scsih_temp_threshold_events(ioc
,
9749 (Mpi2EventDataTemperature_t
*)
9750 mpi_reply
->EventData
);
9752 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
9753 ActiveCableEventData
=
9754 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
9755 switch (ActiveCableEventData
->ReasonCode
) {
9756 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
9757 pr_notice(MPT3SAS_FMT
9758 "Currently an active cable with ReceptacleID %d\n",
9759 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9760 pr_notice("cannot be powered and devices connected\n");
9761 pr_notice("to this active cable will not be seen\n");
9762 pr_notice("This active cable requires %d mW of power\n",
9763 ActiveCableEventData
->ActiveCablePowerRequirement
);
9766 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
9767 pr_notice(MPT3SAS_FMT
9768 "Currently a cable with ReceptacleID %d\n",
9769 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9771 "is not running at optimal speed(12 Gb/s rate)\n");
9777 default: /* ignore the rest */
9781 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
9782 fw_event
= alloc_fw_event_work(sz
);
9784 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
9785 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9789 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
9790 fw_event
->ioc
= ioc
;
9791 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
9792 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
9793 fw_event
->event
= event
;
9794 _scsih_fw_event_add(ioc
, fw_event
);
9795 fw_event_work_put(fw_event
);
9800 * _scsih_expander_node_remove - removing expander device from list.
9801 * @ioc: per adapter object
9802 * @sas_expander: the sas_device object
9804 * Removing object and freeing associated memory from the
9805 * ioc->sas_expander_list.
9810 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
9811 struct _sas_node
*sas_expander
)
9813 struct _sas_port
*mpt3sas_port
, *next
;
9814 unsigned long flags
;
9816 /* remove sibling ports attached to this expander */
9817 list_for_each_entry_safe(mpt3sas_port
, next
,
9818 &sas_expander
->sas_port_list
, port_list
) {
9819 if (ioc
->shost_recovery
)
9821 if (mpt3sas_port
->remote_identify
.device_type
==
9823 mpt3sas_device_remove_by_sas_address(ioc
,
9824 mpt3sas_port
->remote_identify
.sas_address
);
9825 else if (mpt3sas_port
->remote_identify
.device_type
==
9826 SAS_EDGE_EXPANDER_DEVICE
||
9827 mpt3sas_port
->remote_identify
.device_type
==
9828 SAS_FANOUT_EXPANDER_DEVICE
)
9829 mpt3sas_expander_remove(ioc
,
9830 mpt3sas_port
->remote_identify
.sas_address
);
9833 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
9834 sas_expander
->sas_address_parent
);
9837 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9839 sas_expander
->handle
, (unsigned long long)
9840 sas_expander
->sas_address
);
9842 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9843 list_del(&sas_expander
->list
);
9844 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9846 kfree(sas_expander
->phy
);
9847 kfree(sas_expander
);
9851 * _scsih_ir_shutdown - IR shutdown notification
9852 * @ioc: per adapter object
9854 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9855 * the host system is shutting down.
9860 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
9862 Mpi2RaidActionRequest_t
*mpi_request
;
9863 Mpi2RaidActionReply_t
*mpi_reply
;
9866 /* is IR firmware build loaded ? */
9867 if (!ioc
->ir_firmware
)
9870 /* are there any volumes ? */
9871 if (list_empty(&ioc
->raid_device_list
))
9874 mutex_lock(&ioc
->scsih_cmds
.mutex
);
9876 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
9877 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
9878 ioc
->name
, __func__
);
9881 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
9883 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
9885 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
9886 ioc
->name
, __func__
);
9887 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9891 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
9892 ioc
->scsih_cmds
.smid
= smid
;
9893 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
9895 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
9896 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
9898 if (!ioc
->hide_ir_msg
)
9899 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
9900 init_completion(&ioc
->scsih_cmds
.done
);
9901 ioc
->put_smid_default(ioc
, smid
);
9902 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
9904 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
9905 pr_err(MPT3SAS_FMT
"%s: timeout\n",
9906 ioc
->name
, __func__
);
9910 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
9911 mpi_reply
= ioc
->scsih_cmds
.reply
;
9912 if (!ioc
->hide_ir_msg
)
9913 pr_info(MPT3SAS_FMT
"IR shutdown "
9914 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9915 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
9916 le32_to_cpu(mpi_reply
->IOCLogInfo
));
9920 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9921 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
9925 * scsih_remove - detach and remove add host
9926 * @pdev: PCI device struct
9928 * Routine called when unloading the driver.
9931 static void scsih_remove(struct pci_dev
*pdev
)
9933 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9934 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9935 struct _sas_port
*mpt3sas_port
, *next_port
;
9936 struct _raid_device
*raid_device
, *next
;
9937 struct MPT3SAS_TARGET
*sas_target_priv_data
;
9938 struct _pcie_device
*pcie_device
, *pcienext
;
9939 struct workqueue_struct
*wq
;
9940 unsigned long flags
;
9942 ioc
->remove_host
= 1;
9944 mpt3sas_wait_for_commands_to_complete(ioc
);
9945 _scsih_flush_running_cmds(ioc
);
9947 _scsih_fw_event_cleanup_queue(ioc
);
9949 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9950 wq
= ioc
->firmware_event_thread
;
9951 ioc
->firmware_event_thread
= NULL
;
9952 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9954 destroy_workqueue(wq
);
9956 /* release all the volumes */
9957 _scsih_ir_shutdown(ioc
);
9958 sas_remove_host(shost
);
9959 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
9961 if (raid_device
->starget
) {
9962 sas_target_priv_data
=
9963 raid_device
->starget
->hostdata
;
9964 sas_target_priv_data
->deleted
= 1;
9965 scsi_remove_target(&raid_device
->starget
->dev
);
9967 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
9968 ioc
->name
, raid_device
->handle
,
9969 (unsigned long long) raid_device
->wwid
);
9970 _scsih_raid_device_remove(ioc
, raid_device
);
9972 list_for_each_entry_safe(pcie_device
, pcienext
, &ioc
->pcie_device_list
,
9974 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
9975 list_del_init(&pcie_device
->list
);
9976 pcie_device_put(pcie_device
);
9979 /* free ports attached to the sas_host */
9980 list_for_each_entry_safe(mpt3sas_port
, next_port
,
9981 &ioc
->sas_hba
.sas_port_list
, port_list
) {
9982 if (mpt3sas_port
->remote_identify
.device_type
==
9984 mpt3sas_device_remove_by_sas_address(ioc
,
9985 mpt3sas_port
->remote_identify
.sas_address
);
9986 else if (mpt3sas_port
->remote_identify
.device_type
==
9987 SAS_EDGE_EXPANDER_DEVICE
||
9988 mpt3sas_port
->remote_identify
.device_type
==
9989 SAS_FANOUT_EXPANDER_DEVICE
)
9990 mpt3sas_expander_remove(ioc
,
9991 mpt3sas_port
->remote_identify
.sas_address
);
9994 /* free phys attached to the sas_host */
9995 if (ioc
->sas_hba
.num_phys
) {
9996 kfree(ioc
->sas_hba
.phy
);
9997 ioc
->sas_hba
.phy
= NULL
;
9998 ioc
->sas_hba
.num_phys
= 0;
10001 mpt3sas_base_detach(ioc
);
10002 spin_lock(&gioc_lock
);
10003 list_del(&ioc
->list
);
10004 spin_unlock(&gioc_lock
);
10005 scsi_host_put(shost
);
10009 * scsih_shutdown - routine call during system shutdown
10010 * @pdev: PCI device struct
10015 scsih_shutdown(struct pci_dev
*pdev
)
10017 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10018 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10019 struct workqueue_struct
*wq
;
10020 unsigned long flags
;
10022 ioc
->remove_host
= 1;
10024 mpt3sas_wait_for_commands_to_complete(ioc
);
10025 _scsih_flush_running_cmds(ioc
);
10027 _scsih_fw_event_cleanup_queue(ioc
);
10029 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
10030 wq
= ioc
->firmware_event_thread
;
10031 ioc
->firmware_event_thread
= NULL
;
10032 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
10034 destroy_workqueue(wq
);
10036 _scsih_ir_shutdown(ioc
);
10037 mpt3sas_base_detach(ioc
);
10042 * _scsih_probe_boot_devices - reports 1st device
10043 * @ioc: per adapter object
10045 * If specified in bios page 2, this routine reports the 1st
10046 * device scsi-ml or sas transport for persistent boot device
10047 * purposes. Please refer to function _scsih_determine_boot_device()
10050 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
10054 struct _sas_device
*sas_device
;
10055 struct _raid_device
*raid_device
;
10056 struct _pcie_device
*pcie_device
;
10058 u64 sas_address_parent
;
10060 unsigned long flags
;
10064 /* no Bios, return immediately */
10065 if (!ioc
->bios_pg3
.BiosVersion
)
10069 if (ioc
->req_boot_device
.device
) {
10070 device
= ioc
->req_boot_device
.device
;
10071 channel
= ioc
->req_boot_device
.channel
;
10072 } else if (ioc
->req_alt_boot_device
.device
) {
10073 device
= ioc
->req_alt_boot_device
.device
;
10074 channel
= ioc
->req_alt_boot_device
.channel
;
10075 } else if (ioc
->current_boot_device
.device
) {
10076 device
= ioc
->current_boot_device
.device
;
10077 channel
= ioc
->current_boot_device
.channel
;
10083 if (channel
== RAID_CHANNEL
) {
10084 raid_device
= device
;
10085 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
10086 raid_device
->id
, 0);
10088 _scsih_raid_device_remove(ioc
, raid_device
);
10089 } else if (channel
== PCIE_CHANNEL
) {
10090 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10091 pcie_device
= device
;
10092 tid
= pcie_device
->id
;
10093 list_move_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
10094 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10095 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, tid
, 0);
10097 _scsih_pcie_device_remove(ioc
, pcie_device
);
10099 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
10100 sas_device
= device
;
10101 handle
= sas_device
->handle
;
10102 sas_address_parent
= sas_device
->sas_address_parent
;
10103 sas_address
= sas_device
->sas_address
;
10104 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
10105 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
10107 if (ioc
->hide_drives
)
10109 if (!mpt3sas_transport_port_add(ioc
, handle
,
10110 sas_address_parent
)) {
10111 _scsih_sas_device_remove(ioc
, sas_device
);
10112 } else if (!sas_device
->starget
) {
10113 if (!ioc
->is_driver_loading
) {
10114 mpt3sas_transport_port_remove(ioc
,
10116 sas_address_parent
);
10117 _scsih_sas_device_remove(ioc
, sas_device
);
10124 * _scsih_probe_raid - reporting raid volumes to scsi-ml
10125 * @ioc: per adapter object
10127 * Called during initial loading of the driver.
10130 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
10132 struct _raid_device
*raid_device
, *raid_next
;
10135 list_for_each_entry_safe(raid_device
, raid_next
,
10136 &ioc
->raid_device_list
, list
) {
10137 if (raid_device
->starget
)
10139 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
10140 raid_device
->id
, 0);
10142 _scsih_raid_device_remove(ioc
, raid_device
);
10146 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
10148 struct _sas_device
*sas_device
= NULL
;
10149 unsigned long flags
;
10151 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
10152 if (!list_empty(&ioc
->sas_device_init_list
)) {
10153 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
10154 struct _sas_device
, list
);
10155 sas_device_get(sas_device
);
10157 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
10162 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
10163 struct _sas_device
*sas_device
)
10165 unsigned long flags
;
10167 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
10170 * Since we dropped the lock during the call to port_add(), we need to
10171 * be careful here that somebody else didn't move or delete this item
10172 * while we were busy with other things.
10174 * If it was on the list, we need a put() for the reference the list
10175 * had. Either way, we need a get() for the destination list.
10177 if (!list_empty(&sas_device
->list
)) {
10178 list_del_init(&sas_device
->list
);
10179 sas_device_put(sas_device
);
10182 sas_device_get(sas_device
);
10183 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
10185 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
10189 * _scsih_probe_sas - reporting sas devices to sas transport
10190 * @ioc: per adapter object
10192 * Called during initial loading of the driver.
10195 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
10197 struct _sas_device
*sas_device
;
10199 if (ioc
->hide_drives
)
10202 while ((sas_device
= get_next_sas_device(ioc
))) {
10203 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
10204 sas_device
->sas_address_parent
)) {
10205 _scsih_sas_device_remove(ioc
, sas_device
);
10206 sas_device_put(sas_device
);
10208 } else if (!sas_device
->starget
) {
10210 * When asyn scanning is enabled, its not possible to
10211 * remove devices while scanning is turned on due to an
10212 * oops in scsi_sysfs_add_sdev()->add_device()->
10213 * sysfs_addrm_start()
10215 if (!ioc
->is_driver_loading
) {
10216 mpt3sas_transport_port_remove(ioc
,
10217 sas_device
->sas_address
,
10218 sas_device
->sas_address_parent
);
10219 _scsih_sas_device_remove(ioc
, sas_device
);
10220 sas_device_put(sas_device
);
10224 sas_device_make_active(ioc
, sas_device
);
10225 sas_device_put(sas_device
);
10230 * get_next_pcie_device - Get the next pcie device
10231 * @ioc: per adapter object
10233 * Get the next pcie device from pcie_device_init_list list.
10235 * Returns pcie device structure if pcie_device_init_list list is not empty
10236 * otherwise returns NULL
10238 static struct _pcie_device
*get_next_pcie_device(struct MPT3SAS_ADAPTER
*ioc
)
10240 struct _pcie_device
*pcie_device
= NULL
;
10241 unsigned long flags
;
10243 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10244 if (!list_empty(&ioc
->pcie_device_init_list
)) {
10245 pcie_device
= list_first_entry(&ioc
->pcie_device_init_list
,
10246 struct _pcie_device
, list
);
10247 pcie_device_get(pcie_device
);
10249 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10251 return pcie_device
;
10255 * pcie_device_make_active - Add pcie device to pcie_device_list list
10256 * @ioc: per adapter object
10257 * @pcie_device: pcie device object
10259 * Add the pcie device which has registered with SCSI Transport Later to
10260 * pcie_device_list list
10262 static void pcie_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
10263 struct _pcie_device
*pcie_device
)
10265 unsigned long flags
;
10267 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10269 if (!list_empty(&pcie_device
->list
)) {
10270 list_del_init(&pcie_device
->list
);
10271 pcie_device_put(pcie_device
);
10273 pcie_device_get(pcie_device
);
10274 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
10276 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10280 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
10281 * @ioc: per adapter object
10283 * Called during initial loading of the driver.
10286 _scsih_probe_pcie(struct MPT3SAS_ADAPTER
*ioc
)
10288 struct _pcie_device
*pcie_device
;
10291 /* PCIe Device List */
10292 while ((pcie_device
= get_next_pcie_device(ioc
))) {
10293 if (pcie_device
->starget
) {
10294 pcie_device_put(pcie_device
);
10297 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
,
10298 pcie_device
->id
, 0);
10300 _scsih_pcie_device_remove(ioc
, pcie_device
);
10301 pcie_device_put(pcie_device
);
10303 } else if (!pcie_device
->starget
) {
10305 * When async scanning is enabled, its not possible to
10306 * remove devices while scanning is turned on due to an
10307 * oops in scsi_sysfs_add_sdev()->add_device()->
10308 * sysfs_addrm_start()
10310 if (!ioc
->is_driver_loading
) {
10311 /* TODO-- Need to find out whether this condition will
10314 _scsih_pcie_device_remove(ioc
, pcie_device
);
10315 pcie_device_put(pcie_device
);
10319 pcie_device_make_active(ioc
, pcie_device
);
10320 pcie_device_put(pcie_device
);
10325 * _scsih_probe_devices - probing for devices
10326 * @ioc: per adapter object
10328 * Called during initial loading of the driver.
10331 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
10333 u16 volume_mapping_flags
;
10335 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
10336 return; /* return when IOC doesn't support initiator mode */
10338 _scsih_probe_boot_devices(ioc
);
10340 if (ioc
->ir_firmware
) {
10341 volume_mapping_flags
=
10342 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
10343 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
10344 if (volume_mapping_flags
==
10345 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
10346 _scsih_probe_raid(ioc
);
10347 _scsih_probe_sas(ioc
);
10349 _scsih_probe_sas(ioc
);
10350 _scsih_probe_raid(ioc
);
10353 _scsih_probe_sas(ioc
);
10354 _scsih_probe_pcie(ioc
);
10359 * scsih_scan_start - scsi lld callback for .scan_start
10360 * @shost: SCSI host pointer
10362 * The shost has the ability to discover targets on its own instead
10363 * of scanning the entire bus. In our implemention, we will kick off
10364 * firmware discovery.
10367 scsih_scan_start(struct Scsi_Host
*shost
)
10369 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10371 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
10372 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
10374 if (disable_discovery
> 0)
10377 ioc
->start_scan
= 1;
10378 rc
= mpt3sas_port_enable(ioc
);
10381 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
10385 * scsih_scan_finished - scsi lld callback for .scan_finished
10386 * @shost: SCSI host pointer
10387 * @time: elapsed time of the scan in jiffies
10389 * This function will be called periodicallyn until it returns 1 with the
10390 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10391 * we wait for firmware discovery to complete, then return 1.
10394 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
10396 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10398 if (disable_discovery
> 0) {
10399 ioc
->is_driver_loading
= 0;
10400 ioc
->wait_for_discovery_to_complete
= 0;
10404 if (time
>= (300 * HZ
)) {
10405 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
10406 pr_info(MPT3SAS_FMT
10407 "port enable: FAILED with timeout (timeout=300s)\n",
10409 ioc
->is_driver_loading
= 0;
10413 if (ioc
->start_scan
)
10416 if (ioc
->start_scan_failed
) {
10417 pr_info(MPT3SAS_FMT
10418 "port enable: FAILED with (ioc_status=0x%08x)\n",
10419 ioc
->name
, ioc
->start_scan_failed
);
10420 ioc
->is_driver_loading
= 0;
10421 ioc
->wait_for_discovery_to_complete
= 0;
10422 ioc
->remove_host
= 1;
10426 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
10427 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
10429 if (ioc
->wait_for_discovery_to_complete
) {
10430 ioc
->wait_for_discovery_to_complete
= 0;
10431 _scsih_probe_devices(ioc
);
10433 mpt3sas_base_start_watchdog(ioc
);
10434 ioc
->is_driver_loading
= 0;
10438 /* shost template for SAS 2.0 HBA devices */
10439 static struct scsi_host_template mpt2sas_driver_template
= {
10440 .module
= THIS_MODULE
,
10441 .name
= "Fusion MPT SAS Host",
10442 .proc_name
= MPT2SAS_DRIVER_NAME
,
10443 .queuecommand
= scsih_qcmd
,
10444 .target_alloc
= scsih_target_alloc
,
10445 .slave_alloc
= scsih_slave_alloc
,
10446 .slave_configure
= scsih_slave_configure
,
10447 .target_destroy
= scsih_target_destroy
,
10448 .slave_destroy
= scsih_slave_destroy
,
10449 .scan_finished
= scsih_scan_finished
,
10450 .scan_start
= scsih_scan_start
,
10451 .change_queue_depth
= scsih_change_queue_depth
,
10452 .eh_abort_handler
= scsih_abort
,
10453 .eh_device_reset_handler
= scsih_dev_reset
,
10454 .eh_target_reset_handler
= scsih_target_reset
,
10455 .eh_host_reset_handler
= scsih_host_reset
,
10456 .bios_param
= scsih_bios_param
,
10459 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
10460 .max_sectors
= 32767,
10462 .use_clustering
= ENABLE_CLUSTERING
,
10463 .shost_attrs
= mpt3sas_host_attrs
,
10464 .sdev_attrs
= mpt3sas_dev_attrs
,
10465 .track_queue_depth
= 1,
10468 /* raid transport support for SAS 2.0 HBA devices */
10469 static struct raid_function_template mpt2sas_raid_functions
= {
10470 .cookie
= &mpt2sas_driver_template
,
10471 .is_raid
= scsih_is_raid
,
10472 .get_resync
= scsih_get_resync
,
10473 .get_state
= scsih_get_state
,
10476 /* shost template for SAS 3.0 HBA devices */
10477 static struct scsi_host_template mpt3sas_driver_template
= {
10478 .module
= THIS_MODULE
,
10479 .name
= "Fusion MPT SAS Host",
10480 .proc_name
= MPT3SAS_DRIVER_NAME
,
10481 .queuecommand
= scsih_qcmd
,
10482 .target_alloc
= scsih_target_alloc
,
10483 .slave_alloc
= scsih_slave_alloc
,
10484 .slave_configure
= scsih_slave_configure
,
10485 .target_destroy
= scsih_target_destroy
,
10486 .slave_destroy
= scsih_slave_destroy
,
10487 .scan_finished
= scsih_scan_finished
,
10488 .scan_start
= scsih_scan_start
,
10489 .change_queue_depth
= scsih_change_queue_depth
,
10490 .eh_abort_handler
= scsih_abort
,
10491 .eh_device_reset_handler
= scsih_dev_reset
,
10492 .eh_target_reset_handler
= scsih_target_reset
,
10493 .eh_host_reset_handler
= scsih_host_reset
,
10494 .bios_param
= scsih_bios_param
,
10497 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
10498 .max_sectors
= 32767,
10500 .use_clustering
= ENABLE_CLUSTERING
,
10501 .shost_attrs
= mpt3sas_host_attrs
,
10502 .sdev_attrs
= mpt3sas_dev_attrs
,
10503 .track_queue_depth
= 1,
10506 /* raid transport support for SAS 3.0 HBA devices */
10507 static struct raid_function_template mpt3sas_raid_functions
= {
10508 .cookie
= &mpt3sas_driver_template
,
10509 .is_raid
= scsih_is_raid
,
10510 .get_resync
= scsih_get_resync
,
10511 .get_state
= scsih_get_state
,
10515 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10516 * this device belongs to.
10517 * @pdev: PCI device struct
10519 * return MPI2_VERSION for SAS 2.0 HBA devices,
10520 * MPI25_VERSION for SAS 3.0 HBA devices, and
10521 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10524 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
10527 switch (pdev
->device
) {
10528 case MPI2_MFGPAGE_DEVID_SSS6200
:
10529 case MPI2_MFGPAGE_DEVID_SAS2004
:
10530 case MPI2_MFGPAGE_DEVID_SAS2008
:
10531 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
10532 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
10533 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
10534 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
10535 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
10536 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
10537 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
10538 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
10539 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
10540 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
10541 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
10542 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
10543 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
10544 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
10545 return MPI2_VERSION
;
10546 case MPI25_MFGPAGE_DEVID_SAS3004
:
10547 case MPI25_MFGPAGE_DEVID_SAS3008
:
10548 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
10549 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
10550 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
10551 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
10552 return MPI25_VERSION
;
10553 case MPI26_MFGPAGE_DEVID_SAS3216
:
10554 case MPI26_MFGPAGE_DEVID_SAS3224
:
10555 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
10556 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
10557 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
10558 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
10559 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
10560 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
10561 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
10562 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
10563 case MPI26_MFGPAGE_DEVID_SAS3508
:
10564 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10565 case MPI26_MFGPAGE_DEVID_SAS3408
:
10566 case MPI26_MFGPAGE_DEVID_SAS3516
:
10567 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10568 case MPI26_MFGPAGE_DEVID_SAS3416
:
10569 case MPI26_MFGPAGE_DEVID_SAS3616
:
10570 return MPI26_VERSION
;
10576 * _scsih_probe - attach and add scsi host
10577 * @pdev: PCI device struct
10578 * @id: pci device id
10580 * Returns 0 success, anything else error.
10583 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
10585 struct MPT3SAS_ADAPTER
*ioc
;
10586 struct Scsi_Host
*shost
= NULL
;
10588 u16 hba_mpi_version
;
10590 /* Determine in which MPI version class this pci device belongs */
10591 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
10592 if (hba_mpi_version
== 0)
10595 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10596 * for other generation HBA's return with -ENODEV
10598 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
10601 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10602 * for other generation HBA's return with -ENODEV
10604 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
10605 || hba_mpi_version
== MPI26_VERSION
)))
10608 switch (hba_mpi_version
) {
10610 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
10611 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
10612 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10613 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
10614 sizeof(struct MPT3SAS_ADAPTER
));
10617 ioc
= shost_priv(shost
);
10618 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10619 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10620 ioc
->id
= mpt2_ids
++;
10621 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
10622 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
10623 ioc
->is_warpdrive
= 1;
10624 ioc
->hide_ir_msg
= 1;
10626 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
10628 case MPI25_VERSION
:
10629 case MPI26_VERSION
:
10630 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10631 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
10632 sizeof(struct MPT3SAS_ADAPTER
));
10635 ioc
= shost_priv(shost
);
10636 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10637 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10638 ioc
->id
= mpt3_ids
++;
10639 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
10640 switch (pdev
->device
) {
10641 case MPI26_MFGPAGE_DEVID_SAS3508
:
10642 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10643 case MPI26_MFGPAGE_DEVID_SAS3408
:
10644 case MPI26_MFGPAGE_DEVID_SAS3516
:
10645 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10646 case MPI26_MFGPAGE_DEVID_SAS3416
:
10647 case MPI26_MFGPAGE_DEVID_SAS3616
:
10648 ioc
->is_gen35_ioc
= 1;
10651 ioc
->is_gen35_ioc
= 0;
10653 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
10654 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
10655 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
10656 ioc
->combined_reply_queue
= 1;
10657 if (ioc
->is_gen35_ioc
)
10658 ioc
->combined_reply_index_count
=
10659 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
10661 ioc
->combined_reply_index_count
=
10662 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
10669 INIT_LIST_HEAD(&ioc
->list
);
10670 spin_lock(&gioc_lock
);
10671 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
10672 spin_unlock(&gioc_lock
);
10673 ioc
->shost
= shost
;
10675 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
10676 ioc
->tm_cb_idx
= tm_cb_idx
;
10677 ioc
->ctl_cb_idx
= ctl_cb_idx
;
10678 ioc
->base_cb_idx
= base_cb_idx
;
10679 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
10680 ioc
->transport_cb_idx
= transport_cb_idx
;
10681 ioc
->scsih_cb_idx
= scsih_cb_idx
;
10682 ioc
->config_cb_idx
= config_cb_idx
;
10683 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
10684 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
10685 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
10686 ioc
->logging_level
= logging_level
;
10687 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
10688 /* misc semaphores and spin locks */
10689 mutex_init(&ioc
->reset_in_progress_mutex
);
10690 /* initializing pci_access_mutex lock */
10691 mutex_init(&ioc
->pci_access_mutex
);
10692 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
10693 spin_lock_init(&ioc
->scsi_lookup_lock
);
10694 spin_lock_init(&ioc
->sas_device_lock
);
10695 spin_lock_init(&ioc
->sas_node_lock
);
10696 spin_lock_init(&ioc
->fw_event_lock
);
10697 spin_lock_init(&ioc
->raid_device_lock
);
10698 spin_lock_init(&ioc
->pcie_device_lock
);
10699 spin_lock_init(&ioc
->diag_trigger_lock
);
10701 INIT_LIST_HEAD(&ioc
->sas_device_list
);
10702 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
10703 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
10704 INIT_LIST_HEAD(&ioc
->pcie_device_list
);
10705 INIT_LIST_HEAD(&ioc
->pcie_device_init_list
);
10706 INIT_LIST_HEAD(&ioc
->fw_event_list
);
10707 INIT_LIST_HEAD(&ioc
->raid_device_list
);
10708 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
10709 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
10710 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
10711 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
10712 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
10713 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
10715 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
10717 /* init shost parameters */
10718 shost
->max_cmd_len
= 32;
10719 shost
->max_lun
= max_lun
;
10720 shost
->transportt
= mpt3sas_transport_template
;
10721 shost
->unique_id
= ioc
->id
;
10723 if (max_sectors
!= 0xFFFF) {
10724 if (max_sectors
< 64) {
10725 shost
->max_sectors
= 64;
10726 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10727 "for max_sectors, range is 64 to 32767. Assigning "
10728 "value of 64.\n", ioc
->name
, max_sectors
);
10729 } else if (max_sectors
> 32767) {
10730 shost
->max_sectors
= 32767;
10731 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10732 "for max_sectors, range is 64 to 32767. Assigning "
10733 "default value of 32767.\n", ioc
->name
,
10736 shost
->max_sectors
= max_sectors
& 0xFFFE;
10737 pr_info(MPT3SAS_FMT
10738 "The max_sectors value is set to %d\n",
10739 ioc
->name
, shost
->max_sectors
);
10743 /* register EEDP capabilities with SCSI layer */
10745 scsi_host_set_prot(shost
, prot_mask
);
10747 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
10748 | SHOST_DIF_TYPE2_PROTECTION
10749 | SHOST_DIF_TYPE3_PROTECTION
);
10751 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
10754 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
10755 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
10756 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
10757 ioc
->firmware_event_name
, 0);
10758 if (!ioc
->firmware_event_thread
) {
10759 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10760 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10762 goto out_thread_fail
;
10765 ioc
->is_driver_loading
= 1;
10766 if ((mpt3sas_base_attach(ioc
))) {
10767 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10768 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10770 goto out_attach_fail
;
10773 if (ioc
->is_warpdrive
) {
10774 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
10775 ioc
->hide_drives
= 0;
10776 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
10777 ioc
->hide_drives
= 1;
10779 if (mpt3sas_get_num_volumes(ioc
))
10780 ioc
->hide_drives
= 1;
10782 ioc
->hide_drives
= 0;
10785 ioc
->hide_drives
= 0;
10787 rv
= scsi_add_host(shost
, &pdev
->dev
);
10789 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10790 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10791 goto out_add_shost_fail
;
10794 scsi_scan_host(shost
);
10796 out_add_shost_fail
:
10797 mpt3sas_base_detach(ioc
);
10799 destroy_workqueue(ioc
->firmware_event_thread
);
10801 spin_lock(&gioc_lock
);
10802 list_del(&ioc
->list
);
10803 spin_unlock(&gioc_lock
);
10804 scsi_host_put(shost
);
10810 * scsih_suspend - power management suspend main entry point
10811 * @pdev: PCI device struct
10812 * @state: PM state change to (usually PCI_D3)
10814 * Returns 0 success, anything else error.
10817 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10819 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10820 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10821 pci_power_t device_state
;
10823 mpt3sas_base_stop_watchdog(ioc
);
10824 flush_scheduled_work();
10825 scsi_block_requests(shost
);
10826 device_state
= pci_choose_state(pdev
, state
);
10827 pr_info(MPT3SAS_FMT
10828 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10829 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10831 pci_save_state(pdev
);
10832 mpt3sas_base_free_resources(ioc
);
10833 pci_set_power_state(pdev
, device_state
);
10838 * scsih_resume - power management resume main entry point
10839 * @pdev: PCI device struct
10841 * Returns 0 success, anything else error.
10844 scsih_resume(struct pci_dev
*pdev
)
10846 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10847 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10848 pci_power_t device_state
= pdev
->current_state
;
10851 pr_info(MPT3SAS_FMT
10852 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10853 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10855 pci_set_power_state(pdev
, PCI_D0
);
10856 pci_enable_wake(pdev
, PCI_D0
, 0);
10857 pci_restore_state(pdev
);
10859 r
= mpt3sas_base_map_resources(ioc
);
10863 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
10864 scsi_unblock_requests(shost
);
10865 mpt3sas_base_start_watchdog(ioc
);
10868 #endif /* CONFIG_PM */
10871 * scsih_pci_error_detected - Called when a PCI error is detected.
10872 * @pdev: PCI device struct
10873 * @state: PCI channel state
10875 * Description: Called when a PCI error is detected.
10878 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
10880 static pci_ers_result_t
10881 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10883 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10884 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10886 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
10890 case pci_channel_io_normal
:
10891 return PCI_ERS_RESULT_CAN_RECOVER
;
10892 case pci_channel_io_frozen
:
10893 /* Fatal error, prepare for slot reset */
10894 ioc
->pci_error_recovery
= 1;
10895 scsi_block_requests(ioc
->shost
);
10896 mpt3sas_base_stop_watchdog(ioc
);
10897 mpt3sas_base_free_resources(ioc
);
10898 return PCI_ERS_RESULT_NEED_RESET
;
10899 case pci_channel_io_perm_failure
:
10900 /* Permanent error, prepare for device removal */
10901 ioc
->pci_error_recovery
= 1;
10902 mpt3sas_base_stop_watchdog(ioc
);
10903 _scsih_flush_running_cmds(ioc
);
10904 return PCI_ERS_RESULT_DISCONNECT
;
10906 return PCI_ERS_RESULT_NEED_RESET
;
10910 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10911 * @pdev: PCI device struct
10913 * Description: This routine is called by the pci error recovery
10914 * code after the PCI slot has been reset, just before we
10915 * should resume normal operations.
10917 static pci_ers_result_t
10918 scsih_pci_slot_reset(struct pci_dev
*pdev
)
10920 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10921 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10924 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
10927 ioc
->pci_error_recovery
= 0;
10929 pci_restore_state(pdev
);
10930 rc
= mpt3sas_base_map_resources(ioc
);
10932 return PCI_ERS_RESULT_DISCONNECT
;
10934 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
10936 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
10937 (rc
== 0) ? "success" : "failed");
10940 return PCI_ERS_RESULT_RECOVERED
;
10942 return PCI_ERS_RESULT_DISCONNECT
;
10946 * scsih_pci_resume() - resume normal ops after PCI reset
10947 * @pdev: pointer to PCI device
10949 * Called when the error recovery driver tells us that its
10950 * OK to resume normal operation. Use completion to allow
10951 * halted scsi ops to resume.
10954 scsih_pci_resume(struct pci_dev
*pdev
)
10956 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10957 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10959 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
10961 pci_cleanup_aer_uncorrect_error_status(pdev
);
10962 mpt3sas_base_start_watchdog(ioc
);
10963 scsi_unblock_requests(ioc
->shost
);
10967 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10968 * @pdev: pointer to PCI device
10970 static pci_ers_result_t
10971 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
10973 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10974 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10976 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
10979 /* TODO - dump whatever for debugging purposes */
10981 /* This called only if scsih_pci_error_detected returns
10982 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10983 * works, no need to reset slot.
10985 return PCI_ERS_RESULT_RECOVERED
;
10989 * scsih__ncq_prio_supp - Check for NCQ command priority support
10990 * @sdev: scsi device struct
10992 * This is called when a user indicates they would like to enable
10993 * ncq command priorities. This works only on SATA devices.
10995 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
10997 unsigned char *buf
;
10998 bool ncq_prio_supp
= false;
11000 if (!scsi_device_supports_vpd(sdev
))
11001 return ncq_prio_supp
;
11003 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
11005 return ncq_prio_supp
;
11007 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
11008 ncq_prio_supp
= (buf
[213] >> 4) & 1;
11011 return ncq_prio_supp
;
11014 * The pci device ids are defined in mpi/mpi2_cnfg.h.
11016 static const struct pci_device_id mpt3sas_pci_table
[] = {
11017 /* Spitfire ~ 2004 */
11018 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
11019 PCI_ANY_ID
, PCI_ANY_ID
},
11020 /* Falcon ~ 2008 */
11021 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
11022 PCI_ANY_ID
, PCI_ANY_ID
},
11023 /* Liberator ~ 2108 */
11024 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
11025 PCI_ANY_ID
, PCI_ANY_ID
},
11026 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
11027 PCI_ANY_ID
, PCI_ANY_ID
},
11028 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
11029 PCI_ANY_ID
, PCI_ANY_ID
},
11030 /* Meteor ~ 2116 */
11031 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
11032 PCI_ANY_ID
, PCI_ANY_ID
},
11033 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
11034 PCI_ANY_ID
, PCI_ANY_ID
},
11035 /* Thunderbolt ~ 2208 */
11036 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
11037 PCI_ANY_ID
, PCI_ANY_ID
},
11038 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
11039 PCI_ANY_ID
, PCI_ANY_ID
},
11040 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
11041 PCI_ANY_ID
, PCI_ANY_ID
},
11042 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
11043 PCI_ANY_ID
, PCI_ANY_ID
},
11044 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
11045 PCI_ANY_ID
, PCI_ANY_ID
},
11046 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
11047 PCI_ANY_ID
, PCI_ANY_ID
},
11048 /* Mustang ~ 2308 */
11049 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
11050 PCI_ANY_ID
, PCI_ANY_ID
},
11051 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
11052 PCI_ANY_ID
, PCI_ANY_ID
},
11053 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
11054 PCI_ANY_ID
, PCI_ANY_ID
},
11056 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
11057 PCI_ANY_ID
, PCI_ANY_ID
},
11058 /* Fury ~ 3004 and 3008 */
11059 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
11060 PCI_ANY_ID
, PCI_ANY_ID
},
11061 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
11062 PCI_ANY_ID
, PCI_ANY_ID
},
11063 /* Invader ~ 3108 */
11064 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
11065 PCI_ANY_ID
, PCI_ANY_ID
},
11066 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
11067 PCI_ANY_ID
, PCI_ANY_ID
},
11068 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
11069 PCI_ANY_ID
, PCI_ANY_ID
},
11070 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
11071 PCI_ANY_ID
, PCI_ANY_ID
},
11072 /* Cutlass ~ 3216 and 3224 */
11073 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
11074 PCI_ANY_ID
, PCI_ANY_ID
},
11075 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
11076 PCI_ANY_ID
, PCI_ANY_ID
},
11077 /* Intruder ~ 3316 and 3324 */
11078 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
11079 PCI_ANY_ID
, PCI_ANY_ID
},
11080 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
11081 PCI_ANY_ID
, PCI_ANY_ID
},
11082 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
11083 PCI_ANY_ID
, PCI_ANY_ID
},
11084 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
11085 PCI_ANY_ID
, PCI_ANY_ID
},
11086 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
11087 PCI_ANY_ID
, PCI_ANY_ID
},
11088 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
11089 PCI_ANY_ID
, PCI_ANY_ID
},
11090 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
11091 PCI_ANY_ID
, PCI_ANY_ID
},
11092 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
11093 PCI_ANY_ID
, PCI_ANY_ID
},
11094 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
11095 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
11096 PCI_ANY_ID
, PCI_ANY_ID
},
11097 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
11098 PCI_ANY_ID
, PCI_ANY_ID
},
11099 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
11100 PCI_ANY_ID
, PCI_ANY_ID
},
11101 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
11102 PCI_ANY_ID
, PCI_ANY_ID
},
11103 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
11104 PCI_ANY_ID
, PCI_ANY_ID
},
11105 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
11106 PCI_ANY_ID
, PCI_ANY_ID
},
11107 /* Mercator ~ 3616*/
11108 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3616
,
11109 PCI_ANY_ID
, PCI_ANY_ID
},
11110 {0} /* Terminating entry */
11112 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
11114 static struct pci_error_handlers _mpt3sas_err_handler
= {
11115 .error_detected
= scsih_pci_error_detected
,
11116 .mmio_enabled
= scsih_pci_mmio_enabled
,
11117 .slot_reset
= scsih_pci_slot_reset
,
11118 .resume
= scsih_pci_resume
,
11121 static struct pci_driver mpt3sas_driver
= {
11122 .name
= MPT3SAS_DRIVER_NAME
,
11123 .id_table
= mpt3sas_pci_table
,
11124 .probe
= _scsih_probe
,
11125 .remove
= scsih_remove
,
11126 .shutdown
= scsih_shutdown
,
11127 .err_handler
= &_mpt3sas_err_handler
,
11129 .suspend
= scsih_suspend
,
11130 .resume
= scsih_resume
,
11135 * scsih_init - main entry point for this driver.
11137 * Returns 0 success, anything else error.
11145 mpt3sas_base_initialize_callback_handler();
11147 /* queuecommand callback hander */
11148 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
11150 /* task management callback handler */
11151 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
11153 /* base internal commands callback handler */
11154 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
11155 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
11156 mpt3sas_port_enable_done
);
11158 /* transport internal commands callback handler */
11159 transport_cb_idx
= mpt3sas_base_register_callback_handler(
11160 mpt3sas_transport_done
);
11162 /* scsih internal commands callback handler */
11163 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
11165 /* configuration page API internal commands callback handler */
11166 config_cb_idx
= mpt3sas_base_register_callback_handler(
11167 mpt3sas_config_done
);
11169 /* ctl module callback handler */
11170 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
11172 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
11173 _scsih_tm_tr_complete
);
11175 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
11176 _scsih_tm_volume_tr_complete
);
11178 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
11179 _scsih_sas_control_complete
);
11185 * scsih_exit - exit point for this driver (when it is a module).
11187 * Returns 0 success, anything else error.
11193 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
11194 mpt3sas_base_release_callback_handler(tm_cb_idx
);
11195 mpt3sas_base_release_callback_handler(base_cb_idx
);
11196 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
11197 mpt3sas_base_release_callback_handler(transport_cb_idx
);
11198 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
11199 mpt3sas_base_release_callback_handler(config_cb_idx
);
11200 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
11202 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
11203 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
11204 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
11206 /* raid transport support */
11207 if (hbas_to_enumerate
!= 1)
11208 raid_class_release(mpt3sas_raid_template
);
11209 if (hbas_to_enumerate
!= 2)
11210 raid_class_release(mpt2sas_raid_template
);
11211 sas_release_transport(mpt3sas_transport_template
);
11215 * _mpt3sas_init - main entry point for this driver.
11217 * Returns 0 success, anything else error.
11220 _mpt3sas_init(void)
11224 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
11225 MPT3SAS_DRIVER_VERSION
);
11227 mpt3sas_transport_template
=
11228 sas_attach_transport(&mpt3sas_transport_functions
);
11229 if (!mpt3sas_transport_template
)
11232 /* No need attach mpt3sas raid functions template
11233 * if hbas_to_enumarate value is one.
11235 if (hbas_to_enumerate
!= 1) {
11236 mpt3sas_raid_template
=
11237 raid_class_attach(&mpt3sas_raid_functions
);
11238 if (!mpt3sas_raid_template
) {
11239 sas_release_transport(mpt3sas_transport_template
);
11244 /* No need to attach mpt2sas raid functions template
11245 * if hbas_to_enumarate value is two
11247 if (hbas_to_enumerate
!= 2) {
11248 mpt2sas_raid_template
=
11249 raid_class_attach(&mpt2sas_raid_functions
);
11250 if (!mpt2sas_raid_template
) {
11251 sas_release_transport(mpt3sas_transport_template
);
11256 error
= scsih_init();
11262 mpt3sas_ctl_init(hbas_to_enumerate
);
11264 error
= pci_register_driver(&mpt3sas_driver
);
11272 * _mpt3sas_exit - exit point for this driver (when it is a module).
11276 _mpt3sas_exit(void)
11278 pr_info("mpt3sas version %s unloading\n",
11279 MPT3SAS_DRIVER_VERSION
);
11281 pci_unregister_driver(&mpt3sas_driver
);
11283 mpt3sas_ctl_exit(hbas_to_enumerate
);
11288 module_init(_mpt3sas_init
);
11289 module_exit(_mpt3sas_exit
);