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
, 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 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 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 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 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
);
1017 * mpt3sas_get_pdev_by_idchannel - pcie device search
1018 * @ioc: per adapter object
1020 * @channel: Channel ID
1022 * Context: This function will acquire ioc->pcie_device_lock and will release
1023 * before returning the pcie_device object.
1025 * This searches for pcie_device based on id and channel, then return
1026 * pcie_device object.
1028 struct _pcie_device
*
1029 mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
1031 struct _pcie_device
*pcie_device
;
1032 unsigned long flags
;
1034 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1035 pcie_device
= __mpt3sas_get_pdev_by_idchannel(ioc
, id
, channel
);
1036 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1042 struct _pcie_device
*
1043 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1045 struct _pcie_device
*pcie_device
;
1047 assert_spin_locked(&ioc
->pcie_device_lock
);
1049 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
1050 if (pcie_device
->handle
== handle
)
1053 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
1054 if (pcie_device
->handle
== handle
)
1060 pcie_device_get(pcie_device
);
1066 * mpt3sas_get_pdev_by_handle - pcie device search
1067 * @ioc: per adapter object
1068 * @handle: Firmware device handle
1070 * Context: This function will acquire ioc->pcie_device_lock and will release
1071 * before returning the pcie_device object.
1073 * This searches for pcie_device based on handle, then return pcie_device
1076 struct _pcie_device
*
1077 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1079 struct _pcie_device
*pcie_device
;
1080 unsigned long flags
;
1082 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1083 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1084 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1090 * _scsih_pcie_device_remove - remove pcie_device from list.
1091 * @ioc: per adapter object
1092 * @pcie_device: the pcie_device object
1093 * Context: This function will acquire ioc->pcie_device_lock.
1095 * If pcie_device is on the list, remove it and decrement its reference count.
1098 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1099 struct _pcie_device
*pcie_device
)
1101 unsigned long flags
;
1102 int was_on_pcie_device_list
= 0;
1107 "removing handle(0x%04x), wwid(0x%016llx)\n",
1108 ioc
->name
, pcie_device
->handle
,
1109 (unsigned long long) pcie_device
->wwid
);
1110 if (pcie_device
->enclosure_handle
!= 0)
1112 "removing enclosure logical id(0x%016llx), slot(%d)\n",
1114 (unsigned long long)pcie_device
->enclosure_logical_id
,
1116 if (pcie_device
->connector_name
[0] != '\0')
1118 "removing enclosure level(0x%04x), connector name( %s)\n",
1119 ioc
->name
, pcie_device
->enclosure_level
,
1120 pcie_device
->connector_name
);
1122 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1123 if (!list_empty(&pcie_device
->list
)) {
1124 list_del_init(&pcie_device
->list
);
1125 was_on_pcie_device_list
= 1;
1127 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1128 if (was_on_pcie_device_list
) {
1129 kfree(pcie_device
->serial_number
);
1130 pcie_device_put(pcie_device
);
1136 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1137 * @ioc: per adapter object
1138 * @handle: device handle
1143 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1145 struct _pcie_device
*pcie_device
;
1146 unsigned long flags
;
1147 int was_on_pcie_device_list
= 0;
1149 if (ioc
->shost_recovery
)
1152 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1153 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1155 if (!list_empty(&pcie_device
->list
)) {
1156 list_del_init(&pcie_device
->list
);
1157 was_on_pcie_device_list
= 1;
1158 pcie_device_put(pcie_device
);
1161 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1162 if (was_on_pcie_device_list
) {
1163 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
1164 pcie_device_put(pcie_device
);
1169 * _scsih_pcie_device_add - add pcie_device object
1170 * @ioc: per adapter object
1171 * @pcie_device: pcie_device object
1173 * This is added to the pcie_device_list link list.
1176 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1177 struct _pcie_device
*pcie_device
)
1179 unsigned long flags
;
1181 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1182 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1183 pcie_device
->handle
, (unsigned long long)pcie_device
->wwid
));
1184 if (pcie_device
->enclosure_handle
!= 0)
1185 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1186 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1187 ioc
->name
, __func__
,
1188 (unsigned long long)pcie_device
->enclosure_logical_id
,
1189 pcie_device
->slot
));
1190 if (pcie_device
->connector_name
[0] != '\0')
1191 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1192 "%s: enclosure level(0x%04x), connector name( %s)\n",
1193 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
1194 pcie_device
->connector_name
));
1196 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1197 pcie_device_get(pcie_device
);
1198 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
1199 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1201 if (scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, pcie_device
->id
, 0)) {
1202 _scsih_pcie_device_remove(ioc
, pcie_device
);
1203 } else if (!pcie_device
->starget
) {
1204 if (!ioc
->is_driver_loading
) {
1205 /*TODO-- Need to find out whether this condition will occur or not*/
1206 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1209 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1213 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1214 * @ioc: per adapter object
1215 * @pcie_device: the pcie_device object
1216 * Context: This function will acquire ioc->pcie_device_lock.
1218 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1221 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
1222 struct _pcie_device
*pcie_device
)
1224 unsigned long flags
;
1226 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1227 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1228 pcie_device
->handle
, (unsigned long long)pcie_device
->wwid
));
1229 if (pcie_device
->enclosure_handle
!= 0)
1230 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1231 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1232 ioc
->name
, __func__
,
1233 (unsigned long long)pcie_device
->enclosure_logical_id
,
1234 pcie_device
->slot
));
1235 if (pcie_device
->connector_name
[0] != '\0')
1236 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1237 "%s: enclosure level(0x%04x), connector name( %s)\n",
1238 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
1239 pcie_device
->connector_name
));
1241 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1242 pcie_device_get(pcie_device
);
1243 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_init_list
);
1244 _scsih_determine_boot_device(ioc
, pcie_device
, PCIE_CHANNEL
);
1245 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1248 * _scsih_raid_device_find_by_id - raid device search
1249 * @ioc: per adapter object
1250 * @id: sas device target id
1251 * @channel: sas device channel
1252 * Context: Calling function should acquire ioc->raid_device_lock
1254 * This searches for raid_device based on target id, then return raid_device
1257 static struct _raid_device
*
1258 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
1260 struct _raid_device
*raid_device
, *r
;
1263 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1264 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
1275 * mpt3sas_raid_device_find_by_handle - raid device search
1276 * @ioc: per adapter object
1277 * @handle: sas device handle (assigned by firmware)
1278 * Context: Calling function should acquire ioc->raid_device_lock
1280 * This searches for raid_device based on handle, then return raid_device
1283 struct _raid_device
*
1284 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1286 struct _raid_device
*raid_device
, *r
;
1289 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1290 if (raid_device
->handle
!= handle
)
1301 * _scsih_raid_device_find_by_wwid - raid device search
1302 * @ioc: per adapter object
1303 * @handle: sas device handle (assigned by firmware)
1304 * Context: Calling function should acquire ioc->raid_device_lock
1306 * This searches for raid_device based on wwid, then return raid_device
1309 static struct _raid_device
*
1310 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
1312 struct _raid_device
*raid_device
, *r
;
1315 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1316 if (raid_device
->wwid
!= wwid
)
1327 * _scsih_raid_device_add - add raid_device object
1328 * @ioc: per adapter object
1329 * @raid_device: raid_device object
1331 * This is added to the raid_device_list link list.
1334 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1335 struct _raid_device
*raid_device
)
1337 unsigned long flags
;
1339 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
1340 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
1341 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
1343 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1344 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
1345 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1349 * _scsih_raid_device_remove - delete raid_device object
1350 * @ioc: per adapter object
1351 * @raid_device: raid_device object
1355 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1356 struct _raid_device
*raid_device
)
1358 unsigned long flags
;
1360 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1361 list_del(&raid_device
->list
);
1363 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1367 * mpt3sas_scsih_expander_find_by_handle - expander device search
1368 * @ioc: per adapter object
1369 * @handle: expander handle (assigned by firmware)
1370 * Context: Calling function should acquire ioc->sas_device_lock
1372 * This searches for expander device based on handle, then returns the
1376 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1378 struct _sas_node
*sas_expander
, *r
;
1381 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1382 if (sas_expander
->handle
!= handle
)
1392 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1393 * @ioc: per adapter object
1394 * @sas_address: sas address
1395 * Context: Calling function should acquire ioc->sas_node_lock.
1397 * This searches for expander device based on sas_address, then returns the
1401 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1404 struct _sas_node
*sas_expander
, *r
;
1407 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1408 if (sas_expander
->sas_address
!= sas_address
)
1418 * _scsih_expander_node_add - insert expander device to the list.
1419 * @ioc: per adapter object
1420 * @sas_expander: the sas_device object
1421 * Context: This function will acquire ioc->sas_node_lock.
1423 * Adding new object to the ioc->sas_expander_list.
1428 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1429 struct _sas_node
*sas_expander
)
1431 unsigned long flags
;
1433 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1434 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1435 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1439 * _scsih_is_end_device - determines if device is an end device
1440 * @device_info: bitfield providing information about the device.
1443 * Returns 1 if end device.
1446 _scsih_is_end_device(u32 device_info
)
1448 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1449 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1450 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1451 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1458 * _scsih_is_nvme_device - determines if device is an nvme device
1459 * @device_info: bitfield providing information about the device.
1462 * Returns 1 if nvme device.
1465 _scsih_is_nvme_device(u32 device_info
)
1467 if ((device_info
& MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
)
1468 == MPI26_PCIE_DEVINFO_NVME
)
1475 * _scsih_scsi_lookup_get - returns scmd entry
1476 * @ioc: per adapter object
1477 * @smid: system request message index
1479 * Returns the smid stored scmd pointer.
1481 static struct scsi_cmnd
*
1482 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1484 return ioc
->scsi_lookup
[smid
- 1].scmd
;
1488 * __scsih_scsi_lookup_get_clear - returns scmd entry without
1490 * @ioc: per adapter object
1491 * @smid: system request message index
1493 * Returns the smid stored scmd pointer.
1494 * Then will dereference the stored scmd pointer.
1496 static inline struct scsi_cmnd
*
1497 __scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
,
1500 struct scsi_cmnd
*scmd
= NULL
;
1502 swap(scmd
, ioc
->scsi_lookup
[smid
- 1].scmd
);
1508 * _scsih_scsi_lookup_get_clear - returns scmd entry
1509 * @ioc: per adapter object
1510 * @smid: system request message index
1512 * Returns the smid stored scmd pointer.
1513 * Then will derefrence the stored scmd pointer.
1515 static inline struct scsi_cmnd
*
1516 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1518 unsigned long flags
;
1519 struct scsi_cmnd
*scmd
;
1521 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1522 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
1523 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1529 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1530 * @ioc: per adapter object
1531 * @smid: system request message index
1532 * @scmd: pointer to scsi command object
1533 * Context: This function will acquire ioc->scsi_lookup_lock.
1535 * This will search for a scmd pointer in the scsi_lookup array,
1536 * returning the revelent smid. A returned value of zero means invalid.
1539 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1543 unsigned long flags
;
1546 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1548 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1549 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1550 smid
= ioc
->scsi_lookup
[i
].smid
;
1555 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1560 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1561 * @ioc: per adapter object
1564 * Context: This function will acquire ioc->scsi_lookup_lock.
1566 * This will search for a matching channel:id in the scsi_lookup array,
1567 * returning 1 if found.
1570 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1574 unsigned long flags
;
1577 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1579 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1580 if (ioc
->scsi_lookup
[i
].scmd
&&
1581 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1582 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1588 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1593 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1594 * @ioc: per adapter object
1598 * Context: This function will acquire ioc->scsi_lookup_lock.
1600 * This will search for a matching channel:id:lun in the scsi_lookup array,
1601 * returning 1 if found.
1604 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1605 unsigned int lun
, int channel
)
1608 unsigned long flags
;
1611 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1613 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1614 if (ioc
->scsi_lookup
[i
].scmd
&&
1615 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1616 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1617 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1623 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1628 * scsih_change_queue_depth - setting device queue depth
1629 * @sdev: scsi device struct
1630 * @qdepth: requested queue depth
1632 * Returns queue depth.
1635 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1637 struct Scsi_Host
*shost
= sdev
->host
;
1639 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1640 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1641 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1642 struct _sas_device
*sas_device
;
1643 unsigned long flags
;
1645 max_depth
= shost
->can_queue
;
1647 /* limit max device queue for SATA to 32 */
1648 sas_device_priv_data
= sdev
->hostdata
;
1649 if (!sas_device_priv_data
)
1651 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1652 if (!sas_target_priv_data
)
1654 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1657 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1658 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1660 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1661 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1663 sas_device_put(sas_device
);
1665 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1669 if (!sdev
->tagged_supported
)
1671 if (qdepth
> max_depth
)
1673 return scsi_change_queue_depth(sdev
, qdepth
);
1677 * scsih_target_alloc - target add routine
1678 * @starget: scsi target struct
1680 * Returns 0 if ok. Any other return is assumed to be an error and
1681 * the device is ignored.
1684 scsih_target_alloc(struct scsi_target
*starget
)
1686 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1687 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1688 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1689 struct _sas_device
*sas_device
;
1690 struct _raid_device
*raid_device
;
1691 struct _pcie_device
*pcie_device
;
1692 unsigned long flags
;
1693 struct sas_rphy
*rphy
;
1695 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1697 if (!sas_target_priv_data
)
1700 starget
->hostdata
= sas_target_priv_data
;
1701 sas_target_priv_data
->starget
= starget
;
1702 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1705 if (starget
->channel
== RAID_CHANNEL
) {
1706 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1707 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1710 sas_target_priv_data
->handle
= raid_device
->handle
;
1711 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1712 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1713 if (ioc
->is_warpdrive
)
1714 sas_target_priv_data
->raid_device
= raid_device
;
1715 raid_device
->starget
= starget
;
1717 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1722 if (starget
->channel
== PCIE_CHANNEL
) {
1723 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1724 pcie_device
= __mpt3sas_get_pdev_by_idchannel(ioc
, starget
->id
,
1727 sas_target_priv_data
->handle
= pcie_device
->handle
;
1728 sas_target_priv_data
->sas_address
= pcie_device
->wwid
;
1729 sas_target_priv_data
->pcie_dev
= pcie_device
;
1730 pcie_device
->starget
= starget
;
1731 pcie_device
->id
= starget
->id
;
1732 pcie_device
->channel
= starget
->channel
;
1733 sas_target_priv_data
->flags
|=
1734 MPT_TARGET_FLAGS_PCIE_DEVICE
;
1735 if (pcie_device
->fast_path
)
1736 sas_target_priv_data
->flags
|=
1737 MPT_TARGET_FASTPATH_IO
;
1739 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1743 /* sas/sata devices */
1744 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1745 rphy
= dev_to_rphy(starget
->dev
.parent
);
1746 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1747 rphy
->identify
.sas_address
);
1750 sas_target_priv_data
->handle
= sas_device
->handle
;
1751 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1752 sas_target_priv_data
->sas_dev
= sas_device
;
1753 sas_device
->starget
= starget
;
1754 sas_device
->id
= starget
->id
;
1755 sas_device
->channel
= starget
->channel
;
1756 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1757 sas_target_priv_data
->flags
|=
1758 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1759 if (sas_device
->fast_path
)
1760 sas_target_priv_data
->flags
|=
1761 MPT_TARGET_FASTPATH_IO
;
1763 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1769 * scsih_target_destroy - target destroy routine
1770 * @starget: scsi target struct
1775 scsih_target_destroy(struct scsi_target
*starget
)
1777 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1778 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1779 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1780 struct _sas_device
*sas_device
;
1781 struct _raid_device
*raid_device
;
1782 struct _pcie_device
*pcie_device
;
1783 unsigned long flags
;
1784 struct sas_rphy
*rphy
;
1786 sas_target_priv_data
= starget
->hostdata
;
1787 if (!sas_target_priv_data
)
1790 if (starget
->channel
== RAID_CHANNEL
) {
1791 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1792 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1795 raid_device
->starget
= NULL
;
1796 raid_device
->sdev
= NULL
;
1798 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1802 if (starget
->channel
== PCIE_CHANNEL
) {
1803 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1804 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1805 sas_target_priv_data
);
1806 if (pcie_device
&& (pcie_device
->starget
== starget
) &&
1807 (pcie_device
->id
== starget
->id
) &&
1808 (pcie_device
->channel
== starget
->channel
))
1809 pcie_device
->starget
= NULL
;
1813 * Corresponding get() is in _scsih_target_alloc()
1815 sas_target_priv_data
->pcie_dev
= NULL
;
1816 pcie_device_put(pcie_device
);
1817 pcie_device_put(pcie_device
);
1819 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1823 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1824 rphy
= dev_to_rphy(starget
->dev
.parent
);
1825 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1826 if (sas_device
&& (sas_device
->starget
== starget
) &&
1827 (sas_device
->id
== starget
->id
) &&
1828 (sas_device
->channel
== starget
->channel
))
1829 sas_device
->starget
= NULL
;
1833 * Corresponding get() is in _scsih_target_alloc()
1835 sas_target_priv_data
->sas_dev
= NULL
;
1836 sas_device_put(sas_device
);
1838 sas_device_put(sas_device
);
1840 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1843 kfree(sas_target_priv_data
);
1844 starget
->hostdata
= NULL
;
1848 * scsih_slave_alloc - device add routine
1849 * @sdev: scsi device struct
1851 * Returns 0 if ok. Any other return is assumed to be an error and
1852 * the device is ignored.
1855 scsih_slave_alloc(struct scsi_device
*sdev
)
1857 struct Scsi_Host
*shost
;
1858 struct MPT3SAS_ADAPTER
*ioc
;
1859 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1860 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1861 struct scsi_target
*starget
;
1862 struct _raid_device
*raid_device
;
1863 struct _sas_device
*sas_device
;
1864 struct _pcie_device
*pcie_device
;
1865 unsigned long flags
;
1867 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1869 if (!sas_device_priv_data
)
1872 sas_device_priv_data
->lun
= sdev
->lun
;
1873 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1875 starget
= scsi_target(sdev
);
1876 sas_target_priv_data
= starget
->hostdata
;
1877 sas_target_priv_data
->num_luns
++;
1878 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1879 sdev
->hostdata
= sas_device_priv_data
;
1880 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1881 sdev
->no_uld_attach
= 1;
1883 shost
= dev_to_shost(&starget
->dev
);
1884 ioc
= shost_priv(shost
);
1885 if (starget
->channel
== RAID_CHANNEL
) {
1886 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1887 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1888 starget
->id
, starget
->channel
);
1890 raid_device
->sdev
= sdev
; /* raid is single lun */
1891 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1893 if (starget
->channel
== PCIE_CHANNEL
) {
1894 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1895 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
1896 sas_target_priv_data
->sas_address
);
1897 if (pcie_device
&& (pcie_device
->starget
== NULL
)) {
1898 sdev_printk(KERN_INFO
, sdev
,
1899 "%s : pcie_device->starget set to starget @ %d\n",
1900 __func__
, __LINE__
);
1901 pcie_device
->starget
= starget
;
1905 pcie_device_put(pcie_device
);
1906 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1908 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1909 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1910 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1911 sas_target_priv_data
->sas_address
);
1912 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1913 sdev_printk(KERN_INFO
, sdev
,
1914 "%s : sas_device->starget set to starget @ %d\n",
1915 __func__
, __LINE__
);
1916 sas_device
->starget
= starget
;
1920 sas_device_put(sas_device
);
1922 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1929 * scsih_slave_destroy - device destroy routine
1930 * @sdev: scsi device struct
1935 scsih_slave_destroy(struct scsi_device
*sdev
)
1937 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1938 struct scsi_target
*starget
;
1939 struct Scsi_Host
*shost
;
1940 struct MPT3SAS_ADAPTER
*ioc
;
1941 struct _sas_device
*sas_device
;
1942 struct _pcie_device
*pcie_device
;
1943 unsigned long flags
;
1945 if (!sdev
->hostdata
)
1948 starget
= scsi_target(sdev
);
1949 sas_target_priv_data
= starget
->hostdata
;
1950 sas_target_priv_data
->num_luns
--;
1952 shost
= dev_to_shost(&starget
->dev
);
1953 ioc
= shost_priv(shost
);
1955 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
1956 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1957 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1958 sas_target_priv_data
);
1959 if (pcie_device
&& !sas_target_priv_data
->num_luns
)
1960 pcie_device
->starget
= NULL
;
1963 pcie_device_put(pcie_device
);
1965 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1967 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1968 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1969 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1970 sas_target_priv_data
);
1971 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1972 sas_device
->starget
= NULL
;
1975 sas_device_put(sas_device
);
1976 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1979 kfree(sdev
->hostdata
);
1980 sdev
->hostdata
= NULL
;
1984 * _scsih_display_sata_capabilities - sata capabilities
1985 * @ioc: per adapter object
1986 * @handle: device handle
1987 * @sdev: scsi device struct
1990 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1991 u16 handle
, struct scsi_device
*sdev
)
1993 Mpi2ConfigReply_t mpi_reply
;
1994 Mpi2SasDevicePage0_t sas_device_pg0
;
1999 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
2000 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
2001 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2002 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2006 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
2007 MPI2_IOCSTATUS_MASK
;
2008 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2009 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2010 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2014 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
2015 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
2017 sdev_printk(KERN_INFO
, sdev
,
2018 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
2019 "sw_preserve(%s)\n",
2020 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
2021 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
2022 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
2024 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
2025 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
2026 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
2030 * raid transport support -
2031 * Enabled for SLES11 and newer, in older kernels the driver will panic when
2032 * unloading the driver followed by a load - I believe that the subroutine
2033 * raid_class_release() is not cleaning up properly.
2037 * scsih_is_raid - return boolean indicating device is raid volume
2038 * @dev the device struct object
2041 scsih_is_raid(struct device
*dev
)
2043 struct scsi_device
*sdev
= to_scsi_device(dev
);
2044 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2046 if (ioc
->is_warpdrive
)
2048 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
2052 * scsih_get_resync - get raid volume resync percent complete
2053 * @dev the device struct object
2056 scsih_get_resync(struct device
*dev
)
2058 struct scsi_device
*sdev
= to_scsi_device(dev
);
2059 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2060 static struct _raid_device
*raid_device
;
2061 unsigned long flags
;
2062 Mpi2RaidVolPage0_t vol_pg0
;
2063 Mpi2ConfigReply_t mpi_reply
;
2064 u32 volume_status_flags
;
2065 u8 percent_complete
;
2068 percent_complete
= 0;
2070 if (ioc
->is_warpdrive
)
2073 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2074 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
2077 handle
= raid_device
->handle
;
2078 percent_complete
= raid_device
->percent_complete
;
2080 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2085 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
2086 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
2087 sizeof(Mpi2RaidVolPage0_t
))) {
2088 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2089 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2090 percent_complete
= 0;
2094 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2095 if (!(volume_status_flags
&
2096 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
2097 percent_complete
= 0;
2101 switch (ioc
->hba_mpi_version_belonged
) {
2103 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
2107 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
2113 * scsih_get_state - get raid volume level
2114 * @dev the device struct object
2117 scsih_get_state(struct device
*dev
)
2119 struct scsi_device
*sdev
= to_scsi_device(dev
);
2120 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2121 static struct _raid_device
*raid_device
;
2122 unsigned long flags
;
2123 Mpi2RaidVolPage0_t vol_pg0
;
2124 Mpi2ConfigReply_t mpi_reply
;
2126 enum raid_state state
= RAID_STATE_UNKNOWN
;
2129 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2130 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
2133 handle
= raid_device
->handle
;
2134 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2139 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
2140 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
2141 sizeof(Mpi2RaidVolPage0_t
))) {
2142 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2143 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2147 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2148 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
2149 state
= RAID_STATE_RESYNCING
;
2153 switch (vol_pg0
.VolumeState
) {
2154 case MPI2_RAID_VOL_STATE_OPTIMAL
:
2155 case MPI2_RAID_VOL_STATE_ONLINE
:
2156 state
= RAID_STATE_ACTIVE
;
2158 case MPI2_RAID_VOL_STATE_DEGRADED
:
2159 state
= RAID_STATE_DEGRADED
;
2161 case MPI2_RAID_VOL_STATE_FAILED
:
2162 case MPI2_RAID_VOL_STATE_MISSING
:
2163 state
= RAID_STATE_OFFLINE
;
2167 switch (ioc
->hba_mpi_version_belonged
) {
2169 raid_set_state(mpt2sas_raid_template
, dev
, state
);
2173 raid_set_state(mpt3sas_raid_template
, dev
, state
);
2179 * _scsih_set_level - set raid level
2180 * @sdev: scsi device struct
2181 * @volume_type: volume type
2184 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
2185 struct scsi_device
*sdev
, u8 volume_type
)
2187 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
2189 switch (volume_type
) {
2190 case MPI2_RAID_VOL_TYPE_RAID0
:
2191 level
= RAID_LEVEL_0
;
2193 case MPI2_RAID_VOL_TYPE_RAID10
:
2194 level
= RAID_LEVEL_10
;
2196 case MPI2_RAID_VOL_TYPE_RAID1E
:
2197 level
= RAID_LEVEL_1E
;
2199 case MPI2_RAID_VOL_TYPE_RAID1
:
2200 level
= RAID_LEVEL_1
;
2204 switch (ioc
->hba_mpi_version_belonged
) {
2206 raid_set_level(mpt2sas_raid_template
,
2207 &sdev
->sdev_gendev
, level
);
2211 raid_set_level(mpt3sas_raid_template
,
2212 &sdev
->sdev_gendev
, level
);
2219 * _scsih_get_volume_capabilities - volume capabilities
2220 * @ioc: per adapter object
2221 * @sas_device: the raid_device object
2223 * Returns 0 for success, else 1
2226 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
2227 struct _raid_device
*raid_device
)
2229 Mpi2RaidVolPage0_t
*vol_pg0
;
2230 Mpi2RaidPhysDiskPage0_t pd_pg0
;
2231 Mpi2SasDevicePage0_t sas_device_pg0
;
2232 Mpi2ConfigReply_t mpi_reply
;
2236 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
2237 &num_pds
)) || !num_pds
) {
2238 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2239 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2244 raid_device
->num_pds
= num_pds
;
2245 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
2246 sizeof(Mpi2RaidVol0PhysDisk_t
));
2247 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
2249 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2250 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2255 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
2256 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
2257 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2258 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2264 raid_device
->volume_type
= vol_pg0
->VolumeType
;
2266 /* figure out what the underlying devices are by
2267 * obtaining the device_info bits for the 1st device
2269 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
2270 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
2271 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
2272 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
2273 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
2274 le16_to_cpu(pd_pg0
.DevHandle
)))) {
2275 raid_device
->device_info
=
2276 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
2285 * _scsih_enable_tlr - setting TLR flags
2286 * @ioc: per adapter object
2287 * @sdev: scsi device struct
2289 * Enabling Transaction Layer Retries for tape devices when
2290 * vpd page 0x90 is present
2294 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
2298 if (sdev
->type
!= TYPE_TAPE
)
2301 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
2304 sas_enable_tlr(sdev
);
2305 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
2306 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
2312 * scsih_slave_configure - device configure routine.
2313 * @sdev: scsi device struct
2315 * Returns 0 if ok. Any other return is assumed to be an error and
2316 * the device is ignored.
2319 scsih_slave_configure(struct scsi_device
*sdev
)
2321 struct Scsi_Host
*shost
= sdev
->host
;
2322 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2323 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2324 struct MPT3SAS_TARGET
*sas_target_priv_data
;
2325 struct _sas_device
*sas_device
;
2326 struct _raid_device
*raid_device
;
2327 unsigned long flags
;
2332 u16 handle
, volume_handle
= 0;
2333 u64 volume_wwid
= 0;
2336 sas_device_priv_data
= sdev
->hostdata
;
2337 sas_device_priv_data
->configured_lun
= 1;
2338 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2339 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2340 handle
= sas_target_priv_data
->handle
;
2342 /* raid volume handling */
2343 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2345 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2346 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
2347 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2349 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2350 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2351 __LINE__
, __func__
));
2355 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2356 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2357 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2358 __LINE__
, __func__
));
2363 * WARPDRIVE: Initialize the required data for Direct IO
2365 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
2367 /* RAID Queue Depth Support
2368 * IS volume = underlying qdepth of drive type, either
2369 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2370 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2372 if (raid_device
->device_info
&
2373 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2374 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2377 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2378 if (raid_device
->device_info
&
2379 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2385 switch (raid_device
->volume_type
) {
2386 case MPI2_RAID_VOL_TYPE_RAID0
:
2389 case MPI2_RAID_VOL_TYPE_RAID1E
:
2390 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2391 if (ioc
->manu_pg10
.OEMIdentifier
&&
2392 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2393 MFG10_GF0_R10_DISPLAY
) &&
2394 !(raid_device
->num_pds
% 2))
2399 case MPI2_RAID_VOL_TYPE_RAID1
:
2400 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2403 case MPI2_RAID_VOL_TYPE_RAID10
:
2404 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2407 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2409 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2414 if (!ioc
->hide_ir_msg
)
2415 sdev_printk(KERN_INFO
, sdev
,
2416 "%s: handle(0x%04x), wwid(0x%016llx),"
2417 " pd_count(%d), type(%s)\n",
2418 r_level
, raid_device
->handle
,
2419 (unsigned long long)raid_device
->wwid
,
2420 raid_device
->num_pds
, ds
);
2422 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
2423 blk_queue_max_hw_sectors(sdev
->request_queue
,
2424 MPT3SAS_RAID_MAX_SECTORS
);
2425 sdev_printk(KERN_INFO
, sdev
,
2426 "Set queue's max_sector to: %u\n",
2427 MPT3SAS_RAID_MAX_SECTORS
);
2430 scsih_change_queue_depth(sdev
, qdepth
);
2432 /* raid transport support */
2433 if (!ioc
->is_warpdrive
)
2434 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
2438 /* non-raid handling */
2439 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2440 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
2442 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2443 "failure at %s:%d/%s()!\n", ioc
->name
,
2444 __FILE__
, __LINE__
, __func__
));
2447 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
2448 volume_handle
, &volume_wwid
)) {
2449 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2450 "failure at %s:%d/%s()!\n", ioc
->name
,
2451 __FILE__
, __LINE__
, __func__
));
2456 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2457 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
2458 sas_device_priv_data
->sas_target
->sas_address
);
2460 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2461 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
2462 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2467 sas_device
->volume_handle
= volume_handle
;
2468 sas_device
->volume_wwid
= volume_wwid
;
2469 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2470 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2472 if (sas_device
->device_info
&
2473 MPI2_SAS_DEVICE_INFO_SEP
) {
2474 sdev_printk(KERN_WARNING
, sdev
,
2475 "set ignore_delay_remove for handle(0x%04x)\n",
2476 sas_device_priv_data
->sas_target
->handle
);
2477 sas_device_priv_data
->ignore_delay_remove
= 1;
2482 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2483 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2485 else if (sas_device
->device_info
&
2486 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2490 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2491 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2492 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2493 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2495 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, sdev
, NULL
);
2497 sas_device_put(sas_device
);
2498 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2501 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2504 scsih_change_queue_depth(sdev
, qdepth
);
2507 sas_read_port_mode_page(sdev
);
2508 _scsih_enable_tlr(ioc
, sdev
);
2515 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2516 * @sdev: scsi device struct
2517 * @bdev: pointer to block device context
2518 * @capacity: device size (in 512 byte sectors)
2519 * @params: three element array to place output:
2520 * params[0] number of heads (max 255)
2521 * params[1] number of sectors (max 63)
2522 * params[2] number of cylinders
2527 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2528 sector_t capacity
, int params
[])
2538 dummy
= heads
* sectors
;
2539 cylinders
= capacity
;
2540 sector_div(cylinders
, dummy
);
2543 * Handle extended translation size for logical drives
2546 if ((ulong
)capacity
>= 0x200000) {
2549 dummy
= heads
* sectors
;
2550 cylinders
= capacity
;
2551 sector_div(cylinders
, dummy
);
2556 params
[1] = sectors
;
2557 params
[2] = cylinders
;
2563 * _scsih_response_code - translation of device response code
2564 * @ioc: per adapter object
2565 * @response_code: response code returned by the device
2570 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2574 switch (response_code
) {
2575 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2576 desc
= "task management request completed";
2578 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2579 desc
= "invalid frame";
2581 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2582 desc
= "task management request not supported";
2584 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2585 desc
= "task management request failed";
2587 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2588 desc
= "task management request succeeded";
2590 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2591 desc
= "invalid lun";
2594 desc
= "overlapped tag attempted";
2596 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2597 desc
= "task queued, however not sent to target";
2603 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2604 ioc
->name
, response_code
, desc
);
2608 * _scsih_tm_done - tm completion routine
2609 * @ioc: per adapter object
2610 * @smid: system request message index
2611 * @msix_index: MSIX table index supplied by the OS
2612 * @reply: reply message frame(lower 32bit addr)
2615 * The callback handler when using scsih_issue_tm.
2617 * Return 1 meaning mf should be freed from _base_interrupt
2618 * 0 means the mf is freed from this function.
2621 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2623 MPI2DefaultReply_t
*mpi_reply
;
2625 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2627 if (ioc
->tm_cmds
.smid
!= smid
)
2629 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2630 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2632 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2633 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2635 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2636 complete(&ioc
->tm_cmds
.done
);
2641 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2642 * @ioc: per adapter object
2643 * @handle: device handle
2645 * During taskmangement request, we need to freeze the device queue.
2648 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2650 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2651 struct scsi_device
*sdev
;
2654 shost_for_each_device(sdev
, ioc
->shost
) {
2657 sas_device_priv_data
= sdev
->hostdata
;
2658 if (!sas_device_priv_data
)
2660 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2661 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2663 ioc
->ignore_loginfos
= 1;
2669 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2670 * @ioc: per adapter object
2671 * @handle: device handle
2673 * During taskmangement request, we need to freeze the device queue.
2676 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2678 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2679 struct scsi_device
*sdev
;
2682 shost_for_each_device(sdev
, ioc
->shost
) {
2685 sas_device_priv_data
= sdev
->hostdata
;
2686 if (!sas_device_priv_data
)
2688 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2689 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2691 ioc
->ignore_loginfos
= 0;
2697 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2698 * @ioc: per adapter struct
2699 * @device_handle: device handle
2700 * @channel: the channel assigned by the OS
2701 * @id: the id assigned by the OS
2703 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2704 * @smid_task: smid assigned to the task
2705 * @timeout: timeout in seconds
2708 * A generic API for sending task management requests to firmware.
2710 * The callback index is set inside `ioc->tm_cb_idx`.
2712 * Return SUCCESS or FAILED.
2715 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2716 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2718 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2719 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2722 struct scsiio_tracker
*scsi_lookup
= NULL
;
2726 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2728 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2729 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2730 __func__
, ioc
->name
);
2734 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2735 ioc
->pci_error_recovery
) {
2736 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2737 __func__
, ioc
->name
);
2741 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2742 if (ioc_state
& MPI2_DOORBELL_USED
) {
2743 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2744 "unexpected doorbell active!\n", ioc
->name
));
2745 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2746 return (!rc
) ? SUCCESS
: FAILED
;
2749 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2750 mpt3sas_base_fault_info(ioc
, ioc_state
&
2751 MPI2_DOORBELL_DATA_MASK
);
2752 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2753 return (!rc
) ? SUCCESS
: FAILED
;
2756 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2758 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2759 ioc
->name
, __func__
);
2763 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2764 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2766 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2767 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2768 ioc
->name
, handle
, type
, smid_task
));
2769 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2770 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2771 ioc
->tm_cmds
.smid
= smid
;
2772 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2773 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2774 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2775 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2776 mpi_request
->TaskType
= type
;
2777 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2778 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2779 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2780 init_completion(&ioc
->tm_cmds
.done
);
2781 if ((type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) &&
2782 (scsi_lookup
->msix_io
< ioc
->reply_queue_count
))
2783 msix_task
= scsi_lookup
->msix_io
;
2786 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2787 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2788 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2789 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2790 ioc
->name
, __func__
);
2791 _debug_dump_mf(mpi_request
,
2792 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2793 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2794 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2796 rc
= (!rc
) ? SUCCESS
: FAILED
;
2801 /* sync IRQs in case those were busy during flush. */
2802 mpt3sas_base_sync_reply_irqs(ioc
);
2804 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2805 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2806 mpi_reply
= ioc
->tm_cmds
.reply
;
2807 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2808 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2809 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2810 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2811 le32_to_cpu(mpi_reply
->TerminationCount
)));
2812 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2813 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2814 if (mpi_reply
->IOCStatus
)
2815 _debug_dump_mf(mpi_request
,
2816 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2821 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2823 if (scsi_lookup
->scmd
== NULL
)
2828 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2829 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2834 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2835 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2836 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2841 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2850 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2851 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2855 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2856 uint channel
, uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2860 mutex_lock(&ioc
->tm_cmds
.mutex
);
2861 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, channel
, id
, lun
, type
,
2862 smid_task
, timeout
);
2863 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2869 * _scsih_tm_display_info - displays info about the device
2870 * @ioc: per adapter struct
2871 * @scmd: pointer to scsi command object
2873 * Called by task management callback handlers.
2876 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2878 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2879 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2880 struct _sas_device
*sas_device
= NULL
;
2881 unsigned long flags
;
2882 char *device_str
= NULL
;
2886 if (ioc
->hide_ir_msg
)
2887 device_str
= "WarpDrive";
2889 device_str
= "volume";
2891 scsi_print_command(scmd
);
2892 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2893 starget_printk(KERN_INFO
, starget
,
2894 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2895 device_str
, priv_target
->handle
,
2896 device_str
, (unsigned long long)priv_target
->sas_address
);
2898 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2899 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2901 if (priv_target
->flags
&
2902 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2903 starget_printk(KERN_INFO
, starget
,
2904 "volume handle(0x%04x), "
2905 "volume wwid(0x%016llx)\n",
2906 sas_device
->volume_handle
,
2907 (unsigned long long)sas_device
->volume_wwid
);
2909 starget_printk(KERN_INFO
, starget
,
2910 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2912 (unsigned long long)sas_device
->sas_address
,
2915 _scsih_display_enclosure_chassis_info(NULL
, sas_device
,
2918 sas_device_put(sas_device
);
2920 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2925 * scsih_abort - eh threads main abort routine
2926 * @scmd: pointer to scsi command object
2928 * Returns SUCCESS if command aborted else FAILED
2931 scsih_abort(struct scsi_cmnd
*scmd
)
2933 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2934 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2939 sdev_printk(KERN_INFO
, scmd
->device
,
2940 "attempting task abort! scmd(%p)\n", scmd
);
2941 _scsih_tm_display_info(ioc
, scmd
);
2943 sas_device_priv_data
= scmd
->device
->hostdata
;
2944 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2945 sdev_printk(KERN_INFO
, scmd
->device
,
2946 "device been deleted! scmd(%p)\n", scmd
);
2947 scmd
->result
= DID_NO_CONNECT
<< 16;
2948 scmd
->scsi_done(scmd
);
2953 /* search for the command */
2954 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2956 scmd
->result
= DID_RESET
<< 16;
2961 /* for hidden raid components and volumes this is not supported */
2962 if (sas_device_priv_data
->sas_target
->flags
&
2963 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2964 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2965 scmd
->result
= DID_RESET
<< 16;
2970 mpt3sas_halt_firmware(ioc
);
2972 handle
= sas_device_priv_data
->sas_target
->handle
;
2973 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2974 scmd
->device
->id
, scmd
->device
->lun
,
2975 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
2978 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2979 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2984 * scsih_dev_reset - eh threads main device reset routine
2985 * @scmd: pointer to scsi command object
2987 * Returns SUCCESS if command aborted else FAILED
2990 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2992 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2993 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2994 struct _sas_device
*sas_device
= NULL
;
2998 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2999 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
3001 sdev_printk(KERN_INFO
, scmd
->device
,
3002 "attempting device reset! scmd(%p)\n", scmd
);
3003 _scsih_tm_display_info(ioc
, scmd
);
3005 sas_device_priv_data
= scmd
->device
->hostdata
;
3006 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3007 sdev_printk(KERN_INFO
, scmd
->device
,
3008 "device been deleted! scmd(%p)\n", scmd
);
3009 scmd
->result
= DID_NO_CONNECT
<< 16;
3010 scmd
->scsi_done(scmd
);
3015 /* for hidden raid components obtain the volume_handle */
3017 if (sas_device_priv_data
->sas_target
->flags
&
3018 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
3019 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
3022 handle
= sas_device
->volume_handle
;
3024 handle
= sas_device_priv_data
->sas_target
->handle
;
3027 scmd
->result
= DID_RESET
<< 16;
3032 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
3033 scmd
->device
->id
, scmd
->device
->lun
,
3034 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30);
3037 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
3038 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3041 sas_device_put(sas_device
);
3047 * scsih_target_reset - eh threads main target reset routine
3048 * @scmd: pointer to scsi command object
3050 * Returns SUCCESS if command aborted else FAILED
3053 scsih_target_reset(struct scsi_cmnd
*scmd
)
3055 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3056 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3057 struct _sas_device
*sas_device
= NULL
;
3060 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3061 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
3063 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
3065 _scsih_tm_display_info(ioc
, scmd
);
3067 sas_device_priv_data
= scmd
->device
->hostdata
;
3068 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3069 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
3071 scmd
->result
= DID_NO_CONNECT
<< 16;
3072 scmd
->scsi_done(scmd
);
3077 /* for hidden raid components obtain the volume_handle */
3079 if (sas_device_priv_data
->sas_target
->flags
&
3080 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
3081 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
3084 handle
= sas_device
->volume_handle
;
3086 handle
= sas_device_priv_data
->sas_target
->handle
;
3089 scmd
->result
= DID_RESET
<< 16;
3094 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
3095 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
3099 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
3100 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3103 sas_device_put(sas_device
);
3110 * scsih_host_reset - eh threads main host reset routine
3111 * @scmd: pointer to scsi command object
3113 * Returns SUCCESS if command aborted else FAILED
3116 scsih_host_reset(struct scsi_cmnd
*scmd
)
3118 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3121 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
3123 scsi_print_command(scmd
);
3125 if (ioc
->is_driver_loading
) {
3126 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
3132 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
3133 r
= (retval
< 0) ? FAILED
: SUCCESS
;
3135 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
3136 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3142 * _scsih_fw_event_add - insert and queue up fw_event
3143 * @ioc: per adapter object
3144 * @fw_event: object describing the event
3145 * Context: This function will acquire ioc->fw_event_lock.
3147 * This adds the firmware event object into link list, then queues it up to
3148 * be processed from user context.
3153 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
3155 unsigned long flags
;
3157 if (ioc
->firmware_event_thread
== NULL
)
3160 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3161 fw_event_work_get(fw_event
);
3162 INIT_LIST_HEAD(&fw_event
->list
);
3163 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
3164 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
3165 fw_event_work_get(fw_event
);
3166 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
3167 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3171 * _scsih_fw_event_del_from_list - delete fw_event from the list
3172 * @ioc: per adapter object
3173 * @fw_event: object describing the event
3174 * Context: This function will acquire ioc->fw_event_lock.
3176 * If the fw_event is on the fw_event_list, remove it and do a put.
3181 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
3184 unsigned long flags
;
3186 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3187 if (!list_empty(&fw_event
->list
)) {
3188 list_del_init(&fw_event
->list
);
3189 fw_event_work_put(fw_event
);
3191 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3196 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3197 * @ioc: per adapter object
3198 * @event_data: trigger event data
3203 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
3204 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
3206 struct fw_event_work
*fw_event
;
3209 if (ioc
->is_driver_loading
)
3211 sz
= sizeof(*event_data
);
3212 fw_event
= alloc_fw_event_work(sz
);
3215 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
3216 fw_event
->ioc
= ioc
;
3217 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
3218 _scsih_fw_event_add(ioc
, fw_event
);
3219 fw_event_work_put(fw_event
);
3223 * _scsih_error_recovery_delete_devices - remove devices not responding
3224 * @ioc: per adapter object
3229 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
3231 struct fw_event_work
*fw_event
;
3233 if (ioc
->is_driver_loading
)
3235 fw_event
= alloc_fw_event_work(0);
3238 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
3239 fw_event
->ioc
= ioc
;
3240 _scsih_fw_event_add(ioc
, fw_event
);
3241 fw_event_work_put(fw_event
);
3245 * mpt3sas_port_enable_complete - port enable completed (fake event)
3246 * @ioc: per adapter object
3251 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
3253 struct fw_event_work
*fw_event
;
3255 fw_event
= alloc_fw_event_work(0);
3258 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
3259 fw_event
->ioc
= ioc
;
3260 _scsih_fw_event_add(ioc
, fw_event
);
3261 fw_event_work_put(fw_event
);
3264 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
3266 unsigned long flags
;
3267 struct fw_event_work
*fw_event
= NULL
;
3269 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3270 if (!list_empty(&ioc
->fw_event_list
)) {
3271 fw_event
= list_first_entry(&ioc
->fw_event_list
,
3272 struct fw_event_work
, list
);
3273 list_del_init(&fw_event
->list
);
3275 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3281 * _scsih_fw_event_cleanup_queue - cleanup event queue
3282 * @ioc: per adapter object
3284 * Walk the firmware event queue, either killing timers, or waiting
3285 * for outstanding events to complete
3290 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
3292 struct fw_event_work
*fw_event
;
3294 if (list_empty(&ioc
->fw_event_list
) ||
3295 !ioc
->firmware_event_thread
|| in_interrupt())
3298 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
3300 * Wait on the fw_event to complete. If this returns 1, then
3301 * the event was never executed, and we need a put for the
3302 * reference the work had on the fw_event.
3304 * If it did execute, we wait for it to finish, and the put will
3305 * happen from _firmware_event_work()
3307 if (cancel_work_sync(&fw_event
->work
))
3308 fw_event_work_put(fw_event
);
3310 fw_event_work_put(fw_event
);
3315 * _scsih_internal_device_block - block the sdev device
3316 * @sdev: per device object
3317 * @sas_device_priv_data : per device driver private data
3319 * make sure device is blocked without error, if not
3323 _scsih_internal_device_block(struct scsi_device
*sdev
,
3324 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3328 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
3329 sas_device_priv_data
->sas_target
->handle
);
3330 sas_device_priv_data
->block
= 1;
3332 r
= scsi_internal_device_block_nowait(sdev
);
3334 sdev_printk(KERN_WARNING
, sdev
,
3335 "device_block failed with return(%d) for handle(0x%04x)\n",
3336 r
, sas_device_priv_data
->sas_target
->handle
);
3340 * _scsih_internal_device_unblock - unblock the sdev device
3341 * @sdev: per device object
3342 * @sas_device_priv_data : per device driver private data
3343 * make sure device is unblocked without error, if not retry
3344 * by blocking and then unblocking
3348 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
3349 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3353 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
3354 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
3355 sas_device_priv_data
->block
= 0;
3356 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3358 /* The device has been set to SDEV_RUNNING by SD layer during
3359 * device addition but the request queue is still stopped by
3360 * our earlier block call. We need to perform a block again
3361 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3363 sdev_printk(KERN_WARNING
, sdev
,
3364 "device_unblock failed with return(%d) for handle(0x%04x) "
3365 "performing a block followed by an unblock\n",
3366 r
, sas_device_priv_data
->sas_target
->handle
);
3367 sas_device_priv_data
->block
= 1;
3368 r
= scsi_internal_device_block_nowait(sdev
);
3370 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
3371 "failed with return(%d) for handle(0x%04x)\n",
3372 r
, sas_device_priv_data
->sas_target
->handle
);
3374 sas_device_priv_data
->block
= 0;
3375 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3377 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
3378 " failed with return(%d) for handle(0x%04x)\n",
3379 r
, sas_device_priv_data
->sas_target
->handle
);
3384 * _scsih_ublock_io_all_device - unblock every device
3385 * @ioc: per adapter object
3387 * change the device state from block to running
3390 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3392 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3393 struct scsi_device
*sdev
;
3395 shost_for_each_device(sdev
, ioc
->shost
) {
3396 sas_device_priv_data
= sdev
->hostdata
;
3397 if (!sas_device_priv_data
)
3399 if (!sas_device_priv_data
->block
)
3402 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3403 "device_running, handle(0x%04x)\n",
3404 sas_device_priv_data
->sas_target
->handle
));
3405 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
3411 * _scsih_ublock_io_device - prepare device to be deleted
3412 * @ioc: per adapter object
3413 * @sas_addr: sas address
3415 * unblock then put device in offline state
3418 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
3420 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3421 struct scsi_device
*sdev
;
3423 shost_for_each_device(sdev
, ioc
->shost
) {
3424 sas_device_priv_data
= sdev
->hostdata
;
3425 if (!sas_device_priv_data
)
3427 if (sas_device_priv_data
->sas_target
->sas_address
3430 if (sas_device_priv_data
->block
)
3431 _scsih_internal_device_unblock(sdev
,
3432 sas_device_priv_data
);
3437 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3438 * @ioc: per adapter object
3439 * @handle: device handle
3441 * During device pull we need to appropriately set the sdev state.
3444 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3446 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3447 struct scsi_device
*sdev
;
3449 shost_for_each_device(sdev
, ioc
->shost
) {
3450 sas_device_priv_data
= sdev
->hostdata
;
3451 if (!sas_device_priv_data
)
3453 if (sas_device_priv_data
->block
)
3455 if (sas_device_priv_data
->ignore_delay_remove
) {
3456 sdev_printk(KERN_INFO
, sdev
,
3457 "%s skip device_block for SES handle(0x%04x)\n",
3458 __func__
, sas_device_priv_data
->sas_target
->handle
);
3461 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3466 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3467 * @ioc: per adapter object
3468 * @handle: device handle
3470 * During device pull we need to appropriately set the sdev state.
3473 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3475 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3476 struct scsi_device
*sdev
;
3477 struct _sas_device
*sas_device
;
3479 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3481 shost_for_each_device(sdev
, ioc
->shost
) {
3482 sas_device_priv_data
= sdev
->hostdata
;
3483 if (!sas_device_priv_data
)
3485 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3487 if (sas_device_priv_data
->block
)
3489 if (sas_device
&& sas_device
->pend_sas_rphy_add
)
3491 if (sas_device_priv_data
->ignore_delay_remove
) {
3492 sdev_printk(KERN_INFO
, sdev
,
3493 "%s skip device_block for SES handle(0x%04x)\n",
3494 __func__
, sas_device_priv_data
->sas_target
->handle
);
3497 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3501 sas_device_put(sas_device
);
3505 * _scsih_block_io_to_children_attached_to_ex
3506 * @ioc: per adapter object
3507 * @sas_expander: the sas_device object
3509 * This routine set sdev state to SDEV_BLOCK for all devices
3510 * attached to this expander. This function called when expander is
3514 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3515 struct _sas_node
*sas_expander
)
3517 struct _sas_port
*mpt3sas_port
;
3518 struct _sas_device
*sas_device
;
3519 struct _sas_node
*expander_sibling
;
3520 unsigned long flags
;
3525 list_for_each_entry(mpt3sas_port
,
3526 &sas_expander
->sas_port_list
, port_list
) {
3527 if (mpt3sas_port
->remote_identify
.device_type
==
3529 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3530 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3531 mpt3sas_port
->remote_identify
.sas_address
);
3533 set_bit(sas_device
->handle
,
3534 ioc
->blocking_handles
);
3535 sas_device_put(sas_device
);
3537 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3541 list_for_each_entry(mpt3sas_port
,
3542 &sas_expander
->sas_port_list
, port_list
) {
3544 if (mpt3sas_port
->remote_identify
.device_type
==
3545 SAS_EDGE_EXPANDER_DEVICE
||
3546 mpt3sas_port
->remote_identify
.device_type
==
3547 SAS_FANOUT_EXPANDER_DEVICE
) {
3549 mpt3sas_scsih_expander_find_by_sas_address(
3550 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3551 _scsih_block_io_to_children_attached_to_ex(ioc
,
3558 * _scsih_block_io_to_children_attached_directly
3559 * @ioc: per adapter object
3560 * @event_data: topology change event data
3562 * This routine set sdev state to SDEV_BLOCK for all devices
3563 * direct attached during device pull.
3566 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3567 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3573 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3574 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3577 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3578 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3579 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3580 _scsih_block_io_device(ioc
, handle
);
3585 * _scsih_block_io_to_pcie_children_attached_directly
3586 * @ioc: per adapter object
3587 * @event_data: topology change event data
3589 * This routine set sdev state to SDEV_BLOCK for all devices
3590 * direct attached during device pull/reconnect.
3593 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3594 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
3600 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3602 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
3605 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
3607 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
)
3608 _scsih_block_io_device(ioc
, handle
);
3612 * _scsih_tm_tr_send - send task management request
3613 * @ioc: per adapter object
3614 * @handle: device handle
3615 * Context: interrupt time.
3617 * This code is to initiate the device removal handshake protocol
3618 * with controller firmware. This function will issue target reset
3619 * using high priority request queue. It will send a sas iounit
3620 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3622 * This is designed to send muliple task management request at the same
3623 * time to the fifo. If the fifo is full, we will append the request,
3624 * and process it in a future completion.
3627 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3629 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3631 struct _sas_device
*sas_device
= NULL
;
3632 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3633 u64 sas_address
= 0;
3634 unsigned long flags
;
3635 struct _tr_list
*delayed_tr
;
3638 if (ioc
->remove_host
) {
3639 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3640 "%s: host has been removed: handle(0x%04x)\n",
3641 __func__
, ioc
->name
, handle
));
3643 } else if (ioc
->pci_error_recovery
) {
3644 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3645 "%s: host in pci error recovery: handle(0x%04x)\n",
3646 __func__
, ioc
->name
,
3650 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3651 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3652 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3653 "%s: host is not operational: handle(0x%04x)\n",
3654 __func__
, ioc
->name
,
3659 /* if PD, then return */
3660 if (test_bit(handle
, ioc
->pd_handles
))
3663 clear_bit(handle
, ioc
->pend_os_device_add
);
3665 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3666 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3667 if (sas_device
&& sas_device
->starget
&&
3668 sas_device
->starget
->hostdata
) {
3669 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3670 sas_target_priv_data
->deleted
= 1;
3671 sas_address
= sas_device
->sas_address
;
3673 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3675 if (sas_target_priv_data
) {
3676 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3677 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3679 (unsigned long long)sas_address
));
3680 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
,
3681 sas_device
, NULL
, NULL
));
3682 _scsih_ublock_io_device(ioc
, sas_address
);
3683 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3686 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3688 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3691 INIT_LIST_HEAD(&delayed_tr
->list
);
3692 delayed_tr
->handle
= handle
;
3693 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3694 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3695 "DELAYED:tr:handle(0x%04x), (open)\n",
3696 ioc
->name
, handle
));
3700 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3701 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3702 ioc
->name
, handle
, smid
,
3703 ioc
->tm_tr_cb_idx
));
3704 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3705 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3706 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3707 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3708 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3709 set_bit(handle
, ioc
->device_remove_in_progress
);
3710 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3711 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3715 sas_device_put(sas_device
);
3719 * _scsih_tm_tr_complete -
3720 * @ioc: per adapter object
3721 * @smid: system request message index
3722 * @msix_index: MSIX table index supplied by the OS
3723 * @reply: reply message frame(lower 32bit addr)
3724 * Context: interrupt time.
3726 * This is the target reset completion routine.
3727 * This code is part of the code to initiate the device removal
3728 * handshake protocol with controller firmware.
3729 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3731 * Return 1 meaning mf should be freed from _base_interrupt
3732 * 0 means the mf is freed from this function.
3735 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3739 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3740 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3741 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3742 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3745 struct _sc_list
*delayed_sc
;
3747 if (ioc
->remove_host
) {
3748 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3749 "%s: host has been removed\n", __func__
, ioc
->name
));
3751 } else if (ioc
->pci_error_recovery
) {
3752 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3753 "%s: host in pci error recovery\n", __func__
,
3757 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3758 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3759 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3760 "%s: host is not operational\n", __func__
, ioc
->name
));
3763 if (unlikely(!mpi_reply
)) {
3764 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3765 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3768 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3769 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3770 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3771 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3772 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3774 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3778 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3779 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3780 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3781 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3782 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3783 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3784 le32_to_cpu(mpi_reply
->TerminationCount
)));
3786 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3787 if (!smid_sas_ctrl
) {
3788 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3790 return _scsih_check_for_pending_tm(ioc
, smid
);
3791 INIT_LIST_HEAD(&delayed_sc
->list
);
3792 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3793 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3794 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3795 "DELAYED:sc:handle(0x%04x), (open)\n",
3796 ioc
->name
, handle
));
3797 return _scsih_check_for_pending_tm(ioc
, smid
);
3800 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3801 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3802 ioc
->name
, handle
, smid_sas_ctrl
,
3803 ioc
->tm_sas_control_cb_idx
));
3804 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3805 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3806 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3807 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3808 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3809 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3811 return _scsih_check_for_pending_tm(ioc
, smid
);
3816 * _scsih_sas_control_complete - completion routine
3817 * @ioc: per adapter object
3818 * @smid: system request message index
3819 * @msix_index: MSIX table index supplied by the OS
3820 * @reply: reply message frame(lower 32bit addr)
3821 * Context: interrupt time.
3823 * This is the sas iounit control completion routine.
3824 * This code is part of the code to initiate the device removal
3825 * handshake protocol with controller firmware.
3827 * Return 1 meaning mf should be freed from _base_interrupt
3828 * 0 means the mf is freed from this function.
3831 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3832 u8 msix_index
, u32 reply
)
3834 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3835 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3837 if (likely(mpi_reply
)) {
3838 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3839 "sc_complete:handle(0x%04x), (open) "
3840 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3841 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3842 le16_to_cpu(mpi_reply
->IOCStatus
),
3843 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3844 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3845 MPI2_IOCSTATUS_SUCCESS
) {
3846 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3847 ioc
->device_remove_in_progress
);
3850 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3851 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3853 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3857 * _scsih_tm_tr_volume_send - send target reset request for volumes
3858 * @ioc: per adapter object
3859 * @handle: device handle
3860 * Context: interrupt time.
3862 * This is designed to send muliple task management request at the same
3863 * time to the fifo. If the fifo is full, we will append the request,
3864 * and process it in a future completion.
3867 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3869 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3871 struct _tr_list
*delayed_tr
;
3873 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3874 ioc
->pci_error_recovery
) {
3875 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3876 "%s: host reset in progress!\n",
3877 __func__
, ioc
->name
));
3881 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3883 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3886 INIT_LIST_HEAD(&delayed_tr
->list
);
3887 delayed_tr
->handle
= handle
;
3888 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3889 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3890 "DELAYED:tr:handle(0x%04x), (open)\n",
3891 ioc
->name
, handle
));
3895 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3896 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3897 ioc
->name
, handle
, smid
,
3898 ioc
->tm_tr_volume_cb_idx
));
3899 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3900 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3901 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3902 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3903 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3904 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3908 * _scsih_tm_volume_tr_complete - target reset completion
3909 * @ioc: per adapter object
3910 * @smid: system request message index
3911 * @msix_index: MSIX table index supplied by the OS
3912 * @reply: reply message frame(lower 32bit addr)
3913 * Context: interrupt time.
3915 * Return 1 meaning mf should be freed from _base_interrupt
3916 * 0 means the mf is freed from this function.
3919 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3920 u8 msix_index
, u32 reply
)
3923 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3924 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3925 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3927 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3928 ioc
->pci_error_recovery
) {
3929 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3930 "%s: host reset in progress!\n",
3931 __func__
, ioc
->name
));
3934 if (unlikely(!mpi_reply
)) {
3935 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3936 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3940 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3941 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3942 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3943 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3944 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3946 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3950 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3951 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3952 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3953 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3954 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3955 le32_to_cpu(mpi_reply
->TerminationCount
)));
3957 return _scsih_check_for_pending_tm(ioc
, smid
);
3961 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3962 * @ioc: per adapter object
3963 * @smid: system request message index
3965 * @event_context: used to track events uniquely
3967 * Context - processed in interrupt context.
3970 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
3973 Mpi2EventAckRequest_t
*ack_request
;
3974 int i
= smid
- ioc
->internal_smid
;
3975 unsigned long flags
;
3977 /* Without releasing the smid just update the
3978 * call back index and reuse the same smid for
3979 * processing this delayed request
3981 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3982 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3983 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3985 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3986 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3987 ioc
->name
, le16_to_cpu(event
), smid
,
3989 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3990 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3991 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3992 ack_request
->Event
= event
;
3993 ack_request
->EventContext
= event_context
;
3994 ack_request
->VF_ID
= 0; /* TODO */
3995 ack_request
->VP_ID
= 0;
3996 ioc
->put_smid_default(ioc
, smid
);
4000 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
4001 * sas_io_unit_ctrl messages
4002 * @ioc: per adapter object
4003 * @smid: system request message index
4004 * @handle: device handle
4006 * Context - processed in interrupt context.
4009 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
4010 u16 smid
, u16 handle
)
4012 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
4014 int i
= smid
- ioc
->internal_smid
;
4015 unsigned long flags
;
4017 if (ioc
->remove_host
) {
4018 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4019 "%s: host has been removed\n",
4020 __func__
, ioc
->name
));
4022 } else if (ioc
->pci_error_recovery
) {
4023 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4024 "%s: host in pci error recovery\n",
4025 __func__
, ioc
->name
));
4028 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4029 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4030 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4031 "%s: host is not operational\n",
4032 __func__
, ioc
->name
));
4036 /* Without releasing the smid just update the
4037 * call back index and reuse the same smid for
4038 * processing this delayed request
4040 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4041 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
4042 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4044 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4045 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4046 ioc
->name
, le16_to_cpu(handle
), smid
,
4047 ioc
->tm_sas_control_cb_idx
));
4048 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4049 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4050 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4051 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4052 mpi_request
->DevHandle
= handle
;
4053 ioc
->put_smid_default(ioc
, smid
);
4057 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
4058 * @ioc: per adapter object
4059 * @smid: system request message index
4061 * Context: Executed in interrupt context
4063 * This will check delayed internal messages list, and process the
4066 * Return 1 meaning mf should be freed from _base_interrupt
4067 * 0 means the mf is freed from this function.
4070 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4072 struct _sc_list
*delayed_sc
;
4073 struct _event_ack_list
*delayed_event_ack
;
4075 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
4076 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
4077 struct _event_ack_list
, list
);
4078 _scsih_issue_delayed_event_ack(ioc
, smid
,
4079 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
4080 list_del(&delayed_event_ack
->list
);
4081 kfree(delayed_event_ack
);
4085 if (!list_empty(&ioc
->delayed_sc_list
)) {
4086 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
4087 struct _sc_list
, list
);
4088 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
4089 delayed_sc
->handle
);
4090 list_del(&delayed_sc
->list
);
4098 * _scsih_check_for_pending_tm - check for pending task management
4099 * @ioc: per adapter object
4100 * @smid: system request message index
4102 * This will check delayed target reset list, and feed the
4105 * Return 1 meaning mf should be freed from _base_interrupt
4106 * 0 means the mf is freed from this function.
4109 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4111 struct _tr_list
*delayed_tr
;
4113 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
4114 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
4115 struct _tr_list
, list
);
4116 mpt3sas_base_free_smid(ioc
, smid
);
4117 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
4118 list_del(&delayed_tr
->list
);
4123 if (!list_empty(&ioc
->delayed_tr_list
)) {
4124 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
4125 struct _tr_list
, list
);
4126 mpt3sas_base_free_smid(ioc
, smid
);
4127 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
4128 list_del(&delayed_tr
->list
);
4137 * _scsih_check_topo_delete_events - sanity check on topo events
4138 * @ioc: per adapter object
4139 * @event_data: the event data payload
4141 * This routine added to better handle cable breaker.
4143 * This handles the case where driver receives multiple expander
4144 * add and delete events in a single shot. When there is a delete event
4145 * the routine will void any pending add events waiting in the event queue.
4150 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4151 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4153 struct fw_event_work
*fw_event
;
4154 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
4155 u16 expander_handle
;
4156 struct _sas_node
*sas_expander
;
4157 unsigned long flags
;
4161 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
4162 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4165 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4166 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4167 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
4168 _scsih_tm_tr_send(ioc
, handle
);
4171 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4172 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
4173 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4176 if (event_data
->ExpStatus
==
4177 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
4178 /* put expander attached devices into blocking state */
4179 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4180 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
4182 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
4183 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4185 handle
= find_first_bit(ioc
->blocking_handles
,
4186 ioc
->facts
.MaxDevHandle
);
4187 if (handle
< ioc
->facts
.MaxDevHandle
)
4188 _scsih_block_io_device(ioc
, handle
);
4189 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
4190 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
4191 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4193 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4196 /* mark ignore flag for pending events */
4197 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4198 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4199 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
4202 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
4203 fw_event
->event_data
;
4204 if (local_event_data
->ExpStatus
==
4205 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4206 local_event_data
->ExpStatus
==
4207 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4208 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
4210 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4211 "setting ignoring flag\n", ioc
->name
));
4212 fw_event
->ignore
= 1;
4216 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4220 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4222 * @ioc: per adapter object
4223 * @event_data: the event data payload
4225 * This handles the case where driver receives multiple switch
4226 * or device add and delete events in a single shot. When there
4227 * is a delete event the routine will void any pending add
4228 * events waiting in the event queue.
4233 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER
*ioc
,
4234 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
4236 struct fw_event_work
*fw_event
;
4237 Mpi26EventDataPCIeTopologyChangeList_t
*local_event_data
;
4238 unsigned long flags
;
4240 u16 handle
, switch_handle
;
4242 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4244 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
4247 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
4248 if (reason_code
== MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
)
4249 _scsih_tm_tr_send(ioc
, handle
);
4252 switch_handle
= le16_to_cpu(event_data
->SwitchDevHandle
);
4253 if (!switch_handle
) {
4254 _scsih_block_io_to_pcie_children_attached_directly(
4258 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4259 if ((event_data
->SwitchStatus
4260 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
) ||
4261 (event_data
->SwitchStatus
==
4262 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
))
4263 _scsih_block_io_to_pcie_children_attached_directly(
4266 if (event_data
->SwitchStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4269 /* mark ignore flag for pending events */
4270 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4271 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4272 if (fw_event
->event
!= MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
||
4276 (Mpi26EventDataPCIeTopologyChangeList_t
*)
4277 fw_event
->event_data
;
4278 if (local_event_data
->SwitchStatus
==
4279 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4280 local_event_data
->SwitchStatus
==
4281 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4282 if (le16_to_cpu(local_event_data
->SwitchDevHandle
) ==
4284 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4285 "setting ignoring flag for switch event\n",
4287 fw_event
->ignore
= 1;
4291 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4295 * _scsih_set_volume_delete_flag - setting volume delete flag
4296 * @ioc: per adapter object
4297 * @handle: device handle
4299 * This returns nothing.
4302 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4304 struct _raid_device
*raid_device
;
4305 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4306 unsigned long flags
;
4308 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4309 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
4310 if (raid_device
&& raid_device
->starget
&&
4311 raid_device
->starget
->hostdata
) {
4312 sas_target_priv_data
=
4313 raid_device
->starget
->hostdata
;
4314 sas_target_priv_data
->deleted
= 1;
4315 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4316 "setting delete flag: handle(0x%04x), "
4317 "wwid(0x%016llx)\n", ioc
->name
, handle
,
4318 (unsigned long long) raid_device
->wwid
));
4320 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4324 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4325 * @handle: input handle
4326 * @a: handle for volume a
4327 * @b: handle for volume b
4329 * IR firmware only supports two raid volumes. The purpose of this
4330 * routine is to set the volume handle in either a or b. When the given
4331 * input handle is non-zero, or when a and b have not been set before.
4334 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
4336 if (!handle
|| handle
== *a
|| handle
== *b
)
4345 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4346 * @ioc: per adapter object
4347 * @event_data: the event data payload
4348 * Context: interrupt time.
4350 * This routine will send target reset to volume, followed by target
4351 * resets to the PDs. This is called when a PD has been removed, or
4352 * volume has been deleted or removed. When the target reset is sent
4353 * to volume, the PD target resets need to be queued to start upon
4354 * completion of the volume target reset.
4359 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
4360 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4362 Mpi2EventIrConfigElement_t
*element
;
4364 u16 handle
, volume_handle
, a
, b
;
4365 struct _tr_list
*delayed_tr
;
4370 if (ioc
->is_warpdrive
)
4373 /* Volume Resets for Deleted or Removed */
4374 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4375 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4376 if (le32_to_cpu(event_data
->Flags
) &
4377 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4379 if (element
->ReasonCode
==
4380 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
4381 element
->ReasonCode
==
4382 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
4383 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4384 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
4385 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4389 /* Volume Resets for UNHIDE events */
4390 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4391 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4392 if (le32_to_cpu(event_data
->Flags
) &
4393 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4395 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
4396 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4397 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4402 _scsih_tm_tr_volume_send(ioc
, a
);
4404 _scsih_tm_tr_volume_send(ioc
, b
);
4406 /* PD target resets */
4407 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4408 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4409 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
4411 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4412 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4413 clear_bit(handle
, ioc
->pd_handles
);
4415 _scsih_tm_tr_send(ioc
, handle
);
4416 else if (volume_handle
== a
|| volume_handle
== b
) {
4417 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
4418 BUG_ON(!delayed_tr
);
4419 INIT_LIST_HEAD(&delayed_tr
->list
);
4420 delayed_tr
->handle
= handle
;
4421 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
4422 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4423 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
4426 _scsih_tm_tr_send(ioc
, handle
);
4432 * _scsih_check_volume_delete_events - set delete flag for volumes
4433 * @ioc: per adapter object
4434 * @event_data: the event data payload
4435 * Context: interrupt time.
4437 * This will handle the case when the cable connected to entire volume is
4438 * pulled. We will take care of setting the deleted flag so normal IO will
4444 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4445 Mpi2EventDataIrVolume_t
*event_data
)
4449 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4451 state
= le32_to_cpu(event_data
->NewValue
);
4452 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
4453 MPI2_RAID_VOL_STATE_FAILED
)
4454 _scsih_set_volume_delete_flag(ioc
,
4455 le16_to_cpu(event_data
->VolDevHandle
));
4459 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4460 * @ioc: per adapter object
4461 * @event_data: the temp threshold event data
4462 * Context: interrupt time.
4467 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
4468 Mpi2EventDataTemperature_t
*event_data
)
4470 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
4471 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
4472 " exceeded for Sensor: %d !!!\n", ioc
->name
,
4473 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
4474 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
4475 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
4476 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
4477 event_data
->SensorNum
);
4478 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
4479 ioc
->name
, event_data
->CurrentTemperature
);
4483 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
4485 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
4487 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
4491 return test_and_set_bit(0, &priv
->ata_command_pending
);
4493 clear_bit(0, &priv
->ata_command_pending
);
4498 * _scsih_flush_running_cmds - completing outstanding commands.
4499 * @ioc: per adapter object
4501 * The flushing out of all pending scmd commands following host reset,
4502 * where all IO is dropped to the floor.
4507 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
4509 struct scsi_cmnd
*scmd
;
4513 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4514 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4518 _scsih_set_satl_pending(scmd
, false);
4519 mpt3sas_base_free_smid(ioc
, smid
);
4520 scsi_dma_unmap(scmd
);
4521 if (ioc
->pci_error_recovery
)
4522 scmd
->result
= DID_NO_CONNECT
<< 16;
4524 scmd
->result
= DID_RESET
<< 16;
4525 scmd
->scsi_done(scmd
);
4527 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
4532 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4533 * @ioc: per adapter object
4534 * @scmd: pointer to scsi command object
4535 * @mpi_request: pointer to the SCSI_IO request message frame
4537 * Supporting protection 1 and 3.
4542 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4543 Mpi25SCSIIORequest_t
*mpi_request
)
4546 unsigned char prot_op
= scsi_get_prot_op(scmd
);
4547 unsigned char prot_type
= scsi_get_prot_type(scmd
);
4548 Mpi25SCSIIORequest_t
*mpi_request_3v
=
4549 (Mpi25SCSIIORequest_t
*)mpi_request
;
4551 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
4554 if (prot_op
== SCSI_PROT_READ_STRIP
)
4555 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
4556 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
4557 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
4561 switch (prot_type
) {
4562 case SCSI_PROT_DIF_TYPE1
:
4563 case SCSI_PROT_DIF_TYPE2
:
4566 * enable ref/guard checking
4567 * auto increment ref tag
4569 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4570 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4571 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4572 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4573 cpu_to_be32(scsi_prot_ref_tag(scmd
));
4576 case SCSI_PROT_DIF_TYPE3
:
4579 * enable guard checking
4581 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4586 mpi_request_3v
->EEDPBlockSize
=
4587 cpu_to_le16(scmd
->device
->sector_size
);
4589 if (ioc
->is_gen35_ioc
)
4590 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4591 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4595 * _scsih_eedp_error_handling - return sense code for EEDP errors
4596 * @scmd: pointer to scsi command object
4597 * @ioc_status: ioc status
4602 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4606 switch (ioc_status
) {
4607 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4610 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4613 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4620 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4622 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4623 SAM_STAT_CHECK_CONDITION
;
4627 * scsih_qcmd - main scsi request entry point
4628 * @scmd: pointer to scsi command object
4629 * @done: function pointer to be invoked on completion
4631 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4633 * Returns 0 on success. If there's a failure, return either:
4634 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4635 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4638 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4640 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4641 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4642 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4643 struct _raid_device
*raid_device
;
4644 struct request
*rq
= scmd
->request
;
4646 Mpi25SCSIIORequest_t
*mpi_request
;
4647 struct _pcie_device
*pcie_device
= NULL
;
4652 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4653 scsi_print_command(scmd
);
4655 sas_device_priv_data
= scmd
->device
->hostdata
;
4656 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4657 scmd
->result
= DID_NO_CONNECT
<< 16;
4658 scmd
->scsi_done(scmd
);
4662 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
4663 scmd
->result
= DID_NO_CONNECT
<< 16;
4664 scmd
->scsi_done(scmd
);
4669 * Bug work around for firmware SATL handling. The loop
4670 * is based on atomic operations and ensures consistency
4671 * since we're lockless at this point
4674 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
)) {
4675 scmd
->result
= SAM_STAT_BUSY
;
4676 scmd
->scsi_done(scmd
);
4679 } while (_scsih_set_satl_pending(scmd
, true));
4681 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4683 /* invalid device handle */
4684 handle
= sas_target_priv_data
->handle
;
4685 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4686 scmd
->result
= DID_NO_CONNECT
<< 16;
4687 scmd
->scsi_done(scmd
);
4692 /* host recovery or link resets sent via IOCTLs */
4693 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4694 return SCSI_MLQUEUE_HOST_BUSY
;
4696 /* device has been deleted */
4697 else if (sas_target_priv_data
->deleted
) {
4698 scmd
->result
= DID_NO_CONNECT
<< 16;
4699 scmd
->scsi_done(scmd
);
4701 /* device busy with task management */
4702 } else if (sas_target_priv_data
->tm_busy
||
4703 sas_device_priv_data
->block
)
4704 return SCSI_MLQUEUE_DEVICE_BUSY
;
4706 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4707 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4708 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4709 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4711 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4714 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4715 /* NCQ Prio supported, make sure control indicated high priority */
4716 if (sas_device_priv_data
->ncq_prio_enable
) {
4717 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4718 if (class == IOPRIO_CLASS_RT
)
4719 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4721 /* Make sure Device is not raid volume.
4722 * We do not expose raid functionality to upper layer for warpdrive.
4724 if (!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
)
4725 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4726 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4728 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4730 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4731 ioc
->name
, __func__
);
4734 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4735 memset(mpi_request
, 0, ioc
->request_sz
);
4736 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4738 if (scmd
->cmd_len
== 32)
4739 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4740 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4741 if (sas_device_priv_data
->sas_target
->flags
&
4742 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4743 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4745 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4746 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4747 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4748 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4749 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4750 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4751 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4752 mpi_request
->SenseBufferLowAddress
=
4753 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4754 mpi_request
->SGLOffset0
= offsetof(Mpi25SCSIIORequest_t
, SGL
) / 4;
4755 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4757 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4759 if (mpi_request
->DataLength
) {
4760 pcie_device
= sas_target_priv_data
->pcie_dev
;
4761 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
, pcie_device
)) {
4762 mpt3sas_base_free_smid(ioc
, smid
);
4766 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4768 raid_device
= sas_target_priv_data
->raid_device
;
4769 if (raid_device
&& raid_device
->direct_io_enabled
)
4770 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4773 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4774 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4775 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4776 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4777 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4779 ioc
->put_smid_scsi_io(ioc
, smid
,
4780 le16_to_cpu(mpi_request
->DevHandle
));
4782 ioc
->put_smid_default(ioc
, smid
);
4786 return SCSI_MLQUEUE_HOST_BUSY
;
4790 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4791 * @sense_buffer: sense data returned by target
4792 * @data: normalized skey/asc/ascq
4797 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4799 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4800 /* descriptor format */
4801 data
->skey
= sense_buffer
[1] & 0x0F;
4802 data
->asc
= sense_buffer
[2];
4803 data
->ascq
= sense_buffer
[3];
4806 data
->skey
= sense_buffer
[2] & 0x0F;
4807 data
->asc
= sense_buffer
[12];
4808 data
->ascq
= sense_buffer
[13];
4813 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4814 * @ioc: per adapter object
4815 * @scmd: pointer to scsi command object
4816 * @mpi_reply: reply mf payload returned from firmware
4818 * scsi_status - SCSI Status code returned from target device
4819 * scsi_state - state info associated with SCSI_IO determined by ioc
4820 * ioc_status - ioc supplied status info
4825 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4826 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4830 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4831 MPI2_IOCSTATUS_MASK
;
4832 u8 scsi_state
= mpi_reply
->SCSIState
;
4833 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4834 char *desc_ioc_state
= NULL
;
4835 char *desc_scsi_status
= NULL
;
4836 char *desc_scsi_state
= ioc
->tmp_string
;
4837 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4838 struct _sas_device
*sas_device
= NULL
;
4839 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4840 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4841 char *device_str
= NULL
;
4845 if (ioc
->hide_ir_msg
)
4846 device_str
= "WarpDrive";
4848 device_str
= "volume";
4850 if (log_info
== 0x31170000)
4853 switch (ioc_status
) {
4854 case MPI2_IOCSTATUS_SUCCESS
:
4855 desc_ioc_state
= "success";
4857 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4858 desc_ioc_state
= "invalid function";
4860 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4861 desc_ioc_state
= "scsi recovered error";
4863 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4864 desc_ioc_state
= "scsi invalid dev handle";
4866 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4867 desc_ioc_state
= "scsi device not there";
4869 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4870 desc_ioc_state
= "scsi data overrun";
4872 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4873 desc_ioc_state
= "scsi data underrun";
4875 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4876 desc_ioc_state
= "scsi io data error";
4878 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4879 desc_ioc_state
= "scsi protocol error";
4881 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4882 desc_ioc_state
= "scsi task terminated";
4884 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4885 desc_ioc_state
= "scsi residual mismatch";
4887 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4888 desc_ioc_state
= "scsi task mgmt failed";
4890 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4891 desc_ioc_state
= "scsi ioc terminated";
4893 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4894 desc_ioc_state
= "scsi ext terminated";
4896 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4897 desc_ioc_state
= "eedp guard error";
4899 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4900 desc_ioc_state
= "eedp ref tag error";
4902 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4903 desc_ioc_state
= "eedp app tag error";
4905 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4906 desc_ioc_state
= "insufficient power";
4909 desc_ioc_state
= "unknown";
4913 switch (scsi_status
) {
4914 case MPI2_SCSI_STATUS_GOOD
:
4915 desc_scsi_status
= "good";
4917 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4918 desc_scsi_status
= "check condition";
4920 case MPI2_SCSI_STATUS_CONDITION_MET
:
4921 desc_scsi_status
= "condition met";
4923 case MPI2_SCSI_STATUS_BUSY
:
4924 desc_scsi_status
= "busy";
4926 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4927 desc_scsi_status
= "intermediate";
4929 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4930 desc_scsi_status
= "intermediate condmet";
4932 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4933 desc_scsi_status
= "reservation conflict";
4935 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4936 desc_scsi_status
= "command terminated";
4938 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4939 desc_scsi_status
= "task set full";
4941 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4942 desc_scsi_status
= "aca active";
4944 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4945 desc_scsi_status
= "task aborted";
4948 desc_scsi_status
= "unknown";
4952 desc_scsi_state
[0] = '\0';
4954 desc_scsi_state
= " ";
4955 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4956 strcat(desc_scsi_state
, "response info ");
4957 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4958 strcat(desc_scsi_state
, "state terminated ");
4959 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4960 strcat(desc_scsi_state
, "no status ");
4961 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4962 strcat(desc_scsi_state
, "autosense failed ");
4963 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4964 strcat(desc_scsi_state
, "autosense valid ");
4966 scsi_print_command(scmd
);
4968 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4969 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4970 device_str
, (unsigned long long)priv_target
->sas_address
);
4972 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4975 "\tsas_address(0x%016llx), phy(%d)\n",
4976 ioc
->name
, (unsigned long long)
4977 sas_device
->sas_address
, sas_device
->phy
);
4979 _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
4982 sas_device_put(sas_device
);
4987 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4988 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4989 desc_ioc_state
, ioc_status
, smid
);
4991 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4992 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4993 scsi_get_resid(scmd
));
4995 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4996 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4997 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4999 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
5000 ioc
->name
, desc_scsi_status
,
5001 scsi_status
, desc_scsi_state
, scsi_state
);
5003 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5004 struct sense_info data
;
5005 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5007 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
5008 ioc
->name
, data
.skey
,
5009 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
5012 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
5013 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
5014 response_bytes
= (u8
*)&response_info
;
5015 _scsih_response_code(ioc
, response_bytes
[0]);
5020 * _scsih_turn_on_pfa_led - illuminate PFA LED
5021 * @ioc: per adapter object
5022 * @handle: device handle
5028 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5030 Mpi2SepReply_t mpi_reply
;
5031 Mpi2SepRequest_t mpi_request
;
5032 struct _sas_device
*sas_device
;
5034 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
5038 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5039 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5040 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5041 mpi_request
.SlotStatus
=
5042 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
5043 mpi_request
.DevHandle
= cpu_to_le16(handle
);
5044 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
5045 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5046 &mpi_request
)) != 0) {
5047 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5048 __FILE__
, __LINE__
, __func__
);
5051 sas_device
->pfa_led_on
= 1;
5053 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5054 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5055 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5056 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5057 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5061 sas_device_put(sas_device
);
5065 * _scsih_turn_off_pfa_led - turn off Fault LED
5066 * @ioc: per adapter object
5067 * @sas_device: sas device whose PFA LED has to turned off
5073 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
5074 struct _sas_device
*sas_device
)
5076 Mpi2SepReply_t mpi_reply
;
5077 Mpi2SepRequest_t mpi_request
;
5079 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5080 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5081 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5082 mpi_request
.SlotStatus
= 0;
5083 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
5084 mpi_request
.DevHandle
= 0;
5085 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
5086 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
5087 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5088 &mpi_request
)) != 0) {
5089 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
5090 __FILE__
, __LINE__
, __func__
);
5094 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5095 dewtprintk(ioc
, printk(MPT3SAS_FMT
5096 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5097 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
5098 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5104 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5105 * @ioc: per adapter object
5106 * @handle: device handle
5107 * Context: interrupt.
5112 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5114 struct fw_event_work
*fw_event
;
5116 fw_event
= alloc_fw_event_work(0);
5119 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
5120 fw_event
->device_handle
= handle
;
5121 fw_event
->ioc
= ioc
;
5122 _scsih_fw_event_add(ioc
, fw_event
);
5123 fw_event_work_put(fw_event
);
5127 * _scsih_smart_predicted_fault - process smart errors
5128 * @ioc: per adapter object
5129 * @handle: device handle
5130 * Context: interrupt.
5135 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5137 struct scsi_target
*starget
;
5138 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5139 Mpi2EventNotificationReply_t
*event_reply
;
5140 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
5141 struct _sas_device
*sas_device
;
5143 unsigned long flags
;
5145 /* only handle non-raid devices */
5146 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5147 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
5151 starget
= sas_device
->starget
;
5152 sas_target_priv_data
= starget
->hostdata
;
5154 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
5155 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
5158 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, NULL
, starget
);
5160 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5162 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
5163 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
5165 /* insert into event log */
5166 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
5167 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
5168 event_reply
= kzalloc(sz
, GFP_KERNEL
);
5170 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5171 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5175 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
5176 event_reply
->Event
=
5177 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
5178 event_reply
->MsgLength
= sz
/4;
5179 event_reply
->EventDataLength
=
5180 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
5181 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
5182 event_reply
->EventData
;
5183 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
5184 event_data
->ASC
= 0x5D;
5185 event_data
->DevHandle
= cpu_to_le16(handle
);
5186 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
5187 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
5191 sas_device_put(sas_device
);
5195 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5200 * _scsih_io_done - scsi request callback
5201 * @ioc: per adapter object
5202 * @smid: system request message index
5203 * @msix_index: MSIX table index supplied by the OS
5204 * @reply: reply message frame(lower 32bit addr)
5206 * Callback handler when using _scsih_qcmd.
5208 * Return 1 meaning mf should be freed from _base_interrupt
5209 * 0 means the mf is freed from this function.
5212 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5214 Mpi25SCSIIORequest_t
*mpi_request
;
5215 Mpi2SCSIIOReply_t
*mpi_reply
;
5216 struct scsi_cmnd
*scmd
;
5222 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5223 u32 response_code
= 0;
5224 unsigned long flags
;
5226 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5228 if (ioc
->broadcast_aen_busy
|| ioc
->pci_error_recovery
||
5229 ioc
->got_task_abort_from_ioctl
)
5230 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
5232 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
5237 _scsih_set_satl_pending(scmd
, false);
5239 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5241 if (mpi_reply
== NULL
) {
5242 scmd
->result
= DID_OK
<< 16;
5246 sas_device_priv_data
= scmd
->device
->hostdata
;
5247 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
5248 sas_device_priv_data
->sas_target
->deleted
) {
5249 scmd
->result
= DID_NO_CONNECT
<< 16;
5252 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5255 * WARPDRIVE: If direct_io is set then it is directIO,
5256 * the failed direct I/O should be redirected to volume
5258 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
5259 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
5260 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
5261 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5262 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
5263 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5264 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
5265 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
5266 mpi_request
->DevHandle
=
5267 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
5268 ioc
->put_smid_scsi_io(ioc
, smid
,
5269 sas_device_priv_data
->sas_target
->handle
);
5272 /* turning off TLR */
5273 scsi_state
= mpi_reply
->SCSIState
;
5274 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
5276 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
5277 if (!sas_device_priv_data
->tlr_snoop_check
) {
5278 sas_device_priv_data
->tlr_snoop_check
++;
5279 if (!ioc
->is_warpdrive
&&
5280 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
5281 sas_is_tlr_enabled(scmd
->device
) &&
5282 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
5283 sas_disable_tlr(scmd
->device
);
5284 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
5288 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
5289 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
5290 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5291 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5294 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5295 scsi_status
= mpi_reply
->SCSIStatus
;
5297 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
5298 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
5299 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
5300 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
5301 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
5304 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5305 struct sense_info data
;
5306 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
5308 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
5309 le32_to_cpu(mpi_reply
->SenseCount
));
5310 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
5311 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5312 /* failure prediction threshold exceeded */
5313 if (data
.asc
== 0x5D)
5314 _scsih_smart_predicted_fault(ioc
,
5315 le16_to_cpu(mpi_reply
->DevHandle
));
5316 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
5318 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
5319 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
5320 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
5321 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
5322 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5324 switch (ioc_status
) {
5325 case MPI2_IOCSTATUS_BUSY
:
5326 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
5327 scmd
->result
= SAM_STAT_BUSY
;
5330 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
5331 scmd
->result
= DID_NO_CONNECT
<< 16;
5334 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
5335 if (sas_device_priv_data
->block
) {
5336 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
5339 if (log_info
== 0x31110630) {
5340 if (scmd
->retries
> 2) {
5341 scmd
->result
= DID_NO_CONNECT
<< 16;
5342 scsi_device_set_state(scmd
->device
,
5345 scmd
->result
= DID_SOFT_ERROR
<< 16;
5346 scmd
->device
->expecting_cc_ua
= 1;
5349 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
5350 scmd
->result
= DID_RESET
<< 16;
5352 } else if ((scmd
->device
->channel
== RAID_CHANNEL
) &&
5353 (scsi_state
== (MPI2_SCSI_STATE_TERMINATED
|
5354 MPI2_SCSI_STATE_NO_SCSI_STATUS
))) {
5355 scmd
->result
= DID_RESET
<< 16;
5358 scmd
->result
= DID_SOFT_ERROR
<< 16;
5360 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
5361 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
5362 scmd
->result
= DID_RESET
<< 16;
5365 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
5366 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
5367 scmd
->result
= DID_SOFT_ERROR
<< 16;
5369 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5372 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
5373 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5375 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
5378 if (xfer_cnt
< scmd
->underflow
) {
5379 if (scsi_status
== SAM_STAT_BUSY
)
5380 scmd
->result
= SAM_STAT_BUSY
;
5382 scmd
->result
= DID_SOFT_ERROR
<< 16;
5383 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5384 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
5385 scmd
->result
= DID_SOFT_ERROR
<< 16;
5386 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5387 scmd
->result
= DID_RESET
<< 16;
5388 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
5389 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
5390 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
5391 scmd
->result
= (DRIVER_SENSE
<< 24) |
5392 SAM_STAT_CHECK_CONDITION
;
5393 scmd
->sense_buffer
[0] = 0x70;
5394 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
5395 scmd
->sense_buffer
[12] = 0x20;
5396 scmd
->sense_buffer
[13] = 0;
5400 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
5401 scsi_set_resid(scmd
, 0);
5402 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
5403 case MPI2_IOCSTATUS_SUCCESS
:
5404 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5405 if (response_code
==
5406 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
5407 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5408 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
5409 scmd
->result
= DID_SOFT_ERROR
<< 16;
5410 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5411 scmd
->result
= DID_RESET
<< 16;
5414 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
5415 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
5416 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
5417 _scsih_eedp_error_handling(scmd
, ioc_status
);
5420 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
5421 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
5422 case MPI2_IOCSTATUS_INVALID_SGL
:
5423 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
5424 case MPI2_IOCSTATUS_INVALID_FIELD
:
5425 case MPI2_IOCSTATUS_INVALID_STATE
:
5426 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
5427 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
5428 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
5430 scmd
->result
= DID_SOFT_ERROR
<< 16;
5435 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
5436 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5440 scsi_dma_unmap(scmd
);
5442 scmd
->scsi_done(scmd
);
5447 * _scsih_sas_host_refresh - refreshing sas host object contents
5448 * @ioc: per adapter object
5451 * During port enable, fw will send topology events for every device. Its
5452 * possible that the handles may change from the previous setting, so this
5453 * code keeping handles updating if changed.
5458 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
5463 Mpi2ConfigReply_t mpi_reply
;
5464 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5465 u16 attached_handle
;
5468 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
5469 "updating handles for sas_host(0x%016llx)\n",
5470 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
5472 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
5473 * sizeof(Mpi2SasIOUnit0PhyData_t
));
5474 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5475 if (!sas_iounit_pg0
) {
5476 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5477 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5481 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5482 sas_iounit_pg0
, sz
)) != 0)
5484 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5485 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5487 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5488 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
5490 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5491 PhyData
[0].ControllerDevHandle
);
5492 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5493 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
5495 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5496 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
5497 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
5498 attached_handle
, i
, link_rate
);
5501 kfree(sas_iounit_pg0
);
5505 * _scsih_sas_host_add - create sas host object
5506 * @ioc: per adapter object
5508 * Creating host side data object, stored in ioc->sas_hba
5513 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
5516 Mpi2ConfigReply_t mpi_reply
;
5517 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5518 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
5519 Mpi2SasPhyPage0_t phy_pg0
;
5520 Mpi2SasDevicePage0_t sas_device_pg0
;
5521 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5524 u8 device_missing_delay
;
5527 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
5529 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5530 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5533 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
5534 sizeof(struct _sas_phy
), GFP_KERNEL
);
5535 if (!ioc
->sas_hba
.phy
) {
5536 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5537 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5540 ioc
->sas_hba
.num_phys
= num_phys
;
5542 /* sas_iounit page 0 */
5543 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5544 sizeof(Mpi2SasIOUnit0PhyData_t
));
5545 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5546 if (!sas_iounit_pg0
) {
5547 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5548 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5551 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5552 sas_iounit_pg0
, sz
))) {
5553 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5554 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5557 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5558 MPI2_IOCSTATUS_MASK
;
5559 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5560 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5561 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5565 /* sas_iounit page 1 */
5566 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5567 sizeof(Mpi2SasIOUnit1PhyData_t
));
5568 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5569 if (!sas_iounit_pg1
) {
5570 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5571 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5574 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5575 sas_iounit_pg1
, sz
))) {
5576 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5577 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5580 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5581 MPI2_IOCSTATUS_MASK
;
5582 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5583 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5584 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5588 ioc
->io_missing_delay
=
5589 sas_iounit_pg1
->IODeviceMissingDelay
;
5590 device_missing_delay
=
5591 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5592 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5593 ioc
->device_missing_delay
= (device_missing_delay
&
5594 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5596 ioc
->device_missing_delay
= device_missing_delay
&
5597 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5599 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5600 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5601 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5603 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5604 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5607 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5608 MPI2_IOCSTATUS_MASK
;
5609 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5610 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5611 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5616 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5617 PhyData
[0].ControllerDevHandle
);
5618 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5619 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5620 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5621 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5623 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5624 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5625 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5626 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5629 ioc
->sas_hba
.enclosure_handle
=
5630 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5631 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5633 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5634 ioc
->name
, ioc
->sas_hba
.handle
,
5635 (unsigned long long) ioc
->sas_hba
.sas_address
,
5636 ioc
->sas_hba
.num_phys
) ;
5638 if (ioc
->sas_hba
.enclosure_handle
) {
5639 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5640 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5641 ioc
->sas_hba
.enclosure_handle
)))
5642 ioc
->sas_hba
.enclosure_logical_id
=
5643 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5647 kfree(sas_iounit_pg1
);
5648 kfree(sas_iounit_pg0
);
5652 * _scsih_expander_add - creating expander object
5653 * @ioc: per adapter object
5654 * @handle: expander handle
5656 * Creating expander object, stored in ioc->sas_expander_list.
5658 * Return 0 for success, else error.
5661 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5663 struct _sas_node
*sas_expander
;
5664 Mpi2ConfigReply_t mpi_reply
;
5665 Mpi2ExpanderPage0_t expander_pg0
;
5666 Mpi2ExpanderPage1_t expander_pg1
;
5667 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5670 u64 sas_address
, sas_address_parent
= 0;
5672 unsigned long flags
;
5673 struct _sas_port
*mpt3sas_port
= NULL
;
5680 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5683 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5684 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5685 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5686 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5690 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5691 MPI2_IOCSTATUS_MASK
;
5692 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5693 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5694 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5698 /* handle out of order topology events */
5699 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5700 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5702 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5703 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5706 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5707 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5708 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5709 sas_address_parent
);
5710 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5711 if (!sas_expander
) {
5712 rc
= _scsih_expander_add(ioc
, parent_handle
);
5718 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5719 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5720 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5722 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5727 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5729 if (!sas_expander
) {
5730 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5731 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5735 sas_expander
->handle
= handle
;
5736 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5737 sas_expander
->sas_address_parent
= sas_address_parent
;
5738 sas_expander
->sas_address
= sas_address
;
5740 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5741 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5742 handle
, parent_handle
, (unsigned long long)
5743 sas_expander
->sas_address
, sas_expander
->num_phys
);
5745 if (!sas_expander
->num_phys
)
5747 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5748 sizeof(struct _sas_phy
), GFP_KERNEL
);
5749 if (!sas_expander
->phy
) {
5750 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5751 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5756 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5757 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5758 sas_address_parent
);
5759 if (!mpt3sas_port
) {
5760 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5761 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5765 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5767 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5768 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5769 &expander_pg1
, i
, handle
))) {
5770 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5771 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5775 sas_expander
->phy
[i
].handle
= handle
;
5776 sas_expander
->phy
[i
].phy_id
= i
;
5778 if ((mpt3sas_transport_add_expander_phy(ioc
,
5779 &sas_expander
->phy
[i
], expander_pg1
,
5780 sas_expander
->parent_dev
))) {
5781 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5782 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5788 if (sas_expander
->enclosure_handle
) {
5789 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5790 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5791 sas_expander
->enclosure_handle
)))
5792 sas_expander
->enclosure_logical_id
=
5793 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5796 _scsih_expander_node_add(ioc
, sas_expander
);
5802 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5803 sas_address_parent
);
5804 kfree(sas_expander
);
5809 * mpt3sas_expander_remove - removing expander object
5810 * @ioc: per adapter object
5811 * @sas_address: expander sas_address
5816 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5818 struct _sas_node
*sas_expander
;
5819 unsigned long flags
;
5821 if (ioc
->shost_recovery
)
5824 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5825 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5827 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5829 _scsih_expander_node_remove(ioc
, sas_expander
);
5833 * _scsih_done - internal SCSI_IO callback handler.
5834 * @ioc: per adapter object
5835 * @smid: system request message index
5836 * @msix_index: MSIX table index supplied by the OS
5837 * @reply: reply message frame(lower 32bit addr)
5839 * Callback handler when sending internal generated SCSI_IO.
5840 * The callback index passed is `ioc->scsih_cb_idx`
5842 * Return 1 meaning mf should be freed from _base_interrupt
5843 * 0 means the mf is freed from this function.
5846 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5848 MPI2DefaultReply_t
*mpi_reply
;
5850 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5851 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5853 if (ioc
->scsih_cmds
.smid
!= smid
)
5855 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5857 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5858 mpi_reply
->MsgLength
*4);
5859 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5861 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5862 complete(&ioc
->scsih_cmds
.done
);
5869 #define MPT3_MAX_LUNS (255)
5873 * _scsih_check_access_status - check access flags
5874 * @ioc: per adapter object
5875 * @sas_address: sas address
5876 * @handle: sas device handle
5877 * @access_flags: errors returned during discovery of the device
5879 * Return 0 for success, else failure
5882 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5883 u16 handle
, u8 access_status
)
5888 switch (access_status
) {
5889 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5890 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5893 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5894 desc
= "sata capability failed";
5896 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5897 desc
= "sata affiliation conflict";
5899 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5900 desc
= "route not addressable";
5902 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5903 desc
= "smp error not addressable";
5905 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5906 desc
= "device blocked";
5908 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5909 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5910 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5911 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5912 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5913 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5914 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5915 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5916 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5917 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5918 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5919 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5920 desc
= "sata initialization failed";
5931 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5932 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5937 * _scsih_get_enclosure_logicalid_chassis_slot - get device's
5938 * EnclosureLogicalID and ChassisSlot information.
5939 * @ioc: per adapter object
5940 * @sas_device_pg0: SAS device page0
5941 * @sas_device: per sas device object
5946 _scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER
*ioc
,
5947 Mpi2SasDevicePage0_t
*sas_device_pg0
, struct _sas_device
*sas_device
)
5949 Mpi2ConfigReply_t mpi_reply
;
5950 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5952 if (!sas_device_pg0
|| !sas_device
)
5955 sas_device
->enclosure_handle
=
5956 le16_to_cpu(sas_device_pg0
->EnclosureHandle
);
5957 sas_device
->is_chassis_slot_valid
= 0;
5959 if (!le16_to_cpu(sas_device_pg0
->EnclosureHandle
))
5962 if (mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5963 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5964 le16_to_cpu(sas_device_pg0
->EnclosureHandle
))) {
5966 "Enclosure Pg0 read failed for handle(0x%04x)\n",
5967 ioc
->name
, le16_to_cpu(sas_device_pg0
->EnclosureHandle
));
5971 sas_device
->enclosure_logical_id
=
5972 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5974 if (le16_to_cpu(enclosure_pg0
.Flags
) &
5975 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
5976 sas_device
->is_chassis_slot_valid
= 1;
5977 sas_device
->chassis_slot
= enclosure_pg0
.ChassisSlot
;
5983 * _scsih_check_device - checking device responsiveness
5984 * @ioc: per adapter object
5985 * @parent_sas_address: sas address of parent expander or sas host
5986 * @handle: attached device handle
5987 * @phy_numberv: phy number
5988 * @link_rate: new link rate
5993 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5994 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5996 Mpi2ConfigReply_t mpi_reply
;
5997 Mpi2SasDevicePage0_t sas_device_pg0
;
5998 struct _sas_device
*sas_device
;
6000 unsigned long flags
;
6002 struct scsi_target
*starget
;
6003 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6006 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6007 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6010 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6011 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6014 /* wide port handling ~ we need only handle device once for the phy that
6015 * is matched in sas device page zero
6017 if (phy_number
!= sas_device_pg0
.PhyNum
)
6020 /* check if this is end device */
6021 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6022 if (!(_scsih_is_end_device(device_info
)))
6025 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6026 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6027 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6033 if (unlikely(sas_device
->handle
!= handle
)) {
6034 starget
= sas_device
->starget
;
6035 sas_target_priv_data
= starget
->hostdata
;
6036 starget_printk(KERN_INFO
, starget
,
6037 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6038 sas_device
->handle
, handle
);
6039 sas_target_priv_data
->handle
= handle
;
6040 sas_device
->handle
= handle
;
6041 if (le16_to_cpu(sas_device_pg0
.Flags
) &
6042 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6043 sas_device
->enclosure_level
=
6044 sas_device_pg0
.EnclosureLevel
;
6045 memcpy(sas_device
->connector_name
,
6046 sas_device_pg0
.ConnectorName
, 4);
6047 sas_device
->connector_name
[4] = '\0';
6049 sas_device
->enclosure_level
= 0;
6050 sas_device
->connector_name
[0] = '\0';
6053 _scsih_get_enclosure_logicalid_chassis_slot(ioc
,
6054 &sas_device_pg0
, sas_device
);
6057 /* check if device is present */
6058 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6059 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6061 "device is not present handle(0x%04x), flags!!!\n",
6066 /* check if there were any issues with discovery */
6067 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6068 sas_device_pg0
.AccessStatus
))
6071 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6072 _scsih_ublock_io_device(ioc
, sas_address
);
6075 sas_device_put(sas_device
);
6079 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6081 sas_device_put(sas_device
);
6085 * _scsih_add_device - creating sas device object
6086 * @ioc: per adapter object
6087 * @handle: sas device handle
6088 * @phy_num: phy number end device attached to
6089 * @is_pd: is this hidden raid component
6091 * Creating end device object, stored in ioc->sas_device_list.
6093 * Returns 0 for success, non-zero for failure.
6096 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
6099 Mpi2ConfigReply_t mpi_reply
;
6100 Mpi2SasDevicePage0_t sas_device_pg0
;
6101 Mpi2SasEnclosurePage0_t enclosure_pg0
;
6102 struct _sas_device
*sas_device
;
6106 int encl_pg0_rc
= -1;
6108 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6109 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6110 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6111 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6115 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6116 MPI2_IOCSTATUS_MASK
;
6117 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6118 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6119 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6123 /* check if this is end device */
6124 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6125 if (!(_scsih_is_end_device(device_info
)))
6127 set_bit(handle
, ioc
->pend_os_device_add
);
6128 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6130 /* check if device is present */
6131 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6132 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6133 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
6138 /* check if there were any issues with discovery */
6139 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6140 sas_device_pg0
.AccessStatus
))
6143 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
6146 clear_bit(handle
, ioc
->pend_os_device_add
);
6147 sas_device_put(sas_device
);
6151 if (sas_device_pg0
.EnclosureHandle
) {
6152 encl_pg0_rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
6153 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
6154 sas_device_pg0
.EnclosureHandle
);
6157 "Enclosure Pg0 read failed for handle(0x%04x)\n",
6158 ioc
->name
, sas_device_pg0
.EnclosureHandle
);
6161 sas_device
= kzalloc(sizeof(struct _sas_device
),
6164 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6165 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6169 kref_init(&sas_device
->refcount
);
6170 sas_device
->handle
= handle
;
6171 if (_scsih_get_sas_address(ioc
,
6172 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
6173 &sas_device
->sas_address_parent
) != 0)
6174 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6175 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6176 sas_device
->enclosure_handle
=
6177 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
6178 if (sas_device
->enclosure_handle
!= 0)
6180 le16_to_cpu(sas_device_pg0
.Slot
);
6181 sas_device
->device_info
= device_info
;
6182 sas_device
->sas_address
= sas_address
;
6183 sas_device
->phy
= sas_device_pg0
.PhyNum
;
6184 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
6185 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6187 if (le16_to_cpu(sas_device_pg0
.Flags
)
6188 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6189 sas_device
->enclosure_level
=
6190 sas_device_pg0
.EnclosureLevel
;
6191 memcpy(sas_device
->connector_name
,
6192 sas_device_pg0
.ConnectorName
, 4);
6193 sas_device
->connector_name
[4] = '\0';
6195 sas_device
->enclosure_level
= 0;
6196 sas_device
->connector_name
[0] = '\0';
6199 /* get enclosure_logical_id & chassis_slot */
6200 sas_device
->is_chassis_slot_valid
= 0;
6201 if (encl_pg0_rc
== 0) {
6202 sas_device
->enclosure_logical_id
=
6203 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
6205 if (le16_to_cpu(enclosure_pg0
.Flags
) &
6206 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6207 sas_device
->is_chassis_slot_valid
= 1;
6208 sas_device
->chassis_slot
=
6209 enclosure_pg0
.ChassisSlot
;
6213 /* get device name */
6214 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
6216 if (ioc
->wait_for_discovery_to_complete
)
6217 _scsih_sas_device_init_add(ioc
, sas_device
);
6219 _scsih_sas_device_add(ioc
, sas_device
);
6221 sas_device_put(sas_device
);
6226 * _scsih_remove_device - removing sas device object
6227 * @ioc: per adapter object
6228 * @sas_device_delete: the sas_device object
6233 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
6234 struct _sas_device
*sas_device
)
6236 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6238 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
6239 (sas_device
->pfa_led_on
)) {
6240 _scsih_turn_off_pfa_led(ioc
, sas_device
);
6241 sas_device
->pfa_led_on
= 0;
6244 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6245 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6246 ioc
->name
, __func__
,
6247 sas_device
->handle
, (unsigned long long)
6248 sas_device
->sas_address
));
6250 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6253 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6254 sas_target_priv_data
= sas_device
->starget
->hostdata
;
6255 sas_target_priv_data
->deleted
= 1;
6256 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
6257 sas_target_priv_data
->handle
=
6258 MPT3SAS_INVALID_DEVICE_HANDLE
;
6261 if (!ioc
->hide_drives
)
6262 mpt3sas_transport_port_remove(ioc
,
6263 sas_device
->sas_address
,
6264 sas_device
->sas_address_parent
);
6267 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6268 ioc
->name
, sas_device
->handle
,
6269 (unsigned long long) sas_device
->sas_address
);
6271 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
6273 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6274 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6275 ioc
->name
, __func__
,
6276 sas_device
->handle
, (unsigned long long)
6277 sas_device
->sas_address
));
6278 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6283 * _scsih_sas_topology_change_event_debug - debug for topology event
6284 * @ioc: per adapter object
6285 * @event_data: event data payload
6289 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6290 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
6296 char *status_str
= NULL
;
6297 u8 link_rate
, prev_link_rate
;
6299 switch (event_data
->ExpStatus
) {
6300 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
6303 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
6304 status_str
= "remove";
6306 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
6308 status_str
= "responding";
6310 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
6311 status_str
= "remove delay";
6314 status_str
= "unknown status";
6317 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
6318 ioc
->name
, status_str
);
6319 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6320 "start_phy(%02d), count(%d)\n",
6321 le16_to_cpu(event_data
->ExpanderDevHandle
),
6322 le16_to_cpu(event_data
->EnclosureHandle
),
6323 event_data
->StartPhyNum
, event_data
->NumEntries
);
6324 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6325 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6328 phy_number
= event_data
->StartPhyNum
+ i
;
6329 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6330 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6331 switch (reason_code
) {
6332 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6333 status_str
= "target add";
6335 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6336 status_str
= "target remove";
6338 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
6339 status_str
= "delay target remove";
6341 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6342 status_str
= "link rate change";
6344 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
6345 status_str
= "target responding";
6348 status_str
= "unknown";
6351 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6352 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6353 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6354 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
6355 handle
, status_str
, link_rate
, prev_link_rate
);
6361 * _scsih_sas_topology_change_event - handle topology changes
6362 * @ioc: per adapter object
6363 * @fw_event: The fw_event_work object
6368 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6369 struct fw_event_work
*fw_event
)
6372 u16 parent_handle
, handle
;
6374 u8 phy_number
, max_phys
;
6375 struct _sas_node
*sas_expander
;
6377 unsigned long flags
;
6378 u8 link_rate
, prev_link_rate
;
6379 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
6380 (Mpi2EventDataSasTopologyChangeList_t
*)
6381 fw_event
->event_data
;
6383 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6384 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
6386 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
6389 if (!ioc
->sas_hba
.num_phys
)
6390 _scsih_sas_host_add(ioc
);
6392 _scsih_sas_host_refresh(ioc
);
6394 if (fw_event
->ignore
) {
6395 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6396 "ignoring expander event\n", ioc
->name
));
6400 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
6402 /* handle expander add */
6403 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
6404 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
6407 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6408 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
6411 sas_address
= sas_expander
->sas_address
;
6412 max_phys
= sas_expander
->num_phys
;
6413 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
6414 sas_address
= ioc
->sas_hba
.sas_address
;
6415 max_phys
= ioc
->sas_hba
.num_phys
;
6417 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6420 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6422 /* handle siblings events */
6423 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6424 if (fw_event
->ignore
) {
6425 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6426 "ignoring expander event\n", ioc
->name
));
6429 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6431 phy_number
= event_data
->StartPhyNum
+ i
;
6432 if (phy_number
>= max_phys
)
6434 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6435 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6436 if ((event_data
->PHY
[i
].PhyStatus
&
6437 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
6438 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
6440 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6443 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6444 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6445 switch (reason_code
) {
6446 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6448 if (ioc
->shost_recovery
)
6451 if (link_rate
== prev_link_rate
)
6454 mpt3sas_transport_update_links(ioc
, sas_address
,
6455 handle
, phy_number
, link_rate
);
6457 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
6460 _scsih_check_device(ioc
, sas_address
, handle
,
6461 phy_number
, link_rate
);
6463 if (!test_bit(handle
, ioc
->pend_os_device_add
))
6467 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6469 if (ioc
->shost_recovery
)
6472 mpt3sas_transport_update_links(ioc
, sas_address
,
6473 handle
, phy_number
, link_rate
);
6475 _scsih_add_device(ioc
, handle
, phy_number
, 0);
6478 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6480 _scsih_device_remove_by_handle(ioc
, handle
);
6485 /* handle expander removal */
6486 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
6488 mpt3sas_expander_remove(ioc
, sas_address
);
6494 * _scsih_sas_device_status_change_event_debug - debug for device event
6495 * @event_data: event data payload
6501 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6502 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
6504 char *reason_str
= NULL
;
6506 switch (event_data
->ReasonCode
) {
6507 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
6508 reason_str
= "smart data";
6510 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
6511 reason_str
= "unsupported device discovered";
6513 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
6514 reason_str
= "internal device reset";
6516 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
6517 reason_str
= "internal task abort";
6519 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
6520 reason_str
= "internal task abort set";
6522 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
6523 reason_str
= "internal clear task set";
6525 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
6526 reason_str
= "internal query task";
6528 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
6529 reason_str
= "sata init failure";
6531 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
6532 reason_str
= "internal device reset complete";
6534 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
6535 reason_str
= "internal task abort complete";
6537 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
6538 reason_str
= "internal async notification";
6540 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
6541 reason_str
= "expander reduced functionality";
6543 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
6544 reason_str
= "expander reduced functionality complete";
6547 reason_str
= "unknown reason";
6550 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
6551 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6552 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
6553 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
6554 le16_to_cpu(event_data
->TaskTag
));
6555 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
6556 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
6557 event_data
->ASC
, event_data
->ASCQ
);
6562 * _scsih_sas_device_status_change_event - handle device status change
6563 * @ioc: per adapter object
6564 * @fw_event: The fw_event_work object
6570 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6571 struct fw_event_work
*fw_event
)
6573 struct MPT3SAS_TARGET
*target_priv_data
;
6574 struct _sas_device
*sas_device
;
6576 unsigned long flags
;
6577 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
6578 (Mpi2EventDataSasDeviceStatusChange_t
*)
6579 fw_event
->event_data
;
6581 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6582 _scsih_sas_device_status_change_event_debug(ioc
,
6585 /* In MPI Revision K (0xC), the internal device reset complete was
6586 * implemented, so avoid setting tm_busy flag for older firmware.
6588 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
6591 if (event_data
->ReasonCode
!=
6592 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
6593 event_data
->ReasonCode
!=
6594 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
6597 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6598 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6599 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6602 if (!sas_device
|| !sas_device
->starget
)
6605 target_priv_data
= sas_device
->starget
->hostdata
;
6606 if (!target_priv_data
)
6609 if (event_data
->ReasonCode
==
6610 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6611 target_priv_data
->tm_busy
= 1;
6613 target_priv_data
->tm_busy
= 0;
6617 sas_device_put(sas_device
);
6619 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6624 * _scsih_check_pcie_access_status - check access flags
6625 * @ioc: per adapter object
6627 * @handle: sas device handle
6628 * @access_flags: errors returned during discovery of the device
6630 * Return 0 for success, else failure
6633 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6634 u16 handle
, u8 access_status
)
6639 switch (access_status
) {
6640 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS
:
6641 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION
:
6644 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED
:
6645 desc
= "PCIe device capability failed";
6647 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
:
6648 desc
= "PCIe device blocked";
6650 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED
:
6651 desc
= "PCIe device mem space access failed";
6653 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE
:
6654 desc
= "PCIe device unsupported";
6656 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED
:
6657 desc
= "PCIe device MSIx Required";
6659 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX
:
6660 desc
= "PCIe device init fail max";
6662 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN
:
6663 desc
= "PCIe device status unknown";
6665 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT
:
6666 desc
= "nvme ready timeout";
6668 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED
:
6669 desc
= "nvme device configuration unsupported";
6671 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED
:
6672 desc
= "nvme identify failed";
6674 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED
:
6675 desc
= "nvme qconfig failed";
6677 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED
:
6678 desc
= "nvme qcreation failed";
6680 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED
:
6681 desc
= "nvme eventcfg failed";
6683 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED
:
6684 desc
= "nvme get feature stat failed";
6686 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT
:
6687 desc
= "nvme idle timeout";
6689 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS
:
6690 desc
= "nvme failure status";
6694 " NVMe discovery error(0x%02x): wwid(0x%016llx),"
6695 "handle(0x%04x)\n", ioc
->name
, access_status
,
6696 (unsigned long long)wwid
, handle
);
6704 "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6706 (unsigned long long)wwid
, handle
);
6711 * _scsih_pcie_device_remove_from_sml - removing pcie device
6712 * from SML and free up associated memory
6713 * @ioc: per adapter object
6714 * @pcie_device: the pcie_device object
6719 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
6720 struct _pcie_device
*pcie_device
)
6722 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6724 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6725 "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6726 pcie_device
->handle
, (unsigned long long)
6727 pcie_device
->wwid
));
6728 if (pcie_device
->enclosure_handle
!= 0)
6729 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6730 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6731 ioc
->name
, __func__
,
6732 (unsigned long long)pcie_device
->enclosure_logical_id
,
6733 pcie_device
->slot
));
6734 if (pcie_device
->connector_name
[0] != '\0')
6735 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6736 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
6737 ioc
->name
, __func__
,
6738 pcie_device
->enclosure_level
,
6739 pcie_device
->connector_name
));
6741 if (pcie_device
->starget
&& pcie_device
->starget
->hostdata
) {
6742 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
6743 sas_target_priv_data
->deleted
= 1;
6744 _scsih_ublock_io_device(ioc
, pcie_device
->wwid
);
6745 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
6749 "removing handle(0x%04x), wwid (0x%016llx)\n",
6750 ioc
->name
, pcie_device
->handle
,
6751 (unsigned long long) pcie_device
->wwid
);
6752 if (pcie_device
->enclosure_handle
!= 0)
6754 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6756 (unsigned long long)pcie_device
->enclosure_logical_id
,
6758 if (pcie_device
->connector_name
[0] != '\0')
6760 "removing: enclosure level(0x%04x), connector name( %s)\n",
6761 ioc
->name
, pcie_device
->enclosure_level
,
6762 pcie_device
->connector_name
);
6764 if (pcie_device
->starget
)
6765 scsi_remove_target(&pcie_device
->starget
->dev
);
6766 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6767 "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
6768 pcie_device
->handle
, (unsigned long long)
6769 pcie_device
->wwid
));
6770 if (pcie_device
->enclosure_handle
!= 0)
6771 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6772 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6773 ioc
->name
, __func__
,
6774 (unsigned long long)pcie_device
->enclosure_logical_id
,
6775 pcie_device
->slot
));
6776 if (pcie_device
->connector_name
[0] != '\0')
6777 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6778 "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6779 ioc
->name
, __func__
, pcie_device
->enclosure_level
,
6780 pcie_device
->connector_name
));
6782 kfree(pcie_device
->serial_number
);
6787 * _scsih_pcie_check_device - checking device responsiveness
6788 * @ioc: per adapter object
6789 * @handle: attached device handle
6794 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6796 Mpi2ConfigReply_t mpi_reply
;
6797 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6799 struct _pcie_device
*pcie_device
;
6801 unsigned long flags
;
6802 struct scsi_target
*starget
;
6803 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6806 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6807 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6810 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6811 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6814 /* check if this is end device */
6815 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6816 if (!(_scsih_is_nvme_device(device_info
)))
6819 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6820 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
6821 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6824 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6828 if (unlikely(pcie_device
->handle
!= handle
)) {
6829 starget
= pcie_device
->starget
;
6830 sas_target_priv_data
= starget
->hostdata
;
6831 starget_printk(KERN_INFO
, starget
,
6832 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6833 pcie_device
->handle
, handle
);
6834 sas_target_priv_data
->handle
= handle
;
6835 pcie_device
->handle
= handle
;
6837 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6838 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6839 pcie_device
->enclosure_level
=
6840 pcie_device_pg0
.EnclosureLevel
;
6841 memcpy(&pcie_device
->connector_name
[0],
6842 &pcie_device_pg0
.ConnectorName
[0], 4);
6844 pcie_device
->enclosure_level
= 0;
6845 pcie_device
->connector_name
[0] = '\0';
6849 /* check if device is present */
6850 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6851 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6853 "device is not present handle(0x%04x), flags!!!\n",
6855 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6856 pcie_device_put(pcie_device
);
6860 /* check if there were any issues with discovery */
6861 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6862 pcie_device_pg0
.AccessStatus
)) {
6863 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6864 pcie_device_put(pcie_device
);
6868 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6869 pcie_device_put(pcie_device
);
6871 _scsih_ublock_io_device(ioc
, wwid
);
6877 * _scsih_pcie_add_device - creating pcie device object
6878 * @ioc: per adapter object
6879 * @handle: pcie device handle
6881 * Creating end device object, stored in ioc->pcie_device_list.
6883 * Return 1 means queue the event later, 0 means complete the event
6886 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6888 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6889 Mpi26PCIeDevicePage2_t pcie_device_pg2
;
6890 Mpi2ConfigReply_t mpi_reply
;
6891 Mpi2SasEnclosurePage0_t enclosure_pg0
;
6892 struct _pcie_device
*pcie_device
;
6893 u32 pcie_device_type
;
6897 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6898 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6899 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6900 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6903 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6904 MPI2_IOCSTATUS_MASK
;
6905 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6907 "failure at %s:%d/%s()!\n",
6908 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6912 set_bit(handle
, ioc
->pend_os_device_add
);
6913 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6915 /* check if device is present */
6916 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6917 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6919 "device is not present handle(0x04%x)!!!\n",
6924 /* check if there were any issues with discovery */
6925 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6926 pcie_device_pg0
.AccessStatus
))
6929 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
6932 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6934 clear_bit(handle
, ioc
->pend_os_device_add
);
6935 pcie_device_put(pcie_device
);
6939 pcie_device
= kzalloc(sizeof(struct _pcie_device
), GFP_KERNEL
);
6941 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6942 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6946 kref_init(&pcie_device
->refcount
);
6947 pcie_device
->id
= ioc
->pcie_target_id
++;
6948 pcie_device
->channel
= PCIE_CHANNEL
;
6949 pcie_device
->handle
= handle
;
6950 pcie_device
->device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6951 pcie_device
->wwid
= wwid
;
6952 pcie_device
->port_num
= pcie_device_pg0
.PortNum
;
6953 pcie_device
->fast_path
= (le32_to_cpu(pcie_device_pg0
.Flags
) &
6954 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6955 pcie_device_type
= pcie_device
->device_info
&
6956 MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
;
6958 pcie_device
->enclosure_handle
=
6959 le16_to_cpu(pcie_device_pg0
.EnclosureHandle
);
6960 if (pcie_device
->enclosure_handle
!= 0)
6961 pcie_device
->slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
6963 if (le16_to_cpu(pcie_device_pg0
.Flags
) &
6964 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6965 pcie_device
->enclosure_level
= pcie_device_pg0
.EnclosureLevel
;
6966 memcpy(&pcie_device
->connector_name
[0],
6967 &pcie_device_pg0
.ConnectorName
[0], 4);
6969 pcie_device
->enclosure_level
= 0;
6970 pcie_device
->connector_name
[0] = '\0';
6973 /* get enclosure_logical_id */
6974 if (pcie_device
->enclosure_handle
&&
6975 !(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
6976 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
6977 pcie_device
->enclosure_handle
)))
6978 pcie_device
->enclosure_logical_id
=
6979 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
6981 /* TODO -- Add device name once FW supports it */
6982 if (mpt3sas_config_get_pcie_device_pg2(ioc
, &mpi_reply
,
6983 &pcie_device_pg2
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)) {
6984 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6985 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6990 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6991 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6992 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6993 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6997 pcie_device
->nvme_mdts
=
6998 le32_to_cpu(pcie_device_pg2
.MaximumDataTransferSize
);
7000 if (ioc
->wait_for_discovery_to_complete
)
7001 _scsih_pcie_device_init_add(ioc
, pcie_device
);
7003 _scsih_pcie_device_add(ioc
, pcie_device
);
7005 pcie_device_put(pcie_device
);
7010 * _scsih_pcie_topology_change_event_debug - debug for topology
7012 * @ioc: per adapter object
7013 * @event_data: event data payload
7017 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7018 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
7024 char *status_str
= NULL
;
7025 u8 link_rate
, prev_link_rate
;
7027 switch (event_data
->SwitchStatus
) {
7028 case MPI26_EVENT_PCIE_TOPO_SS_ADDED
:
7031 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING
:
7032 status_str
= "remove";
7034 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
:
7036 status_str
= "responding";
7038 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
:
7039 status_str
= "remove delay";
7042 status_str
= "unknown status";
7045 pr_info(MPT3SAS_FMT
"pcie topology change: (%s)\n",
7046 ioc
->name
, status_str
);
7047 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
7048 "start_port(%02d), count(%d)\n",
7049 le16_to_cpu(event_data
->SwitchDevHandle
),
7050 le16_to_cpu(event_data
->EnclosureHandle
),
7051 event_data
->StartPortNum
, event_data
->NumEntries
);
7052 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7054 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7057 port_number
= event_data
->StartPortNum
+ i
;
7058 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7059 switch (reason_code
) {
7060 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7061 status_str
= "target add";
7063 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7064 status_str
= "target remove";
7066 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
:
7067 status_str
= "delay target remove";
7069 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7070 status_str
= "link rate change";
7072 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
:
7073 status_str
= "target responding";
7076 status_str
= "unknown";
7079 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
&
7080 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7081 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
&
7082 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7083 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
7084 " link rate: new(0x%02x), old(0x%02x)\n", port_number
,
7085 handle
, status_str
, link_rate
, prev_link_rate
);
7090 * _scsih_pcie_topology_change_event - handle PCIe topology
7092 * @ioc: per adapter object
7093 * @fw_event: The fw_event_work object
7098 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7099 struct fw_event_work
*fw_event
)
7104 u8 link_rate
, prev_link_rate
;
7105 unsigned long flags
;
7108 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
=
7109 (Mpi26EventDataPCIeTopologyChangeList_t
*) fw_event
->event_data
;
7110 struct _pcie_device
*pcie_device
;
7112 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7113 _scsih_pcie_topology_change_event_debug(ioc
, event_data
);
7115 if (ioc
->shost_recovery
|| ioc
->remove_host
||
7116 ioc
->pci_error_recovery
)
7119 if (fw_event
->ignore
) {
7120 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"ignoring switch event\n",
7125 /* handle siblings events */
7126 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7127 if (fw_event
->ignore
) {
7128 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7129 "ignoring switch event\n", ioc
->name
));
7132 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7134 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7136 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7140 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
7141 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7142 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
7143 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7145 switch (reason_code
) {
7146 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7147 if (ioc
->shost_recovery
)
7149 if (link_rate
== prev_link_rate
)
7151 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7154 _scsih_pcie_check_device(ioc
, handle
);
7156 /* This code after this point handles the test case
7157 * where a device has been added, however its returning
7158 * BUSY for sometime. Then before the Device Missing
7159 * Delay expires and the device becomes READY, the
7160 * device is removed and added back.
7162 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7163 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
7164 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7167 pcie_device_put(pcie_device
);
7171 if (!test_bit(handle
, ioc
->pend_os_device_add
))
7174 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7175 "handle(0x%04x) device not found: convert "
7176 "event to a device add\n", ioc
->name
, handle
));
7177 event_data
->PortEntry
[i
].PortStatus
&= 0xF0;
7178 event_data
->PortEntry
[i
].PortStatus
|=
7179 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
;
7180 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7181 if (ioc
->shost_recovery
)
7183 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7186 rc
= _scsih_pcie_add_device(ioc
, handle
);
7188 /* mark entry vacant */
7189 /* TODO This needs to be reviewed and fixed,
7190 * we dont have an entry
7191 * to make an event void like vacant
7193 event_data
->PortEntry
[i
].PortStatus
|=
7194 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
;
7197 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7198 _scsih_pcie_device_remove_by_handle(ioc
, handle
);
7202 return requeue_event
;
7206 * _scsih_pcie_device_status_change_event_debug - debug for
7208 * @event_data: event data payload
7214 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7215 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
)
7217 char *reason_str
= NULL
;
7219 switch (event_data
->ReasonCode
) {
7220 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
:
7221 reason_str
= "smart data";
7223 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED
:
7224 reason_str
= "unsupported device discovered";
7226 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
:
7227 reason_str
= "internal device reset";
7229 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL
:
7230 reason_str
= "internal task abort";
7232 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
7233 reason_str
= "internal task abort set";
7235 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
7236 reason_str
= "internal clear task set";
7238 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL
:
7239 reason_str
= "internal query task";
7241 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE
:
7242 reason_str
= "device init failure";
7244 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
7245 reason_str
= "internal device reset complete";
7247 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
7248 reason_str
= "internal task abort complete";
7250 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION
:
7251 reason_str
= "internal async notification";
7254 reason_str
= "unknown reason";
7258 pr_info(MPT3SAS_FMT
"PCIE device status change: (%s)\n"
7259 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7260 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
7261 (unsigned long long)le64_to_cpu(event_data
->WWID
),
7262 le16_to_cpu(event_data
->TaskTag
));
7263 if (event_data
->ReasonCode
== MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
)
7264 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
7265 event_data
->ASC
, event_data
->ASCQ
);
7270 * _scsih_pcie_device_status_change_event - handle device status
7272 * @ioc: per adapter object
7273 * @fw_event: The fw_event_work object
7279 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7280 struct fw_event_work
*fw_event
)
7282 struct MPT3SAS_TARGET
*target_priv_data
;
7283 struct _pcie_device
*pcie_device
;
7285 unsigned long flags
;
7286 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
=
7287 (Mpi26EventDataPCIeDeviceStatusChange_t
*)fw_event
->event_data
;
7288 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7289 _scsih_pcie_device_status_change_event_debug(ioc
,
7292 if (event_data
->ReasonCode
!=
7293 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
7294 event_data
->ReasonCode
!=
7295 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
7298 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7299 wwid
= le64_to_cpu(event_data
->WWID
);
7300 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
7302 if (!pcie_device
|| !pcie_device
->starget
)
7305 target_priv_data
= pcie_device
->starget
->hostdata
;
7306 if (!target_priv_data
)
7309 if (event_data
->ReasonCode
==
7310 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
)
7311 target_priv_data
->tm_busy
= 1;
7313 target_priv_data
->tm_busy
= 0;
7316 pcie_device_put(pcie_device
);
7318 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7322 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7324 * @ioc: per adapter object
7325 * @event_data: event data payload
7331 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7332 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
7334 char *reason_str
= NULL
;
7336 switch (event_data
->ReasonCode
) {
7337 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7338 reason_str
= "enclosure add";
7340 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7341 reason_str
= "enclosure remove";
7344 reason_str
= "unknown reason";
7348 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
7349 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
7350 " number slots(%d)\n", ioc
->name
, reason_str
,
7351 le16_to_cpu(event_data
->EnclosureHandle
),
7352 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
7353 le16_to_cpu(event_data
->StartSlot
));
7357 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7358 * @ioc: per adapter object
7359 * @fw_event: The fw_event_work object
7365 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7366 struct fw_event_work
*fw_event
)
7368 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7369 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
7370 (Mpi2EventDataSasEnclDevStatusChange_t
*)
7371 fw_event
->event_data
);
7375 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7376 * @ioc: per adapter object
7377 * @fw_event: The fw_event_work object
7383 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
7384 struct fw_event_work
*fw_event
)
7386 struct scsi_cmnd
*scmd
;
7387 struct scsi_device
*sdev
;
7390 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7391 u32 termination_count
;
7393 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
7394 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
7395 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7396 fw_event
->event_data
;
7398 unsigned long flags
;
7401 u8 task_abort_retries
;
7403 mutex_lock(&ioc
->tm_cmds
.mutex
);
7405 "%s: enter: phy number(%d), width(%d)\n",
7406 ioc
->name
, __func__
, event_data
->PhyNum
,
7407 event_data
->PortWidth
);
7409 _scsih_block_io_all_device(ioc
);
7411 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7412 mpi_reply
= ioc
->tm_cmds
.reply
;
7413 broadcast_aen_retry
:
7415 /* sanity checks for retrying this loop */
7416 if (max_retries
++ == 5) {
7417 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
7418 ioc
->name
, __func__
));
7420 } else if (max_retries
> 1)
7421 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
7422 ioc
->name
, __func__
, max_retries
- 1));
7424 termination_count
= 0;
7426 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
7427 if (ioc
->shost_recovery
)
7429 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
7432 sdev
= scmd
->device
;
7433 sas_device_priv_data
= sdev
->hostdata
;
7434 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
7436 /* skip hidden raid components */
7437 if (sas_device_priv_data
->sas_target
->flags
&
7438 MPT_TARGET_FLAGS_RAID_COMPONENT
)
7441 if (sas_device_priv_data
->sas_target
->flags
&
7442 MPT_TARGET_FLAGS_VOLUME
)
7445 handle
= sas_device_priv_data
->sas_target
->handle
;
7446 lun
= sas_device_priv_data
->lun
;
7449 if (ioc
->shost_recovery
)
7452 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7453 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
7454 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
7456 sdev_printk(KERN_WARNING
, sdev
,
7457 "mpt3sas_scsih_issue_tm: FAILED when sending "
7458 "QUERY_TASK: scmd(%p)\n", scmd
);
7459 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7460 goto broadcast_aen_retry
;
7462 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
7463 & MPI2_IOCSTATUS_MASK
;
7464 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7465 sdev_printk(KERN_WARNING
, sdev
,
7466 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7468 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7469 goto broadcast_aen_retry
;
7472 /* see if IO is still owned by IOC and target */
7473 if (mpi_reply
->ResponseCode
==
7474 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
7475 mpi_reply
->ResponseCode
==
7476 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
7477 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7480 task_abort_retries
= 0;
7482 if (task_abort_retries
++ == 60) {
7483 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7484 "%s: ABORT_TASK: giving up\n", ioc
->name
,
7486 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7487 goto broadcast_aen_retry
;
7490 if (ioc
->shost_recovery
)
7493 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
7494 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
,
7497 sdev_printk(KERN_WARNING
, sdev
,
7498 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7499 "scmd(%p)\n", scmd
);
7503 if (task_abort_retries
> 1)
7504 sdev_printk(KERN_WARNING
, sdev
,
7505 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7507 task_abort_retries
- 1, scmd
);
7509 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
7510 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7513 if (ioc
->broadcast_aen_pending
) {
7514 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7515 "%s: loop back due to pending AEN\n",
7516 ioc
->name
, __func__
));
7517 ioc
->broadcast_aen_pending
= 0;
7518 goto broadcast_aen_retry
;
7522 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7525 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7526 "%s - exit, query_count = %d termination_count = %d\n",
7527 ioc
->name
, __func__
, query_count
, termination_count
));
7529 ioc
->broadcast_aen_busy
= 0;
7530 if (!ioc
->shost_recovery
)
7531 _scsih_ublock_io_all_device(ioc
);
7532 mutex_unlock(&ioc
->tm_cmds
.mutex
);
7536 * _scsih_sas_discovery_event - handle discovery events
7537 * @ioc: per adapter object
7538 * @fw_event: The fw_event_work object
7544 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
7545 struct fw_event_work
*fw_event
)
7547 Mpi2EventDataSasDiscovery_t
*event_data
=
7548 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
7550 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
7551 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
7552 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
7554 if (event_data
->DiscoveryStatus
)
7555 pr_info("discovery_status(0x%08x)",
7556 le32_to_cpu(event_data
->DiscoveryStatus
));
7560 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
7561 !ioc
->sas_hba
.num_phys
) {
7562 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
7563 /* Wait for the reset to complete */
7564 while (ioc
->shost_recovery
)
7567 _scsih_sas_host_add(ioc
);
7572 * _scsih_pcie_enumeration_event - handle enumeration events
7573 * @ioc: per adapter object
7574 * @fw_event: The fw_event_work object
7580 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER
*ioc
,
7581 struct fw_event_work
*fw_event
)
7583 Mpi26EventDataPCIeEnumeration_t
*event_data
=
7584 (Mpi26EventDataPCIeEnumeration_t
*)fw_event
->event_data
;
7586 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
7587 pr_info(MPT3SAS_FMT
"pcie enumeration event: (%s) Flag 0x%02x",
7589 ((event_data
->ReasonCode
==
7590 MPI26_EVENT_PCIE_ENUM_RC_STARTED
) ?
7591 "started" : "completed"), event_data
->Flags
);
7592 if (event_data
->EnumerationStatus
)
7593 pr_info("enumeration_status(0x%08x)",
7594 le32_to_cpu(event_data
->EnumerationStatus
));
7600 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7601 * @ioc: per adapter object
7602 * @handle: device handle for physical disk
7603 * @phys_disk_num: physical disk number
7605 * Return 0 for success, else failure.
7608 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
7610 Mpi2RaidActionRequest_t
*mpi_request
;
7611 Mpi2RaidActionReply_t
*mpi_reply
;
7618 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
7621 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7623 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7624 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7625 ioc
->name
, __func__
);
7629 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7631 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7633 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7634 ioc
->name
, __func__
);
7635 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7640 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7641 ioc
->scsih_cmds
.smid
= smid
;
7642 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7644 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7645 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
7646 mpi_request
->PhysDiskNum
= phys_disk_num
;
7648 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
7649 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
7650 handle
, phys_disk_num
));
7652 init_completion(&ioc
->scsih_cmds
.done
);
7653 ioc
->put_smid_default(ioc
, smid
);
7654 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7656 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7657 pr_err(MPT3SAS_FMT
"%s: timeout\n",
7658 ioc
->name
, __func__
);
7659 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
7665 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7667 mpi_reply
= ioc
->scsih_cmds
.reply
;
7668 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
7669 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
7670 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
7673 ioc_status
&= MPI2_IOCSTATUS_MASK
;
7674 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7675 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7676 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
7677 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
7681 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7682 "IR RAID_ACTION: completed successfully\n",
7687 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7688 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7691 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
7696 * _scsih_reprobe_lun - reprobing lun
7697 * @sdev: scsi device struct
7698 * @no_uld_attach: sdev->no_uld_attach flag setting
7702 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
7704 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
7705 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
7706 sdev
->no_uld_attach
? "hiding" : "exposing");
7707 WARN_ON(scsi_device_reprobe(sdev
));
7711 * _scsih_sas_volume_add - add new volume
7712 * @ioc: per adapter object
7713 * @element: IR config element data
7719 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
7720 Mpi2EventIrConfigElement_t
*element
)
7722 struct _raid_device
*raid_device
;
7723 unsigned long flags
;
7725 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
7728 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
7731 "failure at %s:%d/%s()!\n", ioc
->name
,
7732 __FILE__
, __LINE__
, __func__
);
7736 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7737 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
7738 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7743 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
7746 "failure at %s:%d/%s()!\n", ioc
->name
,
7747 __FILE__
, __LINE__
, __func__
);
7751 raid_device
->id
= ioc
->sas_id
++;
7752 raid_device
->channel
= RAID_CHANNEL
;
7753 raid_device
->handle
= handle
;
7754 raid_device
->wwid
= wwid
;
7755 _scsih_raid_device_add(ioc
, raid_device
);
7756 if (!ioc
->wait_for_discovery_to_complete
) {
7757 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7758 raid_device
->id
, 0);
7760 _scsih_raid_device_remove(ioc
, raid_device
);
7762 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7763 _scsih_determine_boot_device(ioc
, raid_device
, 1);
7764 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7769 * _scsih_sas_volume_delete - delete volume
7770 * @ioc: per adapter object
7771 * @handle: volume device handle
7777 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
7779 struct _raid_device
*raid_device
;
7780 unsigned long flags
;
7781 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7782 struct scsi_target
*starget
= NULL
;
7784 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7785 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7787 if (raid_device
->starget
) {
7788 starget
= raid_device
->starget
;
7789 sas_target_priv_data
= starget
->hostdata
;
7790 sas_target_priv_data
->deleted
= 1;
7792 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7793 ioc
->name
, raid_device
->handle
,
7794 (unsigned long long) raid_device
->wwid
);
7795 list_del(&raid_device
->list
);
7798 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7800 scsi_remove_target(&starget
->dev
);
7804 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7805 * @ioc: per adapter object
7806 * @element: IR config element data
7812 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
7813 Mpi2EventIrConfigElement_t
*element
)
7815 struct _sas_device
*sas_device
;
7816 struct scsi_target
*starget
= NULL
;
7817 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7818 unsigned long flags
;
7819 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7821 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7822 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7824 sas_device
->volume_handle
= 0;
7825 sas_device
->volume_wwid
= 0;
7826 clear_bit(handle
, ioc
->pd_handles
);
7827 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7828 starget
= sas_device
->starget
;
7829 sas_target_priv_data
= starget
->hostdata
;
7830 sas_target_priv_data
->flags
&=
7831 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
7834 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7838 /* exposing raid component */
7840 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
7842 sas_device_put(sas_device
);
7846 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7847 * @ioc: per adapter object
7848 * @element: IR config element data
7854 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
7855 Mpi2EventIrConfigElement_t
*element
)
7857 struct _sas_device
*sas_device
;
7858 struct scsi_target
*starget
= NULL
;
7859 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7860 unsigned long flags
;
7861 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7862 u16 volume_handle
= 0;
7863 u64 volume_wwid
= 0;
7865 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
7867 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
7870 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7871 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7873 set_bit(handle
, ioc
->pd_handles
);
7874 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7875 starget
= sas_device
->starget
;
7876 sas_target_priv_data
= starget
->hostdata
;
7877 sas_target_priv_data
->flags
|=
7878 MPT_TARGET_FLAGS_RAID_COMPONENT
;
7879 sas_device
->volume_handle
= volume_handle
;
7880 sas_device
->volume_wwid
= volume_wwid
;
7883 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7887 /* hiding raid component */
7888 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7891 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
7893 sas_device_put(sas_device
);
7897 * _scsih_sas_pd_delete - delete pd component
7898 * @ioc: per adapter object
7899 * @element: IR config element data
7905 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
7906 Mpi2EventIrConfigElement_t
*element
)
7908 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7910 _scsih_device_remove_by_handle(ioc
, handle
);
7914 * _scsih_sas_pd_add - remove pd component
7915 * @ioc: per adapter object
7916 * @element: IR config element data
7922 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
7923 Mpi2EventIrConfigElement_t
*element
)
7925 struct _sas_device
*sas_device
;
7926 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7927 Mpi2ConfigReply_t mpi_reply
;
7928 Mpi2SasDevicePage0_t sas_device_pg0
;
7933 set_bit(handle
, ioc
->pd_handles
);
7935 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7937 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7938 sas_device_put(sas_device
);
7942 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
7943 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
7944 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7945 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7949 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7950 MPI2_IOCSTATUS_MASK
;
7951 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7952 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7953 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7957 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7958 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
7959 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7960 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7962 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7963 _scsih_add_device(ioc
, handle
, 0, 1);
7967 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
7968 * @ioc: per adapter object
7969 * @event_data: event data payload
7975 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7976 Mpi2EventDataIrConfigChangeList_t
*event_data
)
7978 Mpi2EventIrConfigElement_t
*element
;
7981 char *reason_str
= NULL
, *element_str
= NULL
;
7983 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
7985 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
7986 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
7987 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
7988 "foreign" : "native", event_data
->NumElements
);
7989 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
7990 switch (element
->ReasonCode
) {
7991 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
7994 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
7995 reason_str
= "remove";
7997 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
7998 reason_str
= "no change";
8000 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8001 reason_str
= "hide";
8003 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8004 reason_str
= "unhide";
8006 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8007 reason_str
= "volume_created";
8009 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8010 reason_str
= "volume_deleted";
8012 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8013 reason_str
= "pd_created";
8015 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8016 reason_str
= "pd_deleted";
8019 reason_str
= "unknown reason";
8022 element_type
= le16_to_cpu(element
->ElementFlags
) &
8023 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
8024 switch (element_type
) {
8025 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
8026 element_str
= "volume";
8028 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
8029 element_str
= "phys disk";
8031 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
8032 element_str
= "hot spare";
8035 element_str
= "unknown element";
8038 pr_info("\t(%s:%s), vol handle(0x%04x), " \
8039 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
8040 reason_str
, le16_to_cpu(element
->VolDevHandle
),
8041 le16_to_cpu(element
->PhysDiskDevHandle
),
8042 element
->PhysDiskNum
);
8047 * _scsih_sas_ir_config_change_event - handle ir configuration change events
8048 * @ioc: per adapter object
8049 * @fw_event: The fw_event_work object
8055 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
8056 struct fw_event_work
*fw_event
)
8058 Mpi2EventIrConfigElement_t
*element
;
8061 Mpi2EventDataIrConfigChangeList_t
*event_data
=
8062 (Mpi2EventDataIrConfigChangeList_t
*)
8063 fw_event
->event_data
;
8065 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8066 (!ioc
->hide_ir_msg
))
8067 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
8069 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
8070 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
8072 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8073 if (ioc
->shost_recovery
&&
8074 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
8075 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8076 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
8077 _scsih_ir_fastpath(ioc
,
8078 le16_to_cpu(element
->PhysDiskDevHandle
),
8079 element
->PhysDiskNum
);
8084 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8086 switch (element
->ReasonCode
) {
8087 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8088 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8089 if (!foreign_config
)
8090 _scsih_sas_volume_add(ioc
, element
);
8092 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8093 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8094 if (!foreign_config
)
8095 _scsih_sas_volume_delete(ioc
,
8096 le16_to_cpu(element
->VolDevHandle
));
8098 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8099 if (!ioc
->is_warpdrive
)
8100 _scsih_sas_pd_hide(ioc
, element
);
8102 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8103 if (!ioc
->is_warpdrive
)
8104 _scsih_sas_pd_expose(ioc
, element
);
8106 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8107 if (!ioc
->is_warpdrive
)
8108 _scsih_sas_pd_add(ioc
, element
);
8110 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8111 if (!ioc
->is_warpdrive
)
8112 _scsih_sas_pd_delete(ioc
, element
);
8119 * _scsih_sas_ir_volume_event - IR volume event
8120 * @ioc: per adapter object
8121 * @fw_event: The fw_event_work object
8127 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
8128 struct fw_event_work
*fw_event
)
8131 unsigned long flags
;
8132 struct _raid_device
*raid_device
;
8136 Mpi2EventDataIrVolume_t
*event_data
=
8137 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
8139 if (ioc
->shost_recovery
)
8142 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
8145 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8146 state
= le32_to_cpu(event_data
->NewValue
);
8147 if (!ioc
->hide_ir_msg
)
8148 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8149 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8150 ioc
->name
, __func__
, handle
,
8151 le32_to_cpu(event_data
->PreviousValue
), state
));
8153 case MPI2_RAID_VOL_STATE_MISSING
:
8154 case MPI2_RAID_VOL_STATE_FAILED
:
8155 _scsih_sas_volume_delete(ioc
, handle
);
8158 case MPI2_RAID_VOL_STATE_ONLINE
:
8159 case MPI2_RAID_VOL_STATE_DEGRADED
:
8160 case MPI2_RAID_VOL_STATE_OPTIMAL
:
8162 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8163 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8164 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8169 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
8172 "failure at %s:%d/%s()!\n", ioc
->name
,
8173 __FILE__
, __LINE__
, __func__
);
8177 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
8180 "failure at %s:%d/%s()!\n", ioc
->name
,
8181 __FILE__
, __LINE__
, __func__
);
8185 raid_device
->id
= ioc
->sas_id
++;
8186 raid_device
->channel
= RAID_CHANNEL
;
8187 raid_device
->handle
= handle
;
8188 raid_device
->wwid
= wwid
;
8189 _scsih_raid_device_add(ioc
, raid_device
);
8190 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8191 raid_device
->id
, 0);
8193 _scsih_raid_device_remove(ioc
, raid_device
);
8196 case MPI2_RAID_VOL_STATE_INITIALIZING
:
8203 * _scsih_sas_ir_physical_disk_event - PD event
8204 * @ioc: per adapter object
8205 * @fw_event: The fw_event_work object
8211 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
8212 struct fw_event_work
*fw_event
)
8214 u16 handle
, parent_handle
;
8216 struct _sas_device
*sas_device
;
8217 Mpi2ConfigReply_t mpi_reply
;
8218 Mpi2SasDevicePage0_t sas_device_pg0
;
8220 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
8221 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
8224 if (ioc
->shost_recovery
)
8227 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
8230 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
8231 state
= le32_to_cpu(event_data
->NewValue
);
8233 if (!ioc
->hide_ir_msg
)
8234 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
8235 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8236 ioc
->name
, __func__
, handle
,
8237 le32_to_cpu(event_data
->PreviousValue
), state
));
8240 case MPI2_RAID_PD_STATE_ONLINE
:
8241 case MPI2_RAID_PD_STATE_DEGRADED
:
8242 case MPI2_RAID_PD_STATE_REBUILDING
:
8243 case MPI2_RAID_PD_STATE_OPTIMAL
:
8244 case MPI2_RAID_PD_STATE_HOT_SPARE
:
8246 if (!ioc
->is_warpdrive
)
8247 set_bit(handle
, ioc
->pd_handles
);
8249 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8251 sas_device_put(sas_device
);
8255 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8256 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
8258 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8259 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8263 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8264 MPI2_IOCSTATUS_MASK
;
8265 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8266 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8267 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8271 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8272 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
8273 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
8274 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
8276 _scsih_add_device(ioc
, handle
, 0, 1);
8280 case MPI2_RAID_PD_STATE_OFFLINE
:
8281 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
8282 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
8289 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8290 * @ioc: per adapter object
8291 * @event_data: event data payload
8297 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8298 Mpi2EventDataIrOperationStatus_t
*event_data
)
8300 char *reason_str
= NULL
;
8302 switch (event_data
->RAIDOperation
) {
8303 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
8304 reason_str
= "resync";
8306 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
8307 reason_str
= "online capacity expansion";
8309 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
8310 reason_str
= "consistency check";
8312 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
8313 reason_str
= "background init";
8315 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
8316 reason_str
= "make data consistent";
8323 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
8324 "\thandle(0x%04x), percent complete(%d)\n",
8325 ioc
->name
, reason_str
,
8326 le16_to_cpu(event_data
->VolDevHandle
),
8327 event_data
->PercentComplete
);
8331 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8332 * @ioc: per adapter object
8333 * @fw_event: The fw_event_work object
8339 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
8340 struct fw_event_work
*fw_event
)
8342 Mpi2EventDataIrOperationStatus_t
*event_data
=
8343 (Mpi2EventDataIrOperationStatus_t
*)
8344 fw_event
->event_data
;
8345 static struct _raid_device
*raid_device
;
8346 unsigned long flags
;
8349 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8350 (!ioc
->hide_ir_msg
))
8351 _scsih_sas_ir_operation_status_event_debug(ioc
,
8354 /* code added for raid transport support */
8355 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
8357 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8358 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8359 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8361 raid_device
->percent_complete
=
8362 event_data
->PercentComplete
;
8363 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8368 * _scsih_prep_device_scan - initialize parameters prior to device scan
8369 * @ioc: per adapter object
8371 * Set the deleted flag prior to device scan. If the device is found during
8372 * the scan, then we clear the deleted flag.
8375 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
8377 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
8378 struct scsi_device
*sdev
;
8380 shost_for_each_device(sdev
, ioc
->shost
) {
8381 sas_device_priv_data
= sdev
->hostdata
;
8382 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
8383 sas_device_priv_data
->sas_target
->deleted
= 1;
8388 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8389 * @ioc: per adapter object
8390 * @sas_device_pg0: SAS Device page 0
8392 * After host reset, find out whether devices are still responding.
8393 * Used in _scsih_remove_unresponsive_sas_devices.
8398 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
8399 Mpi2SasDevicePage0_t
*sas_device_pg0
)
8401 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8402 struct scsi_target
*starget
;
8403 struct _sas_device
*sas_device
= NULL
;
8404 unsigned long flags
;
8406 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8407 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
8408 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
8409 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
8410 sas_device
->responding
= 1;
8411 starget
= sas_device
->starget
;
8412 if (starget
&& starget
->hostdata
) {
8413 sas_target_priv_data
= starget
->hostdata
;
8414 sas_target_priv_data
->tm_busy
= 0;
8415 sas_target_priv_data
->deleted
= 0;
8417 sas_target_priv_data
= NULL
;
8419 starget_printk(KERN_INFO
, starget
,
8420 "handle(0x%04x), sas_addr(0x%016llx)\n",
8421 sas_device_pg0
->DevHandle
,
8422 (unsigned long long)
8423 sas_device
->sas_address
);
8425 if (sas_device
->enclosure_handle
!= 0)
8426 starget_printk(KERN_INFO
, starget
,
8427 "enclosure logical id(0x%016llx),"
8429 (unsigned long long)
8430 sas_device
->enclosure_logical_id
,
8433 if (sas_device_pg0
->Flags
&
8434 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
8435 sas_device
->enclosure_level
=
8436 sas_device_pg0
->EnclosureLevel
;
8437 memcpy(&sas_device
->connector_name
[0],
8438 &sas_device_pg0
->ConnectorName
[0], 4);
8440 sas_device
->enclosure_level
= 0;
8441 sas_device
->connector_name
[0] = '\0';
8444 _scsih_get_enclosure_logicalid_chassis_slot(ioc
,
8445 sas_device_pg0
, sas_device
);
8447 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
8449 pr_info("\thandle changed from(0x%04x)!!!\n",
8450 sas_device
->handle
);
8451 sas_device
->handle
= sas_device_pg0
->DevHandle
;
8452 if (sas_target_priv_data
)
8453 sas_target_priv_data
->handle
=
8454 sas_device_pg0
->DevHandle
;
8459 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8463 * _scsih_search_responding_sas_devices -
8464 * @ioc: per adapter object
8466 * After host reset, find out whether devices are still responding.
8472 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
8474 Mpi2SasDevicePage0_t sas_device_pg0
;
8475 Mpi2ConfigReply_t mpi_reply
;
8480 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
8482 if (list_empty(&ioc
->sas_device_list
))
8486 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8487 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8489 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8490 MPI2_IOCSTATUS_MASK
;
8491 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8493 handle
= sas_device_pg0
.DevHandle
=
8494 le16_to_cpu(sas_device_pg0
.DevHandle
);
8495 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
8496 if (!(_scsih_is_end_device(device_info
)))
8498 sas_device_pg0
.SASAddress
=
8499 le64_to_cpu(sas_device_pg0
.SASAddress
);
8500 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
8501 sas_device_pg0
.Flags
= le16_to_cpu(sas_device_pg0
.Flags
);
8502 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
8506 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
8511 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8512 * @ioc: per adapter object
8513 * @wwid: world wide identifier for raid volume
8514 * @handle: device handle
8516 * After host reset, find out whether devices are still responding.
8517 * Used in _scsih_remove_unresponsive_raid_devices.
8522 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
8525 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8526 struct scsi_target
*starget
;
8527 struct _raid_device
*raid_device
;
8528 unsigned long flags
;
8530 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8531 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
8532 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
8533 starget
= raid_device
->starget
;
8534 if (starget
&& starget
->hostdata
) {
8535 sas_target_priv_data
= starget
->hostdata
;
8536 sas_target_priv_data
->deleted
= 0;
8538 sas_target_priv_data
= NULL
;
8539 raid_device
->responding
= 1;
8540 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8541 starget_printk(KERN_INFO
, raid_device
->starget
,
8542 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
8543 (unsigned long long)raid_device
->wwid
);
8546 * WARPDRIVE: The handles of the PDs might have changed
8547 * across the host reset so re-initialize the
8548 * required data for Direct IO
8550 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
8551 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8552 if (raid_device
->handle
== handle
) {
8553 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
8557 pr_info("\thandle changed from(0x%04x)!!!\n",
8558 raid_device
->handle
);
8559 raid_device
->handle
= handle
;
8560 if (sas_target_priv_data
)
8561 sas_target_priv_data
->handle
= handle
;
8562 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8566 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8570 * _scsih_search_responding_raid_devices -
8571 * @ioc: per adapter object
8573 * After host reset, find out whether devices are still responding.
8579 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
8581 Mpi2RaidVolPage1_t volume_pg1
;
8582 Mpi2RaidVolPage0_t volume_pg0
;
8583 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8584 Mpi2ConfigReply_t mpi_reply
;
8589 if (!ioc
->ir_firmware
)
8592 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
8595 if (list_empty(&ioc
->raid_device_list
))
8599 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
8600 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
8601 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8602 MPI2_IOCSTATUS_MASK
;
8603 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8605 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
8607 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
8608 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
8609 sizeof(Mpi2RaidVolPage0_t
)))
8612 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
8613 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
8614 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
8615 _scsih_mark_responding_raid_device(ioc
,
8616 le64_to_cpu(volume_pg1
.WWID
), handle
);
8619 /* refresh the pd_handles */
8620 if (!ioc
->is_warpdrive
) {
8621 phys_disk_num
= 0xFF;
8622 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
8623 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
8624 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
8626 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8627 MPI2_IOCSTATUS_MASK
;
8628 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8630 phys_disk_num
= pd_pg0
.PhysDiskNum
;
8631 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
8632 set_bit(handle
, ioc
->pd_handles
);
8636 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
8641 * _scsih_mark_responding_expander - mark a expander as responding
8642 * @ioc: per adapter object
8643 * @expander_pg0:SAS Expander Config Page0
8645 * After host reset, find out whether devices are still responding.
8646 * Used in _scsih_remove_unresponsive_expanders.
8651 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
,
8652 Mpi2ExpanderPage0_t
*expander_pg0
)
8654 struct _sas_node
*sas_expander
= NULL
;
8655 unsigned long flags
;
8656 int i
, encl_pg0_rc
= -1;
8657 Mpi2ConfigReply_t mpi_reply
;
8658 Mpi2SasEnclosurePage0_t enclosure_pg0
;
8659 u16 handle
= le16_to_cpu(expander_pg0
->DevHandle
);
8660 u64 sas_address
= le64_to_cpu(expander_pg0
->SASAddress
);
8662 if (le16_to_cpu(expander_pg0
->EnclosureHandle
)) {
8663 encl_pg0_rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
8664 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
8665 le16_to_cpu(expander_pg0
->EnclosureHandle
));
8668 "Enclosure Pg0 read failed for handle(0x%04x)\n",
8670 le16_to_cpu(expander_pg0
->EnclosureHandle
));
8673 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8674 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
8675 if (sas_expander
->sas_address
!= sas_address
)
8677 sas_expander
->responding
= 1;
8680 sas_expander
->enclosure_logical_id
=
8681 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
8683 sas_expander
->enclosure_handle
=
8684 le16_to_cpu(expander_pg0
->EnclosureHandle
);
8686 if (sas_expander
->handle
== handle
)
8688 pr_info("\texpander(0x%016llx): handle changed" \
8689 " from(0x%04x) to (0x%04x)!!!\n",
8690 (unsigned long long)sas_expander
->sas_address
,
8691 sas_expander
->handle
, handle
);
8692 sas_expander
->handle
= handle
;
8693 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
8694 sas_expander
->phy
[i
].handle
= handle
;
8698 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8702 * _scsih_search_responding_expanders -
8703 * @ioc: per adapter object
8705 * After host reset, find out whether devices are still responding.
8711 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
8713 Mpi2ExpanderPage0_t expander_pg0
;
8714 Mpi2ConfigReply_t mpi_reply
;
8719 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
8721 if (list_empty(&ioc
->sas_expander_list
))
8725 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8726 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8728 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8729 MPI2_IOCSTATUS_MASK
;
8730 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8733 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
8734 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
8735 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8737 (unsigned long long)sas_address
);
8738 _scsih_mark_responding_expander(ioc
, &expander_pg0
);
8742 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
8746 * _scsih_remove_unresponding_devices - removing unresponding devices
8747 * @ioc: per adapter object
8752 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER
*ioc
)
8754 struct _sas_device
*sas_device
, *sas_device_next
;
8755 struct _sas_node
*sas_expander
, *sas_expander_next
;
8756 struct _raid_device
*raid_device
, *raid_device_next
;
8757 struct _pcie_device
*pcie_device
, *pcie_device_next
;
8758 struct list_head tmp_list
;
8759 unsigned long flags
;
8762 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
8765 /* removing unresponding end devices */
8766 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
8769 * Iterate, pulling off devices marked as non-responding. We become the
8770 * owner for the reference the list had on any object we prune.
8772 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8773 list_for_each_entry_safe(sas_device
, sas_device_next
,
8774 &ioc
->sas_device_list
, list
) {
8775 if (!sas_device
->responding
)
8776 list_move_tail(&sas_device
->list
, &head
);
8778 sas_device
->responding
= 0;
8780 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8783 * Now, uninitialize and remove the unresponding devices we pruned.
8785 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
8786 _scsih_remove_device(ioc
, sas_device
);
8787 list_del_init(&sas_device
->list
);
8788 sas_device_put(sas_device
);
8792 " Removing unresponding devices: pcie end-devices\n"
8794 INIT_LIST_HEAD(&head
);
8795 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8796 list_for_each_entry_safe(pcie_device
, pcie_device_next
,
8797 &ioc
->pcie_device_list
, list
) {
8798 if (!pcie_device
->responding
)
8799 list_move_tail(&pcie_device
->list
, &head
);
8801 pcie_device
->responding
= 0;
8803 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8805 list_for_each_entry_safe(pcie_device
, pcie_device_next
, &head
, list
) {
8806 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
8807 list_del_init(&pcie_device
->list
);
8808 pcie_device_put(pcie_device
);
8811 /* removing unresponding volumes */
8812 if (ioc
->ir_firmware
) {
8813 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
8815 list_for_each_entry_safe(raid_device
, raid_device_next
,
8816 &ioc
->raid_device_list
, list
) {
8817 if (!raid_device
->responding
)
8818 _scsih_sas_volume_delete(ioc
,
8819 raid_device
->handle
);
8821 raid_device
->responding
= 0;
8825 /* removing unresponding expanders */
8826 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
8828 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8829 INIT_LIST_HEAD(&tmp_list
);
8830 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
8831 &ioc
->sas_expander_list
, list
) {
8832 if (!sas_expander
->responding
)
8833 list_move_tail(&sas_expander
->list
, &tmp_list
);
8835 sas_expander
->responding
= 0;
8837 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8838 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
8840 _scsih_expander_node_remove(ioc
, sas_expander
);
8843 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
8846 /* unblock devices */
8847 _scsih_ublock_io_all_device(ioc
);
8851 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
8852 struct _sas_node
*sas_expander
, u16 handle
)
8854 Mpi2ExpanderPage1_t expander_pg1
;
8855 Mpi2ConfigReply_t mpi_reply
;
8858 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
8859 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
8860 &expander_pg1
, i
, handle
))) {
8861 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8862 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8866 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
8867 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
8868 expander_pg1
.NegotiatedLinkRate
>> 4);
8873 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
8874 * @ioc: per adapter object
8879 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
8881 Mpi2ExpanderPage0_t expander_pg0
;
8882 Mpi2SasDevicePage0_t sas_device_pg0
;
8883 Mpi2RaidVolPage1_t volume_pg1
;
8884 Mpi2RaidVolPage0_t volume_pg0
;
8885 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8886 Mpi2EventIrConfigElement_t element
;
8887 Mpi2ConfigReply_t mpi_reply
;
8890 u16 handle
, parent_handle
;
8892 struct _sas_device
*sas_device
;
8893 struct _sas_node
*expander_device
;
8894 static struct _raid_device
*raid_device
;
8896 unsigned long flags
;
8898 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
8900 _scsih_sas_host_refresh(ioc
);
8902 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
8906 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8907 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8908 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8909 MPI2_IOCSTATUS_MASK
;
8910 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8911 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
8912 "ioc_status(0x%04x), loginfo(0x%08x)\n",
8913 ioc
->name
, ioc_status
,
8914 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8917 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
8918 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8919 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
8920 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
8921 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8922 if (expander_device
)
8923 _scsih_refresh_expander_links(ioc
, expander_device
,
8926 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
8927 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
8928 handle
, (unsigned long long)
8929 le64_to_cpu(expander_pg0
.SASAddress
));
8930 _scsih_expander_add(ioc
, handle
);
8931 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
8932 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
8933 handle
, (unsigned long long)
8934 le64_to_cpu(expander_pg0
.SASAddress
));
8938 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
8941 if (!ioc
->ir_firmware
)
8944 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
8947 phys_disk_num
= 0xFF;
8948 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
8949 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
8951 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8952 MPI2_IOCSTATUS_MASK
;
8953 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8954 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
8955 "ioc_status(0x%04x), loginfo(0x%08x)\n",
8956 ioc
->name
, ioc_status
,
8957 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8960 phys_disk_num
= pd_pg0
.PhysDiskNum
;
8961 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
8962 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8964 sas_device_put(sas_device
);
8967 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8968 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
8971 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8972 MPI2_IOCSTATUS_MASK
;
8973 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8974 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
8975 "ioc_status(0x%04x), loginfo(0x%08x)\n",
8976 ioc
->name
, ioc_status
,
8977 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8980 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8981 if (!_scsih_get_sas_address(ioc
, parent_handle
,
8983 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
8984 " handle (0x%04x), sas_addr(0x%016llx)\n",
8985 ioc
->name
, handle
, (unsigned long long)
8986 le64_to_cpu(sas_device_pg0
.SASAddress
));
8987 mpt3sas_transport_update_links(ioc
, sas_address
,
8988 handle
, sas_device_pg0
.PhyNum
,
8989 MPI2_SAS_NEG_LINK_RATE_1_5
);
8990 set_bit(handle
, ioc
->pd_handles
);
8992 /* This will retry adding the end device.
8993 * _scsih_add_device() will decide on retries and
8994 * return "1" when it should be retried
8996 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9000 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
9001 " handle (0x%04x), sas_addr(0x%016llx)\n",
9002 ioc
->name
, handle
, (unsigned long long)
9003 le64_to_cpu(sas_device_pg0
.SASAddress
));
9007 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
9010 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
9014 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
9015 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
9016 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9017 MPI2_IOCSTATUS_MASK
;
9018 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9019 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9020 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9021 ioc
->name
, ioc_status
,
9022 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9025 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
9026 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
9027 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
9028 le64_to_cpu(volume_pg1
.WWID
));
9029 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
9032 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
9033 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
9034 sizeof(Mpi2RaidVolPage0_t
)))
9036 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9037 MPI2_IOCSTATUS_MASK
;
9038 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9039 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
9040 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9041 ioc
->name
, ioc_status
,
9042 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9045 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
9046 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
9047 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
9048 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
9049 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
9050 element
.VolDevHandle
= volume_pg1
.DevHandle
;
9052 "\tBEFORE adding volume: handle (0x%04x)\n",
9053 ioc
->name
, volume_pg1
.DevHandle
);
9054 _scsih_sas_volume_add(ioc
, &element
);
9056 "\tAFTER adding volume: handle (0x%04x)\n",
9057 ioc
->name
, volume_pg1
.DevHandle
);
9061 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
9066 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
9071 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9072 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9074 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9075 MPI2_IOCSTATUS_MASK
;
9076 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9077 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
9078 " ioc_status(0x%04x), loginfo(0x%08x)\n",
9079 ioc
->name
, ioc_status
,
9080 le32_to_cpu(mpi_reply
.IOCLogInfo
));
9083 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
9084 if (!(_scsih_is_end_device(
9085 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
9087 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
9088 le64_to_cpu(sas_device_pg0
.SASAddress
));
9090 sas_device_put(sas_device
);
9093 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9094 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
9095 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
9096 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9097 handle
, (unsigned long long)
9098 le64_to_cpu(sas_device_pg0
.SASAddress
));
9099 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
9100 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
9102 /* This will retry adding the end device.
9103 * _scsih_add_device() will decide on retries and
9104 * return "1" when it should be retried
9106 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9110 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
9111 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
9112 handle
, (unsigned long long)
9113 le64_to_cpu(sas_device_pg0
.SASAddress
));
9116 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
9119 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
9122 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9123 * @ioc: per adapter object
9124 * @reset_phase: phase
9126 * The handler for doing any required cleanup or initialization.
9128 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
9129 * MPT3_IOC_DONE_RESET
9134 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
9136 switch (reset_phase
) {
9137 case MPT3_IOC_PRE_RESET
:
9138 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9139 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
9141 case MPT3_IOC_AFTER_RESET
:
9142 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9143 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
9144 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
9145 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
9146 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
9147 complete(&ioc
->scsih_cmds
.done
);
9149 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
9150 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
9151 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
9152 complete(&ioc
->tm_cmds
.done
);
9155 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
9156 memset(ioc
->device_remove_in_progress
, 0,
9157 ioc
->device_remove_in_progress_sz
);
9158 _scsih_fw_event_cleanup_queue(ioc
);
9159 _scsih_flush_running_cmds(ioc
);
9161 case MPT3_IOC_DONE_RESET
:
9162 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
9163 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
9164 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
9165 !ioc
->sas_hba
.num_phys
)) {
9166 _scsih_prep_device_scan(ioc
);
9167 _scsih_search_responding_sas_devices(ioc
);
9168 _scsih_search_responding_raid_devices(ioc
);
9169 _scsih_search_responding_expanders(ioc
);
9170 _scsih_error_recovery_delete_devices(ioc
);
9177 * _mpt3sas_fw_work - delayed task for processing firmware events
9178 * @ioc: per adapter object
9179 * @fw_event: The fw_event_work object
9185 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
9187 _scsih_fw_event_del_from_list(ioc
, fw_event
);
9189 /* the queue is being flushed so ignore this event */
9190 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
9191 fw_event_work_put(fw_event
);
9195 switch (fw_event
->event
) {
9196 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
9197 mpt3sas_process_trigger_data(ioc
,
9198 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
9199 fw_event
->event_data
);
9201 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
9202 while (scsi_host_in_recovery(ioc
->shost
) ||
9203 ioc
->shost_recovery
) {
9205 * If we're unloading, bail. Otherwise, this can become
9208 if (ioc
->remove_host
)
9212 _scsih_remove_unresponding_devices(ioc
);
9213 _scsih_scan_for_devices_after_reset(ioc
);
9215 case MPT3SAS_PORT_ENABLE_COMPLETE
:
9216 ioc
->start_scan
= 0;
9217 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
9218 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
9220 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
9221 "port enable: complete from worker thread\n",
9224 case MPT3SAS_TURN_ON_PFA_LED
:
9225 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
9227 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9228 _scsih_sas_topology_change_event(ioc
, fw_event
);
9230 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9231 _scsih_sas_device_status_change_event(ioc
, fw_event
);
9233 case MPI2_EVENT_SAS_DISCOVERY
:
9234 _scsih_sas_discovery_event(ioc
, fw_event
);
9236 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9237 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
9239 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9240 _scsih_sas_enclosure_dev_status_change_event(ioc
,
9243 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9244 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
9246 case MPI2_EVENT_IR_VOLUME
:
9247 _scsih_sas_ir_volume_event(ioc
, fw_event
);
9249 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9250 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
9252 case MPI2_EVENT_IR_OPERATION_STATUS
:
9253 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
9255 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9256 _scsih_pcie_device_status_change_event(ioc
, fw_event
);
9258 case MPI2_EVENT_PCIE_ENUMERATION
:
9259 _scsih_pcie_enumeration_event(ioc
, fw_event
);
9261 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9262 _scsih_pcie_topology_change_event(ioc
, fw_event
);
9267 fw_event_work_put(fw_event
);
9271 * _firmware_event_work
9272 * @ioc: per adapter object
9273 * @work: The fw_event_work object
9276 * wrappers for the work thread handling firmware events
9282 _firmware_event_work(struct work_struct
*work
)
9284 struct fw_event_work
*fw_event
= container_of(work
,
9285 struct fw_event_work
, work
);
9287 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
9291 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9292 * @ioc: per adapter object
9293 * @msix_index: MSIX table index supplied by the OS
9294 * @reply: reply message frame(lower 32bit addr)
9295 * Context: interrupt.
9297 * This function merely adds a new work task into ioc->firmware_event_thread.
9298 * The tasks are worked from _firmware_event_work in user context.
9300 * Return 1 meaning mf should be freed from _base_interrupt
9301 * 0 means the mf is freed from this function.
9304 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
9307 struct fw_event_work
*fw_event
;
9308 Mpi2EventNotificationReply_t
*mpi_reply
;
9311 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
9313 /* events turned off due to host reset or driver unloading */
9314 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
9317 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
9319 if (unlikely(!mpi_reply
)) {
9320 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
9321 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9325 event
= le16_to_cpu(mpi_reply
->Event
);
9327 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
9328 mpt3sas_trigger_event(ioc
, event
, 0);
9332 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9334 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
9335 (Mpi2EventDataSasBroadcastPrimitive_t
*)
9336 mpi_reply
->EventData
;
9338 if (baen_data
->Primitive
!=
9339 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
9342 if (ioc
->broadcast_aen_busy
) {
9343 ioc
->broadcast_aen_pending
++;
9346 ioc
->broadcast_aen_busy
= 1;
9350 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9351 _scsih_check_topo_delete_events(ioc
,
9352 (Mpi2EventDataSasTopologyChangeList_t
*)
9353 mpi_reply
->EventData
);
9355 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9356 _scsih_check_pcie_topo_remove_events(ioc
,
9357 (Mpi26EventDataPCIeTopologyChangeList_t
*)
9358 mpi_reply
->EventData
);
9360 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9361 _scsih_check_ir_config_unhide_events(ioc
,
9362 (Mpi2EventDataIrConfigChangeList_t
*)
9363 mpi_reply
->EventData
);
9365 case MPI2_EVENT_IR_VOLUME
:
9366 _scsih_check_volume_delete_events(ioc
,
9367 (Mpi2EventDataIrVolume_t
*)
9368 mpi_reply
->EventData
);
9370 case MPI2_EVENT_LOG_ENTRY_ADDED
:
9372 Mpi2EventDataLogEntryAdded_t
*log_entry
;
9375 if (!ioc
->is_warpdrive
)
9378 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
9379 mpi_reply
->EventData
;
9380 log_code
= (u32
*)log_entry
->LogData
;
9382 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
9383 != MPT2_WARPDRIVE_LOGENTRY
)
9386 switch (le32_to_cpu(*log_code
)) {
9387 case MPT2_WARPDRIVE_LC_SSDT
:
9388 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9389 "IO Throttling has occurred in the WarpDrive "
9390 "subsystem. Check WarpDrive documentation for "
9391 "additional details.\n", ioc
->name
);
9393 case MPT2_WARPDRIVE_LC_SSDLW
:
9394 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
9395 "Program/Erase Cycles for the WarpDrive subsystem "
9396 "in degraded range. Check WarpDrive documentation "
9397 "for additional details.\n", ioc
->name
);
9399 case MPT2_WARPDRIVE_LC_SSDLF
:
9400 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9401 "There are no Program/Erase Cycles for the "
9402 "WarpDrive subsystem. The storage device will be "
9403 "in read-only mode. Check WarpDrive documentation "
9404 "for additional details.\n", ioc
->name
);
9406 case MPT2_WARPDRIVE_LC_BRMF
:
9407 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
9408 "The Backup Rail Monitor has failed on the "
9409 "WarpDrive subsystem. Check WarpDrive "
9410 "documentation for additional details.\n",
9417 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9418 case MPI2_EVENT_IR_OPERATION_STATUS
:
9419 case MPI2_EVENT_SAS_DISCOVERY
:
9420 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9421 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9422 case MPI2_EVENT_PCIE_ENUMERATION
:
9423 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9426 case MPI2_EVENT_TEMP_THRESHOLD
:
9427 _scsih_temp_threshold_events(ioc
,
9428 (Mpi2EventDataTemperature_t
*)
9429 mpi_reply
->EventData
);
9431 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
9432 ActiveCableEventData
=
9433 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
9434 switch (ActiveCableEventData
->ReasonCode
) {
9435 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
9436 pr_notice(MPT3SAS_FMT
9437 "Currently an active cable with ReceptacleID %d\n",
9438 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9439 pr_notice("cannot be powered and devices connected\n");
9440 pr_notice("to this active cable will not be seen\n");
9441 pr_notice("This active cable requires %d mW of power\n",
9442 ActiveCableEventData
->ActiveCablePowerRequirement
);
9445 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
9446 pr_notice(MPT3SAS_FMT
9447 "Currently a cable with ReceptacleID %d\n",
9448 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
9450 "is not running at optimal speed(12 Gb/s rate)\n");
9456 default: /* ignore the rest */
9460 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
9461 fw_event
= alloc_fw_event_work(sz
);
9463 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
9464 ioc
->name
, __FILE__
, __LINE__
, __func__
);
9468 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
9469 fw_event
->ioc
= ioc
;
9470 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
9471 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
9472 fw_event
->event
= event
;
9473 _scsih_fw_event_add(ioc
, fw_event
);
9474 fw_event_work_put(fw_event
);
9479 * _scsih_expander_node_remove - removing expander device from list.
9480 * @ioc: per adapter object
9481 * @sas_expander: the sas_device object
9483 * Removing object and freeing associated memory from the
9484 * ioc->sas_expander_list.
9489 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
9490 struct _sas_node
*sas_expander
)
9492 struct _sas_port
*mpt3sas_port
, *next
;
9493 unsigned long flags
;
9495 /* remove sibling ports attached to this expander */
9496 list_for_each_entry_safe(mpt3sas_port
, next
,
9497 &sas_expander
->sas_port_list
, port_list
) {
9498 if (ioc
->shost_recovery
)
9500 if (mpt3sas_port
->remote_identify
.device_type
==
9502 mpt3sas_device_remove_by_sas_address(ioc
,
9503 mpt3sas_port
->remote_identify
.sas_address
);
9504 else if (mpt3sas_port
->remote_identify
.device_type
==
9505 SAS_EDGE_EXPANDER_DEVICE
||
9506 mpt3sas_port
->remote_identify
.device_type
==
9507 SAS_FANOUT_EXPANDER_DEVICE
)
9508 mpt3sas_expander_remove(ioc
,
9509 mpt3sas_port
->remote_identify
.sas_address
);
9512 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
9513 sas_expander
->sas_address_parent
);
9516 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9518 sas_expander
->handle
, (unsigned long long)
9519 sas_expander
->sas_address
);
9521 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9522 list_del(&sas_expander
->list
);
9523 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9525 kfree(sas_expander
->phy
);
9526 kfree(sas_expander
);
9530 * _scsih_ir_shutdown - IR shutdown notification
9531 * @ioc: per adapter object
9533 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9534 * the host system is shutting down.
9539 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
9541 Mpi2RaidActionRequest_t
*mpi_request
;
9542 Mpi2RaidActionReply_t
*mpi_reply
;
9545 /* is IR firmware build loaded ? */
9546 if (!ioc
->ir_firmware
)
9549 /* are there any volumes ? */
9550 if (list_empty(&ioc
->raid_device_list
))
9553 mutex_lock(&ioc
->scsih_cmds
.mutex
);
9555 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
9556 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
9557 ioc
->name
, __func__
);
9560 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
9562 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
9564 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
9565 ioc
->name
, __func__
);
9566 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9570 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
9571 ioc
->scsih_cmds
.smid
= smid
;
9572 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
9574 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
9575 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
9577 if (!ioc
->hide_ir_msg
)
9578 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
9579 init_completion(&ioc
->scsih_cmds
.done
);
9580 ioc
->put_smid_default(ioc
, smid
);
9581 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
9583 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
9584 pr_err(MPT3SAS_FMT
"%s: timeout\n",
9585 ioc
->name
, __func__
);
9589 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
9590 mpi_reply
= ioc
->scsih_cmds
.reply
;
9591 if (!ioc
->hide_ir_msg
)
9592 pr_info(MPT3SAS_FMT
"IR shutdown "
9593 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9594 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
9595 le32_to_cpu(mpi_reply
->IOCLogInfo
));
9599 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9600 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
9604 * scsih_remove - detach and remove add host
9605 * @pdev: PCI device struct
9607 * Routine called when unloading the driver.
9610 static void scsih_remove(struct pci_dev
*pdev
)
9612 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9613 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9614 struct _sas_port
*mpt3sas_port
, *next_port
;
9615 struct _raid_device
*raid_device
, *next
;
9616 struct MPT3SAS_TARGET
*sas_target_priv_data
;
9617 struct _pcie_device
*pcie_device
, *pcienext
;
9618 struct workqueue_struct
*wq
;
9619 unsigned long flags
;
9621 ioc
->remove_host
= 1;
9622 _scsih_fw_event_cleanup_queue(ioc
);
9624 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9625 wq
= ioc
->firmware_event_thread
;
9626 ioc
->firmware_event_thread
= NULL
;
9627 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9629 destroy_workqueue(wq
);
9631 /* release all the volumes */
9632 _scsih_ir_shutdown(ioc
);
9633 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
9635 if (raid_device
->starget
) {
9636 sas_target_priv_data
=
9637 raid_device
->starget
->hostdata
;
9638 sas_target_priv_data
->deleted
= 1;
9639 scsi_remove_target(&raid_device
->starget
->dev
);
9641 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
9642 ioc
->name
, raid_device
->handle
,
9643 (unsigned long long) raid_device
->wwid
);
9644 _scsih_raid_device_remove(ioc
, raid_device
);
9646 list_for_each_entry_safe(pcie_device
, pcienext
, &ioc
->pcie_device_list
,
9648 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
9649 list_del_init(&pcie_device
->list
);
9650 pcie_device_put(pcie_device
);
9653 /* free ports attached to the sas_host */
9654 list_for_each_entry_safe(mpt3sas_port
, next_port
,
9655 &ioc
->sas_hba
.sas_port_list
, port_list
) {
9656 if (mpt3sas_port
->remote_identify
.device_type
==
9658 mpt3sas_device_remove_by_sas_address(ioc
,
9659 mpt3sas_port
->remote_identify
.sas_address
);
9660 else if (mpt3sas_port
->remote_identify
.device_type
==
9661 SAS_EDGE_EXPANDER_DEVICE
||
9662 mpt3sas_port
->remote_identify
.device_type
==
9663 SAS_FANOUT_EXPANDER_DEVICE
)
9664 mpt3sas_expander_remove(ioc
,
9665 mpt3sas_port
->remote_identify
.sas_address
);
9668 /* free phys attached to the sas_host */
9669 if (ioc
->sas_hba
.num_phys
) {
9670 kfree(ioc
->sas_hba
.phy
);
9671 ioc
->sas_hba
.phy
= NULL
;
9672 ioc
->sas_hba
.num_phys
= 0;
9675 sas_remove_host(shost
);
9676 mpt3sas_base_detach(ioc
);
9677 spin_lock(&gioc_lock
);
9678 list_del(&ioc
->list
);
9679 spin_unlock(&gioc_lock
);
9680 scsi_host_put(shost
);
9684 * scsih_shutdown - routine call during system shutdown
9685 * @pdev: PCI device struct
9690 scsih_shutdown(struct pci_dev
*pdev
)
9692 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9693 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9694 struct workqueue_struct
*wq
;
9695 unsigned long flags
;
9697 ioc
->remove_host
= 1;
9698 _scsih_fw_event_cleanup_queue(ioc
);
9700 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9701 wq
= ioc
->firmware_event_thread
;
9702 ioc
->firmware_event_thread
= NULL
;
9703 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9705 destroy_workqueue(wq
);
9707 _scsih_ir_shutdown(ioc
);
9708 mpt3sas_base_detach(ioc
);
9713 * _scsih_probe_boot_devices - reports 1st device
9714 * @ioc: per adapter object
9716 * If specified in bios page 2, this routine reports the 1st
9717 * device scsi-ml or sas transport for persistent boot device
9718 * purposes. Please refer to function _scsih_determine_boot_device()
9721 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
9725 struct _sas_device
*sas_device
;
9726 struct _raid_device
*raid_device
;
9727 struct _pcie_device
*pcie_device
;
9729 u64 sas_address_parent
;
9731 unsigned long flags
;
9735 /* no Bios, return immediately */
9736 if (!ioc
->bios_pg3
.BiosVersion
)
9740 if (ioc
->req_boot_device
.device
) {
9741 device
= ioc
->req_boot_device
.device
;
9742 channel
= ioc
->req_boot_device
.channel
;
9743 } else if (ioc
->req_alt_boot_device
.device
) {
9744 device
= ioc
->req_alt_boot_device
.device
;
9745 channel
= ioc
->req_alt_boot_device
.channel
;
9746 } else if (ioc
->current_boot_device
.device
) {
9747 device
= ioc
->current_boot_device
.device
;
9748 channel
= ioc
->current_boot_device
.channel
;
9754 if (channel
== RAID_CHANNEL
) {
9755 raid_device
= device
;
9756 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9757 raid_device
->id
, 0);
9759 _scsih_raid_device_remove(ioc
, raid_device
);
9760 } else if (channel
== PCIE_CHANNEL
) {
9761 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9762 pcie_device
= device
;
9763 tid
= pcie_device
->id
;
9764 list_move_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
9765 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9766 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, tid
, 0);
9768 _scsih_pcie_device_remove(ioc
, pcie_device
);
9770 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9771 sas_device
= device
;
9772 handle
= sas_device
->handle
;
9773 sas_address_parent
= sas_device
->sas_address_parent
;
9774 sas_address
= sas_device
->sas_address
;
9775 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
9776 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9778 if (ioc
->hide_drives
)
9780 if (!mpt3sas_transport_port_add(ioc
, handle
,
9781 sas_address_parent
)) {
9782 _scsih_sas_device_remove(ioc
, sas_device
);
9783 } else if (!sas_device
->starget
) {
9784 if (!ioc
->is_driver_loading
) {
9785 mpt3sas_transport_port_remove(ioc
,
9787 sas_address_parent
);
9788 _scsih_sas_device_remove(ioc
, sas_device
);
9795 * _scsih_probe_raid - reporting raid volumes to scsi-ml
9796 * @ioc: per adapter object
9798 * Called during initial loading of the driver.
9801 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
9803 struct _raid_device
*raid_device
, *raid_next
;
9806 list_for_each_entry_safe(raid_device
, raid_next
,
9807 &ioc
->raid_device_list
, list
) {
9808 if (raid_device
->starget
)
9810 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9811 raid_device
->id
, 0);
9813 _scsih_raid_device_remove(ioc
, raid_device
);
9817 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
9819 struct _sas_device
*sas_device
= NULL
;
9820 unsigned long flags
;
9822 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9823 if (!list_empty(&ioc
->sas_device_init_list
)) {
9824 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
9825 struct _sas_device
, list
);
9826 sas_device_get(sas_device
);
9828 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9833 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
9834 struct _sas_device
*sas_device
)
9836 unsigned long flags
;
9838 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9841 * Since we dropped the lock during the call to port_add(), we need to
9842 * be careful here that somebody else didn't move or delete this item
9843 * while we were busy with other things.
9845 * If it was on the list, we need a put() for the reference the list
9846 * had. Either way, we need a get() for the destination list.
9848 if (!list_empty(&sas_device
->list
)) {
9849 list_del_init(&sas_device
->list
);
9850 sas_device_put(sas_device
);
9853 sas_device_get(sas_device
);
9854 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
9856 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9860 * _scsih_probe_sas - reporting sas devices to sas transport
9861 * @ioc: per adapter object
9863 * Called during initial loading of the driver.
9866 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
9868 struct _sas_device
*sas_device
;
9870 if (ioc
->hide_drives
)
9873 while ((sas_device
= get_next_sas_device(ioc
))) {
9874 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
9875 sas_device
->sas_address_parent
)) {
9876 _scsih_sas_device_remove(ioc
, sas_device
);
9877 sas_device_put(sas_device
);
9879 } else if (!sas_device
->starget
) {
9881 * When asyn scanning is enabled, its not possible to
9882 * remove devices while scanning is turned on due to an
9883 * oops in scsi_sysfs_add_sdev()->add_device()->
9884 * sysfs_addrm_start()
9886 if (!ioc
->is_driver_loading
) {
9887 mpt3sas_transport_port_remove(ioc
,
9888 sas_device
->sas_address
,
9889 sas_device
->sas_address_parent
);
9890 _scsih_sas_device_remove(ioc
, sas_device
);
9891 sas_device_put(sas_device
);
9895 sas_device_make_active(ioc
, sas_device
);
9896 sas_device_put(sas_device
);
9901 * get_next_pcie_device - Get the next pcie device
9902 * @ioc: per adapter object
9904 * Get the next pcie device from pcie_device_init_list list.
9906 * Returns pcie device structure if pcie_device_init_list list is not empty
9907 * otherwise returns NULL
9909 static struct _pcie_device
*get_next_pcie_device(struct MPT3SAS_ADAPTER
*ioc
)
9911 struct _pcie_device
*pcie_device
= NULL
;
9912 unsigned long flags
;
9914 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9915 if (!list_empty(&ioc
->pcie_device_init_list
)) {
9916 pcie_device
= list_first_entry(&ioc
->pcie_device_init_list
,
9917 struct _pcie_device
, list
);
9918 pcie_device_get(pcie_device
);
9920 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9926 * pcie_device_make_active - Add pcie device to pcie_device_list list
9927 * @ioc: per adapter object
9928 * @pcie_device: pcie device object
9930 * Add the pcie device which has registered with SCSI Transport Later to
9931 * pcie_device_list list
9933 static void pcie_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
9934 struct _pcie_device
*pcie_device
)
9936 unsigned long flags
;
9938 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9940 if (!list_empty(&pcie_device
->list
)) {
9941 list_del_init(&pcie_device
->list
);
9942 pcie_device_put(pcie_device
);
9944 pcie_device_get(pcie_device
);
9945 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
9947 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9951 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
9952 * @ioc: per adapter object
9954 * Called during initial loading of the driver.
9957 _scsih_probe_pcie(struct MPT3SAS_ADAPTER
*ioc
)
9959 struct _pcie_device
*pcie_device
;
9962 /* PCIe Device List */
9963 while ((pcie_device
= get_next_pcie_device(ioc
))) {
9964 if (pcie_device
->starget
) {
9965 pcie_device_put(pcie_device
);
9968 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
,
9969 pcie_device
->id
, 0);
9971 _scsih_pcie_device_remove(ioc
, pcie_device
);
9972 pcie_device_put(pcie_device
);
9974 } else if (!pcie_device
->starget
) {
9976 * When async scanning is enabled, its not possible to
9977 * remove devices while scanning is turned on due to an
9978 * oops in scsi_sysfs_add_sdev()->add_device()->
9979 * sysfs_addrm_start()
9981 if (!ioc
->is_driver_loading
) {
9982 /* TODO-- Need to find out whether this condition will
9985 _scsih_pcie_device_remove(ioc
, pcie_device
);
9986 pcie_device_put(pcie_device
);
9990 pcie_device_make_active(ioc
, pcie_device
);
9991 pcie_device_put(pcie_device
);
9996 * _scsih_probe_devices - probing for devices
9997 * @ioc: per adapter object
9999 * Called during initial loading of the driver.
10002 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
10004 u16 volume_mapping_flags
;
10006 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
10007 return; /* return when IOC doesn't support initiator mode */
10009 _scsih_probe_boot_devices(ioc
);
10011 if (ioc
->ir_firmware
) {
10012 volume_mapping_flags
=
10013 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
10014 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
10015 if (volume_mapping_flags
==
10016 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
10017 _scsih_probe_raid(ioc
);
10018 _scsih_probe_sas(ioc
);
10020 _scsih_probe_sas(ioc
);
10021 _scsih_probe_raid(ioc
);
10024 _scsih_probe_sas(ioc
);
10025 _scsih_probe_pcie(ioc
);
10030 * scsih_scan_start - scsi lld callback for .scan_start
10031 * @shost: SCSI host pointer
10033 * The shost has the ability to discover targets on its own instead
10034 * of scanning the entire bus. In our implemention, we will kick off
10035 * firmware discovery.
10038 scsih_scan_start(struct Scsi_Host
*shost
)
10040 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10042 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
10043 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
10045 if (disable_discovery
> 0)
10048 ioc
->start_scan
= 1;
10049 rc
= mpt3sas_port_enable(ioc
);
10052 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
10056 * scsih_scan_finished - scsi lld callback for .scan_finished
10057 * @shost: SCSI host pointer
10058 * @time: elapsed time of the scan in jiffies
10060 * This function will be called periodicallyn until it returns 1 with the
10061 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10062 * we wait for firmware discovery to complete, then return 1.
10065 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
10067 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10069 if (disable_discovery
> 0) {
10070 ioc
->is_driver_loading
= 0;
10071 ioc
->wait_for_discovery_to_complete
= 0;
10075 if (time
>= (300 * HZ
)) {
10076 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
10077 pr_info(MPT3SAS_FMT
10078 "port enable: FAILED with timeout (timeout=300s)\n",
10080 ioc
->is_driver_loading
= 0;
10084 if (ioc
->start_scan
)
10087 if (ioc
->start_scan_failed
) {
10088 pr_info(MPT3SAS_FMT
10089 "port enable: FAILED with (ioc_status=0x%08x)\n",
10090 ioc
->name
, ioc
->start_scan_failed
);
10091 ioc
->is_driver_loading
= 0;
10092 ioc
->wait_for_discovery_to_complete
= 0;
10093 ioc
->remove_host
= 1;
10097 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
10098 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
10100 if (ioc
->wait_for_discovery_to_complete
) {
10101 ioc
->wait_for_discovery_to_complete
= 0;
10102 _scsih_probe_devices(ioc
);
10104 mpt3sas_base_start_watchdog(ioc
);
10105 ioc
->is_driver_loading
= 0;
10109 /* shost template for SAS 2.0 HBA devices */
10110 static struct scsi_host_template mpt2sas_driver_template
= {
10111 .module
= THIS_MODULE
,
10112 .name
= "Fusion MPT SAS Host",
10113 .proc_name
= MPT2SAS_DRIVER_NAME
,
10114 .queuecommand
= scsih_qcmd
,
10115 .target_alloc
= scsih_target_alloc
,
10116 .slave_alloc
= scsih_slave_alloc
,
10117 .slave_configure
= scsih_slave_configure
,
10118 .target_destroy
= scsih_target_destroy
,
10119 .slave_destroy
= scsih_slave_destroy
,
10120 .scan_finished
= scsih_scan_finished
,
10121 .scan_start
= scsih_scan_start
,
10122 .change_queue_depth
= scsih_change_queue_depth
,
10123 .eh_abort_handler
= scsih_abort
,
10124 .eh_device_reset_handler
= scsih_dev_reset
,
10125 .eh_target_reset_handler
= scsih_target_reset
,
10126 .eh_host_reset_handler
= scsih_host_reset
,
10127 .bios_param
= scsih_bios_param
,
10130 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
10131 .max_sectors
= 32767,
10133 .use_clustering
= ENABLE_CLUSTERING
,
10134 .shost_attrs
= mpt3sas_host_attrs
,
10135 .sdev_attrs
= mpt3sas_dev_attrs
,
10136 .track_queue_depth
= 1,
10139 /* raid transport support for SAS 2.0 HBA devices */
10140 static struct raid_function_template mpt2sas_raid_functions
= {
10141 .cookie
= &mpt2sas_driver_template
,
10142 .is_raid
= scsih_is_raid
,
10143 .get_resync
= scsih_get_resync
,
10144 .get_state
= scsih_get_state
,
10147 /* shost template for SAS 3.0 HBA devices */
10148 static struct scsi_host_template mpt3sas_driver_template
= {
10149 .module
= THIS_MODULE
,
10150 .name
= "Fusion MPT SAS Host",
10151 .proc_name
= MPT3SAS_DRIVER_NAME
,
10152 .queuecommand
= scsih_qcmd
,
10153 .target_alloc
= scsih_target_alloc
,
10154 .slave_alloc
= scsih_slave_alloc
,
10155 .slave_configure
= scsih_slave_configure
,
10156 .target_destroy
= scsih_target_destroy
,
10157 .slave_destroy
= scsih_slave_destroy
,
10158 .scan_finished
= scsih_scan_finished
,
10159 .scan_start
= scsih_scan_start
,
10160 .change_queue_depth
= scsih_change_queue_depth
,
10161 .eh_abort_handler
= scsih_abort
,
10162 .eh_device_reset_handler
= scsih_dev_reset
,
10163 .eh_target_reset_handler
= scsih_target_reset
,
10164 .eh_host_reset_handler
= scsih_host_reset
,
10165 .bios_param
= scsih_bios_param
,
10168 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
10169 .max_sectors
= 32767,
10171 .use_clustering
= ENABLE_CLUSTERING
,
10172 .shost_attrs
= mpt3sas_host_attrs
,
10173 .sdev_attrs
= mpt3sas_dev_attrs
,
10174 .track_queue_depth
= 1,
10177 /* raid transport support for SAS 3.0 HBA devices */
10178 static struct raid_function_template mpt3sas_raid_functions
= {
10179 .cookie
= &mpt3sas_driver_template
,
10180 .is_raid
= scsih_is_raid
,
10181 .get_resync
= scsih_get_resync
,
10182 .get_state
= scsih_get_state
,
10186 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10187 * this device belongs to.
10188 * @pdev: PCI device struct
10190 * return MPI2_VERSION for SAS 2.0 HBA devices,
10191 * MPI25_VERSION for SAS 3.0 HBA devices, and
10192 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10195 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
10198 switch (pdev
->device
) {
10199 case MPI2_MFGPAGE_DEVID_SSS6200
:
10200 case MPI2_MFGPAGE_DEVID_SAS2004
:
10201 case MPI2_MFGPAGE_DEVID_SAS2008
:
10202 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
10203 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
10204 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
10205 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
10206 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
10207 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
10208 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
10209 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
10210 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
10211 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
10212 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
10213 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
10214 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
10215 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
10216 return MPI2_VERSION
;
10217 case MPI25_MFGPAGE_DEVID_SAS3004
:
10218 case MPI25_MFGPAGE_DEVID_SAS3008
:
10219 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
10220 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
10221 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
10222 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
10223 return MPI25_VERSION
;
10224 case MPI26_MFGPAGE_DEVID_SAS3216
:
10225 case MPI26_MFGPAGE_DEVID_SAS3224
:
10226 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
10227 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
10228 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
10229 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
10230 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
10231 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
10232 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
10233 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
10234 case MPI26_MFGPAGE_DEVID_SAS3508
:
10235 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10236 case MPI26_MFGPAGE_DEVID_SAS3408
:
10237 case MPI26_MFGPAGE_DEVID_SAS3516
:
10238 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10239 case MPI26_MFGPAGE_DEVID_SAS3416
:
10240 case MPI26_MFGPAGE_DEVID_SAS3616
:
10241 return MPI26_VERSION
;
10247 * _scsih_probe - attach and add scsi host
10248 * @pdev: PCI device struct
10249 * @id: pci device id
10251 * Returns 0 success, anything else error.
10254 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
10256 struct MPT3SAS_ADAPTER
*ioc
;
10257 struct Scsi_Host
*shost
= NULL
;
10259 u16 hba_mpi_version
;
10261 /* Determine in which MPI version class this pci device belongs */
10262 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
10263 if (hba_mpi_version
== 0)
10266 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10267 * for other generation HBA's return with -ENODEV
10269 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
10272 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10273 * for other generation HBA's return with -ENODEV
10275 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
10276 || hba_mpi_version
== MPI26_VERSION
)))
10279 switch (hba_mpi_version
) {
10281 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
10282 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
10283 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10284 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
10285 sizeof(struct MPT3SAS_ADAPTER
));
10288 ioc
= shost_priv(shost
);
10289 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10290 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10291 ioc
->id
= mpt2_ids
++;
10292 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
10293 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
10294 ioc
->is_warpdrive
= 1;
10295 ioc
->hide_ir_msg
= 1;
10297 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
10299 case MPI25_VERSION
:
10300 case MPI26_VERSION
:
10301 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10302 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
10303 sizeof(struct MPT3SAS_ADAPTER
));
10306 ioc
= shost_priv(shost
);
10307 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10308 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10309 ioc
->id
= mpt3_ids
++;
10310 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
10311 switch (pdev
->device
) {
10312 case MPI26_MFGPAGE_DEVID_SAS3508
:
10313 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10314 case MPI26_MFGPAGE_DEVID_SAS3408
:
10315 case MPI26_MFGPAGE_DEVID_SAS3516
:
10316 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10317 case MPI26_MFGPAGE_DEVID_SAS3416
:
10318 case MPI26_MFGPAGE_DEVID_SAS3616
:
10319 ioc
->is_gen35_ioc
= 1;
10322 ioc
->is_gen35_ioc
= 0;
10324 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
10325 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
10326 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
10327 ioc
->combined_reply_queue
= 1;
10328 if (ioc
->is_gen35_ioc
)
10329 ioc
->combined_reply_index_count
=
10330 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
10332 ioc
->combined_reply_index_count
=
10333 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
10340 INIT_LIST_HEAD(&ioc
->list
);
10341 spin_lock(&gioc_lock
);
10342 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
10343 spin_unlock(&gioc_lock
);
10344 ioc
->shost
= shost
;
10346 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
10347 ioc
->tm_cb_idx
= tm_cb_idx
;
10348 ioc
->ctl_cb_idx
= ctl_cb_idx
;
10349 ioc
->base_cb_idx
= base_cb_idx
;
10350 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
10351 ioc
->transport_cb_idx
= transport_cb_idx
;
10352 ioc
->scsih_cb_idx
= scsih_cb_idx
;
10353 ioc
->config_cb_idx
= config_cb_idx
;
10354 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
10355 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
10356 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
10357 ioc
->logging_level
= logging_level
;
10358 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
10359 /* misc semaphores and spin locks */
10360 mutex_init(&ioc
->reset_in_progress_mutex
);
10361 /* initializing pci_access_mutex lock */
10362 mutex_init(&ioc
->pci_access_mutex
);
10363 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
10364 spin_lock_init(&ioc
->scsi_lookup_lock
);
10365 spin_lock_init(&ioc
->sas_device_lock
);
10366 spin_lock_init(&ioc
->sas_node_lock
);
10367 spin_lock_init(&ioc
->fw_event_lock
);
10368 spin_lock_init(&ioc
->raid_device_lock
);
10369 spin_lock_init(&ioc
->pcie_device_lock
);
10370 spin_lock_init(&ioc
->diag_trigger_lock
);
10372 INIT_LIST_HEAD(&ioc
->sas_device_list
);
10373 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
10374 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
10375 INIT_LIST_HEAD(&ioc
->pcie_device_list
);
10376 INIT_LIST_HEAD(&ioc
->pcie_device_init_list
);
10377 INIT_LIST_HEAD(&ioc
->fw_event_list
);
10378 INIT_LIST_HEAD(&ioc
->raid_device_list
);
10379 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
10380 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
10381 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
10382 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
10383 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
10384 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
10386 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
10388 /* init shost parameters */
10389 shost
->max_cmd_len
= 32;
10390 shost
->max_lun
= max_lun
;
10391 shost
->transportt
= mpt3sas_transport_template
;
10392 shost
->unique_id
= ioc
->id
;
10394 if (max_sectors
!= 0xFFFF) {
10395 if (max_sectors
< 64) {
10396 shost
->max_sectors
= 64;
10397 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10398 "for max_sectors, range is 64 to 32767. Assigning "
10399 "value of 64.\n", ioc
->name
, max_sectors
);
10400 } else if (max_sectors
> 32767) {
10401 shost
->max_sectors
= 32767;
10402 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
10403 "for max_sectors, range is 64 to 32767. Assigning "
10404 "default value of 32767.\n", ioc
->name
,
10407 shost
->max_sectors
= max_sectors
& 0xFFFE;
10408 pr_info(MPT3SAS_FMT
10409 "The max_sectors value is set to %d\n",
10410 ioc
->name
, shost
->max_sectors
);
10414 /* register EEDP capabilities with SCSI layer */
10416 scsi_host_set_prot(shost
, prot_mask
);
10418 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
10419 | SHOST_DIF_TYPE2_PROTECTION
10420 | SHOST_DIF_TYPE3_PROTECTION
);
10422 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
10425 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
10426 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
10427 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
10428 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
10429 if (!ioc
->firmware_event_thread
) {
10430 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10431 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10433 goto out_thread_fail
;
10436 ioc
->is_driver_loading
= 1;
10437 if ((mpt3sas_base_attach(ioc
))) {
10438 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10439 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10441 goto out_attach_fail
;
10444 if (ioc
->is_warpdrive
) {
10445 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
10446 ioc
->hide_drives
= 0;
10447 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
10448 ioc
->hide_drives
= 1;
10450 if (mpt3sas_get_num_volumes(ioc
))
10451 ioc
->hide_drives
= 1;
10453 ioc
->hide_drives
= 0;
10456 ioc
->hide_drives
= 0;
10458 rv
= scsi_add_host(shost
, &pdev
->dev
);
10460 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
10461 ioc
->name
, __FILE__
, __LINE__
, __func__
);
10462 goto out_add_shost_fail
;
10465 scsi_scan_host(shost
);
10467 out_add_shost_fail
:
10468 mpt3sas_base_detach(ioc
);
10470 destroy_workqueue(ioc
->firmware_event_thread
);
10472 spin_lock(&gioc_lock
);
10473 list_del(&ioc
->list
);
10474 spin_unlock(&gioc_lock
);
10475 scsi_host_put(shost
);
10481 * scsih_suspend - power management suspend main entry point
10482 * @pdev: PCI device struct
10483 * @state: PM state change to (usually PCI_D3)
10485 * Returns 0 success, anything else error.
10488 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10490 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10491 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10492 pci_power_t device_state
;
10494 mpt3sas_base_stop_watchdog(ioc
);
10495 flush_scheduled_work();
10496 scsi_block_requests(shost
);
10497 device_state
= pci_choose_state(pdev
, state
);
10498 pr_info(MPT3SAS_FMT
10499 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10500 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10502 pci_save_state(pdev
);
10503 mpt3sas_base_free_resources(ioc
);
10504 pci_set_power_state(pdev
, device_state
);
10509 * scsih_resume - power management resume main entry point
10510 * @pdev: PCI device struct
10512 * Returns 0 success, anything else error.
10515 scsih_resume(struct pci_dev
*pdev
)
10517 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10518 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10519 pci_power_t device_state
= pdev
->current_state
;
10522 pr_info(MPT3SAS_FMT
10523 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10524 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
10526 pci_set_power_state(pdev
, PCI_D0
);
10527 pci_enable_wake(pdev
, PCI_D0
, 0);
10528 pci_restore_state(pdev
);
10530 r
= mpt3sas_base_map_resources(ioc
);
10534 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
10535 scsi_unblock_requests(shost
);
10536 mpt3sas_base_start_watchdog(ioc
);
10539 #endif /* CONFIG_PM */
10542 * scsih_pci_error_detected - Called when a PCI error is detected.
10543 * @pdev: PCI device struct
10544 * @state: PCI channel state
10546 * Description: Called when a PCI error is detected.
10549 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
10551 static pci_ers_result_t
10552 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10554 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10555 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10557 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
10561 case pci_channel_io_normal
:
10562 return PCI_ERS_RESULT_CAN_RECOVER
;
10563 case pci_channel_io_frozen
:
10564 /* Fatal error, prepare for slot reset */
10565 ioc
->pci_error_recovery
= 1;
10566 scsi_block_requests(ioc
->shost
);
10567 mpt3sas_base_stop_watchdog(ioc
);
10568 mpt3sas_base_free_resources(ioc
);
10569 return PCI_ERS_RESULT_NEED_RESET
;
10570 case pci_channel_io_perm_failure
:
10571 /* Permanent error, prepare for device removal */
10572 ioc
->pci_error_recovery
= 1;
10573 mpt3sas_base_stop_watchdog(ioc
);
10574 _scsih_flush_running_cmds(ioc
);
10575 return PCI_ERS_RESULT_DISCONNECT
;
10577 return PCI_ERS_RESULT_NEED_RESET
;
10581 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10582 * @pdev: PCI device struct
10584 * Description: This routine is called by the pci error recovery
10585 * code after the PCI slot has been reset, just before we
10586 * should resume normal operations.
10588 static pci_ers_result_t
10589 scsih_pci_slot_reset(struct pci_dev
*pdev
)
10591 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10592 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10595 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
10598 ioc
->pci_error_recovery
= 0;
10600 pci_restore_state(pdev
);
10601 rc
= mpt3sas_base_map_resources(ioc
);
10603 return PCI_ERS_RESULT_DISCONNECT
;
10605 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
10607 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
10608 (rc
== 0) ? "success" : "failed");
10611 return PCI_ERS_RESULT_RECOVERED
;
10613 return PCI_ERS_RESULT_DISCONNECT
;
10617 * scsih_pci_resume() - resume normal ops after PCI reset
10618 * @pdev: pointer to PCI device
10620 * Called when the error recovery driver tells us that its
10621 * OK to resume normal operation. Use completion to allow
10622 * halted scsi ops to resume.
10625 scsih_pci_resume(struct pci_dev
*pdev
)
10627 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10628 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10630 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
10632 pci_cleanup_aer_uncorrect_error_status(pdev
);
10633 mpt3sas_base_start_watchdog(ioc
);
10634 scsi_unblock_requests(ioc
->shost
);
10638 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10639 * @pdev: pointer to PCI device
10641 static pci_ers_result_t
10642 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
10644 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10645 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10647 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
10650 /* TODO - dump whatever for debugging purposes */
10652 /* This called only if scsih_pci_error_detected returns
10653 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10654 * works, no need to reset slot.
10656 return PCI_ERS_RESULT_RECOVERED
;
10660 * scsih__ncq_prio_supp - Check for NCQ command priority support
10661 * @sdev: scsi device struct
10663 * This is called when a user indicates they would like to enable
10664 * ncq command priorities. This works only on SATA devices.
10666 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
10668 unsigned char *buf
;
10669 bool ncq_prio_supp
= false;
10671 if (!scsi_device_supports_vpd(sdev
))
10672 return ncq_prio_supp
;
10674 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
10676 return ncq_prio_supp
;
10678 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
10679 ncq_prio_supp
= (buf
[213] >> 4) & 1;
10682 return ncq_prio_supp
;
10685 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10687 static const struct pci_device_id mpt3sas_pci_table
[] = {
10688 /* Spitfire ~ 2004 */
10689 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
10690 PCI_ANY_ID
, PCI_ANY_ID
},
10691 /* Falcon ~ 2008 */
10692 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
10693 PCI_ANY_ID
, PCI_ANY_ID
},
10694 /* Liberator ~ 2108 */
10695 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
10696 PCI_ANY_ID
, PCI_ANY_ID
},
10697 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
10698 PCI_ANY_ID
, PCI_ANY_ID
},
10699 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
10700 PCI_ANY_ID
, PCI_ANY_ID
},
10701 /* Meteor ~ 2116 */
10702 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
10703 PCI_ANY_ID
, PCI_ANY_ID
},
10704 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
10705 PCI_ANY_ID
, PCI_ANY_ID
},
10706 /* Thunderbolt ~ 2208 */
10707 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
10708 PCI_ANY_ID
, PCI_ANY_ID
},
10709 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
10710 PCI_ANY_ID
, PCI_ANY_ID
},
10711 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
10712 PCI_ANY_ID
, PCI_ANY_ID
},
10713 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
10714 PCI_ANY_ID
, PCI_ANY_ID
},
10715 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
10716 PCI_ANY_ID
, PCI_ANY_ID
},
10717 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
10718 PCI_ANY_ID
, PCI_ANY_ID
},
10719 /* Mustang ~ 2308 */
10720 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
10721 PCI_ANY_ID
, PCI_ANY_ID
},
10722 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
10723 PCI_ANY_ID
, PCI_ANY_ID
},
10724 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
10725 PCI_ANY_ID
, PCI_ANY_ID
},
10727 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
10728 PCI_ANY_ID
, PCI_ANY_ID
},
10729 /* Fury ~ 3004 and 3008 */
10730 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
10731 PCI_ANY_ID
, PCI_ANY_ID
},
10732 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
10733 PCI_ANY_ID
, PCI_ANY_ID
},
10734 /* Invader ~ 3108 */
10735 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
10736 PCI_ANY_ID
, PCI_ANY_ID
},
10737 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
10738 PCI_ANY_ID
, PCI_ANY_ID
},
10739 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
10740 PCI_ANY_ID
, PCI_ANY_ID
},
10741 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
10742 PCI_ANY_ID
, PCI_ANY_ID
},
10743 /* Cutlass ~ 3216 and 3224 */
10744 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
10745 PCI_ANY_ID
, PCI_ANY_ID
},
10746 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
10747 PCI_ANY_ID
, PCI_ANY_ID
},
10748 /* Intruder ~ 3316 and 3324 */
10749 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
10750 PCI_ANY_ID
, PCI_ANY_ID
},
10751 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
10752 PCI_ANY_ID
, PCI_ANY_ID
},
10753 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
10754 PCI_ANY_ID
, PCI_ANY_ID
},
10755 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
10756 PCI_ANY_ID
, PCI_ANY_ID
},
10757 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
10758 PCI_ANY_ID
, PCI_ANY_ID
},
10759 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
10760 PCI_ANY_ID
, PCI_ANY_ID
},
10761 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
10762 PCI_ANY_ID
, PCI_ANY_ID
},
10763 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
10764 PCI_ANY_ID
, PCI_ANY_ID
},
10765 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
10766 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
10767 PCI_ANY_ID
, PCI_ANY_ID
},
10768 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
10769 PCI_ANY_ID
, PCI_ANY_ID
},
10770 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
10771 PCI_ANY_ID
, PCI_ANY_ID
},
10772 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
10773 PCI_ANY_ID
, PCI_ANY_ID
},
10774 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
10775 PCI_ANY_ID
, PCI_ANY_ID
},
10776 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
10777 PCI_ANY_ID
, PCI_ANY_ID
},
10778 /* Mercator ~ 3616*/
10779 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3616
,
10780 PCI_ANY_ID
, PCI_ANY_ID
},
10781 {0} /* Terminating entry */
10783 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
10785 static struct pci_error_handlers _mpt3sas_err_handler
= {
10786 .error_detected
= scsih_pci_error_detected
,
10787 .mmio_enabled
= scsih_pci_mmio_enabled
,
10788 .slot_reset
= scsih_pci_slot_reset
,
10789 .resume
= scsih_pci_resume
,
10792 static struct pci_driver mpt3sas_driver
= {
10793 .name
= MPT3SAS_DRIVER_NAME
,
10794 .id_table
= mpt3sas_pci_table
,
10795 .probe
= _scsih_probe
,
10796 .remove
= scsih_remove
,
10797 .shutdown
= scsih_shutdown
,
10798 .err_handler
= &_mpt3sas_err_handler
,
10800 .suspend
= scsih_suspend
,
10801 .resume
= scsih_resume
,
10806 * scsih_init - main entry point for this driver.
10808 * Returns 0 success, anything else error.
10816 mpt3sas_base_initialize_callback_handler();
10818 /* queuecommand callback hander */
10819 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
10821 /* task management callback handler */
10822 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
10824 /* base internal commands callback handler */
10825 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
10826 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
10827 mpt3sas_port_enable_done
);
10829 /* transport internal commands callback handler */
10830 transport_cb_idx
= mpt3sas_base_register_callback_handler(
10831 mpt3sas_transport_done
);
10833 /* scsih internal commands callback handler */
10834 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
10836 /* configuration page API internal commands callback handler */
10837 config_cb_idx
= mpt3sas_base_register_callback_handler(
10838 mpt3sas_config_done
);
10840 /* ctl module callback handler */
10841 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
10843 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
10844 _scsih_tm_tr_complete
);
10846 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
10847 _scsih_tm_volume_tr_complete
);
10849 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
10850 _scsih_sas_control_complete
);
10856 * scsih_exit - exit point for this driver (when it is a module).
10858 * Returns 0 success, anything else error.
10864 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
10865 mpt3sas_base_release_callback_handler(tm_cb_idx
);
10866 mpt3sas_base_release_callback_handler(base_cb_idx
);
10867 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
10868 mpt3sas_base_release_callback_handler(transport_cb_idx
);
10869 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
10870 mpt3sas_base_release_callback_handler(config_cb_idx
);
10871 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
10873 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
10874 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
10875 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
10877 /* raid transport support */
10878 if (hbas_to_enumerate
!= 1)
10879 raid_class_release(mpt3sas_raid_template
);
10880 if (hbas_to_enumerate
!= 2)
10881 raid_class_release(mpt2sas_raid_template
);
10882 sas_release_transport(mpt3sas_transport_template
);
10886 * _mpt3sas_init - main entry point for this driver.
10888 * Returns 0 success, anything else error.
10891 _mpt3sas_init(void)
10895 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
10896 MPT3SAS_DRIVER_VERSION
);
10898 mpt3sas_transport_template
=
10899 sas_attach_transport(&mpt3sas_transport_functions
);
10900 if (!mpt3sas_transport_template
)
10903 /* No need attach mpt3sas raid functions template
10904 * if hbas_to_enumarate value is one.
10906 if (hbas_to_enumerate
!= 1) {
10907 mpt3sas_raid_template
=
10908 raid_class_attach(&mpt3sas_raid_functions
);
10909 if (!mpt3sas_raid_template
) {
10910 sas_release_transport(mpt3sas_transport_template
);
10915 /* No need to attach mpt2sas raid functions template
10916 * if hbas_to_enumarate value is two
10918 if (hbas_to_enumerate
!= 2) {
10919 mpt2sas_raid_template
=
10920 raid_class_attach(&mpt2sas_raid_functions
);
10921 if (!mpt2sas_raid_template
) {
10922 sas_release_transport(mpt3sas_transport_template
);
10927 error
= scsih_init();
10933 mpt3sas_ctl_init(hbas_to_enumerate
);
10935 error
= pci_register_driver(&mpt3sas_driver
);
10943 * _mpt3sas_exit - exit point for this driver (when it is a module).
10947 _mpt3sas_exit(void)
10949 pr_info("mpt3sas version %s unloading\n",
10950 MPT3SAS_DRIVER_VERSION
);
10952 pci_unregister_driver(&mpt3sas_driver
);
10954 mpt3sas_ctl_exit(hbas_to_enumerate
);
10959 module_init(_mpt3sas_init
);
10960 module_exit(_mpt3sas_exit
);