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 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
65 struct _sas_node
*sas_expander
);
66 static void _firmware_event_work(struct work_struct
*work
);
68 static void _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
69 struct _sas_device
*sas_device
);
70 static int _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
71 u8 retry_count
, u8 is_pd
);
73 static u8
_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
);
75 /* global parameters */
76 LIST_HEAD(mpt3sas_ioc_list
);
77 /* global ioc lock for list operations */
78 DEFINE_SPINLOCK(gioc_lock
);
80 MODULE_AUTHOR(MPT3SAS_AUTHOR
);
81 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION
);
82 MODULE_LICENSE("GPL");
83 MODULE_VERSION(MPT3SAS_DRIVER_VERSION
);
84 MODULE_ALIAS("mpt2sas");
86 /* local parameters */
87 static u8 scsi_io_cb_idx
= -1;
88 static u8 tm_cb_idx
= -1;
89 static u8 ctl_cb_idx
= -1;
90 static u8 base_cb_idx
= -1;
91 static u8 port_enable_cb_idx
= -1;
92 static u8 transport_cb_idx
= -1;
93 static u8 scsih_cb_idx
= -1;
94 static u8 config_cb_idx
= -1;
98 static u8 tm_tr_cb_idx
= -1 ;
99 static u8 tm_tr_volume_cb_idx
= -1 ;
100 static u8 tm_sas_control_cb_idx
= -1;
102 /* command line options */
103 static u32 logging_level
;
104 MODULE_PARM_DESC(logging_level
,
105 " bits for enabling additional logging info (default=0)");
108 static ushort max_sectors
= 0xFFFF;
109 module_param(max_sectors
, ushort
, 0);
110 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
113 static int missing_delay
[2] = {-1, -1};
114 module_param_array(missing_delay
, int, NULL
, 0);
115 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
117 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
118 #define MPT3SAS_MAX_LUN (16895)
119 static u64 max_lun
= MPT3SAS_MAX_LUN
;
120 module_param(max_lun
, ullong
, 0);
121 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
123 static ushort hbas_to_enumerate
;
124 module_param(hbas_to_enumerate
, ushort
, 0);
125 MODULE_PARM_DESC(hbas_to_enumerate
,
126 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
127 1 - enumerates only SAS 2.0 generation HBAs\n \
128 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
130 /* diag_buffer_enable is bitwise
132 * bit 1 set = SNAPSHOT
133 * bit 2 set = EXTENDED
135 * Either bit can be set, or both
137 static int diag_buffer_enable
= -1;
138 module_param(diag_buffer_enable
, int, 0);
139 MODULE_PARM_DESC(diag_buffer_enable
,
140 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
141 static int disable_discovery
= -1;
142 module_param(disable_discovery
, int, 0);
143 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
146 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
147 static int prot_mask
= -1;
148 module_param(prot_mask
, int, 0);
149 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
152 /* raid transport support */
153 struct raid_template
*mpt3sas_raid_template
;
154 struct raid_template
*mpt2sas_raid_template
;
158 * struct sense_info - common structure for obtaining sense keys
160 * @asc: additional sense code
161 * @ascq: additional sense code qualifier
169 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
170 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
171 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
172 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
173 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
175 * struct fw_event_work - firmware event struct
176 * @list: link list framework
177 * @work: work object (ioc->fault_reset_work_q)
178 * @ioc: per adapter object
179 * @device_handle: device handle
180 * @VF_ID: virtual function id
181 * @VP_ID: virtual port id
182 * @ignore: flag meaning this event has been marked to ignore
183 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
184 * @refcount: kref for this event
185 * @event_data: reply event data payload follows
187 * This object stored on ioc->fw_event_list.
189 struct fw_event_work
{
190 struct list_head list
;
191 struct work_struct work
;
193 struct MPT3SAS_ADAPTER
*ioc
;
199 struct kref refcount
;
200 char event_data
[0] __aligned(4);
203 static void fw_event_work_free(struct kref
*r
)
205 kfree(container_of(r
, struct fw_event_work
, refcount
));
208 static void fw_event_work_get(struct fw_event_work
*fw_work
)
210 kref_get(&fw_work
->refcount
);
213 static void fw_event_work_put(struct fw_event_work
*fw_work
)
215 kref_put(&fw_work
->refcount
, fw_event_work_free
);
218 static struct fw_event_work
*alloc_fw_event_work(int len
)
220 struct fw_event_work
*fw_event
;
222 fw_event
= kzalloc(sizeof(*fw_event
) + len
, GFP_ATOMIC
);
226 kref_init(&fw_event
->refcount
);
231 * struct _scsi_io_transfer - scsi io transfer
232 * @handle: sas device handle (assigned by firmware)
233 * @is_raid: flag set for hidden raid components
234 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
235 * @data_length: data transfer length
236 * @data_dma: dma pointer to data
239 * @cdb_length: cdb length
241 * @timeout: timeout for this command
242 * @VF_ID: virtual function id
243 * @VP_ID: virtual port id
244 * @valid_reply: flag set for reply message
245 * @sense_length: sense length
246 * @ioc_status: ioc status
247 * @scsi_state: scsi state
248 * @scsi_status: scsi staus
249 * @log_info: log information
250 * @transfer_length: data length transfer when there is a reply message
252 * Used for sending internal scsi commands to devices within this module.
253 * Refer to _scsi_send_scsi_io().
255 struct _scsi_io_transfer
{
258 enum dma_data_direction dir
;
261 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
269 /* the following bits are only valid when 'valid_reply = 1' */
279 * _scsih_set_debug_level - global setting of ioc->logging_level.
281 * Note: The logging levels are defined in mpt3sas_debug.h.
284 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
286 int ret
= param_set_int(val
, kp
);
287 struct MPT3SAS_ADAPTER
*ioc
;
292 pr_info("setting logging_level(0x%08x)\n", logging_level
);
293 spin_lock(&gioc_lock
);
294 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
295 ioc
->logging_level
= logging_level
;
296 spin_unlock(&gioc_lock
);
299 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
300 &logging_level
, 0644);
303 * _scsih_srch_boot_sas_address - search based on sas_address
304 * @sas_address: sas address
305 * @boot_device: boot device object from bios page 2
307 * Returns 1 when there's a match, 0 means no match.
310 _scsih_srch_boot_sas_address(u64 sas_address
,
311 Mpi2BootDeviceSasWwid_t
*boot_device
)
313 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
317 * _scsih_srch_boot_device_name - search based on device name
318 * @device_name: device name specified in INDENTIFY fram
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_device_name(u64 device_name
,
325 Mpi2BootDeviceDeviceName_t
*boot_device
)
327 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
331 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
332 * @enclosure_logical_id: enclosure logical id
333 * @slot_number: slot number
334 * @boot_device: boot device object from bios page 2
336 * Returns 1 when there's a match, 0 means no match.
339 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
340 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
342 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
343 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
344 SlotNumber
)) ? 1 : 0;
348 * _scsih_is_boot_device - search for matching boot device.
349 * @sas_address: sas address
350 * @device_name: device name specified in INDENTIFY fram
351 * @enclosure_logical_id: enclosure logical id
352 * @slot_number: slot number
353 * @form: specifies boot device form
354 * @boot_device: boot device object from bios page 2
356 * Returns 1 when there's a match, 0 means no match.
359 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
360 u64 enclosure_logical_id
, u16 slot
, u8 form
,
361 Mpi2BiosPage2BootDevice_t
*boot_device
)
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
369 rc
= _scsih_srch_boot_sas_address(
370 sas_address
, &boot_device
->SasWwid
);
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
373 if (!enclosure_logical_id
)
375 rc
= _scsih_srch_boot_encl_slot(
376 enclosure_logical_id
,
377 slot
, &boot_device
->EnclosureSlot
);
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
382 rc
= _scsih_srch_boot_device_name(
383 device_name
, &boot_device
->DeviceName
);
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
393 * _scsih_get_sas_address - set the sas_address for given device handle
394 * @handle: device handle
395 * @sas_address: sas address
397 * Returns 0 success, non-zero when failure
400 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
403 Mpi2SasDevicePage0_t sas_device_pg0
;
404 Mpi2ConfigReply_t mpi_reply
;
409 if (handle
<= ioc
->sas_hba
.num_phys
) {
410 *sas_address
= ioc
->sas_hba
.sas_address
;
414 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
415 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
416 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
417 __FILE__
, __LINE__
, __func__
);
421 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
422 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
423 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
427 /* we hit this because the given parent handle doesn't exist */
428 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
431 /* else error case */
433 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
434 ioc
->name
, handle
, ioc_status
,
435 __FILE__
, __LINE__
, __func__
);
440 * _scsih_determine_boot_device - determine boot device.
441 * @ioc: per adapter object
442 * @device: either sas_device or raid_device object
443 * @is_raid: [flag] 1 = raid object, 0 = sas object
445 * Determines whether this device should be first reported device to
446 * to scsi-ml or sas transport, this purpose is for persistent boot device.
447 * There are primary, alternate, and current entries in bios page 2. The order
448 * priority is primary, alternate, then current. This routine saves
449 * the corresponding device object and is_raid flag in the ioc object.
450 * The saved data to be used later in _scsih_probe_boot_devices().
453 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
,
454 void *device
, u8 is_raid
)
456 struct _sas_device
*sas_device
;
457 struct _raid_device
*raid_device
;
460 u64 enclosure_logical_id
;
463 /* only process this function when driver loads */
464 if (!ioc
->is_driver_loading
)
467 /* no Bios, return immediately */
468 if (!ioc
->bios_pg3
.BiosVersion
)
473 sas_address
= sas_device
->sas_address
;
474 device_name
= sas_device
->device_name
;
475 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
476 slot
= sas_device
->slot
;
478 raid_device
= device
;
479 sas_address
= raid_device
->wwid
;
481 enclosure_logical_id
= 0;
485 if (!ioc
->req_boot_device
.device
) {
486 if (_scsih_is_boot_device(sas_address
, device_name
,
487 enclosure_logical_id
, slot
,
488 (ioc
->bios_pg2
.ReqBootDeviceForm
&
489 MPI2_BIOSPAGE2_FORM_MASK
),
490 &ioc
->bios_pg2
.RequestedBootDevice
)) {
491 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
492 "%s: req_boot_device(0x%016llx)\n",
494 (unsigned long long)sas_address
));
495 ioc
->req_boot_device
.device
= device
;
496 ioc
->req_boot_device
.is_raid
= is_raid
;
500 if (!ioc
->req_alt_boot_device
.device
) {
501 if (_scsih_is_boot_device(sas_address
, device_name
,
502 enclosure_logical_id
, slot
,
503 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
504 MPI2_BIOSPAGE2_FORM_MASK
),
505 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
506 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
507 "%s: req_alt_boot_device(0x%016llx)\n",
509 (unsigned long long)sas_address
));
510 ioc
->req_alt_boot_device
.device
= device
;
511 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
515 if (!ioc
->current_boot_device
.device
) {
516 if (_scsih_is_boot_device(sas_address
, device_name
,
517 enclosure_logical_id
, slot
,
518 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
519 MPI2_BIOSPAGE2_FORM_MASK
),
520 &ioc
->bios_pg2
.CurrentBootDevice
)) {
521 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
522 "%s: current_boot_device(0x%016llx)\n",
524 (unsigned long long)sas_address
));
525 ioc
->current_boot_device
.device
= device
;
526 ioc
->current_boot_device
.is_raid
= is_raid
;
531 static struct _sas_device
*
532 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
533 struct MPT3SAS_TARGET
*tgt_priv
)
535 struct _sas_device
*ret
;
537 assert_spin_locked(&ioc
->sas_device_lock
);
539 ret
= tgt_priv
->sdev
;
546 static struct _sas_device
*
547 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
548 struct MPT3SAS_TARGET
*tgt_priv
)
550 struct _sas_device
*ret
;
553 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
554 ret
= __mpt3sas_get_sdev_from_target(ioc
, tgt_priv
);
555 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
562 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
565 struct _sas_device
*sas_device
;
567 assert_spin_locked(&ioc
->sas_device_lock
);
569 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
570 if (sas_device
->sas_address
== sas_address
)
573 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
574 if (sas_device
->sas_address
== sas_address
)
580 sas_device_get(sas_device
);
585 * mpt3sas_get_sdev_by_addr - sas device search
586 * @ioc: per adapter object
587 * @sas_address: sas address
588 * Context: Calling function should acquire ioc->sas_device_lock
590 * This searches for sas_device based on sas_address, then return sas_device
594 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
597 struct _sas_device
*sas_device
;
600 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
601 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
603 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
608 static struct _sas_device
*
609 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
611 struct _sas_device
*sas_device
;
613 assert_spin_locked(&ioc
->sas_device_lock
);
615 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
616 if (sas_device
->handle
== handle
)
619 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
620 if (sas_device
->handle
== handle
)
626 sas_device_get(sas_device
);
631 * mpt3sas_get_sdev_by_handle - sas device search
632 * @ioc: per adapter object
633 * @handle: sas device handle (assigned by firmware)
634 * Context: Calling function should acquire ioc->sas_device_lock
636 * This searches for sas_device based on sas_address, then return sas_device
639 static struct _sas_device
*
640 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
642 struct _sas_device
*sas_device
;
645 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
646 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
647 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
653 * _scsih_sas_device_remove - remove sas_device from list.
654 * @ioc: per adapter object
655 * @sas_device: the sas_device object
656 * Context: This function will acquire ioc->sas_device_lock.
658 * If sas_device is on the list, remove it and decrement its reference count.
661 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
662 struct _sas_device
*sas_device
)
669 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
670 ioc
->name
, sas_device
->handle
,
671 (unsigned long long) sas_device
->sas_address
);
673 if (sas_device
->enclosure_handle
!= 0)
675 "removing enclosure logical id(0x%016llx), slot(%d)\n",
676 ioc
->name
, (unsigned long long)
677 sas_device
->enclosure_logical_id
, sas_device
->slot
);
679 if (sas_device
->connector_name
[0] != '\0')
681 "removing enclosure level(0x%04x), connector name( %s)\n",
682 ioc
->name
, sas_device
->enclosure_level
,
683 sas_device
->connector_name
);
686 * The lock serializes access to the list, but we still need to verify
687 * that nobody removed the entry while we were waiting on the lock.
689 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
690 if (!list_empty(&sas_device
->list
)) {
691 list_del_init(&sas_device
->list
);
692 sas_device_put(sas_device
);
694 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
698 * _scsih_device_remove_by_handle - removing device object by handle
699 * @ioc: per adapter object
700 * @handle: device handle
705 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
707 struct _sas_device
*sas_device
;
710 if (ioc
->shost_recovery
)
713 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
714 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
716 list_del_init(&sas_device
->list
);
717 sas_device_put(sas_device
);
719 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
721 _scsih_remove_device(ioc
, sas_device
);
722 sas_device_put(sas_device
);
727 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
728 * @ioc: per adapter object
729 * @sas_address: device sas_address
734 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
737 struct _sas_device
*sas_device
;
740 if (ioc
->shost_recovery
)
743 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
744 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
, sas_address
);
746 list_del_init(&sas_device
->list
);
747 sas_device_put(sas_device
);
749 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
751 _scsih_remove_device(ioc
, sas_device
);
752 sas_device_put(sas_device
);
757 * _scsih_sas_device_add - insert sas_device to the list.
758 * @ioc: per adapter object
759 * @sas_device: the sas_device object
760 * Context: This function will acquire ioc->sas_device_lock.
762 * Adding new object to the ioc->sas_device_list.
765 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
766 struct _sas_device
*sas_device
)
770 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
771 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
772 ioc
->name
, __func__
, sas_device
->handle
,
773 (unsigned long long)sas_device
->sas_address
));
775 if (sas_device
->enclosure_handle
!= 0)
776 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
777 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
778 ioc
->name
, __func__
, (unsigned long long)
779 sas_device
->enclosure_logical_id
, sas_device
->slot
));
781 if (sas_device
->connector_name
[0] != '\0')
782 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
783 "%s: enclosure level(0x%04x), connector name( %s)\n",
785 sas_device
->enclosure_level
, sas_device
->connector_name
));
787 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
788 sas_device_get(sas_device
);
789 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
790 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
792 if (ioc
->hide_drives
) {
793 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
797 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
798 sas_device
->sas_address_parent
)) {
799 _scsih_sas_device_remove(ioc
, sas_device
);
800 } else if (!sas_device
->starget
) {
802 * When asyn scanning is enabled, its not possible to remove
803 * devices while scanning is turned on due to an oops in
804 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
806 if (!ioc
->is_driver_loading
) {
807 mpt3sas_transport_port_remove(ioc
,
808 sas_device
->sas_address
,
809 sas_device
->sas_address_parent
);
810 _scsih_sas_device_remove(ioc
, sas_device
);
813 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
817 * _scsih_sas_device_init_add - insert sas_device to the list.
818 * @ioc: per adapter object
819 * @sas_device: the sas_device object
820 * Context: This function will acquire ioc->sas_device_lock.
822 * Adding new object at driver load time to the ioc->sas_device_init_list.
825 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
826 struct _sas_device
*sas_device
)
830 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
831 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
832 __func__
, sas_device
->handle
,
833 (unsigned long long)sas_device
->sas_address
));
835 if (sas_device
->enclosure_handle
!= 0)
836 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
837 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
838 ioc
->name
, __func__
, (unsigned long long)
839 sas_device
->enclosure_logical_id
, sas_device
->slot
));
841 if (sas_device
->connector_name
[0] != '\0')
842 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
843 "%s: enclosure level(0x%04x), connector name( %s)\n",
844 ioc
->name
, __func__
, sas_device
->enclosure_level
,
845 sas_device
->connector_name
));
847 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
848 sas_device_get(sas_device
);
849 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
850 _scsih_determine_boot_device(ioc
, sas_device
, 0);
851 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
855 * _scsih_raid_device_find_by_id - raid device search
856 * @ioc: per adapter object
857 * @id: sas device target id
858 * @channel: sas device channel
859 * Context: Calling function should acquire ioc->raid_device_lock
861 * This searches for raid_device based on target id, then return raid_device
864 static struct _raid_device
*
865 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
867 struct _raid_device
*raid_device
, *r
;
870 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
871 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
882 * mpt3sas_raid_device_find_by_handle - raid device search
883 * @ioc: per adapter object
884 * @handle: sas device handle (assigned by firmware)
885 * Context: Calling function should acquire ioc->raid_device_lock
887 * This searches for raid_device based on handle, then return raid_device
890 struct _raid_device
*
891 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
893 struct _raid_device
*raid_device
, *r
;
896 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
897 if (raid_device
->handle
!= handle
)
908 * _scsih_raid_device_find_by_wwid - raid device search
909 * @ioc: per adapter object
910 * @handle: sas device handle (assigned by firmware)
911 * Context: Calling function should acquire ioc->raid_device_lock
913 * This searches for raid_device based on wwid, then return raid_device
916 static struct _raid_device
*
917 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
919 struct _raid_device
*raid_device
, *r
;
922 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
923 if (raid_device
->wwid
!= wwid
)
934 * _scsih_raid_device_add - add raid_device object
935 * @ioc: per adapter object
936 * @raid_device: raid_device object
938 * This is added to the raid_device_list link list.
941 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
942 struct _raid_device
*raid_device
)
946 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
947 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
948 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
950 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
951 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
952 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
956 * _scsih_raid_device_remove - delete raid_device object
957 * @ioc: per adapter object
958 * @raid_device: raid_device object
962 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
963 struct _raid_device
*raid_device
)
967 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
968 list_del(&raid_device
->list
);
970 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
974 * mpt3sas_scsih_expander_find_by_handle - expander device search
975 * @ioc: per adapter object
976 * @handle: expander handle (assigned by firmware)
977 * Context: Calling function should acquire ioc->sas_device_lock
979 * This searches for expander device based on handle, then returns the
983 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
985 struct _sas_node
*sas_expander
, *r
;
988 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
989 if (sas_expander
->handle
!= handle
)
999 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1000 * @ioc: per adapter object
1001 * @sas_address: sas address
1002 * Context: Calling function should acquire ioc->sas_node_lock.
1004 * This searches for expander device based on sas_address, then returns the
1008 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1011 struct _sas_node
*sas_expander
, *r
;
1014 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1015 if (sas_expander
->sas_address
!= sas_address
)
1025 * _scsih_expander_node_add - insert expander device to the list.
1026 * @ioc: per adapter object
1027 * @sas_expander: the sas_device object
1028 * Context: This function will acquire ioc->sas_node_lock.
1030 * Adding new object to the ioc->sas_expander_list.
1035 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1036 struct _sas_node
*sas_expander
)
1038 unsigned long flags
;
1040 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1041 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1042 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1046 * _scsih_is_end_device - determines if device is an end device
1047 * @device_info: bitfield providing information about the device.
1050 * Returns 1 if end device.
1053 _scsih_is_end_device(u32 device_info
)
1055 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1056 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1057 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1058 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1065 * _scsih_scsi_lookup_get - returns scmd entry
1066 * @ioc: per adapter object
1067 * @smid: system request message index
1069 * Returns the smid stored scmd pointer.
1071 static struct scsi_cmnd
*
1072 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1074 return ioc
->scsi_lookup
[smid
- 1].scmd
;
1078 * __scsih_scsi_lookup_get_clear - returns scmd entry without
1080 * @ioc: per adapter object
1081 * @smid: system request message index
1083 * Returns the smid stored scmd pointer.
1084 * Then will dereference the stored scmd pointer.
1086 static inline struct scsi_cmnd
*
1087 __scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
,
1090 struct scsi_cmnd
*scmd
= NULL
;
1092 swap(scmd
, ioc
->scsi_lookup
[smid
- 1].scmd
);
1098 * _scsih_scsi_lookup_get_clear - returns scmd entry
1099 * @ioc: per adapter object
1100 * @smid: system request message index
1102 * Returns the smid stored scmd pointer.
1103 * Then will derefrence the stored scmd pointer.
1105 static inline struct scsi_cmnd
*
1106 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1108 unsigned long flags
;
1109 struct scsi_cmnd
*scmd
;
1111 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1112 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
1113 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1119 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1120 * @ioc: per adapter object
1121 * @smid: system request message index
1122 * @scmd: pointer to scsi command object
1123 * Context: This function will acquire ioc->scsi_lookup_lock.
1125 * This will search for a scmd pointer in the scsi_lookup array,
1126 * returning the revelent smid. A returned value of zero means invalid.
1129 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1133 unsigned long flags
;
1136 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1138 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1139 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1140 smid
= ioc
->scsi_lookup
[i
].smid
;
1145 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1150 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1151 * @ioc: per adapter object
1154 * Context: This function will acquire ioc->scsi_lookup_lock.
1156 * This will search for a matching channel:id in the scsi_lookup array,
1157 * returning 1 if found.
1160 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1164 unsigned long flags
;
1167 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1169 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1170 if (ioc
->scsi_lookup
[i
].scmd
&&
1171 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1172 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1178 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1183 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1184 * @ioc: per adapter object
1188 * Context: This function will acquire ioc->scsi_lookup_lock.
1190 * This will search for a matching channel:id:lun in the scsi_lookup array,
1191 * returning 1 if found.
1194 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1195 unsigned int lun
, int channel
)
1198 unsigned long flags
;
1201 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1203 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1204 if (ioc
->scsi_lookup
[i
].scmd
&&
1205 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1206 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1207 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1213 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1218 * scsih_change_queue_depth - setting device queue depth
1219 * @sdev: scsi device struct
1220 * @qdepth: requested queue depth
1222 * Returns queue depth.
1225 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1227 struct Scsi_Host
*shost
= sdev
->host
;
1229 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1230 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1231 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1232 struct _sas_device
*sas_device
;
1233 unsigned long flags
;
1235 max_depth
= shost
->can_queue
;
1237 /* limit max device queue for SATA to 32 */
1238 sas_device_priv_data
= sdev
->hostdata
;
1239 if (!sas_device_priv_data
)
1241 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1242 if (!sas_target_priv_data
)
1244 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1247 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1248 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1250 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1251 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1253 sas_device_put(sas_device
);
1255 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1259 if (!sdev
->tagged_supported
)
1261 if (qdepth
> max_depth
)
1263 return scsi_change_queue_depth(sdev
, qdepth
);
1267 * scsih_target_alloc - target add routine
1268 * @starget: scsi target struct
1270 * Returns 0 if ok. Any other return is assumed to be an error and
1271 * the device is ignored.
1274 scsih_target_alloc(struct scsi_target
*starget
)
1276 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1277 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1278 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1279 struct _sas_device
*sas_device
;
1280 struct _raid_device
*raid_device
;
1281 unsigned long flags
;
1282 struct sas_rphy
*rphy
;
1284 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1286 if (!sas_target_priv_data
)
1289 starget
->hostdata
= sas_target_priv_data
;
1290 sas_target_priv_data
->starget
= starget
;
1291 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1294 if (starget
->channel
== RAID_CHANNEL
) {
1295 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1296 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1299 sas_target_priv_data
->handle
= raid_device
->handle
;
1300 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1301 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1302 if (ioc
->is_warpdrive
)
1303 sas_target_priv_data
->raid_device
= raid_device
;
1304 raid_device
->starget
= starget
;
1306 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1310 /* sas/sata devices */
1311 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1312 rphy
= dev_to_rphy(starget
->dev
.parent
);
1313 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1314 rphy
->identify
.sas_address
);
1317 sas_target_priv_data
->handle
= sas_device
->handle
;
1318 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1319 sas_target_priv_data
->sdev
= sas_device
;
1320 sas_device
->starget
= starget
;
1321 sas_device
->id
= starget
->id
;
1322 sas_device
->channel
= starget
->channel
;
1323 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1324 sas_target_priv_data
->flags
|=
1325 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1326 if (sas_device
->fast_path
)
1327 sas_target_priv_data
->flags
|= MPT_TARGET_FASTPATH_IO
;
1329 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1335 * scsih_target_destroy - target destroy routine
1336 * @starget: scsi target struct
1341 scsih_target_destroy(struct scsi_target
*starget
)
1343 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1344 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1345 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1346 struct _sas_device
*sas_device
;
1347 struct _raid_device
*raid_device
;
1348 unsigned long flags
;
1350 sas_target_priv_data
= starget
->hostdata
;
1351 if (!sas_target_priv_data
)
1354 if (starget
->channel
== RAID_CHANNEL
) {
1355 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1356 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1359 raid_device
->starget
= NULL
;
1360 raid_device
->sdev
= NULL
;
1362 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1366 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1367 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1368 if (sas_device
&& (sas_device
->starget
== starget
) &&
1369 (sas_device
->id
== starget
->id
) &&
1370 (sas_device
->channel
== starget
->channel
))
1371 sas_device
->starget
= NULL
;
1375 * Corresponding get() is in _scsih_target_alloc()
1377 sas_target_priv_data
->sdev
= NULL
;
1378 sas_device_put(sas_device
);
1380 sas_device_put(sas_device
);
1382 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1385 kfree(sas_target_priv_data
);
1386 starget
->hostdata
= NULL
;
1390 * scsih_slave_alloc - device add routine
1391 * @sdev: scsi device struct
1393 * Returns 0 if ok. Any other return is assumed to be an error and
1394 * the device is ignored.
1397 scsih_slave_alloc(struct scsi_device
*sdev
)
1399 struct Scsi_Host
*shost
;
1400 struct MPT3SAS_ADAPTER
*ioc
;
1401 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1402 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1403 struct scsi_target
*starget
;
1404 struct _raid_device
*raid_device
;
1405 struct _sas_device
*sas_device
;
1406 unsigned long flags
;
1408 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1410 if (!sas_device_priv_data
)
1413 sas_device_priv_data
->lun
= sdev
->lun
;
1414 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1416 starget
= scsi_target(sdev
);
1417 sas_target_priv_data
= starget
->hostdata
;
1418 sas_target_priv_data
->num_luns
++;
1419 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1420 sdev
->hostdata
= sas_device_priv_data
;
1421 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1422 sdev
->no_uld_attach
= 1;
1424 shost
= dev_to_shost(&starget
->dev
);
1425 ioc
= shost_priv(shost
);
1426 if (starget
->channel
== RAID_CHANNEL
) {
1427 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1428 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1429 starget
->id
, starget
->channel
);
1431 raid_device
->sdev
= sdev
; /* raid is single lun */
1432 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1435 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1436 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1437 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1438 sas_target_priv_data
->sas_address
);
1439 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1440 sdev_printk(KERN_INFO
, sdev
,
1441 "%s : sas_device->starget set to starget @ %d\n",
1442 __func__
, __LINE__
);
1443 sas_device
->starget
= starget
;
1447 sas_device_put(sas_device
);
1449 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1456 * scsih_slave_destroy - device destroy routine
1457 * @sdev: scsi device struct
1462 scsih_slave_destroy(struct scsi_device
*sdev
)
1464 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1465 struct scsi_target
*starget
;
1466 struct Scsi_Host
*shost
;
1467 struct MPT3SAS_ADAPTER
*ioc
;
1468 struct _sas_device
*sas_device
;
1469 unsigned long flags
;
1471 if (!sdev
->hostdata
)
1474 starget
= scsi_target(sdev
);
1475 sas_target_priv_data
= starget
->hostdata
;
1476 sas_target_priv_data
->num_luns
--;
1478 shost
= dev_to_shost(&starget
->dev
);
1479 ioc
= shost_priv(shost
);
1481 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1482 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1483 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1484 sas_target_priv_data
);
1485 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1486 sas_device
->starget
= NULL
;
1489 sas_device_put(sas_device
);
1490 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1493 kfree(sdev
->hostdata
);
1494 sdev
->hostdata
= NULL
;
1498 * _scsih_display_sata_capabilities - sata capabilities
1499 * @ioc: per adapter object
1500 * @handle: device handle
1501 * @sdev: scsi device struct
1504 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1505 u16 handle
, struct scsi_device
*sdev
)
1507 Mpi2ConfigReply_t mpi_reply
;
1508 Mpi2SasDevicePage0_t sas_device_pg0
;
1513 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1514 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1515 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1516 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1520 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1521 MPI2_IOCSTATUS_MASK
;
1522 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1523 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1524 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1528 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1529 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1531 sdev_printk(KERN_INFO
, sdev
,
1532 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1533 "sw_preserve(%s)\n",
1534 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1535 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1536 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1538 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1539 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1540 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1544 * raid transport support -
1545 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1546 * unloading the driver followed by a load - I believe that the subroutine
1547 * raid_class_release() is not cleaning up properly.
1551 * scsih_is_raid - return boolean indicating device is raid volume
1552 * @dev the device struct object
1555 scsih_is_raid(struct device
*dev
)
1557 struct scsi_device
*sdev
= to_scsi_device(dev
);
1558 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1560 if (ioc
->is_warpdrive
)
1562 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1566 * scsih_get_resync - get raid volume resync percent complete
1567 * @dev the device struct object
1570 scsih_get_resync(struct device
*dev
)
1572 struct scsi_device
*sdev
= to_scsi_device(dev
);
1573 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1574 static struct _raid_device
*raid_device
;
1575 unsigned long flags
;
1576 Mpi2RaidVolPage0_t vol_pg0
;
1577 Mpi2ConfigReply_t mpi_reply
;
1578 u32 volume_status_flags
;
1579 u8 percent_complete
;
1582 percent_complete
= 0;
1584 if (ioc
->is_warpdrive
)
1587 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1588 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1591 handle
= raid_device
->handle
;
1592 percent_complete
= raid_device
->percent_complete
;
1594 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1599 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1600 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1601 sizeof(Mpi2RaidVolPage0_t
))) {
1602 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1603 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1604 percent_complete
= 0;
1608 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1609 if (!(volume_status_flags
&
1610 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1611 percent_complete
= 0;
1615 switch (ioc
->hba_mpi_version_belonged
) {
1617 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1621 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1627 * scsih_get_state - get raid volume level
1628 * @dev the device struct object
1631 scsih_get_state(struct device
*dev
)
1633 struct scsi_device
*sdev
= to_scsi_device(dev
);
1634 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1635 static struct _raid_device
*raid_device
;
1636 unsigned long flags
;
1637 Mpi2RaidVolPage0_t vol_pg0
;
1638 Mpi2ConfigReply_t mpi_reply
;
1640 enum raid_state state
= RAID_STATE_UNKNOWN
;
1643 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1644 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1647 handle
= raid_device
->handle
;
1648 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1653 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1654 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1655 sizeof(Mpi2RaidVolPage0_t
))) {
1656 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1657 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1661 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1662 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1663 state
= RAID_STATE_RESYNCING
;
1667 switch (vol_pg0
.VolumeState
) {
1668 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1669 case MPI2_RAID_VOL_STATE_ONLINE
:
1670 state
= RAID_STATE_ACTIVE
;
1672 case MPI2_RAID_VOL_STATE_DEGRADED
:
1673 state
= RAID_STATE_DEGRADED
;
1675 case MPI2_RAID_VOL_STATE_FAILED
:
1676 case MPI2_RAID_VOL_STATE_MISSING
:
1677 state
= RAID_STATE_OFFLINE
;
1681 switch (ioc
->hba_mpi_version_belonged
) {
1683 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1687 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1693 * _scsih_set_level - set raid level
1694 * @sdev: scsi device struct
1695 * @volume_type: volume type
1698 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
1699 struct scsi_device
*sdev
, u8 volume_type
)
1701 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1703 switch (volume_type
) {
1704 case MPI2_RAID_VOL_TYPE_RAID0
:
1705 level
= RAID_LEVEL_0
;
1707 case MPI2_RAID_VOL_TYPE_RAID10
:
1708 level
= RAID_LEVEL_10
;
1710 case MPI2_RAID_VOL_TYPE_RAID1E
:
1711 level
= RAID_LEVEL_1E
;
1713 case MPI2_RAID_VOL_TYPE_RAID1
:
1714 level
= RAID_LEVEL_1
;
1718 switch (ioc
->hba_mpi_version_belonged
) {
1720 raid_set_level(mpt2sas_raid_template
,
1721 &sdev
->sdev_gendev
, level
);
1725 raid_set_level(mpt3sas_raid_template
,
1726 &sdev
->sdev_gendev
, level
);
1733 * _scsih_get_volume_capabilities - volume capabilities
1734 * @ioc: per adapter object
1735 * @sas_device: the raid_device object
1737 * Returns 0 for success, else 1
1740 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1741 struct _raid_device
*raid_device
)
1743 Mpi2RaidVolPage0_t
*vol_pg0
;
1744 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1745 Mpi2SasDevicePage0_t sas_device_pg0
;
1746 Mpi2ConfigReply_t mpi_reply
;
1750 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1751 &num_pds
)) || !num_pds
) {
1752 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1753 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1758 raid_device
->num_pds
= num_pds
;
1759 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1760 sizeof(Mpi2RaidVol0PhysDisk_t
));
1761 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1763 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1764 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1769 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1770 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1771 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1772 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1778 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1780 /* figure out what the underlying devices are by
1781 * obtaining the device_info bits for the 1st device
1783 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1784 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1785 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1786 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1787 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1788 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1789 raid_device
->device_info
=
1790 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1799 * _scsih_enable_tlr - setting TLR flags
1800 * @ioc: per adapter object
1801 * @sdev: scsi device struct
1803 * Enabling Transaction Layer Retries for tape devices when
1804 * vpd page 0x90 is present
1808 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1812 if (sdev
->type
!= TYPE_TAPE
)
1815 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1818 sas_enable_tlr(sdev
);
1819 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1820 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1826 * scsih_slave_configure - device configure routine.
1827 * @sdev: scsi device struct
1829 * Returns 0 if ok. Any other return is assumed to be an error and
1830 * the device is ignored.
1833 scsih_slave_configure(struct scsi_device
*sdev
)
1835 struct Scsi_Host
*shost
= sdev
->host
;
1836 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1837 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1838 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1839 struct _sas_device
*sas_device
;
1840 struct _raid_device
*raid_device
;
1841 unsigned long flags
;
1846 u16 handle
, volume_handle
= 0;
1847 u64 volume_wwid
= 0;
1850 sas_device_priv_data
= sdev
->hostdata
;
1851 sas_device_priv_data
->configured_lun
= 1;
1852 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1853 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1854 handle
= sas_target_priv_data
->handle
;
1856 /* raid volume handling */
1857 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1859 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1860 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
1861 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1863 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1864 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1865 __LINE__
, __func__
));
1869 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1870 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1871 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1872 __LINE__
, __func__
));
1877 * WARPDRIVE: Initialize the required data for Direct IO
1879 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
1881 /* RAID Queue Depth Support
1882 * IS volume = underlying qdepth of drive type, either
1883 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1884 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1886 if (raid_device
->device_info
&
1887 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1888 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1891 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1892 if (raid_device
->device_info
&
1893 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1899 switch (raid_device
->volume_type
) {
1900 case MPI2_RAID_VOL_TYPE_RAID0
:
1903 case MPI2_RAID_VOL_TYPE_RAID1E
:
1904 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1905 if (ioc
->manu_pg10
.OEMIdentifier
&&
1906 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1907 MFG10_GF0_R10_DISPLAY
) &&
1908 !(raid_device
->num_pds
% 2))
1913 case MPI2_RAID_VOL_TYPE_RAID1
:
1914 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1917 case MPI2_RAID_VOL_TYPE_RAID10
:
1918 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1921 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1923 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1928 if (!ioc
->hide_ir_msg
)
1929 sdev_printk(KERN_INFO
, sdev
,
1930 "%s: handle(0x%04x), wwid(0x%016llx),"
1931 " pd_count(%d), type(%s)\n",
1932 r_level
, raid_device
->handle
,
1933 (unsigned long long)raid_device
->wwid
,
1934 raid_device
->num_pds
, ds
);
1936 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
1937 blk_queue_max_hw_sectors(sdev
->request_queue
,
1938 MPT3SAS_RAID_MAX_SECTORS
);
1939 sdev_printk(KERN_INFO
, sdev
,
1940 "Set queue's max_sector to: %u\n",
1941 MPT3SAS_RAID_MAX_SECTORS
);
1944 scsih_change_queue_depth(sdev
, qdepth
);
1946 /* raid transport support */
1947 if (!ioc
->is_warpdrive
)
1948 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
1952 /* non-raid handling */
1953 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1954 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1956 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1957 "failure at %s:%d/%s()!\n", ioc
->name
,
1958 __FILE__
, __LINE__
, __func__
));
1961 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1962 volume_handle
, &volume_wwid
)) {
1963 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1964 "failure at %s:%d/%s()!\n", ioc
->name
,
1965 __FILE__
, __LINE__
, __func__
));
1970 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1971 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1972 sas_device_priv_data
->sas_target
->sas_address
);
1974 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1975 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1976 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1981 sas_device
->volume_handle
= volume_handle
;
1982 sas_device
->volume_wwid
= volume_wwid
;
1983 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1984 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1986 if (sas_device
->device_info
&
1987 MPI2_SAS_DEVICE_INFO_SEP
) {
1988 sdev_printk(KERN_WARNING
, sdev
,
1989 "set ignore_delay_remove for handle(0x%04x)\n",
1990 sas_device_priv_data
->sas_target
->handle
);
1991 sas_device_priv_data
->ignore_delay_remove
= 1;
1996 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1997 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1999 else if (sas_device
->device_info
&
2000 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2004 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2005 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2006 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2007 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2008 if (sas_device
->enclosure_handle
!= 0)
2009 sdev_printk(KERN_INFO
, sdev
,
2010 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
2011 ds
, (unsigned long long)
2012 sas_device
->enclosure_logical_id
, sas_device
->slot
);
2013 if (sas_device
->connector_name
[0] != '\0')
2014 sdev_printk(KERN_INFO
, sdev
,
2015 "%s: enclosure level(0x%04x), connector name( %s)\n",
2016 ds
, sas_device
->enclosure_level
,
2017 sas_device
->connector_name
);
2019 sas_device_put(sas_device
);
2020 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2023 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2026 scsih_change_queue_depth(sdev
, qdepth
);
2029 sas_read_port_mode_page(sdev
);
2030 _scsih_enable_tlr(ioc
, sdev
);
2037 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2038 * @sdev: scsi device struct
2039 * @bdev: pointer to block device context
2040 * @capacity: device size (in 512 byte sectors)
2041 * @params: three element array to place output:
2042 * params[0] number of heads (max 255)
2043 * params[1] number of sectors (max 63)
2044 * params[2] number of cylinders
2049 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2050 sector_t capacity
, int params
[])
2060 dummy
= heads
* sectors
;
2061 cylinders
= capacity
;
2062 sector_div(cylinders
, dummy
);
2065 * Handle extended translation size for logical drives
2068 if ((ulong
)capacity
>= 0x200000) {
2071 dummy
= heads
* sectors
;
2072 cylinders
= capacity
;
2073 sector_div(cylinders
, dummy
);
2078 params
[1] = sectors
;
2079 params
[2] = cylinders
;
2085 * _scsih_response_code - translation of device response code
2086 * @ioc: per adapter object
2087 * @response_code: response code returned by the device
2092 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2096 switch (response_code
) {
2097 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2098 desc
= "task management request completed";
2100 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2101 desc
= "invalid frame";
2103 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2104 desc
= "task management request not supported";
2106 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2107 desc
= "task management request failed";
2109 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2110 desc
= "task management request succeeded";
2112 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2113 desc
= "invalid lun";
2116 desc
= "overlapped tag attempted";
2118 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2119 desc
= "task queued, however not sent to target";
2125 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2126 ioc
->name
, response_code
, desc
);
2130 * _scsih_tm_done - tm completion routine
2131 * @ioc: per adapter object
2132 * @smid: system request message index
2133 * @msix_index: MSIX table index supplied by the OS
2134 * @reply: reply message frame(lower 32bit addr)
2137 * The callback handler when using scsih_issue_tm.
2139 * Return 1 meaning mf should be freed from _base_interrupt
2140 * 0 means the mf is freed from this function.
2143 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2145 MPI2DefaultReply_t
*mpi_reply
;
2147 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2149 if (ioc
->tm_cmds
.smid
!= smid
)
2151 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2152 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2154 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2155 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2157 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2158 complete(&ioc
->tm_cmds
.done
);
2163 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2164 * @ioc: per adapter object
2165 * @handle: device handle
2167 * During taskmangement request, we need to freeze the device queue.
2170 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2172 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2173 struct scsi_device
*sdev
;
2176 shost_for_each_device(sdev
, ioc
->shost
) {
2179 sas_device_priv_data
= sdev
->hostdata
;
2180 if (!sas_device_priv_data
)
2182 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2183 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2185 ioc
->ignore_loginfos
= 1;
2191 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2192 * @ioc: per adapter object
2193 * @handle: device handle
2195 * During taskmangement request, we need to freeze the device queue.
2198 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2200 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2201 struct scsi_device
*sdev
;
2204 shost_for_each_device(sdev
, ioc
->shost
) {
2207 sas_device_priv_data
= sdev
->hostdata
;
2208 if (!sas_device_priv_data
)
2210 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2211 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2213 ioc
->ignore_loginfos
= 0;
2219 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2220 * @ioc: per adapter struct
2221 * @device_handle: device handle
2222 * @channel: the channel assigned by the OS
2223 * @id: the id assigned by the OS
2225 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2226 * @smid_task: smid assigned to the task
2227 * @timeout: timeout in seconds
2230 * A generic API for sending task management requests to firmware.
2232 * The callback index is set inside `ioc->tm_cb_idx`.
2234 * Return SUCCESS or FAILED.
2237 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2238 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2240 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2241 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2244 struct scsiio_tracker
*scsi_lookup
= NULL
;
2248 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2250 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2251 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2252 __func__
, ioc
->name
);
2256 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2257 ioc
->pci_error_recovery
) {
2258 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2259 __func__
, ioc
->name
);
2263 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2264 if (ioc_state
& MPI2_DOORBELL_USED
) {
2265 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2266 "unexpected doorbell active!\n", ioc
->name
));
2267 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2268 return (!rc
) ? SUCCESS
: FAILED
;
2271 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2272 mpt3sas_base_fault_info(ioc
, ioc_state
&
2273 MPI2_DOORBELL_DATA_MASK
);
2274 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2275 return (!rc
) ? SUCCESS
: FAILED
;
2278 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2280 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2281 ioc
->name
, __func__
);
2285 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2286 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2288 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2289 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2290 ioc
->name
, handle
, type
, smid_task
));
2291 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2292 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2293 ioc
->tm_cmds
.smid
= smid
;
2294 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2295 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2296 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2297 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2298 mpi_request
->TaskType
= type
;
2299 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2300 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2301 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2302 init_completion(&ioc
->tm_cmds
.done
);
2303 if ((type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) &&
2304 (scsi_lookup
->msix_io
< ioc
->reply_queue_count
))
2305 msix_task
= scsi_lookup
->msix_io
;
2308 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2309 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2310 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2311 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2312 ioc
->name
, __func__
);
2313 _debug_dump_mf(mpi_request
,
2314 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2315 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2316 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2318 rc
= (!rc
) ? SUCCESS
: FAILED
;
2323 /* sync IRQs in case those were busy during flush. */
2324 mpt3sas_base_sync_reply_irqs(ioc
);
2326 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2327 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2328 mpi_reply
= ioc
->tm_cmds
.reply
;
2329 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2330 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2331 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2332 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2333 le32_to_cpu(mpi_reply
->TerminationCount
)));
2334 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2335 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2336 if (mpi_reply
->IOCStatus
)
2337 _debug_dump_mf(mpi_request
,
2338 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2343 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2345 if (scsi_lookup
->scmd
== NULL
)
2350 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2351 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2356 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2357 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2358 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2363 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2372 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2373 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2377 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2378 uint channel
, uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2382 mutex_lock(&ioc
->tm_cmds
.mutex
);
2383 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, channel
, id
, lun
, type
,
2384 smid_task
, timeout
);
2385 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2391 * _scsih_tm_display_info - displays info about the device
2392 * @ioc: per adapter struct
2393 * @scmd: pointer to scsi command object
2395 * Called by task management callback handlers.
2398 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2400 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2401 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2402 struct _sas_device
*sas_device
= NULL
;
2403 unsigned long flags
;
2404 char *device_str
= NULL
;
2408 if (ioc
->hide_ir_msg
)
2409 device_str
= "WarpDrive";
2411 device_str
= "volume";
2413 scsi_print_command(scmd
);
2414 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2415 starget_printk(KERN_INFO
, starget
,
2416 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2417 device_str
, priv_target
->handle
,
2418 device_str
, (unsigned long long)priv_target
->sas_address
);
2420 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2421 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2423 if (priv_target
->flags
&
2424 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2425 starget_printk(KERN_INFO
, starget
,
2426 "volume handle(0x%04x), "
2427 "volume wwid(0x%016llx)\n",
2428 sas_device
->volume_handle
,
2429 (unsigned long long)sas_device
->volume_wwid
);
2431 starget_printk(KERN_INFO
, starget
,
2432 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2434 (unsigned long long)sas_device
->sas_address
,
2436 if (sas_device
->enclosure_handle
!= 0)
2437 starget_printk(KERN_INFO
, starget
,
2438 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2439 (unsigned long long)
2440 sas_device
->enclosure_logical_id
,
2442 if (sas_device
->connector_name
[0] != '\0')
2443 starget_printk(KERN_INFO
, starget
,
2444 "enclosure level(0x%04x),connector name(%s)\n",
2445 sas_device
->enclosure_level
,
2446 sas_device
->connector_name
);
2448 sas_device_put(sas_device
);
2450 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2455 * scsih_abort - eh threads main abort routine
2456 * @scmd: pointer to scsi command object
2458 * Returns SUCCESS if command aborted else FAILED
2461 scsih_abort(struct scsi_cmnd
*scmd
)
2463 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2464 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2469 sdev_printk(KERN_INFO
, scmd
->device
,
2470 "attempting task abort! scmd(%p)\n", scmd
);
2471 _scsih_tm_display_info(ioc
, scmd
);
2473 sas_device_priv_data
= scmd
->device
->hostdata
;
2474 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2475 sdev_printk(KERN_INFO
, scmd
->device
,
2476 "device been deleted! scmd(%p)\n", scmd
);
2477 scmd
->result
= DID_NO_CONNECT
<< 16;
2478 scmd
->scsi_done(scmd
);
2483 /* search for the command */
2484 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2486 scmd
->result
= DID_RESET
<< 16;
2491 /* for hidden raid components and volumes this is not supported */
2492 if (sas_device_priv_data
->sas_target
->flags
&
2493 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2494 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2495 scmd
->result
= DID_RESET
<< 16;
2500 mpt3sas_halt_firmware(ioc
);
2502 handle
= sas_device_priv_data
->sas_target
->handle
;
2503 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2504 scmd
->device
->id
, scmd
->device
->lun
,
2505 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
2508 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2509 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2514 * scsih_dev_reset - eh threads main device reset routine
2515 * @scmd: pointer to scsi command object
2517 * Returns SUCCESS if command aborted else FAILED
2520 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2522 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2523 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2524 struct _sas_device
*sas_device
= NULL
;
2528 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2529 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2531 sdev_printk(KERN_INFO
, scmd
->device
,
2532 "attempting device reset! scmd(%p)\n", scmd
);
2533 _scsih_tm_display_info(ioc
, scmd
);
2535 sas_device_priv_data
= scmd
->device
->hostdata
;
2536 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2537 sdev_printk(KERN_INFO
, scmd
->device
,
2538 "device been deleted! scmd(%p)\n", scmd
);
2539 scmd
->result
= DID_NO_CONNECT
<< 16;
2540 scmd
->scsi_done(scmd
);
2545 /* for hidden raid components obtain the volume_handle */
2547 if (sas_device_priv_data
->sas_target
->flags
&
2548 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2549 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2552 handle
= sas_device
->volume_handle
;
2554 handle
= sas_device_priv_data
->sas_target
->handle
;
2557 scmd
->result
= DID_RESET
<< 16;
2562 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2563 scmd
->device
->id
, scmd
->device
->lun
,
2564 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30);
2567 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2568 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2571 sas_device_put(sas_device
);
2577 * scsih_target_reset - eh threads main target reset routine
2578 * @scmd: pointer to scsi command object
2580 * Returns SUCCESS if command aborted else FAILED
2583 scsih_target_reset(struct scsi_cmnd
*scmd
)
2585 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2586 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2587 struct _sas_device
*sas_device
= NULL
;
2590 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2591 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2593 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2595 _scsih_tm_display_info(ioc
, scmd
);
2597 sas_device_priv_data
= scmd
->device
->hostdata
;
2598 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2599 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2601 scmd
->result
= DID_NO_CONNECT
<< 16;
2602 scmd
->scsi_done(scmd
);
2607 /* for hidden raid components obtain the volume_handle */
2609 if (sas_device_priv_data
->sas_target
->flags
&
2610 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2611 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2614 handle
= sas_device
->volume_handle
;
2616 handle
= sas_device_priv_data
->sas_target
->handle
;
2619 scmd
->result
= DID_RESET
<< 16;
2624 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2625 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2629 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2630 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2633 sas_device_put(sas_device
);
2640 * scsih_host_reset - eh threads main host reset routine
2641 * @scmd: pointer to scsi command object
2643 * Returns SUCCESS if command aborted else FAILED
2646 scsih_host_reset(struct scsi_cmnd
*scmd
)
2648 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2651 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
2653 scsi_print_command(scmd
);
2655 if (ioc
->is_driver_loading
) {
2656 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
2662 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2663 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2665 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2666 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2672 * _scsih_fw_event_add - insert and queue up fw_event
2673 * @ioc: per adapter object
2674 * @fw_event: object describing the event
2675 * Context: This function will acquire ioc->fw_event_lock.
2677 * This adds the firmware event object into link list, then queues it up to
2678 * be processed from user context.
2683 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2685 unsigned long flags
;
2687 if (ioc
->firmware_event_thread
== NULL
)
2690 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2691 fw_event_work_get(fw_event
);
2692 INIT_LIST_HEAD(&fw_event
->list
);
2693 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2694 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2695 fw_event_work_get(fw_event
);
2696 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2697 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2701 * _scsih_fw_event_del_from_list - delete fw_event from the list
2702 * @ioc: per adapter object
2703 * @fw_event: object describing the event
2704 * Context: This function will acquire ioc->fw_event_lock.
2706 * If the fw_event is on the fw_event_list, remove it and do a put.
2711 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2714 unsigned long flags
;
2716 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2717 if (!list_empty(&fw_event
->list
)) {
2718 list_del_init(&fw_event
->list
);
2719 fw_event_work_put(fw_event
);
2721 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2726 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2727 * @ioc: per adapter object
2728 * @event_data: trigger event data
2733 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2734 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2736 struct fw_event_work
*fw_event
;
2739 if (ioc
->is_driver_loading
)
2741 sz
= sizeof(*event_data
);
2742 fw_event
= alloc_fw_event_work(sz
);
2745 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2746 fw_event
->ioc
= ioc
;
2747 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2748 _scsih_fw_event_add(ioc
, fw_event
);
2749 fw_event_work_put(fw_event
);
2753 * _scsih_error_recovery_delete_devices - remove devices not responding
2754 * @ioc: per adapter object
2759 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2761 struct fw_event_work
*fw_event
;
2763 if (ioc
->is_driver_loading
)
2765 fw_event
= alloc_fw_event_work(0);
2768 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2769 fw_event
->ioc
= ioc
;
2770 _scsih_fw_event_add(ioc
, fw_event
);
2771 fw_event_work_put(fw_event
);
2775 * mpt3sas_port_enable_complete - port enable completed (fake event)
2776 * @ioc: per adapter object
2781 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2783 struct fw_event_work
*fw_event
;
2785 fw_event
= alloc_fw_event_work(0);
2788 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2789 fw_event
->ioc
= ioc
;
2790 _scsih_fw_event_add(ioc
, fw_event
);
2791 fw_event_work_put(fw_event
);
2794 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
2796 unsigned long flags
;
2797 struct fw_event_work
*fw_event
= NULL
;
2799 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2800 if (!list_empty(&ioc
->fw_event_list
)) {
2801 fw_event
= list_first_entry(&ioc
->fw_event_list
,
2802 struct fw_event_work
, list
);
2803 list_del_init(&fw_event
->list
);
2805 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2811 * _scsih_fw_event_cleanup_queue - cleanup event queue
2812 * @ioc: per adapter object
2814 * Walk the firmware event queue, either killing timers, or waiting
2815 * for outstanding events to complete
2820 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2822 struct fw_event_work
*fw_event
;
2824 if (list_empty(&ioc
->fw_event_list
) ||
2825 !ioc
->firmware_event_thread
|| in_interrupt())
2828 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
2830 * Wait on the fw_event to complete. If this returns 1, then
2831 * the event was never executed, and we need a put for the
2832 * reference the work had on the fw_event.
2834 * If it did execute, we wait for it to finish, and the put will
2835 * happen from _firmware_event_work()
2837 if (cancel_work_sync(&fw_event
->work
))
2838 fw_event_work_put(fw_event
);
2840 fw_event_work_put(fw_event
);
2845 * _scsih_internal_device_block - block the sdev device
2846 * @sdev: per device object
2847 * @sas_device_priv_data : per device driver private data
2849 * make sure device is blocked without error, if not
2853 _scsih_internal_device_block(struct scsi_device
*sdev
,
2854 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2858 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
2859 sas_device_priv_data
->sas_target
->handle
);
2860 sas_device_priv_data
->block
= 1;
2862 r
= scsi_internal_device_block(sdev
);
2864 sdev_printk(KERN_WARNING
, sdev
,
2865 "device_block failed with return(%d) for handle(0x%04x)\n",
2866 r
, sas_device_priv_data
->sas_target
->handle
);
2870 * _scsih_internal_device_unblock - unblock the sdev device
2871 * @sdev: per device object
2872 * @sas_device_priv_data : per device driver private data
2873 * make sure device is unblocked without error, if not retry
2874 * by blocking and then unblocking
2878 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
2879 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2883 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
2884 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
2885 sas_device_priv_data
->block
= 0;
2886 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2888 /* The device has been set to SDEV_RUNNING by SD layer during
2889 * device addition but the request queue is still stopped by
2890 * our earlier block call. We need to perform a block again
2891 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2893 sdev_printk(KERN_WARNING
, sdev
,
2894 "device_unblock failed with return(%d) for handle(0x%04x) "
2895 "performing a block followed by an unblock\n",
2896 r
, sas_device_priv_data
->sas_target
->handle
);
2897 sas_device_priv_data
->block
= 1;
2898 r
= scsi_internal_device_block(sdev
);
2900 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
2901 "failed with return(%d) for handle(0x%04x)\n",
2902 r
, sas_device_priv_data
->sas_target
->handle
);
2904 sas_device_priv_data
->block
= 0;
2905 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2907 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
2908 " failed with return(%d) for handle(0x%04x)\n",
2909 r
, sas_device_priv_data
->sas_target
->handle
);
2914 * _scsih_ublock_io_all_device - unblock every device
2915 * @ioc: per adapter object
2917 * change the device state from block to running
2920 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2922 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2923 struct scsi_device
*sdev
;
2925 shost_for_each_device(sdev
, ioc
->shost
) {
2926 sas_device_priv_data
= sdev
->hostdata
;
2927 if (!sas_device_priv_data
)
2929 if (!sas_device_priv_data
->block
)
2932 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2933 "device_running, handle(0x%04x)\n",
2934 sas_device_priv_data
->sas_target
->handle
));
2935 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
2941 * _scsih_ublock_io_device - prepare device to be deleted
2942 * @ioc: per adapter object
2943 * @sas_addr: sas address
2945 * unblock then put device in offline state
2948 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2950 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2951 struct scsi_device
*sdev
;
2953 shost_for_each_device(sdev
, ioc
->shost
) {
2954 sas_device_priv_data
= sdev
->hostdata
;
2955 if (!sas_device_priv_data
)
2957 if (sas_device_priv_data
->sas_target
->sas_address
2960 if (sas_device_priv_data
->block
)
2961 _scsih_internal_device_unblock(sdev
,
2962 sas_device_priv_data
);
2967 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2968 * @ioc: per adapter object
2969 * @handle: device handle
2971 * During device pull we need to appropriately set the sdev state.
2974 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2976 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2977 struct scsi_device
*sdev
;
2979 shost_for_each_device(sdev
, ioc
->shost
) {
2980 sas_device_priv_data
= sdev
->hostdata
;
2981 if (!sas_device_priv_data
)
2983 if (sas_device_priv_data
->block
)
2985 if (sas_device_priv_data
->ignore_delay_remove
) {
2986 sdev_printk(KERN_INFO
, sdev
,
2987 "%s skip device_block for SES handle(0x%04x)\n",
2988 __func__
, sas_device_priv_data
->sas_target
->handle
);
2991 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2996 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2997 * @ioc: per adapter object
2998 * @handle: device handle
3000 * During device pull we need to appropriately set the sdev state.
3003 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3005 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3006 struct scsi_device
*sdev
;
3007 struct _sas_device
*sas_device
;
3009 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3013 shost_for_each_device(sdev
, ioc
->shost
) {
3014 sas_device_priv_data
= sdev
->hostdata
;
3015 if (!sas_device_priv_data
)
3017 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3019 if (sas_device_priv_data
->block
)
3021 if (sas_device
->pend_sas_rphy_add
)
3023 if (sas_device_priv_data
->ignore_delay_remove
) {
3024 sdev_printk(KERN_INFO
, sdev
,
3025 "%s skip device_block for SES handle(0x%04x)\n",
3026 __func__
, sas_device_priv_data
->sas_target
->handle
);
3029 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3032 sas_device_put(sas_device
);
3036 * _scsih_block_io_to_children_attached_to_ex
3037 * @ioc: per adapter object
3038 * @sas_expander: the sas_device object
3040 * This routine set sdev state to SDEV_BLOCK for all devices
3041 * attached to this expander. This function called when expander is
3045 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3046 struct _sas_node
*sas_expander
)
3048 struct _sas_port
*mpt3sas_port
;
3049 struct _sas_device
*sas_device
;
3050 struct _sas_node
*expander_sibling
;
3051 unsigned long flags
;
3056 list_for_each_entry(mpt3sas_port
,
3057 &sas_expander
->sas_port_list
, port_list
) {
3058 if (mpt3sas_port
->remote_identify
.device_type
==
3060 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3061 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3062 mpt3sas_port
->remote_identify
.sas_address
);
3064 set_bit(sas_device
->handle
,
3065 ioc
->blocking_handles
);
3066 sas_device_put(sas_device
);
3068 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3072 list_for_each_entry(mpt3sas_port
,
3073 &sas_expander
->sas_port_list
, port_list
) {
3075 if (mpt3sas_port
->remote_identify
.device_type
==
3076 SAS_EDGE_EXPANDER_DEVICE
||
3077 mpt3sas_port
->remote_identify
.device_type
==
3078 SAS_FANOUT_EXPANDER_DEVICE
) {
3080 mpt3sas_scsih_expander_find_by_sas_address(
3081 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3082 _scsih_block_io_to_children_attached_to_ex(ioc
,
3089 * _scsih_block_io_to_children_attached_directly
3090 * @ioc: per adapter object
3091 * @event_data: topology change event data
3093 * This routine set sdev state to SDEV_BLOCK for all devices
3094 * direct attached during device pull.
3097 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3098 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3104 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3105 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3108 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3109 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3110 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3111 _scsih_block_io_device(ioc
, handle
);
3116 * _scsih_tm_tr_send - send task management request
3117 * @ioc: per adapter object
3118 * @handle: device handle
3119 * Context: interrupt time.
3121 * This code is to initiate the device removal handshake protocol
3122 * with controller firmware. This function will issue target reset
3123 * using high priority request queue. It will send a sas iounit
3124 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3126 * This is designed to send muliple task management request at the same
3127 * time to the fifo. If the fifo is full, we will append the request,
3128 * and process it in a future completion.
3131 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3133 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3135 struct _sas_device
*sas_device
= NULL
;
3136 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3137 u64 sas_address
= 0;
3138 unsigned long flags
;
3139 struct _tr_list
*delayed_tr
;
3142 if (ioc
->remove_host
) {
3143 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3144 "%s: host has been removed: handle(0x%04x)\n",
3145 __func__
, ioc
->name
, handle
));
3147 } else if (ioc
->pci_error_recovery
) {
3148 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3149 "%s: host in pci error recovery: handle(0x%04x)\n",
3150 __func__
, ioc
->name
,
3154 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3155 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3156 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3157 "%s: host is not operational: handle(0x%04x)\n",
3158 __func__
, ioc
->name
,
3163 /* if PD, then return */
3164 if (test_bit(handle
, ioc
->pd_handles
))
3167 clear_bit(handle
, ioc
->pend_os_device_add
);
3169 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3170 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3171 if (sas_device
&& sas_device
->starget
&&
3172 sas_device
->starget
->hostdata
) {
3173 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3174 sas_target_priv_data
->deleted
= 1;
3175 sas_address
= sas_device
->sas_address
;
3177 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3179 if (sas_target_priv_data
) {
3180 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3181 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3183 (unsigned long long)sas_address
));
3184 if (sas_device
->enclosure_handle
!= 0)
3185 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3186 "setting delete flag:enclosure logical id(0x%016llx),"
3187 " slot(%d)\n", ioc
->name
, (unsigned long long)
3188 sas_device
->enclosure_logical_id
,
3190 if (sas_device
->connector_name
[0] != '\0')
3191 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3192 "setting delete flag: enclosure level(0x%04x),"
3193 " connector name( %s)\n", ioc
->name
,
3194 sas_device
->enclosure_level
,
3195 sas_device
->connector_name
));
3196 _scsih_ublock_io_device(ioc
, sas_address
);
3197 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3200 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3202 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3205 INIT_LIST_HEAD(&delayed_tr
->list
);
3206 delayed_tr
->handle
= handle
;
3207 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3208 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3209 "DELAYED:tr:handle(0x%04x), (open)\n",
3210 ioc
->name
, handle
));
3214 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3215 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3216 ioc
->name
, handle
, smid
,
3217 ioc
->tm_tr_cb_idx
));
3218 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3219 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3220 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3221 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3222 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3223 set_bit(handle
, ioc
->device_remove_in_progress
);
3224 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3225 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3229 sas_device_put(sas_device
);
3233 * _scsih_tm_tr_complete -
3234 * @ioc: per adapter object
3235 * @smid: system request message index
3236 * @msix_index: MSIX table index supplied by the OS
3237 * @reply: reply message frame(lower 32bit addr)
3238 * Context: interrupt time.
3240 * This is the target reset completion routine.
3241 * This code is part of the code to initiate the device removal
3242 * handshake protocol with controller firmware.
3243 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3245 * Return 1 meaning mf should be freed from _base_interrupt
3246 * 0 means the mf is freed from this function.
3249 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3253 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3254 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3255 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3256 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3259 struct _sc_list
*delayed_sc
;
3261 if (ioc
->remove_host
) {
3262 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3263 "%s: host has been removed\n", __func__
, ioc
->name
));
3265 } else if (ioc
->pci_error_recovery
) {
3266 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3267 "%s: host in pci error recovery\n", __func__
,
3271 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3272 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3273 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3274 "%s: host is not operational\n", __func__
, ioc
->name
));
3277 if (unlikely(!mpi_reply
)) {
3278 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3279 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3282 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3283 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3284 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3285 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3286 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3288 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3292 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3293 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3294 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3295 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3296 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3297 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3298 le32_to_cpu(mpi_reply
->TerminationCount
)));
3300 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3301 if (!smid_sas_ctrl
) {
3302 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3304 return _scsih_check_for_pending_tm(ioc
, smid
);
3305 INIT_LIST_HEAD(&delayed_sc
->list
);
3306 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3307 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3308 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3309 "DELAYED:sc:handle(0x%04x), (open)\n",
3310 ioc
->name
, handle
));
3311 return _scsih_check_for_pending_tm(ioc
, smid
);
3314 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3315 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3316 ioc
->name
, handle
, smid_sas_ctrl
,
3317 ioc
->tm_sas_control_cb_idx
));
3318 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3319 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3320 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3321 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3322 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3323 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3325 return _scsih_check_for_pending_tm(ioc
, smid
);
3330 * _scsih_sas_control_complete - completion routine
3331 * @ioc: per adapter object
3332 * @smid: system request message index
3333 * @msix_index: MSIX table index supplied by the OS
3334 * @reply: reply message frame(lower 32bit addr)
3335 * Context: interrupt time.
3337 * This is the sas iounit control completion routine.
3338 * This code is part of the code to initiate the device removal
3339 * handshake protocol with controller firmware.
3341 * Return 1 meaning mf should be freed from _base_interrupt
3342 * 0 means the mf is freed from this function.
3345 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3346 u8 msix_index
, u32 reply
)
3348 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3349 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3351 if (likely(mpi_reply
)) {
3352 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3353 "sc_complete:handle(0x%04x), (open) "
3354 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3355 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3356 le16_to_cpu(mpi_reply
->IOCStatus
),
3357 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3358 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3359 MPI2_IOCSTATUS_SUCCESS
) {
3360 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3361 ioc
->device_remove_in_progress
);
3364 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3365 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3367 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3371 * _scsih_tm_tr_volume_send - send target reset request for volumes
3372 * @ioc: per adapter object
3373 * @handle: device handle
3374 * Context: interrupt time.
3376 * This is designed to send muliple task management request at the same
3377 * time to the fifo. If the fifo is full, we will append the request,
3378 * and process it in a future completion.
3381 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3383 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3385 struct _tr_list
*delayed_tr
;
3387 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3388 ioc
->pci_error_recovery
) {
3389 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3390 "%s: host reset in progress!\n",
3391 __func__
, ioc
->name
));
3395 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3397 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3400 INIT_LIST_HEAD(&delayed_tr
->list
);
3401 delayed_tr
->handle
= handle
;
3402 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3403 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3404 "DELAYED:tr:handle(0x%04x), (open)\n",
3405 ioc
->name
, handle
));
3409 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3410 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3411 ioc
->name
, handle
, smid
,
3412 ioc
->tm_tr_volume_cb_idx
));
3413 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3414 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3415 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3416 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3417 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3418 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3422 * _scsih_tm_volume_tr_complete - target reset completion
3423 * @ioc: per adapter object
3424 * @smid: system request message index
3425 * @msix_index: MSIX table index supplied by the OS
3426 * @reply: reply message frame(lower 32bit addr)
3427 * Context: interrupt time.
3429 * Return 1 meaning mf should be freed from _base_interrupt
3430 * 0 means the mf is freed from this function.
3433 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3434 u8 msix_index
, u32 reply
)
3437 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3438 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3439 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3441 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3442 ioc
->pci_error_recovery
) {
3443 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3444 "%s: host reset in progress!\n",
3445 __func__
, ioc
->name
));
3448 if (unlikely(!mpi_reply
)) {
3449 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3450 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3454 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3455 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3456 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3457 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3458 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3460 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3464 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3465 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3466 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3467 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3468 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3469 le32_to_cpu(mpi_reply
->TerminationCount
)));
3471 return _scsih_check_for_pending_tm(ioc
, smid
);
3475 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3476 * @ioc: per adapter object
3477 * @smid: system request message index
3479 * @event_context: used to track events uniquely
3481 * Context - processed in interrupt context.
3484 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
3487 Mpi2EventAckRequest_t
*ack_request
;
3488 int i
= smid
- ioc
->internal_smid
;
3489 unsigned long flags
;
3491 /* Without releasing the smid just update the
3492 * call back index and reuse the same smid for
3493 * processing this delayed request
3495 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3496 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3497 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3499 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3500 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3501 ioc
->name
, le16_to_cpu(event
), smid
,
3503 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3504 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3505 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3506 ack_request
->Event
= event
;
3507 ack_request
->EventContext
= event_context
;
3508 ack_request
->VF_ID
= 0; /* TODO */
3509 ack_request
->VP_ID
= 0;
3510 ioc
->put_smid_default(ioc
, smid
);
3514 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3515 * sas_io_unit_ctrl messages
3516 * @ioc: per adapter object
3517 * @smid: system request message index
3518 * @handle: device handle
3520 * Context - processed in interrupt context.
3523 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
3524 u16 smid
, u16 handle
)
3526 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3528 int i
= smid
- ioc
->internal_smid
;
3529 unsigned long flags
;
3531 if (ioc
->remove_host
) {
3532 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3533 "%s: host has been removed\n",
3534 __func__
, ioc
->name
));
3536 } else if (ioc
->pci_error_recovery
) {
3537 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3538 "%s: host in pci error recovery\n",
3539 __func__
, ioc
->name
));
3542 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3543 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3544 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3545 "%s: host is not operational\n",
3546 __func__
, ioc
->name
));
3550 /* Without releasing the smid just update the
3551 * call back index and reuse the same smid for
3552 * processing this delayed request
3554 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3555 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
3556 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3558 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3559 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3560 ioc
->name
, le16_to_cpu(handle
), smid
,
3561 ioc
->tm_sas_control_cb_idx
));
3562 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3563 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3564 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3565 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3566 mpi_request
->DevHandle
= handle
;
3567 ioc
->put_smid_default(ioc
, smid
);
3571 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3572 * @ioc: per adapter object
3573 * @smid: system request message index
3575 * Context: Executed in interrupt context
3577 * This will check delayed internal messages list, and process the
3580 * Return 1 meaning mf should be freed from _base_interrupt
3581 * 0 means the mf is freed from this function.
3584 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3586 struct _sc_list
*delayed_sc
;
3587 struct _event_ack_list
*delayed_event_ack
;
3589 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
3590 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
3591 struct _event_ack_list
, list
);
3592 _scsih_issue_delayed_event_ack(ioc
, smid
,
3593 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
3594 list_del(&delayed_event_ack
->list
);
3595 kfree(delayed_event_ack
);
3599 if (!list_empty(&ioc
->delayed_sc_list
)) {
3600 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
3601 struct _sc_list
, list
);
3602 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
3603 delayed_sc
->handle
);
3604 list_del(&delayed_sc
->list
);
3612 * _scsih_check_for_pending_tm - check for pending task management
3613 * @ioc: per adapter object
3614 * @smid: system request message index
3616 * This will check delayed target reset list, and feed the
3619 * Return 1 meaning mf should be freed from _base_interrupt
3620 * 0 means the mf is freed from this function.
3623 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3625 struct _tr_list
*delayed_tr
;
3627 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3628 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3629 struct _tr_list
, list
);
3630 mpt3sas_base_free_smid(ioc
, smid
);
3631 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3632 list_del(&delayed_tr
->list
);
3637 if (!list_empty(&ioc
->delayed_tr_list
)) {
3638 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3639 struct _tr_list
, list
);
3640 mpt3sas_base_free_smid(ioc
, smid
);
3641 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3642 list_del(&delayed_tr
->list
);
3651 * _scsih_check_topo_delete_events - sanity check on topo events
3652 * @ioc: per adapter object
3653 * @event_data: the event data payload
3655 * This routine added to better handle cable breaker.
3657 * This handles the case where driver receives multiple expander
3658 * add and delete events in a single shot. When there is a delete event
3659 * the routine will void any pending add events waiting in the event queue.
3664 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3665 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3667 struct fw_event_work
*fw_event
;
3668 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3669 u16 expander_handle
;
3670 struct _sas_node
*sas_expander
;
3671 unsigned long flags
;
3675 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3676 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3679 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3680 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3681 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3682 _scsih_tm_tr_send(ioc
, handle
);
3685 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3686 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3687 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3690 if (event_data
->ExpStatus
==
3691 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3692 /* put expander attached devices into blocking state */
3693 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3694 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3696 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3697 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3699 handle
= find_first_bit(ioc
->blocking_handles
,
3700 ioc
->facts
.MaxDevHandle
);
3701 if (handle
< ioc
->facts
.MaxDevHandle
)
3702 _scsih_block_io_device(ioc
, handle
);
3703 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3704 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3705 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3707 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3710 /* mark ignore flag for pending events */
3711 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3712 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3713 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3716 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3717 fw_event
->event_data
;
3718 if (local_event_data
->ExpStatus
==
3719 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3720 local_event_data
->ExpStatus
==
3721 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3722 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3724 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3725 "setting ignoring flag\n", ioc
->name
));
3726 fw_event
->ignore
= 1;
3730 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3734 * _scsih_set_volume_delete_flag - setting volume delete flag
3735 * @ioc: per adapter object
3736 * @handle: device handle
3738 * This returns nothing.
3741 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3743 struct _raid_device
*raid_device
;
3744 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3745 unsigned long flags
;
3747 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3748 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
3749 if (raid_device
&& raid_device
->starget
&&
3750 raid_device
->starget
->hostdata
) {
3751 sas_target_priv_data
=
3752 raid_device
->starget
->hostdata
;
3753 sas_target_priv_data
->deleted
= 1;
3754 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3755 "setting delete flag: handle(0x%04x), "
3756 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3757 (unsigned long long) raid_device
->wwid
));
3759 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3763 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3764 * @handle: input handle
3765 * @a: handle for volume a
3766 * @b: handle for volume b
3768 * IR firmware only supports two raid volumes. The purpose of this
3769 * routine is to set the volume handle in either a or b. When the given
3770 * input handle is non-zero, or when a and b have not been set before.
3773 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3775 if (!handle
|| handle
== *a
|| handle
== *b
)
3784 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3785 * @ioc: per adapter object
3786 * @event_data: the event data payload
3787 * Context: interrupt time.
3789 * This routine will send target reset to volume, followed by target
3790 * resets to the PDs. This is called when a PD has been removed, or
3791 * volume has been deleted or removed. When the target reset is sent
3792 * to volume, the PD target resets need to be queued to start upon
3793 * completion of the volume target reset.
3798 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3799 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3801 Mpi2EventIrConfigElement_t
*element
;
3803 u16 handle
, volume_handle
, a
, b
;
3804 struct _tr_list
*delayed_tr
;
3809 if (ioc
->is_warpdrive
)
3812 /* Volume Resets for Deleted or Removed */
3813 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3814 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3815 if (le32_to_cpu(event_data
->Flags
) &
3816 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3818 if (element
->ReasonCode
==
3819 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3820 element
->ReasonCode
==
3821 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3822 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3823 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3824 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3828 /* Volume Resets for UNHIDE events */
3829 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3830 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3831 if (le32_to_cpu(event_data
->Flags
) &
3832 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3834 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3835 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3836 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3841 _scsih_tm_tr_volume_send(ioc
, a
);
3843 _scsih_tm_tr_volume_send(ioc
, b
);
3845 /* PD target resets */
3846 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3847 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3848 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3850 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3851 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3852 clear_bit(handle
, ioc
->pd_handles
);
3854 _scsih_tm_tr_send(ioc
, handle
);
3855 else if (volume_handle
== a
|| volume_handle
== b
) {
3856 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3857 BUG_ON(!delayed_tr
);
3858 INIT_LIST_HEAD(&delayed_tr
->list
);
3859 delayed_tr
->handle
= handle
;
3860 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3861 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3862 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3865 _scsih_tm_tr_send(ioc
, handle
);
3871 * _scsih_check_volume_delete_events - set delete flag for volumes
3872 * @ioc: per adapter object
3873 * @event_data: the event data payload
3874 * Context: interrupt time.
3876 * This will handle the case when the cable connected to entire volume is
3877 * pulled. We will take care of setting the deleted flag so normal IO will
3883 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3884 Mpi2EventDataIrVolume_t
*event_data
)
3888 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3890 state
= le32_to_cpu(event_data
->NewValue
);
3891 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3892 MPI2_RAID_VOL_STATE_FAILED
)
3893 _scsih_set_volume_delete_flag(ioc
,
3894 le16_to_cpu(event_data
->VolDevHandle
));
3898 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3899 * @ioc: per adapter object
3900 * @event_data: the temp threshold event data
3901 * Context: interrupt time.
3906 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
3907 Mpi2EventDataTemperature_t
*event_data
)
3909 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3910 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
3911 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3912 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3913 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3914 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3915 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3916 event_data
->SensorNum
);
3917 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
3918 ioc
->name
, event_data
->CurrentTemperature
);
3922 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
3924 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
3926 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
3930 return test_and_set_bit(0, &priv
->ata_command_pending
);
3932 clear_bit(0, &priv
->ata_command_pending
);
3937 * _scsih_flush_running_cmds - completing outstanding commands.
3938 * @ioc: per adapter object
3940 * The flushing out of all pending scmd commands following host reset,
3941 * where all IO is dropped to the floor.
3946 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3948 struct scsi_cmnd
*scmd
;
3952 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3953 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3957 _scsih_set_satl_pending(scmd
, false);
3958 mpt3sas_base_free_smid(ioc
, smid
);
3959 scsi_dma_unmap(scmd
);
3960 if (ioc
->pci_error_recovery
)
3961 scmd
->result
= DID_NO_CONNECT
<< 16;
3963 scmd
->result
= DID_RESET
<< 16;
3964 scmd
->scsi_done(scmd
);
3966 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3971 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3972 * @ioc: per adapter object
3973 * @scmd: pointer to scsi command object
3974 * @mpi_request: pointer to the SCSI_IO request message frame
3976 * Supporting protection 1 and 3.
3981 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3982 Mpi2SCSIIORequest_t
*mpi_request
)
3985 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3986 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3987 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3988 (Mpi25SCSIIORequest_t
*)mpi_request
;
3990 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3993 if (prot_op
== SCSI_PROT_READ_STRIP
)
3994 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3995 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3996 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
4000 switch (prot_type
) {
4001 case SCSI_PROT_DIF_TYPE1
:
4002 case SCSI_PROT_DIF_TYPE2
:
4005 * enable ref/guard checking
4006 * auto increment ref tag
4008 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4009 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4010 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4011 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4012 cpu_to_be32(scsi_prot_ref_tag(scmd
));
4015 case SCSI_PROT_DIF_TYPE3
:
4018 * enable guard checking
4020 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4025 mpi_request_3v
->EEDPBlockSize
=
4026 cpu_to_le16(scmd
->device
->sector_size
);
4028 if (ioc
->is_gen35_ioc
)
4029 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4030 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4034 * _scsih_eedp_error_handling - return sense code for EEDP errors
4035 * @scmd: pointer to scsi command object
4036 * @ioc_status: ioc status
4041 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4045 switch (ioc_status
) {
4046 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4049 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4052 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4059 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4061 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4062 SAM_STAT_CHECK_CONDITION
;
4066 * scsih_qcmd - main scsi request entry point
4067 * @scmd: pointer to scsi command object
4068 * @done: function pointer to be invoked on completion
4070 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4072 * Returns 0 on success. If there's a failure, return either:
4073 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4074 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4077 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4079 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4080 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4081 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4082 struct _raid_device
*raid_device
;
4083 struct request
*rq
= scmd
->request
;
4085 Mpi2SCSIIORequest_t
*mpi_request
;
4090 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4091 scsi_print_command(scmd
);
4093 sas_device_priv_data
= scmd
->device
->hostdata
;
4094 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4095 scmd
->result
= DID_NO_CONNECT
<< 16;
4096 scmd
->scsi_done(scmd
);
4100 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
4101 scmd
->result
= DID_NO_CONNECT
<< 16;
4102 scmd
->scsi_done(scmd
);
4107 * Bug work around for firmware SATL handling. The loop
4108 * is based on atomic operations and ensures consistency
4109 * since we're lockless at this point
4112 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
)) {
4113 scmd
->result
= SAM_STAT_BUSY
;
4114 scmd
->scsi_done(scmd
);
4117 } while (_scsih_set_satl_pending(scmd
, true));
4119 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4121 /* invalid device handle */
4122 handle
= sas_target_priv_data
->handle
;
4123 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4124 scmd
->result
= DID_NO_CONNECT
<< 16;
4125 scmd
->scsi_done(scmd
);
4130 /* host recovery or link resets sent via IOCTLs */
4131 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4132 return SCSI_MLQUEUE_HOST_BUSY
;
4134 /* device has been deleted */
4135 else if (sas_target_priv_data
->deleted
) {
4136 scmd
->result
= DID_NO_CONNECT
<< 16;
4137 scmd
->scsi_done(scmd
);
4139 /* device busy with task management */
4140 } else if (sas_target_priv_data
->tm_busy
||
4141 sas_device_priv_data
->block
)
4142 return SCSI_MLQUEUE_DEVICE_BUSY
;
4144 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4145 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4146 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4147 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4149 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4152 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4153 /* NCQ Prio supported, make sure control indicated high priority */
4154 if (sas_device_priv_data
->ncq_prio_enable
) {
4155 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4156 if (class == IOPRIO_CLASS_RT
)
4157 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4159 /* Make sure Device is not raid volume.
4160 * We do not expose raid functionality to upper layer for warpdrive.
4162 if (!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
)
4163 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4164 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4166 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4168 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4169 ioc
->name
, __func__
);
4172 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4173 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
4174 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4176 if (scmd
->cmd_len
== 32)
4177 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4178 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4179 if (sas_device_priv_data
->sas_target
->flags
&
4180 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4181 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4183 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4184 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4185 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4186 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4187 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4188 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4189 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4190 mpi_request
->SenseBufferLowAddress
=
4191 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4192 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4193 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4195 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4197 if (mpi_request
->DataLength
) {
4198 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
4199 mpt3sas_base_free_smid(ioc
, smid
);
4203 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4205 raid_device
= sas_target_priv_data
->raid_device
;
4206 if (raid_device
&& raid_device
->direct_io_enabled
)
4207 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4210 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4211 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4212 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4213 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4214 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4216 ioc
->put_smid_scsi_io(ioc
, smid
,
4217 le16_to_cpu(mpi_request
->DevHandle
));
4219 ioc
->put_smid_default(ioc
, smid
);
4223 return SCSI_MLQUEUE_HOST_BUSY
;
4227 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4228 * @sense_buffer: sense data returned by target
4229 * @data: normalized skey/asc/ascq
4234 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4236 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4237 /* descriptor format */
4238 data
->skey
= sense_buffer
[1] & 0x0F;
4239 data
->asc
= sense_buffer
[2];
4240 data
->ascq
= sense_buffer
[3];
4243 data
->skey
= sense_buffer
[2] & 0x0F;
4244 data
->asc
= sense_buffer
[12];
4245 data
->ascq
= sense_buffer
[13];
4250 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4251 * @ioc: per adapter object
4252 * @scmd: pointer to scsi command object
4253 * @mpi_reply: reply mf payload returned from firmware
4255 * scsi_status - SCSI Status code returned from target device
4256 * scsi_state - state info associated with SCSI_IO determined by ioc
4257 * ioc_status - ioc supplied status info
4262 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4263 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4267 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4268 MPI2_IOCSTATUS_MASK
;
4269 u8 scsi_state
= mpi_reply
->SCSIState
;
4270 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4271 char *desc_ioc_state
= NULL
;
4272 char *desc_scsi_status
= NULL
;
4273 char *desc_scsi_state
= ioc
->tmp_string
;
4274 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4275 struct _sas_device
*sas_device
= NULL
;
4276 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4277 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4278 char *device_str
= NULL
;
4282 if (ioc
->hide_ir_msg
)
4283 device_str
= "WarpDrive";
4285 device_str
= "volume";
4287 if (log_info
== 0x31170000)
4290 switch (ioc_status
) {
4291 case MPI2_IOCSTATUS_SUCCESS
:
4292 desc_ioc_state
= "success";
4294 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4295 desc_ioc_state
= "invalid function";
4297 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4298 desc_ioc_state
= "scsi recovered error";
4300 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4301 desc_ioc_state
= "scsi invalid dev handle";
4303 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4304 desc_ioc_state
= "scsi device not there";
4306 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4307 desc_ioc_state
= "scsi data overrun";
4309 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4310 desc_ioc_state
= "scsi data underrun";
4312 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4313 desc_ioc_state
= "scsi io data error";
4315 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4316 desc_ioc_state
= "scsi protocol error";
4318 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4319 desc_ioc_state
= "scsi task terminated";
4321 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4322 desc_ioc_state
= "scsi residual mismatch";
4324 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4325 desc_ioc_state
= "scsi task mgmt failed";
4327 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4328 desc_ioc_state
= "scsi ioc terminated";
4330 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4331 desc_ioc_state
= "scsi ext terminated";
4333 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4334 desc_ioc_state
= "eedp guard error";
4336 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4337 desc_ioc_state
= "eedp ref tag error";
4339 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4340 desc_ioc_state
= "eedp app tag error";
4342 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4343 desc_ioc_state
= "insufficient power";
4346 desc_ioc_state
= "unknown";
4350 switch (scsi_status
) {
4351 case MPI2_SCSI_STATUS_GOOD
:
4352 desc_scsi_status
= "good";
4354 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4355 desc_scsi_status
= "check condition";
4357 case MPI2_SCSI_STATUS_CONDITION_MET
:
4358 desc_scsi_status
= "condition met";
4360 case MPI2_SCSI_STATUS_BUSY
:
4361 desc_scsi_status
= "busy";
4363 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4364 desc_scsi_status
= "intermediate";
4366 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4367 desc_scsi_status
= "intermediate condmet";
4369 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4370 desc_scsi_status
= "reservation conflict";
4372 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4373 desc_scsi_status
= "command terminated";
4375 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4376 desc_scsi_status
= "task set full";
4378 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4379 desc_scsi_status
= "aca active";
4381 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4382 desc_scsi_status
= "task aborted";
4385 desc_scsi_status
= "unknown";
4389 desc_scsi_state
[0] = '\0';
4391 desc_scsi_state
= " ";
4392 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4393 strcat(desc_scsi_state
, "response info ");
4394 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4395 strcat(desc_scsi_state
, "state terminated ");
4396 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4397 strcat(desc_scsi_state
, "no status ");
4398 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4399 strcat(desc_scsi_state
, "autosense failed ");
4400 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4401 strcat(desc_scsi_state
, "autosense valid ");
4403 scsi_print_command(scmd
);
4405 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4406 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4407 device_str
, (unsigned long long)priv_target
->sas_address
);
4409 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4412 "\tsas_address(0x%016llx), phy(%d)\n",
4413 ioc
->name
, (unsigned long long)
4414 sas_device
->sas_address
, sas_device
->phy
);
4415 if (sas_device
->enclosure_handle
!= 0)
4417 "\tenclosure_logical_id(0x%016llx),"
4418 "slot(%d)\n", ioc
->name
,
4419 (unsigned long long)
4420 sas_device
->enclosure_logical_id
,
4422 if (sas_device
->connector_name
[0])
4424 "\tenclosure level(0x%04x),"
4425 " connector name( %s)\n", ioc
->name
,
4426 sas_device
->enclosure_level
,
4427 sas_device
->connector_name
);
4429 sas_device_put(sas_device
);
4434 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4435 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4436 desc_ioc_state
, ioc_status
, smid
);
4438 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4439 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4440 scsi_get_resid(scmd
));
4442 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4443 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4444 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4446 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4447 ioc
->name
, desc_scsi_status
,
4448 scsi_status
, desc_scsi_state
, scsi_state
);
4450 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4451 struct sense_info data
;
4452 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4454 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4455 ioc
->name
, data
.skey
,
4456 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4459 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4460 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4461 response_bytes
= (u8
*)&response_info
;
4462 _scsih_response_code(ioc
, response_bytes
[0]);
4467 * _scsih_turn_on_pfa_led - illuminate PFA LED
4468 * @ioc: per adapter object
4469 * @handle: device handle
4475 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4477 Mpi2SepReply_t mpi_reply
;
4478 Mpi2SepRequest_t mpi_request
;
4479 struct _sas_device
*sas_device
;
4481 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4485 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4486 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4487 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4488 mpi_request
.SlotStatus
=
4489 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4490 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4491 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4492 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4493 &mpi_request
)) != 0) {
4494 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4495 __FILE__
, __LINE__
, __func__
);
4498 sas_device
->pfa_led_on
= 1;
4500 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4501 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4502 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4503 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4504 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4508 sas_device_put(sas_device
);
4512 * _scsih_turn_off_pfa_led - turn off Fault LED
4513 * @ioc: per adapter object
4514 * @sas_device: sas device whose PFA LED has to turned off
4520 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4521 struct _sas_device
*sas_device
)
4523 Mpi2SepReply_t mpi_reply
;
4524 Mpi2SepRequest_t mpi_request
;
4526 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4527 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4528 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4529 mpi_request
.SlotStatus
= 0;
4530 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4531 mpi_request
.DevHandle
= 0;
4532 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4533 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4534 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4535 &mpi_request
)) != 0) {
4536 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4537 __FILE__
, __LINE__
, __func__
);
4541 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4542 dewtprintk(ioc
, printk(MPT3SAS_FMT
4543 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4544 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4545 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4551 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4552 * @ioc: per adapter object
4553 * @handle: device handle
4554 * Context: interrupt.
4559 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4561 struct fw_event_work
*fw_event
;
4563 fw_event
= alloc_fw_event_work(0);
4566 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4567 fw_event
->device_handle
= handle
;
4568 fw_event
->ioc
= ioc
;
4569 _scsih_fw_event_add(ioc
, fw_event
);
4570 fw_event_work_put(fw_event
);
4574 * _scsih_smart_predicted_fault - process smart errors
4575 * @ioc: per adapter object
4576 * @handle: device handle
4577 * Context: interrupt.
4582 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4584 struct scsi_target
*starget
;
4585 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4586 Mpi2EventNotificationReply_t
*event_reply
;
4587 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4588 struct _sas_device
*sas_device
;
4590 unsigned long flags
;
4592 /* only handle non-raid devices */
4593 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4594 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
4598 starget
= sas_device
->starget
;
4599 sas_target_priv_data
= starget
->hostdata
;
4601 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4602 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
4605 if (sas_device
->enclosure_handle
!= 0)
4606 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4607 "enclosure logical id(0x%016llx), slot(%d)\n",
4608 (unsigned long long)sas_device
->enclosure_logical_id
,
4610 if (sas_device
->connector_name
[0] != '\0')
4611 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4612 "enclosure level(0x%04x), connector name( %s)\n",
4613 sas_device
->enclosure_level
,
4614 sas_device
->connector_name
);
4615 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4617 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4618 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4620 /* insert into event log */
4621 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4622 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4623 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4625 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4626 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4630 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4631 event_reply
->Event
=
4632 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4633 event_reply
->MsgLength
= sz
/4;
4634 event_reply
->EventDataLength
=
4635 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4636 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4637 event_reply
->EventData
;
4638 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4639 event_data
->ASC
= 0x5D;
4640 event_data
->DevHandle
= cpu_to_le16(handle
);
4641 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4642 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4646 sas_device_put(sas_device
);
4650 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4655 * _scsih_io_done - scsi request callback
4656 * @ioc: per adapter object
4657 * @smid: system request message index
4658 * @msix_index: MSIX table index supplied by the OS
4659 * @reply: reply message frame(lower 32bit addr)
4661 * Callback handler when using _scsih_qcmd.
4663 * Return 1 meaning mf should be freed from _base_interrupt
4664 * 0 means the mf is freed from this function.
4667 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4669 Mpi2SCSIIORequest_t
*mpi_request
;
4670 Mpi2SCSIIOReply_t
*mpi_reply
;
4671 struct scsi_cmnd
*scmd
;
4677 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4678 u32 response_code
= 0;
4679 unsigned long flags
;
4680 unsigned int sector_sz
;
4682 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4684 if (ioc
->broadcast_aen_busy
|| ioc
->pci_error_recovery
||
4685 ioc
->got_task_abort_from_ioctl
)
4686 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4688 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
4693 _scsih_set_satl_pending(scmd
, false);
4695 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4697 if (mpi_reply
== NULL
) {
4698 scmd
->result
= DID_OK
<< 16;
4702 sas_device_priv_data
= scmd
->device
->hostdata
;
4703 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4704 sas_device_priv_data
->sas_target
->deleted
) {
4705 scmd
->result
= DID_NO_CONNECT
<< 16;
4708 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4711 * WARPDRIVE: If direct_io is set then it is directIO,
4712 * the failed direct I/O should be redirected to volume
4714 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
4715 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4716 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4717 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4718 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4719 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4720 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
4721 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4722 mpi_request
->DevHandle
=
4723 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4724 ioc
->put_smid_scsi_io(ioc
, smid
,
4725 sas_device_priv_data
->sas_target
->handle
);
4728 /* turning off TLR */
4729 scsi_state
= mpi_reply
->SCSIState
;
4730 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4732 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4733 if (!sas_device_priv_data
->tlr_snoop_check
) {
4734 sas_device_priv_data
->tlr_snoop_check
++;
4735 if (!ioc
->is_warpdrive
&&
4736 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4737 sas_is_tlr_enabled(scmd
->device
) &&
4738 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4739 sas_disable_tlr(scmd
->device
);
4740 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4744 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4746 /* In case of bogus fw or device, we could end up having
4747 * unaligned partial completion. We can force alignment here,
4748 * then scsi-ml does not need to handle this misbehavior.
4750 sector_sz
= scmd
->device
->sector_size
;
4751 if (unlikely(!blk_rq_is_passthrough(scmd
->request
) && sector_sz
&&
4752 xfer_cnt
% sector_sz
)) {
4753 sdev_printk(KERN_INFO
, scmd
->device
,
4754 "unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4755 xfer_cnt
, sector_sz
);
4756 xfer_cnt
= round_down(xfer_cnt
, sector_sz
);
4759 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4760 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4761 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4764 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4765 scsi_status
= mpi_reply
->SCSIStatus
;
4767 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4768 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4769 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4770 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4771 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4774 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4775 struct sense_info data
;
4776 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4778 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4779 le32_to_cpu(mpi_reply
->SenseCount
));
4780 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4781 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4782 /* failure prediction threshold exceeded */
4783 if (data
.asc
== 0x5D)
4784 _scsih_smart_predicted_fault(ioc
,
4785 le16_to_cpu(mpi_reply
->DevHandle
));
4786 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4788 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4789 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4790 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4791 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4792 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4794 switch (ioc_status
) {
4795 case MPI2_IOCSTATUS_BUSY
:
4796 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4797 scmd
->result
= SAM_STAT_BUSY
;
4800 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4801 scmd
->result
= DID_NO_CONNECT
<< 16;
4804 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4805 if (sas_device_priv_data
->block
) {
4806 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4809 if (log_info
== 0x31110630) {
4810 if (scmd
->retries
> 2) {
4811 scmd
->result
= DID_NO_CONNECT
<< 16;
4812 scsi_device_set_state(scmd
->device
,
4815 scmd
->result
= DID_SOFT_ERROR
<< 16;
4816 scmd
->device
->expecting_cc_ua
= 1;
4819 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4820 scmd
->result
= DID_RESET
<< 16;
4823 scmd
->result
= DID_SOFT_ERROR
<< 16;
4825 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4826 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4827 scmd
->result
= DID_RESET
<< 16;
4830 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4831 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4832 scmd
->result
= DID_SOFT_ERROR
<< 16;
4834 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4837 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4838 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4840 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4843 if (xfer_cnt
< scmd
->underflow
) {
4844 if (scsi_status
== SAM_STAT_BUSY
)
4845 scmd
->result
= SAM_STAT_BUSY
;
4847 scmd
->result
= DID_SOFT_ERROR
<< 16;
4848 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4849 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4850 scmd
->result
= DID_SOFT_ERROR
<< 16;
4851 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4852 scmd
->result
= DID_RESET
<< 16;
4853 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4854 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4855 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4856 scmd
->result
= (DRIVER_SENSE
<< 24) |
4857 SAM_STAT_CHECK_CONDITION
;
4858 scmd
->sense_buffer
[0] = 0x70;
4859 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4860 scmd
->sense_buffer
[12] = 0x20;
4861 scmd
->sense_buffer
[13] = 0;
4865 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4866 scsi_set_resid(scmd
, 0);
4867 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4868 case MPI2_IOCSTATUS_SUCCESS
:
4869 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4870 if (response_code
==
4871 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4872 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4873 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4874 scmd
->result
= DID_SOFT_ERROR
<< 16;
4875 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4876 scmd
->result
= DID_RESET
<< 16;
4879 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4880 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4881 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4882 _scsih_eedp_error_handling(scmd
, ioc_status
);
4885 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4886 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4887 case MPI2_IOCSTATUS_INVALID_SGL
:
4888 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4889 case MPI2_IOCSTATUS_INVALID_FIELD
:
4890 case MPI2_IOCSTATUS_INVALID_STATE
:
4891 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4892 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4893 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4895 scmd
->result
= DID_SOFT_ERROR
<< 16;
4900 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4901 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4905 scsi_dma_unmap(scmd
);
4907 scmd
->scsi_done(scmd
);
4912 * _scsih_sas_host_refresh - refreshing sas host object contents
4913 * @ioc: per adapter object
4916 * During port enable, fw will send topology events for every device. Its
4917 * possible that the handles may change from the previous setting, so this
4918 * code keeping handles updating if changed.
4923 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4928 Mpi2ConfigReply_t mpi_reply
;
4929 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4930 u16 attached_handle
;
4933 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4934 "updating handles for sas_host(0x%016llx)\n",
4935 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4937 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4938 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4939 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4940 if (!sas_iounit_pg0
) {
4941 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4942 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4946 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4947 sas_iounit_pg0
, sz
)) != 0)
4949 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4950 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4952 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4953 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4955 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4956 PhyData
[0].ControllerDevHandle
);
4957 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4958 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4960 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4961 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4962 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4963 attached_handle
, i
, link_rate
);
4966 kfree(sas_iounit_pg0
);
4970 * _scsih_sas_host_add - create sas host object
4971 * @ioc: per adapter object
4973 * Creating host side data object, stored in ioc->sas_hba
4978 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4981 Mpi2ConfigReply_t mpi_reply
;
4982 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4983 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4984 Mpi2SasPhyPage0_t phy_pg0
;
4985 Mpi2SasDevicePage0_t sas_device_pg0
;
4986 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4989 u8 device_missing_delay
;
4992 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
4994 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4995 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4998 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
4999 sizeof(struct _sas_phy
), GFP_KERNEL
);
5000 if (!ioc
->sas_hba
.phy
) {
5001 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5002 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5005 ioc
->sas_hba
.num_phys
= num_phys
;
5007 /* sas_iounit page 0 */
5008 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5009 sizeof(Mpi2SasIOUnit0PhyData_t
));
5010 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5011 if (!sas_iounit_pg0
) {
5012 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5013 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5016 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5017 sas_iounit_pg0
, sz
))) {
5018 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5019 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5022 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5023 MPI2_IOCSTATUS_MASK
;
5024 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5025 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5026 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5030 /* sas_iounit page 1 */
5031 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5032 sizeof(Mpi2SasIOUnit1PhyData_t
));
5033 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5034 if (!sas_iounit_pg1
) {
5035 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5036 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5039 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5040 sas_iounit_pg1
, sz
))) {
5041 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5042 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5045 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5046 MPI2_IOCSTATUS_MASK
;
5047 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5048 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5049 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5053 ioc
->io_missing_delay
=
5054 sas_iounit_pg1
->IODeviceMissingDelay
;
5055 device_missing_delay
=
5056 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5057 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5058 ioc
->device_missing_delay
= (device_missing_delay
&
5059 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5061 ioc
->device_missing_delay
= device_missing_delay
&
5062 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5064 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5065 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5066 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5068 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5069 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5072 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5073 MPI2_IOCSTATUS_MASK
;
5074 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5075 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5076 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5081 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5082 PhyData
[0].ControllerDevHandle
);
5083 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5084 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5085 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5086 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5088 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5089 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5090 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5091 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5094 ioc
->sas_hba
.enclosure_handle
=
5095 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5096 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5098 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5099 ioc
->name
, ioc
->sas_hba
.handle
,
5100 (unsigned long long) ioc
->sas_hba
.sas_address
,
5101 ioc
->sas_hba
.num_phys
) ;
5103 if (ioc
->sas_hba
.enclosure_handle
) {
5104 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5105 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5106 ioc
->sas_hba
.enclosure_handle
)))
5107 ioc
->sas_hba
.enclosure_logical_id
=
5108 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5112 kfree(sas_iounit_pg1
);
5113 kfree(sas_iounit_pg0
);
5117 * _scsih_expander_add - creating expander object
5118 * @ioc: per adapter object
5119 * @handle: expander handle
5121 * Creating expander object, stored in ioc->sas_expander_list.
5123 * Return 0 for success, else error.
5126 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5128 struct _sas_node
*sas_expander
;
5129 Mpi2ConfigReply_t mpi_reply
;
5130 Mpi2ExpanderPage0_t expander_pg0
;
5131 Mpi2ExpanderPage1_t expander_pg1
;
5132 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5135 u64 sas_address
, sas_address_parent
= 0;
5137 unsigned long flags
;
5138 struct _sas_port
*mpt3sas_port
= NULL
;
5145 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5148 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5149 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5150 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5151 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5155 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5156 MPI2_IOCSTATUS_MASK
;
5157 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5158 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5159 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5163 /* handle out of order topology events */
5164 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5165 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5167 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5168 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5171 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5172 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5173 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5174 sas_address_parent
);
5175 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5176 if (!sas_expander
) {
5177 rc
= _scsih_expander_add(ioc
, parent_handle
);
5183 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5184 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5185 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5187 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5192 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5194 if (!sas_expander
) {
5195 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5196 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5200 sas_expander
->handle
= handle
;
5201 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5202 sas_expander
->sas_address_parent
= sas_address_parent
;
5203 sas_expander
->sas_address
= sas_address
;
5205 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5206 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5207 handle
, parent_handle
, (unsigned long long)
5208 sas_expander
->sas_address
, sas_expander
->num_phys
);
5210 if (!sas_expander
->num_phys
)
5212 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5213 sizeof(struct _sas_phy
), GFP_KERNEL
);
5214 if (!sas_expander
->phy
) {
5215 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5216 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5221 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5222 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5223 sas_address_parent
);
5224 if (!mpt3sas_port
) {
5225 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5226 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5230 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5232 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5233 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5234 &expander_pg1
, i
, handle
))) {
5235 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5236 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5240 sas_expander
->phy
[i
].handle
= handle
;
5241 sas_expander
->phy
[i
].phy_id
= i
;
5243 if ((mpt3sas_transport_add_expander_phy(ioc
,
5244 &sas_expander
->phy
[i
], expander_pg1
,
5245 sas_expander
->parent_dev
))) {
5246 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5247 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5253 if (sas_expander
->enclosure_handle
) {
5254 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5255 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5256 sas_expander
->enclosure_handle
)))
5257 sas_expander
->enclosure_logical_id
=
5258 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5261 _scsih_expander_node_add(ioc
, sas_expander
);
5267 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5268 sas_address_parent
);
5269 kfree(sas_expander
);
5274 * mpt3sas_expander_remove - removing expander object
5275 * @ioc: per adapter object
5276 * @sas_address: expander sas_address
5281 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5283 struct _sas_node
*sas_expander
;
5284 unsigned long flags
;
5286 if (ioc
->shost_recovery
)
5289 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5290 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5293 list_del(&sas_expander
->list
);
5294 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5296 _scsih_expander_node_remove(ioc
, sas_expander
);
5300 * _scsih_done - internal SCSI_IO callback handler.
5301 * @ioc: per adapter object
5302 * @smid: system request message index
5303 * @msix_index: MSIX table index supplied by the OS
5304 * @reply: reply message frame(lower 32bit addr)
5306 * Callback handler when sending internal generated SCSI_IO.
5307 * The callback index passed is `ioc->scsih_cb_idx`
5309 * Return 1 meaning mf should be freed from _base_interrupt
5310 * 0 means the mf is freed from this function.
5313 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5315 MPI2DefaultReply_t
*mpi_reply
;
5317 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5318 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5320 if (ioc
->scsih_cmds
.smid
!= smid
)
5322 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5324 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5325 mpi_reply
->MsgLength
*4);
5326 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5328 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5329 complete(&ioc
->scsih_cmds
.done
);
5336 #define MPT3_MAX_LUNS (255)
5340 * _scsih_check_access_status - check access flags
5341 * @ioc: per adapter object
5342 * @sas_address: sas address
5343 * @handle: sas device handle
5344 * @access_flags: errors returned during discovery of the device
5346 * Return 0 for success, else failure
5349 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5350 u16 handle
, u8 access_status
)
5355 switch (access_status
) {
5356 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5357 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5360 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5361 desc
= "sata capability failed";
5363 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5364 desc
= "sata affiliation conflict";
5366 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5367 desc
= "route not addressable";
5369 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5370 desc
= "smp error not addressable";
5372 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5373 desc
= "device blocked";
5375 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5376 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5377 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5378 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5379 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5380 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5381 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5382 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5383 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5384 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5385 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5386 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5387 desc
= "sata initialization failed";
5398 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5399 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5404 * _scsih_check_device - checking device responsiveness
5405 * @ioc: per adapter object
5406 * @parent_sas_address: sas address of parent expander or sas host
5407 * @handle: attached device handle
5408 * @phy_numberv: phy number
5409 * @link_rate: new link rate
5414 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5415 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5417 Mpi2ConfigReply_t mpi_reply
;
5418 Mpi2SasDevicePage0_t sas_device_pg0
;
5419 struct _sas_device
*sas_device
;
5421 unsigned long flags
;
5423 struct scsi_target
*starget
;
5424 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5428 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5429 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5432 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5433 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5436 /* wide port handling ~ we need only handle device once for the phy that
5437 * is matched in sas device page zero
5439 if (phy_number
!= sas_device_pg0
.PhyNum
)
5442 /* check if this is end device */
5443 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5444 if (!(_scsih_is_end_device(device_info
)))
5447 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5448 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5449 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5455 if (unlikely(sas_device
->handle
!= handle
)) {
5456 starget
= sas_device
->starget
;
5457 sas_target_priv_data
= starget
->hostdata
;
5458 starget_printk(KERN_INFO
, starget
,
5459 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5460 sas_device
->handle
, handle
);
5461 sas_target_priv_data
->handle
= handle
;
5462 sas_device
->handle
= handle
;
5463 if (le16_to_cpu(sas_device_pg0
.Flags
) &
5464 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5465 sas_device
->enclosure_level
=
5466 sas_device_pg0
.EnclosureLevel
;
5467 memcpy(sas_device
->connector_name
,
5468 sas_device_pg0
.ConnectorName
, 4);
5469 sas_device
->connector_name
[4] = '\0';
5471 sas_device
->enclosure_level
= 0;
5472 sas_device
->connector_name
[0] = '\0';
5476 /* check if device is present */
5477 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5478 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5480 "device is not present handle(0x%04x), flags!!!\n",
5485 /* check if there were any issues with discovery */
5486 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5487 sas_device_pg0
.AccessStatus
))
5490 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5491 _scsih_ublock_io_device(ioc
, sas_address
);
5494 sas_device_put(sas_device
);
5498 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5500 sas_device_put(sas_device
);
5504 * _scsih_add_device - creating sas device object
5505 * @ioc: per adapter object
5506 * @handle: sas device handle
5507 * @phy_num: phy number end device attached to
5508 * @is_pd: is this hidden raid component
5510 * Creating end device object, stored in ioc->sas_device_list.
5512 * Returns 0 for success, non-zero for failure.
5515 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
5518 Mpi2ConfigReply_t mpi_reply
;
5519 Mpi2SasDevicePage0_t sas_device_pg0
;
5520 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5521 struct _sas_device
*sas_device
;
5526 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5527 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5528 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5529 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5533 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5534 MPI2_IOCSTATUS_MASK
;
5535 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5536 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5537 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5541 /* check if this is end device */
5542 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5543 if (!(_scsih_is_end_device(device_info
)))
5545 set_bit(handle
, ioc
->pend_os_device_add
);
5546 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5548 /* check if device is present */
5549 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5550 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5551 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5556 /* check if there were any issues with discovery */
5557 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5558 sas_device_pg0
.AccessStatus
))
5561 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
5564 clear_bit(handle
, ioc
->pend_os_device_add
);
5565 sas_device_put(sas_device
);
5569 sas_device
= kzalloc(sizeof(struct _sas_device
),
5572 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5573 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5577 kref_init(&sas_device
->refcount
);
5578 sas_device
->handle
= handle
;
5579 if (_scsih_get_sas_address(ioc
,
5580 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5581 &sas_device
->sas_address_parent
) != 0)
5582 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5583 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5584 sas_device
->enclosure_handle
=
5585 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5586 if (sas_device
->enclosure_handle
!= 0)
5588 le16_to_cpu(sas_device_pg0
.Slot
);
5589 sas_device
->device_info
= device_info
;
5590 sas_device
->sas_address
= sas_address
;
5591 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5592 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5593 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5595 if (le16_to_cpu(sas_device_pg0
.Flags
)
5596 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5597 sas_device
->enclosure_level
=
5598 sas_device_pg0
.EnclosureLevel
;
5599 memcpy(sas_device
->connector_name
,
5600 sas_device_pg0
.ConnectorName
, 4);
5601 sas_device
->connector_name
[4] = '\0';
5603 sas_device
->enclosure_level
= 0;
5604 sas_device
->connector_name
[0] = '\0';
5606 /* get enclosure_logical_id */
5607 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5608 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5609 sas_device
->enclosure_handle
)))
5610 sas_device
->enclosure_logical_id
=
5611 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5613 /* get device name */
5614 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5616 if (ioc
->wait_for_discovery_to_complete
)
5617 _scsih_sas_device_init_add(ioc
, sas_device
);
5619 _scsih_sas_device_add(ioc
, sas_device
);
5621 sas_device_put(sas_device
);
5626 * _scsih_remove_device - removing sas device object
5627 * @ioc: per adapter object
5628 * @sas_device_delete: the sas_device object
5633 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5634 struct _sas_device
*sas_device
)
5636 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5638 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5639 (sas_device
->pfa_led_on
)) {
5640 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5641 sas_device
->pfa_led_on
= 0;
5643 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5644 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5645 ioc
->name
, __func__
,
5646 sas_device
->handle
, (unsigned long long)
5647 sas_device
->sas_address
));
5648 if (sas_device
->enclosure_handle
!= 0)
5649 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5650 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5651 ioc
->name
, __func__
,
5652 (unsigned long long)sas_device
->enclosure_logical_id
,
5654 if (sas_device
->connector_name
[0] != '\0')
5655 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5656 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5657 ioc
->name
, __func__
,
5658 sas_device
->enclosure_level
,
5659 sas_device
->connector_name
));
5661 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5662 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5663 sas_target_priv_data
->deleted
= 1;
5664 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5665 sas_target_priv_data
->handle
=
5666 MPT3SAS_INVALID_DEVICE_HANDLE
;
5669 if (!ioc
->hide_drives
)
5670 mpt3sas_transport_port_remove(ioc
,
5671 sas_device
->sas_address
,
5672 sas_device
->sas_address_parent
);
5675 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5676 ioc
->name
, sas_device
->handle
,
5677 (unsigned long long) sas_device
->sas_address
);
5678 if (sas_device
->enclosure_handle
!= 0)
5680 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5682 (unsigned long long)sas_device
->enclosure_logical_id
,
5684 if (sas_device
->connector_name
[0] != '\0')
5686 "removing enclosure level(0x%04x), connector name( %s)\n",
5687 ioc
->name
, sas_device
->enclosure_level
,
5688 sas_device
->connector_name
);
5690 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5691 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5692 ioc
->name
, __func__
,
5693 sas_device
->handle
, (unsigned long long)
5694 sas_device
->sas_address
));
5695 if (sas_device
->enclosure_handle
!= 0)
5696 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5697 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5698 ioc
->name
, __func__
,
5699 (unsigned long long)sas_device
->enclosure_logical_id
,
5701 if (sas_device
->connector_name
[0] != '\0')
5702 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5703 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5704 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5705 sas_device
->connector_name
));
5709 * _scsih_sas_topology_change_event_debug - debug for topology event
5710 * @ioc: per adapter object
5711 * @event_data: event data payload
5715 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5716 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5722 char *status_str
= NULL
;
5723 u8 link_rate
, prev_link_rate
;
5725 switch (event_data
->ExpStatus
) {
5726 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5729 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5730 status_str
= "remove";
5732 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5734 status_str
= "responding";
5736 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5737 status_str
= "remove delay";
5740 status_str
= "unknown status";
5743 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5744 ioc
->name
, status_str
);
5745 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5746 "start_phy(%02d), count(%d)\n",
5747 le16_to_cpu(event_data
->ExpanderDevHandle
),
5748 le16_to_cpu(event_data
->EnclosureHandle
),
5749 event_data
->StartPhyNum
, event_data
->NumEntries
);
5750 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5751 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5754 phy_number
= event_data
->StartPhyNum
+ i
;
5755 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5756 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5757 switch (reason_code
) {
5758 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5759 status_str
= "target add";
5761 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5762 status_str
= "target remove";
5764 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5765 status_str
= "delay target remove";
5767 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5768 status_str
= "link rate change";
5770 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5771 status_str
= "target responding";
5774 status_str
= "unknown";
5777 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5778 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5779 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5780 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5781 handle
, status_str
, link_rate
, prev_link_rate
);
5787 * _scsih_sas_topology_change_event - handle topology changes
5788 * @ioc: per adapter object
5789 * @fw_event: The fw_event_work object
5794 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5795 struct fw_event_work
*fw_event
)
5798 u16 parent_handle
, handle
;
5800 u8 phy_number
, max_phys
;
5801 struct _sas_node
*sas_expander
;
5803 unsigned long flags
;
5804 u8 link_rate
, prev_link_rate
;
5805 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5806 (Mpi2EventDataSasTopologyChangeList_t
*)
5807 fw_event
->event_data
;
5809 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5810 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5812 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5815 if (!ioc
->sas_hba
.num_phys
)
5816 _scsih_sas_host_add(ioc
);
5818 _scsih_sas_host_refresh(ioc
);
5820 if (fw_event
->ignore
) {
5821 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5822 "ignoring expander event\n", ioc
->name
));
5826 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5828 /* handle expander add */
5829 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5830 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5833 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5834 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5837 sas_address
= sas_expander
->sas_address
;
5838 max_phys
= sas_expander
->num_phys
;
5839 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5840 sas_address
= ioc
->sas_hba
.sas_address
;
5841 max_phys
= ioc
->sas_hba
.num_phys
;
5843 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5846 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5848 /* handle siblings events */
5849 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5850 if (fw_event
->ignore
) {
5851 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5852 "ignoring expander event\n", ioc
->name
));
5855 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5857 phy_number
= event_data
->StartPhyNum
+ i
;
5858 if (phy_number
>= max_phys
)
5860 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5861 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5862 if ((event_data
->PHY
[i
].PhyStatus
&
5863 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5864 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5866 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5869 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5870 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5871 switch (reason_code
) {
5872 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5874 if (ioc
->shost_recovery
)
5877 if (link_rate
== prev_link_rate
)
5880 mpt3sas_transport_update_links(ioc
, sas_address
,
5881 handle
, phy_number
, link_rate
);
5883 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5886 _scsih_check_device(ioc
, sas_address
, handle
,
5887 phy_number
, link_rate
);
5889 if (!test_bit(handle
, ioc
->pend_os_device_add
))
5893 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5895 if (ioc
->shost_recovery
)
5898 mpt3sas_transport_update_links(ioc
, sas_address
,
5899 handle
, phy_number
, link_rate
);
5901 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5904 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5906 _scsih_device_remove_by_handle(ioc
, handle
);
5911 /* handle expander removal */
5912 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5914 mpt3sas_expander_remove(ioc
, sas_address
);
5920 * _scsih_sas_device_status_change_event_debug - debug for device event
5921 * @event_data: event data payload
5927 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5928 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5930 char *reason_str
= NULL
;
5932 switch (event_data
->ReasonCode
) {
5933 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5934 reason_str
= "smart data";
5936 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5937 reason_str
= "unsupported device discovered";
5939 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5940 reason_str
= "internal device reset";
5942 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5943 reason_str
= "internal task abort";
5945 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5946 reason_str
= "internal task abort set";
5948 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5949 reason_str
= "internal clear task set";
5951 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5952 reason_str
= "internal query task";
5954 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5955 reason_str
= "sata init failure";
5957 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5958 reason_str
= "internal device reset complete";
5960 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5961 reason_str
= "internal task abort complete";
5963 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5964 reason_str
= "internal async notification";
5966 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5967 reason_str
= "expander reduced functionality";
5969 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5970 reason_str
= "expander reduced functionality complete";
5973 reason_str
= "unknown reason";
5976 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5977 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5978 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5979 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5980 le16_to_cpu(event_data
->TaskTag
));
5981 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5982 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5983 event_data
->ASC
, event_data
->ASCQ
);
5988 * _scsih_sas_device_status_change_event - handle device status change
5989 * @ioc: per adapter object
5990 * @fw_event: The fw_event_work object
5996 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5997 struct fw_event_work
*fw_event
)
5999 struct MPT3SAS_TARGET
*target_priv_data
;
6000 struct _sas_device
*sas_device
;
6002 unsigned long flags
;
6003 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
6004 (Mpi2EventDataSasDeviceStatusChange_t
*)
6005 fw_event
->event_data
;
6007 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6008 _scsih_sas_device_status_change_event_debug(ioc
,
6011 /* In MPI Revision K (0xC), the internal device reset complete was
6012 * implemented, so avoid setting tm_busy flag for older firmware.
6014 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
6017 if (event_data
->ReasonCode
!=
6018 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
6019 event_data
->ReasonCode
!=
6020 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
6023 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6024 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6025 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6028 if (!sas_device
|| !sas_device
->starget
)
6031 target_priv_data
= sas_device
->starget
->hostdata
;
6032 if (!target_priv_data
)
6035 if (event_data
->ReasonCode
==
6036 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6037 target_priv_data
->tm_busy
= 1;
6039 target_priv_data
->tm_busy
= 0;
6043 sas_device_put(sas_device
);
6045 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6050 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
6052 * @ioc: per adapter object
6053 * @event_data: event data payload
6059 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6060 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
6062 char *reason_str
= NULL
;
6064 switch (event_data
->ReasonCode
) {
6065 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
6066 reason_str
= "enclosure add";
6068 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
6069 reason_str
= "enclosure remove";
6072 reason_str
= "unknown reason";
6076 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
6077 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
6078 " number slots(%d)\n", ioc
->name
, reason_str
,
6079 le16_to_cpu(event_data
->EnclosureHandle
),
6080 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
6081 le16_to_cpu(event_data
->StartSlot
));
6085 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
6086 * @ioc: per adapter object
6087 * @fw_event: The fw_event_work object
6093 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6094 struct fw_event_work
*fw_event
)
6096 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6097 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
6098 (Mpi2EventDataSasEnclDevStatusChange_t
*)
6099 fw_event
->event_data
);
6103 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6104 * @ioc: per adapter object
6105 * @fw_event: The fw_event_work object
6111 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
6112 struct fw_event_work
*fw_event
)
6114 struct scsi_cmnd
*scmd
;
6115 struct scsi_device
*sdev
;
6118 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6119 u32 termination_count
;
6121 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
6122 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
6123 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6124 fw_event
->event_data
;
6126 unsigned long flags
;
6129 u8 task_abort_retries
;
6131 mutex_lock(&ioc
->tm_cmds
.mutex
);
6133 "%s: enter: phy number(%d), width(%d)\n",
6134 ioc
->name
, __func__
, event_data
->PhyNum
,
6135 event_data
->PortWidth
);
6137 _scsih_block_io_all_device(ioc
);
6139 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6140 mpi_reply
= ioc
->tm_cmds
.reply
;
6141 broadcast_aen_retry
:
6143 /* sanity checks for retrying this loop */
6144 if (max_retries
++ == 5) {
6145 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
6146 ioc
->name
, __func__
));
6148 } else if (max_retries
> 1)
6149 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
6150 ioc
->name
, __func__
, max_retries
- 1));
6152 termination_count
= 0;
6154 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
6155 if (ioc
->shost_recovery
)
6157 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
6160 sdev
= scmd
->device
;
6161 sas_device_priv_data
= sdev
->hostdata
;
6162 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
6164 /* skip hidden raid components */
6165 if (sas_device_priv_data
->sas_target
->flags
&
6166 MPT_TARGET_FLAGS_RAID_COMPONENT
)
6169 if (sas_device_priv_data
->sas_target
->flags
&
6170 MPT_TARGET_FLAGS_VOLUME
)
6173 handle
= sas_device_priv_data
->sas_target
->handle
;
6174 lun
= sas_device_priv_data
->lun
;
6177 if (ioc
->shost_recovery
)
6180 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6181 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
6182 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
6184 sdev_printk(KERN_WARNING
, sdev
,
6185 "mpt3sas_scsih_issue_tm: FAILED when sending "
6186 "QUERY_TASK: scmd(%p)\n", scmd
);
6187 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6188 goto broadcast_aen_retry
;
6190 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
6191 & MPI2_IOCSTATUS_MASK
;
6192 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6193 sdev_printk(KERN_WARNING
, sdev
,
6194 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6196 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6197 goto broadcast_aen_retry
;
6200 /* see if IO is still owned by IOC and target */
6201 if (mpi_reply
->ResponseCode
==
6202 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
6203 mpi_reply
->ResponseCode
==
6204 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
6205 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6208 task_abort_retries
= 0;
6210 if (task_abort_retries
++ == 60) {
6211 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6212 "%s: ABORT_TASK: giving up\n", ioc
->name
,
6214 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6215 goto broadcast_aen_retry
;
6218 if (ioc
->shost_recovery
)
6221 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
6222 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
,
6225 sdev_printk(KERN_WARNING
, sdev
,
6226 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6227 "scmd(%p)\n", scmd
);
6231 if (task_abort_retries
> 1)
6232 sdev_printk(KERN_WARNING
, sdev
,
6233 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6235 task_abort_retries
- 1, scmd
);
6237 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
6238 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6241 if (ioc
->broadcast_aen_pending
) {
6242 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6243 "%s: loop back due to pending AEN\n",
6244 ioc
->name
, __func__
));
6245 ioc
->broadcast_aen_pending
= 0;
6246 goto broadcast_aen_retry
;
6250 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6253 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6254 "%s - exit, query_count = %d termination_count = %d\n",
6255 ioc
->name
, __func__
, query_count
, termination_count
));
6257 ioc
->broadcast_aen_busy
= 0;
6258 if (!ioc
->shost_recovery
)
6259 _scsih_ublock_io_all_device(ioc
);
6260 mutex_unlock(&ioc
->tm_cmds
.mutex
);
6264 * _scsih_sas_discovery_event - handle discovery events
6265 * @ioc: per adapter object
6266 * @fw_event: The fw_event_work object
6272 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
6273 struct fw_event_work
*fw_event
)
6275 Mpi2EventDataSasDiscovery_t
*event_data
=
6276 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
6278 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
6279 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
6280 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
6282 if (event_data
->DiscoveryStatus
)
6283 pr_info("discovery_status(0x%08x)",
6284 le32_to_cpu(event_data
->DiscoveryStatus
));
6288 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
6289 !ioc
->sas_hba
.num_phys
) {
6290 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6291 /* Wait for the reset to complete */
6292 while (ioc
->shost_recovery
)
6295 _scsih_sas_host_add(ioc
);
6300 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6301 * @ioc: per adapter object
6302 * @handle: device handle for physical disk
6303 * @phys_disk_num: physical disk number
6305 * Return 0 for success, else failure.
6308 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
6310 Mpi2RaidActionRequest_t
*mpi_request
;
6311 Mpi2RaidActionReply_t
*mpi_reply
;
6318 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
6321 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6323 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
6324 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
6325 ioc
->name
, __func__
);
6329 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
6331 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6333 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
6334 ioc
->name
, __func__
);
6335 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6340 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
6341 ioc
->scsih_cmds
.smid
= smid
;
6342 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6344 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6345 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
6346 mpi_request
->PhysDiskNum
= phys_disk_num
;
6348 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
6349 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
6350 handle
, phys_disk_num
));
6352 init_completion(&ioc
->scsih_cmds
.done
);
6353 ioc
->put_smid_default(ioc
, smid
);
6354 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6356 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
6357 pr_err(MPT3SAS_FMT
"%s: timeout\n",
6358 ioc
->name
, __func__
);
6359 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
6365 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
6367 mpi_reply
= ioc
->scsih_cmds
.reply
;
6368 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
6369 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
6370 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
6373 ioc_status
&= MPI2_IOCSTATUS_MASK
;
6374 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6375 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6376 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6377 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
6381 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6382 "IR RAID_ACTION: completed successfully\n",
6387 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6388 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6391 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
6396 * _scsih_reprobe_lun - reprobing lun
6397 * @sdev: scsi device struct
6398 * @no_uld_attach: sdev->no_uld_attach flag setting
6402 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6404 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6405 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6406 sdev
->no_uld_attach
? "hiding" : "exposing");
6407 WARN_ON(scsi_device_reprobe(sdev
));
6411 * _scsih_sas_volume_add - add new volume
6412 * @ioc: per adapter object
6413 * @element: IR config element data
6419 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
6420 Mpi2EventIrConfigElement_t
*element
)
6422 struct _raid_device
*raid_device
;
6423 unsigned long flags
;
6425 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6428 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6431 "failure at %s:%d/%s()!\n", ioc
->name
,
6432 __FILE__
, __LINE__
, __func__
);
6436 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6437 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6438 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6443 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6446 "failure at %s:%d/%s()!\n", ioc
->name
,
6447 __FILE__
, __LINE__
, __func__
);
6451 raid_device
->id
= ioc
->sas_id
++;
6452 raid_device
->channel
= RAID_CHANNEL
;
6453 raid_device
->handle
= handle
;
6454 raid_device
->wwid
= wwid
;
6455 _scsih_raid_device_add(ioc
, raid_device
);
6456 if (!ioc
->wait_for_discovery_to_complete
) {
6457 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6458 raid_device
->id
, 0);
6460 _scsih_raid_device_remove(ioc
, raid_device
);
6462 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6463 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6464 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6469 * _scsih_sas_volume_delete - delete volume
6470 * @ioc: per adapter object
6471 * @handle: volume device handle
6477 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6479 struct _raid_device
*raid_device
;
6480 unsigned long flags
;
6481 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6482 struct scsi_target
*starget
= NULL
;
6484 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6485 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6487 if (raid_device
->starget
) {
6488 starget
= raid_device
->starget
;
6489 sas_target_priv_data
= starget
->hostdata
;
6490 sas_target_priv_data
->deleted
= 1;
6492 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
6493 ioc
->name
, raid_device
->handle
,
6494 (unsigned long long) raid_device
->wwid
);
6495 list_del(&raid_device
->list
);
6498 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6500 scsi_remove_target(&starget
->dev
);
6504 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6505 * @ioc: per adapter object
6506 * @element: IR config element data
6512 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6513 Mpi2EventIrConfigElement_t
*element
)
6515 struct _sas_device
*sas_device
;
6516 struct scsi_target
*starget
= NULL
;
6517 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6518 unsigned long flags
;
6519 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6521 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6522 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6524 sas_device
->volume_handle
= 0;
6525 sas_device
->volume_wwid
= 0;
6526 clear_bit(handle
, ioc
->pd_handles
);
6527 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6528 starget
= sas_device
->starget
;
6529 sas_target_priv_data
= starget
->hostdata
;
6530 sas_target_priv_data
->flags
&=
6531 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6534 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6538 /* exposing raid component */
6540 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6542 sas_device_put(sas_device
);
6546 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6547 * @ioc: per adapter object
6548 * @element: IR config element data
6554 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6555 Mpi2EventIrConfigElement_t
*element
)
6557 struct _sas_device
*sas_device
;
6558 struct scsi_target
*starget
= NULL
;
6559 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6560 unsigned long flags
;
6561 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6562 u16 volume_handle
= 0;
6563 u64 volume_wwid
= 0;
6565 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6567 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6570 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6571 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6573 set_bit(handle
, ioc
->pd_handles
);
6574 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6575 starget
= sas_device
->starget
;
6576 sas_target_priv_data
= starget
->hostdata
;
6577 sas_target_priv_data
->flags
|=
6578 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6579 sas_device
->volume_handle
= volume_handle
;
6580 sas_device
->volume_wwid
= volume_wwid
;
6583 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6587 /* hiding raid component */
6588 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6591 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6593 sas_device_put(sas_device
);
6597 * _scsih_sas_pd_delete - delete pd component
6598 * @ioc: per adapter object
6599 * @element: IR config element data
6605 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6606 Mpi2EventIrConfigElement_t
*element
)
6608 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6610 _scsih_device_remove_by_handle(ioc
, handle
);
6614 * _scsih_sas_pd_add - remove pd component
6615 * @ioc: per adapter object
6616 * @element: IR config element data
6622 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6623 Mpi2EventIrConfigElement_t
*element
)
6625 struct _sas_device
*sas_device
;
6626 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6627 Mpi2ConfigReply_t mpi_reply
;
6628 Mpi2SasDevicePage0_t sas_device_pg0
;
6633 set_bit(handle
, ioc
->pd_handles
);
6635 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6637 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6638 sas_device_put(sas_device
);
6642 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6643 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6644 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6645 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6649 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6650 MPI2_IOCSTATUS_MASK
;
6651 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6652 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6653 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6657 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6658 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6659 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6660 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6662 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6663 _scsih_add_device(ioc
, handle
, 0, 1);
6667 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6668 * @ioc: per adapter object
6669 * @event_data: event data payload
6675 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6676 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6678 Mpi2EventIrConfigElement_t
*element
;
6681 char *reason_str
= NULL
, *element_str
= NULL
;
6683 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6685 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6686 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6687 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6688 "foreign" : "native", event_data
->NumElements
);
6689 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6690 switch (element
->ReasonCode
) {
6691 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6694 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6695 reason_str
= "remove";
6697 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6698 reason_str
= "no change";
6700 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6701 reason_str
= "hide";
6703 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6704 reason_str
= "unhide";
6706 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6707 reason_str
= "volume_created";
6709 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6710 reason_str
= "volume_deleted";
6712 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6713 reason_str
= "pd_created";
6715 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6716 reason_str
= "pd_deleted";
6719 reason_str
= "unknown reason";
6722 element_type
= le16_to_cpu(element
->ElementFlags
) &
6723 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6724 switch (element_type
) {
6725 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6726 element_str
= "volume";
6728 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6729 element_str
= "phys disk";
6731 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6732 element_str
= "hot spare";
6735 element_str
= "unknown element";
6738 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6739 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6740 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6741 le16_to_cpu(element
->PhysDiskDevHandle
),
6742 element
->PhysDiskNum
);
6747 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6748 * @ioc: per adapter object
6749 * @fw_event: The fw_event_work object
6755 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6756 struct fw_event_work
*fw_event
)
6758 Mpi2EventIrConfigElement_t
*element
;
6761 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6762 (Mpi2EventDataIrConfigChangeList_t
*)
6763 fw_event
->event_data
;
6765 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6766 (!ioc
->hide_ir_msg
))
6767 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6769 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6770 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6772 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6773 if (ioc
->shost_recovery
&&
6774 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
6775 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6776 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6777 _scsih_ir_fastpath(ioc
,
6778 le16_to_cpu(element
->PhysDiskDevHandle
),
6779 element
->PhysDiskNum
);
6784 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6786 switch (element
->ReasonCode
) {
6787 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6788 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6789 if (!foreign_config
)
6790 _scsih_sas_volume_add(ioc
, element
);
6792 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6793 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6794 if (!foreign_config
)
6795 _scsih_sas_volume_delete(ioc
,
6796 le16_to_cpu(element
->VolDevHandle
));
6798 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6799 if (!ioc
->is_warpdrive
)
6800 _scsih_sas_pd_hide(ioc
, element
);
6802 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6803 if (!ioc
->is_warpdrive
)
6804 _scsih_sas_pd_expose(ioc
, element
);
6806 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6807 if (!ioc
->is_warpdrive
)
6808 _scsih_sas_pd_add(ioc
, element
);
6810 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6811 if (!ioc
->is_warpdrive
)
6812 _scsih_sas_pd_delete(ioc
, element
);
6819 * _scsih_sas_ir_volume_event - IR volume event
6820 * @ioc: per adapter object
6821 * @fw_event: The fw_event_work object
6827 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6828 struct fw_event_work
*fw_event
)
6831 unsigned long flags
;
6832 struct _raid_device
*raid_device
;
6836 Mpi2EventDataIrVolume_t
*event_data
=
6837 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6839 if (ioc
->shost_recovery
)
6842 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6845 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6846 state
= le32_to_cpu(event_data
->NewValue
);
6847 if (!ioc
->hide_ir_msg
)
6848 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6849 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6850 ioc
->name
, __func__
, handle
,
6851 le32_to_cpu(event_data
->PreviousValue
), state
));
6853 case MPI2_RAID_VOL_STATE_MISSING
:
6854 case MPI2_RAID_VOL_STATE_FAILED
:
6855 _scsih_sas_volume_delete(ioc
, handle
);
6858 case MPI2_RAID_VOL_STATE_ONLINE
:
6859 case MPI2_RAID_VOL_STATE_DEGRADED
:
6860 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6862 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6863 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6864 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6869 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6872 "failure at %s:%d/%s()!\n", ioc
->name
,
6873 __FILE__
, __LINE__
, __func__
);
6877 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6880 "failure at %s:%d/%s()!\n", ioc
->name
,
6881 __FILE__
, __LINE__
, __func__
);
6885 raid_device
->id
= ioc
->sas_id
++;
6886 raid_device
->channel
= RAID_CHANNEL
;
6887 raid_device
->handle
= handle
;
6888 raid_device
->wwid
= wwid
;
6889 _scsih_raid_device_add(ioc
, raid_device
);
6890 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6891 raid_device
->id
, 0);
6893 _scsih_raid_device_remove(ioc
, raid_device
);
6896 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6903 * _scsih_sas_ir_physical_disk_event - PD event
6904 * @ioc: per adapter object
6905 * @fw_event: The fw_event_work object
6911 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6912 struct fw_event_work
*fw_event
)
6914 u16 handle
, parent_handle
;
6916 struct _sas_device
*sas_device
;
6917 Mpi2ConfigReply_t mpi_reply
;
6918 Mpi2SasDevicePage0_t sas_device_pg0
;
6920 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6921 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6924 if (ioc
->shost_recovery
)
6927 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6930 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6931 state
= le32_to_cpu(event_data
->NewValue
);
6933 if (!ioc
->hide_ir_msg
)
6934 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6935 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6936 ioc
->name
, __func__
, handle
,
6937 le32_to_cpu(event_data
->PreviousValue
), state
));
6940 case MPI2_RAID_PD_STATE_ONLINE
:
6941 case MPI2_RAID_PD_STATE_DEGRADED
:
6942 case MPI2_RAID_PD_STATE_REBUILDING
:
6943 case MPI2_RAID_PD_STATE_OPTIMAL
:
6944 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6946 if (!ioc
->is_warpdrive
)
6947 set_bit(handle
, ioc
->pd_handles
);
6949 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6951 sas_device_put(sas_device
);
6955 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6956 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6958 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6959 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6963 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6964 MPI2_IOCSTATUS_MASK
;
6965 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6966 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6967 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6971 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6972 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6973 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6974 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6976 _scsih_add_device(ioc
, handle
, 0, 1);
6980 case MPI2_RAID_PD_STATE_OFFLINE
:
6981 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6982 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6989 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6990 * @ioc: per adapter object
6991 * @event_data: event data payload
6997 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6998 Mpi2EventDataIrOperationStatus_t
*event_data
)
7000 char *reason_str
= NULL
;
7002 switch (event_data
->RAIDOperation
) {
7003 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
7004 reason_str
= "resync";
7006 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
7007 reason_str
= "online capacity expansion";
7009 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
7010 reason_str
= "consistency check";
7012 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
7013 reason_str
= "background init";
7015 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
7016 reason_str
= "make data consistent";
7023 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
7024 "\thandle(0x%04x), percent complete(%d)\n",
7025 ioc
->name
, reason_str
,
7026 le16_to_cpu(event_data
->VolDevHandle
),
7027 event_data
->PercentComplete
);
7031 * _scsih_sas_ir_operation_status_event - handle RAID operation events
7032 * @ioc: per adapter object
7033 * @fw_event: The fw_event_work object
7039 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
7040 struct fw_event_work
*fw_event
)
7042 Mpi2EventDataIrOperationStatus_t
*event_data
=
7043 (Mpi2EventDataIrOperationStatus_t
*)
7044 fw_event
->event_data
;
7045 static struct _raid_device
*raid_device
;
7046 unsigned long flags
;
7049 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
7050 (!ioc
->hide_ir_msg
))
7051 _scsih_sas_ir_operation_status_event_debug(ioc
,
7054 /* code added for raid transport support */
7055 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
7057 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7058 handle
= le16_to_cpu(event_data
->VolDevHandle
);
7059 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7061 raid_device
->percent_complete
=
7062 event_data
->PercentComplete
;
7063 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7068 * _scsih_prep_device_scan - initialize parameters prior to device scan
7069 * @ioc: per adapter object
7071 * Set the deleted flag prior to device scan. If the device is found during
7072 * the scan, then we clear the deleted flag.
7075 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
7077 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7078 struct scsi_device
*sdev
;
7080 shost_for_each_device(sdev
, ioc
->shost
) {
7081 sas_device_priv_data
= sdev
->hostdata
;
7082 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
7083 sas_device_priv_data
->sas_target
->deleted
= 1;
7088 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
7089 * @ioc: per adapter object
7090 * @sas_device_pg0: SAS Device page 0
7092 * After host reset, find out whether devices are still responding.
7093 * Used in _scsih_remove_unresponsive_sas_devices.
7098 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
7099 Mpi2SasDevicePage0_t
*sas_device_pg0
)
7101 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7102 struct scsi_target
*starget
;
7103 struct _sas_device
*sas_device
;
7104 unsigned long flags
;
7106 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7107 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
7108 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
7109 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
7110 sas_device
->responding
= 1;
7111 starget
= sas_device
->starget
;
7112 if (starget
&& starget
->hostdata
) {
7113 sas_target_priv_data
= starget
->hostdata
;
7114 sas_target_priv_data
->tm_busy
= 0;
7115 sas_target_priv_data
->deleted
= 0;
7117 sas_target_priv_data
= NULL
;
7119 starget_printk(KERN_INFO
, starget
,
7120 "handle(0x%04x), sas_addr(0x%016llx)\n",
7121 sas_device_pg0
->DevHandle
,
7122 (unsigned long long)
7123 sas_device
->sas_address
);
7125 if (sas_device
->enclosure_handle
!= 0)
7126 starget_printk(KERN_INFO
, starget
,
7127 "enclosure logical id(0x%016llx),"
7129 (unsigned long long)
7130 sas_device
->enclosure_logical_id
,
7133 if (sas_device_pg0
->Flags
&
7134 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
7135 sas_device
->enclosure_level
=
7136 sas_device_pg0
->EnclosureLevel
;
7137 memcpy(&sas_device
->connector_name
[0],
7138 &sas_device_pg0
->ConnectorName
[0], 4);
7140 sas_device
->enclosure_level
= 0;
7141 sas_device
->connector_name
[0] = '\0';
7144 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
7146 pr_info("\thandle changed from(0x%04x)!!!\n",
7147 sas_device
->handle
);
7148 sas_device
->handle
= sas_device_pg0
->DevHandle
;
7149 if (sas_target_priv_data
)
7150 sas_target_priv_data
->handle
=
7151 sas_device_pg0
->DevHandle
;
7156 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7160 * _scsih_search_responding_sas_devices -
7161 * @ioc: per adapter object
7163 * After host reset, find out whether devices are still responding.
7169 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7171 Mpi2SasDevicePage0_t sas_device_pg0
;
7172 Mpi2ConfigReply_t mpi_reply
;
7177 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
7179 if (list_empty(&ioc
->sas_device_list
))
7183 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7184 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7186 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7187 MPI2_IOCSTATUS_MASK
;
7188 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7190 handle
= sas_device_pg0
.DevHandle
=
7191 le16_to_cpu(sas_device_pg0
.DevHandle
);
7192 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
7193 if (!(_scsih_is_end_device(device_info
)))
7195 sas_device_pg0
.SASAddress
=
7196 le64_to_cpu(sas_device_pg0
.SASAddress
);
7197 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
7198 sas_device_pg0
.Flags
= le16_to_cpu(sas_device_pg0
.Flags
);
7199 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
7203 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
7208 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7209 * @ioc: per adapter object
7210 * @wwid: world wide identifier for raid volume
7211 * @handle: device handle
7213 * After host reset, find out whether devices are still responding.
7214 * Used in _scsih_remove_unresponsive_raid_devices.
7219 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
7222 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7223 struct scsi_target
*starget
;
7224 struct _raid_device
*raid_device
;
7225 unsigned long flags
;
7227 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7228 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
7229 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
7230 starget
= raid_device
->starget
;
7231 if (starget
&& starget
->hostdata
) {
7232 sas_target_priv_data
= starget
->hostdata
;
7233 sas_target_priv_data
->deleted
= 0;
7235 sas_target_priv_data
= NULL
;
7236 raid_device
->responding
= 1;
7237 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7238 starget_printk(KERN_INFO
, raid_device
->starget
,
7239 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
7240 (unsigned long long)raid_device
->wwid
);
7243 * WARPDRIVE: The handles of the PDs might have changed
7244 * across the host reset so re-initialize the
7245 * required data for Direct IO
7247 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
7248 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7249 if (raid_device
->handle
== handle
) {
7250 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
7254 pr_info("\thandle changed from(0x%04x)!!!\n",
7255 raid_device
->handle
);
7256 raid_device
->handle
= handle
;
7257 if (sas_target_priv_data
)
7258 sas_target_priv_data
->handle
= handle
;
7259 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7263 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7267 * _scsih_search_responding_raid_devices -
7268 * @ioc: per adapter object
7270 * After host reset, find out whether devices are still responding.
7276 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
7278 Mpi2RaidVolPage1_t volume_pg1
;
7279 Mpi2RaidVolPage0_t volume_pg0
;
7280 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7281 Mpi2ConfigReply_t mpi_reply
;
7286 if (!ioc
->ir_firmware
)
7289 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
7292 if (list_empty(&ioc
->raid_device_list
))
7296 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7297 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7298 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7299 MPI2_IOCSTATUS_MASK
;
7300 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7302 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7304 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7305 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7306 sizeof(Mpi2RaidVolPage0_t
)))
7309 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7310 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7311 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
7312 _scsih_mark_responding_raid_device(ioc
,
7313 le64_to_cpu(volume_pg1
.WWID
), handle
);
7316 /* refresh the pd_handles */
7317 if (!ioc
->is_warpdrive
) {
7318 phys_disk_num
= 0xFF;
7319 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
7320 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7321 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7323 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7324 MPI2_IOCSTATUS_MASK
;
7325 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7327 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7328 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7329 set_bit(handle
, ioc
->pd_handles
);
7333 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
7338 * _scsih_mark_responding_expander - mark a expander as responding
7339 * @ioc: per adapter object
7340 * @sas_address: sas address
7343 * After host reset, find out whether devices are still responding.
7344 * Used in _scsih_remove_unresponsive_expanders.
7349 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
7352 struct _sas_node
*sas_expander
;
7353 unsigned long flags
;
7356 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7357 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
7358 if (sas_expander
->sas_address
!= sas_address
)
7360 sas_expander
->responding
= 1;
7361 if (sas_expander
->handle
== handle
)
7363 pr_info("\texpander(0x%016llx): handle changed" \
7364 " from(0x%04x) to (0x%04x)!!!\n",
7365 (unsigned long long)sas_expander
->sas_address
,
7366 sas_expander
->handle
, handle
);
7367 sas_expander
->handle
= handle
;
7368 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
7369 sas_expander
->phy
[i
].handle
= handle
;
7373 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7377 * _scsih_search_responding_expanders -
7378 * @ioc: per adapter object
7380 * After host reset, find out whether devices are still responding.
7386 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
7388 Mpi2ExpanderPage0_t expander_pg0
;
7389 Mpi2ConfigReply_t mpi_reply
;
7394 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
7396 if (list_empty(&ioc
->sas_expander_list
))
7400 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7401 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7403 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7404 MPI2_IOCSTATUS_MASK
;
7405 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7408 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7409 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7410 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7412 (unsigned long long)sas_address
);
7413 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7417 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
7421 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7422 * @ioc: per adapter object
7427 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7429 struct _sas_device
*sas_device
, *sas_device_next
;
7430 struct _sas_node
*sas_expander
, *sas_expander_next
;
7431 struct _raid_device
*raid_device
, *raid_device_next
;
7432 struct list_head tmp_list
;
7433 unsigned long flags
;
7436 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
7439 /* removing unresponding end devices */
7440 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
7443 * Iterate, pulling off devices marked as non-responding. We become the
7444 * owner for the reference the list had on any object we prune.
7446 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7447 list_for_each_entry_safe(sas_device
, sas_device_next
,
7448 &ioc
->sas_device_list
, list
) {
7449 if (!sas_device
->responding
)
7450 list_move_tail(&sas_device
->list
, &head
);
7452 sas_device
->responding
= 0;
7454 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7457 * Now, uninitialize and remove the unresponding devices we pruned.
7459 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
7460 _scsih_remove_device(ioc
, sas_device
);
7461 list_del_init(&sas_device
->list
);
7462 sas_device_put(sas_device
);
7465 /* removing unresponding volumes */
7466 if (ioc
->ir_firmware
) {
7467 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
7469 list_for_each_entry_safe(raid_device
, raid_device_next
,
7470 &ioc
->raid_device_list
, list
) {
7471 if (!raid_device
->responding
)
7472 _scsih_sas_volume_delete(ioc
,
7473 raid_device
->handle
);
7475 raid_device
->responding
= 0;
7479 /* removing unresponding expanders */
7480 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
7482 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7483 INIT_LIST_HEAD(&tmp_list
);
7484 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7485 &ioc
->sas_expander_list
, list
) {
7486 if (!sas_expander
->responding
)
7487 list_move_tail(&sas_expander
->list
, &tmp_list
);
7489 sas_expander
->responding
= 0;
7491 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7492 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7494 list_del(&sas_expander
->list
);
7495 _scsih_expander_node_remove(ioc
, sas_expander
);
7498 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
7501 /* unblock devices */
7502 _scsih_ublock_io_all_device(ioc
);
7506 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
7507 struct _sas_node
*sas_expander
, u16 handle
)
7509 Mpi2ExpanderPage1_t expander_pg1
;
7510 Mpi2ConfigReply_t mpi_reply
;
7513 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7514 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7515 &expander_pg1
, i
, handle
))) {
7516 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7517 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7521 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7522 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7523 expander_pg1
.NegotiatedLinkRate
>> 4);
7528 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7529 * @ioc: per adapter object
7534 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
7536 Mpi2ExpanderPage0_t expander_pg0
;
7537 Mpi2SasDevicePage0_t sas_device_pg0
;
7538 Mpi2RaidVolPage1_t volume_pg1
;
7539 Mpi2RaidVolPage0_t volume_pg0
;
7540 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7541 Mpi2EventIrConfigElement_t element
;
7542 Mpi2ConfigReply_t mpi_reply
;
7545 u16 handle
, parent_handle
;
7547 struct _sas_device
*sas_device
;
7548 struct _sas_node
*expander_device
;
7549 static struct _raid_device
*raid_device
;
7551 unsigned long flags
;
7553 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7555 _scsih_sas_host_refresh(ioc
);
7557 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7561 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7562 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7563 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7564 MPI2_IOCSTATUS_MASK
;
7565 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7566 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7567 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7568 ioc
->name
, ioc_status
,
7569 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7572 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7573 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7574 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7575 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7576 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7577 if (expander_device
)
7578 _scsih_refresh_expander_links(ioc
, expander_device
,
7581 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7582 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7583 handle
, (unsigned long long)
7584 le64_to_cpu(expander_pg0
.SASAddress
));
7585 _scsih_expander_add(ioc
, handle
);
7586 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7587 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7588 handle
, (unsigned long long)
7589 le64_to_cpu(expander_pg0
.SASAddress
));
7593 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7596 if (!ioc
->ir_firmware
)
7599 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7602 phys_disk_num
= 0xFF;
7603 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7604 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7606 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7607 MPI2_IOCSTATUS_MASK
;
7608 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7609 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7610 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7611 ioc
->name
, ioc_status
,
7612 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7615 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7616 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7617 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7619 sas_device_put(sas_device
);
7622 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7623 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7626 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7627 MPI2_IOCSTATUS_MASK
;
7628 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7629 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7630 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7631 ioc
->name
, ioc_status
,
7632 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7635 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7636 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7638 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7639 " handle (0x%04x), sas_addr(0x%016llx)\n",
7640 ioc
->name
, handle
, (unsigned long long)
7641 le64_to_cpu(sas_device_pg0
.SASAddress
));
7642 mpt3sas_transport_update_links(ioc
, sas_address
,
7643 handle
, sas_device_pg0
.PhyNum
,
7644 MPI2_SAS_NEG_LINK_RATE_1_5
);
7645 set_bit(handle
, ioc
->pd_handles
);
7647 /* This will retry adding the end device.
7648 * _scsih_add_device() will decide on retries and
7649 * return "1" when it should be retried
7651 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7655 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7656 " handle (0x%04x), sas_addr(0x%016llx)\n",
7657 ioc
->name
, handle
, (unsigned long long)
7658 le64_to_cpu(sas_device_pg0
.SASAddress
));
7662 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7665 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7669 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7670 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7671 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7672 MPI2_IOCSTATUS_MASK
;
7673 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7674 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7675 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7676 ioc
->name
, ioc_status
,
7677 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7680 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7681 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7682 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7683 le64_to_cpu(volume_pg1
.WWID
));
7684 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7687 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7688 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7689 sizeof(Mpi2RaidVolPage0_t
)))
7691 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7692 MPI2_IOCSTATUS_MASK
;
7693 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7694 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7695 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7696 ioc
->name
, ioc_status
,
7697 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7700 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7701 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7702 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7703 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7704 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7705 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7707 "\tBEFORE adding volume: handle (0x%04x)\n",
7708 ioc
->name
, volume_pg1
.DevHandle
);
7709 _scsih_sas_volume_add(ioc
, &element
);
7711 "\tAFTER adding volume: handle (0x%04x)\n",
7712 ioc
->name
, volume_pg1
.DevHandle
);
7716 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7721 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7726 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7727 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7729 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7730 MPI2_IOCSTATUS_MASK
;
7731 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7732 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7733 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7734 ioc
->name
, ioc_status
,
7735 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7738 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7739 if (!(_scsih_is_end_device(
7740 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7742 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
7743 le64_to_cpu(sas_device_pg0
.SASAddress
));
7745 sas_device_put(sas_device
);
7748 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7749 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7750 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7751 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7752 handle
, (unsigned long long)
7753 le64_to_cpu(sas_device_pg0
.SASAddress
));
7754 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7755 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7757 /* This will retry adding the end device.
7758 * _scsih_add_device() will decide on retries and
7759 * return "1" when it should be retried
7761 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7765 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7766 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7767 handle
, (unsigned long long)
7768 le64_to_cpu(sas_device_pg0
.SASAddress
));
7771 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7774 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7777 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7778 * @ioc: per adapter object
7779 * @reset_phase: phase
7781 * The handler for doing any required cleanup or initialization.
7783 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7784 * MPT3_IOC_DONE_RESET
7789 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7791 switch (reset_phase
) {
7792 case MPT3_IOC_PRE_RESET
:
7793 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7794 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7796 case MPT3_IOC_AFTER_RESET
:
7797 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7798 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7799 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7800 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7801 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7802 complete(&ioc
->scsih_cmds
.done
);
7804 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7805 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7806 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7807 complete(&ioc
->tm_cmds
.done
);
7810 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
7811 memset(ioc
->device_remove_in_progress
, 0,
7812 ioc
->device_remove_in_progress_sz
);
7813 _scsih_fw_event_cleanup_queue(ioc
);
7814 _scsih_flush_running_cmds(ioc
);
7816 case MPT3_IOC_DONE_RESET
:
7817 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7818 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7819 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7820 !ioc
->sas_hba
.num_phys
)) {
7821 _scsih_prep_device_scan(ioc
);
7822 _scsih_search_responding_sas_devices(ioc
);
7823 _scsih_search_responding_raid_devices(ioc
);
7824 _scsih_search_responding_expanders(ioc
);
7825 _scsih_error_recovery_delete_devices(ioc
);
7832 * _mpt3sas_fw_work - delayed task for processing firmware events
7833 * @ioc: per adapter object
7834 * @fw_event: The fw_event_work object
7840 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7842 _scsih_fw_event_del_from_list(ioc
, fw_event
);
7844 /* the queue is being flushed so ignore this event */
7845 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
7846 fw_event_work_put(fw_event
);
7850 switch (fw_event
->event
) {
7851 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7852 mpt3sas_process_trigger_data(ioc
,
7853 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7854 fw_event
->event_data
);
7856 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7857 while (scsi_host_in_recovery(ioc
->shost
) ||
7858 ioc
->shost_recovery
) {
7860 * If we're unloading, bail. Otherwise, this can become
7863 if (ioc
->remove_host
)
7867 _scsih_remove_unresponding_sas_devices(ioc
);
7868 _scsih_scan_for_devices_after_reset(ioc
);
7870 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7871 ioc
->start_scan
= 0;
7872 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7873 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7875 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7876 "port enable: complete from worker thread\n",
7879 case MPT3SAS_TURN_ON_PFA_LED
:
7880 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7882 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7883 _scsih_sas_topology_change_event(ioc
, fw_event
);
7885 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7886 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7888 case MPI2_EVENT_SAS_DISCOVERY
:
7889 _scsih_sas_discovery_event(ioc
, fw_event
);
7891 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7892 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7894 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7895 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7898 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7899 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7901 case MPI2_EVENT_IR_VOLUME
:
7902 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7904 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7905 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7907 case MPI2_EVENT_IR_OPERATION_STATUS
:
7908 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7912 fw_event_work_put(fw_event
);
7916 * _firmware_event_work
7917 * @ioc: per adapter object
7918 * @work: The fw_event_work object
7921 * wrappers for the work thread handling firmware events
7927 _firmware_event_work(struct work_struct
*work
)
7929 struct fw_event_work
*fw_event
= container_of(work
,
7930 struct fw_event_work
, work
);
7932 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7936 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7937 * @ioc: per adapter object
7938 * @msix_index: MSIX table index supplied by the OS
7939 * @reply: reply message frame(lower 32bit addr)
7940 * Context: interrupt.
7942 * This function merely adds a new work task into ioc->firmware_event_thread.
7943 * The tasks are worked from _firmware_event_work in user context.
7945 * Return 1 meaning mf should be freed from _base_interrupt
7946 * 0 means the mf is freed from this function.
7949 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7952 struct fw_event_work
*fw_event
;
7953 Mpi2EventNotificationReply_t
*mpi_reply
;
7956 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
7958 /* events turned off due to host reset or driver unloading */
7959 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7962 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7964 if (unlikely(!mpi_reply
)) {
7965 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7966 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7970 event
= le16_to_cpu(mpi_reply
->Event
);
7972 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7973 mpt3sas_trigger_event(ioc
, event
, 0);
7977 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7979 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7980 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7981 mpi_reply
->EventData
;
7983 if (baen_data
->Primitive
!=
7984 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7987 if (ioc
->broadcast_aen_busy
) {
7988 ioc
->broadcast_aen_pending
++;
7991 ioc
->broadcast_aen_busy
= 1;
7995 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7996 _scsih_check_topo_delete_events(ioc
,
7997 (Mpi2EventDataSasTopologyChangeList_t
*)
7998 mpi_reply
->EventData
);
8000 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
8001 _scsih_check_ir_config_unhide_events(ioc
,
8002 (Mpi2EventDataIrConfigChangeList_t
*)
8003 mpi_reply
->EventData
);
8005 case MPI2_EVENT_IR_VOLUME
:
8006 _scsih_check_volume_delete_events(ioc
,
8007 (Mpi2EventDataIrVolume_t
*)
8008 mpi_reply
->EventData
);
8010 case MPI2_EVENT_LOG_ENTRY_ADDED
:
8012 Mpi2EventDataLogEntryAdded_t
*log_entry
;
8015 if (!ioc
->is_warpdrive
)
8018 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
8019 mpi_reply
->EventData
;
8020 log_code
= (u32
*)log_entry
->LogData
;
8022 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
8023 != MPT2_WARPDRIVE_LOGENTRY
)
8026 switch (le32_to_cpu(*log_code
)) {
8027 case MPT2_WARPDRIVE_LC_SSDT
:
8028 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
8029 "IO Throttling has occurred in the WarpDrive "
8030 "subsystem. Check WarpDrive documentation for "
8031 "additional details.\n", ioc
->name
);
8033 case MPT2_WARPDRIVE_LC_SSDLW
:
8034 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
8035 "Program/Erase Cycles for the WarpDrive subsystem "
8036 "in degraded range. Check WarpDrive documentation "
8037 "for additional details.\n", ioc
->name
);
8039 case MPT2_WARPDRIVE_LC_SSDLF
:
8040 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
8041 "There are no Program/Erase Cycles for the "
8042 "WarpDrive subsystem. The storage device will be "
8043 "in read-only mode. Check WarpDrive documentation "
8044 "for additional details.\n", ioc
->name
);
8046 case MPT2_WARPDRIVE_LC_BRMF
:
8047 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
8048 "The Backup Rail Monitor has failed on the "
8049 "WarpDrive subsystem. Check WarpDrive "
8050 "documentation for additional details.\n",
8057 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
8058 case MPI2_EVENT_IR_OPERATION_STATUS
:
8059 case MPI2_EVENT_SAS_DISCOVERY
:
8060 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
8061 case MPI2_EVENT_IR_PHYSICAL_DISK
:
8064 case MPI2_EVENT_TEMP_THRESHOLD
:
8065 _scsih_temp_threshold_events(ioc
,
8066 (Mpi2EventDataTemperature_t
*)
8067 mpi_reply
->EventData
);
8069 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
8070 ActiveCableEventData
=
8071 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
8072 switch (ActiveCableEventData
->ReasonCode
) {
8073 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
8074 pr_notice(MPT3SAS_FMT
"Receptacle ID %d: This active cable"
8075 " requires %d mW of power\n", ioc
->name
,
8076 ActiveCableEventData
->ReceptacleID
,
8077 ActiveCableEventData
->ActiveCablePowerRequirement
);
8078 pr_notice(MPT3SAS_FMT
"Receptacle ID %d: Devices connected"
8079 " to this active cable will not be seen\n",
8080 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
8083 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
8084 pr_notice(MPT3SAS_FMT
"ReceptacleID %d: This cable",
8085 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
8086 pr_notice(" is not running at an optimal speed(12 Gb/s)\n");
8092 default: /* ignore the rest */
8096 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
8097 fw_event
= alloc_fw_event_work(sz
);
8099 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8100 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8104 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
8105 fw_event
->ioc
= ioc
;
8106 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
8107 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
8108 fw_event
->event
= event
;
8109 _scsih_fw_event_add(ioc
, fw_event
);
8110 fw_event_work_put(fw_event
);
8115 * _scsih_expander_node_remove - removing expander device from list.
8116 * @ioc: per adapter object
8117 * @sas_expander: the sas_device object
8118 * Context: Calling function should acquire ioc->sas_node_lock.
8120 * Removing object and freeing associated memory from the
8121 * ioc->sas_expander_list.
8126 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
8127 struct _sas_node
*sas_expander
)
8129 struct _sas_port
*mpt3sas_port
, *next
;
8131 /* remove sibling ports attached to this expander */
8132 list_for_each_entry_safe(mpt3sas_port
, next
,
8133 &sas_expander
->sas_port_list
, port_list
) {
8134 if (ioc
->shost_recovery
)
8136 if (mpt3sas_port
->remote_identify
.device_type
==
8138 mpt3sas_device_remove_by_sas_address(ioc
,
8139 mpt3sas_port
->remote_identify
.sas_address
);
8140 else if (mpt3sas_port
->remote_identify
.device_type
==
8141 SAS_EDGE_EXPANDER_DEVICE
||
8142 mpt3sas_port
->remote_identify
.device_type
==
8143 SAS_FANOUT_EXPANDER_DEVICE
)
8144 mpt3sas_expander_remove(ioc
,
8145 mpt3sas_port
->remote_identify
.sas_address
);
8148 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
8149 sas_expander
->sas_address_parent
);
8152 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8154 sas_expander
->handle
, (unsigned long long)
8155 sas_expander
->sas_address
);
8157 kfree(sas_expander
->phy
);
8158 kfree(sas_expander
);
8162 * _scsih_ir_shutdown - IR shutdown notification
8163 * @ioc: per adapter object
8165 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8166 * the host system is shutting down.
8171 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
8173 Mpi2RaidActionRequest_t
*mpi_request
;
8174 Mpi2RaidActionReply_t
*mpi_reply
;
8177 /* is IR firmware build loaded ? */
8178 if (!ioc
->ir_firmware
)
8181 /* are there any volumes ? */
8182 if (list_empty(&ioc
->raid_device_list
))
8185 mutex_lock(&ioc
->scsih_cmds
.mutex
);
8187 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
8188 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
8189 ioc
->name
, __func__
);
8192 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
8194 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
8196 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
8197 ioc
->name
, __func__
);
8198 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8202 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
8203 ioc
->scsih_cmds
.smid
= smid
;
8204 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
8206 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
8207 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
8209 if (!ioc
->hide_ir_msg
)
8210 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
8211 init_completion(&ioc
->scsih_cmds
.done
);
8212 ioc
->put_smid_default(ioc
, smid
);
8213 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
8215 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
8216 pr_err(MPT3SAS_FMT
"%s: timeout\n",
8217 ioc
->name
, __func__
);
8221 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
8222 mpi_reply
= ioc
->scsih_cmds
.reply
;
8223 if (!ioc
->hide_ir_msg
)
8224 pr_info(MPT3SAS_FMT
"IR shutdown "
8225 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8226 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
8227 le32_to_cpu(mpi_reply
->IOCLogInfo
));
8231 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8232 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
8236 * scsih_remove - detach and remove add host
8237 * @pdev: PCI device struct
8239 * Routine called when unloading the driver.
8242 static void scsih_remove(struct pci_dev
*pdev
)
8244 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8245 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8246 struct _sas_port
*mpt3sas_port
, *next_port
;
8247 struct _raid_device
*raid_device
, *next
;
8248 struct MPT3SAS_TARGET
*sas_target_priv_data
;
8249 struct workqueue_struct
*wq
;
8250 unsigned long flags
;
8252 ioc
->remove_host
= 1;
8253 _scsih_fw_event_cleanup_queue(ioc
);
8255 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8256 wq
= ioc
->firmware_event_thread
;
8257 ioc
->firmware_event_thread
= NULL
;
8258 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8260 destroy_workqueue(wq
);
8262 /* release all the volumes */
8263 _scsih_ir_shutdown(ioc
);
8264 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
8266 if (raid_device
->starget
) {
8267 sas_target_priv_data
=
8268 raid_device
->starget
->hostdata
;
8269 sas_target_priv_data
->deleted
= 1;
8270 scsi_remove_target(&raid_device
->starget
->dev
);
8272 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
8273 ioc
->name
, raid_device
->handle
,
8274 (unsigned long long) raid_device
->wwid
);
8275 _scsih_raid_device_remove(ioc
, raid_device
);
8278 /* free ports attached to the sas_host */
8279 list_for_each_entry_safe(mpt3sas_port
, next_port
,
8280 &ioc
->sas_hba
.sas_port_list
, port_list
) {
8281 if (mpt3sas_port
->remote_identify
.device_type
==
8283 mpt3sas_device_remove_by_sas_address(ioc
,
8284 mpt3sas_port
->remote_identify
.sas_address
);
8285 else if (mpt3sas_port
->remote_identify
.device_type
==
8286 SAS_EDGE_EXPANDER_DEVICE
||
8287 mpt3sas_port
->remote_identify
.device_type
==
8288 SAS_FANOUT_EXPANDER_DEVICE
)
8289 mpt3sas_expander_remove(ioc
,
8290 mpt3sas_port
->remote_identify
.sas_address
);
8293 /* free phys attached to the sas_host */
8294 if (ioc
->sas_hba
.num_phys
) {
8295 kfree(ioc
->sas_hba
.phy
);
8296 ioc
->sas_hba
.phy
= NULL
;
8297 ioc
->sas_hba
.num_phys
= 0;
8300 sas_remove_host(shost
);
8301 scsi_remove_host(shost
);
8302 mpt3sas_base_detach(ioc
);
8303 spin_lock(&gioc_lock
);
8304 list_del(&ioc
->list
);
8305 spin_unlock(&gioc_lock
);
8306 scsi_host_put(shost
);
8310 * scsih_shutdown - routine call during system shutdown
8311 * @pdev: PCI device struct
8316 scsih_shutdown(struct pci_dev
*pdev
)
8318 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8319 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8320 struct workqueue_struct
*wq
;
8321 unsigned long flags
;
8323 ioc
->remove_host
= 1;
8324 _scsih_fw_event_cleanup_queue(ioc
);
8326 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8327 wq
= ioc
->firmware_event_thread
;
8328 ioc
->firmware_event_thread
= NULL
;
8329 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8331 destroy_workqueue(wq
);
8333 _scsih_ir_shutdown(ioc
);
8334 mpt3sas_base_detach(ioc
);
8339 * _scsih_probe_boot_devices - reports 1st device
8340 * @ioc: per adapter object
8342 * If specified in bios page 2, this routine reports the 1st
8343 * device scsi-ml or sas transport for persistent boot device
8344 * purposes. Please refer to function _scsih_determine_boot_device()
8347 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
8351 struct _sas_device
*sas_device
;
8352 struct _raid_device
*raid_device
;
8354 u64 sas_address_parent
;
8356 unsigned long flags
;
8359 /* no Bios, return immediately */
8360 if (!ioc
->bios_pg3
.BiosVersion
)
8365 if (ioc
->req_boot_device
.device
) {
8366 device
= ioc
->req_boot_device
.device
;
8367 is_raid
= ioc
->req_boot_device
.is_raid
;
8368 } else if (ioc
->req_alt_boot_device
.device
) {
8369 device
= ioc
->req_alt_boot_device
.device
;
8370 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
8371 } else if (ioc
->current_boot_device
.device
) {
8372 device
= ioc
->current_boot_device
.device
;
8373 is_raid
= ioc
->current_boot_device
.is_raid
;
8380 raid_device
= device
;
8381 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8382 raid_device
->id
, 0);
8384 _scsih_raid_device_remove(ioc
, raid_device
);
8386 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8387 sas_device
= device
;
8388 handle
= sas_device
->handle
;
8389 sas_address_parent
= sas_device
->sas_address_parent
;
8390 sas_address
= sas_device
->sas_address
;
8391 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8392 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8394 if (ioc
->hide_drives
)
8396 if (!mpt3sas_transport_port_add(ioc
, handle
,
8397 sas_address_parent
)) {
8398 _scsih_sas_device_remove(ioc
, sas_device
);
8399 } else if (!sas_device
->starget
) {
8400 if (!ioc
->is_driver_loading
) {
8401 mpt3sas_transport_port_remove(ioc
,
8403 sas_address_parent
);
8404 _scsih_sas_device_remove(ioc
, sas_device
);
8411 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8412 * @ioc: per adapter object
8414 * Called during initial loading of the driver.
8417 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
8419 struct _raid_device
*raid_device
, *raid_next
;
8422 list_for_each_entry_safe(raid_device
, raid_next
,
8423 &ioc
->raid_device_list
, list
) {
8424 if (raid_device
->starget
)
8426 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8427 raid_device
->id
, 0);
8429 _scsih_raid_device_remove(ioc
, raid_device
);
8433 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
8435 struct _sas_device
*sas_device
= NULL
;
8436 unsigned long flags
;
8438 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8439 if (!list_empty(&ioc
->sas_device_init_list
)) {
8440 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
8441 struct _sas_device
, list
);
8442 sas_device_get(sas_device
);
8444 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8449 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
8450 struct _sas_device
*sas_device
)
8452 unsigned long flags
;
8454 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8457 * Since we dropped the lock during the call to port_add(), we need to
8458 * be careful here that somebody else didn't move or delete this item
8459 * while we were busy with other things.
8461 * If it was on the list, we need a put() for the reference the list
8462 * had. Either way, we need a get() for the destination list.
8464 if (!list_empty(&sas_device
->list
)) {
8465 list_del_init(&sas_device
->list
);
8466 sas_device_put(sas_device
);
8469 sas_device_get(sas_device
);
8470 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8472 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8476 * _scsih_probe_sas - reporting sas devices to sas transport
8477 * @ioc: per adapter object
8479 * Called during initial loading of the driver.
8482 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
8484 struct _sas_device
*sas_device
;
8486 if (ioc
->hide_drives
)
8489 while ((sas_device
= get_next_sas_device(ioc
))) {
8490 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
8491 sas_device
->sas_address_parent
)) {
8492 _scsih_sas_device_remove(ioc
, sas_device
);
8493 sas_device_put(sas_device
);
8495 } else if (!sas_device
->starget
) {
8497 * When asyn scanning is enabled, its not possible to
8498 * remove devices while scanning is turned on due to an
8499 * oops in scsi_sysfs_add_sdev()->add_device()->
8500 * sysfs_addrm_start()
8502 if (!ioc
->is_driver_loading
) {
8503 mpt3sas_transport_port_remove(ioc
,
8504 sas_device
->sas_address
,
8505 sas_device
->sas_address_parent
);
8506 _scsih_sas_device_remove(ioc
, sas_device
);
8507 sas_device_put(sas_device
);
8511 sas_device_make_active(ioc
, sas_device
);
8512 sas_device_put(sas_device
);
8517 * _scsih_probe_devices - probing for devices
8518 * @ioc: per adapter object
8520 * Called during initial loading of the driver.
8523 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
8525 u16 volume_mapping_flags
;
8527 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8528 return; /* return when IOC doesn't support initiator mode */
8530 _scsih_probe_boot_devices(ioc
);
8532 if (ioc
->ir_firmware
) {
8533 volume_mapping_flags
=
8534 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8535 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8536 if (volume_mapping_flags
==
8537 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8538 _scsih_probe_raid(ioc
);
8539 _scsih_probe_sas(ioc
);
8541 _scsih_probe_sas(ioc
);
8542 _scsih_probe_raid(ioc
);
8545 _scsih_probe_sas(ioc
);
8549 * scsih_scan_start - scsi lld callback for .scan_start
8550 * @shost: SCSI host pointer
8552 * The shost has the ability to discover targets on its own instead
8553 * of scanning the entire bus. In our implemention, we will kick off
8554 * firmware discovery.
8557 scsih_scan_start(struct Scsi_Host
*shost
)
8559 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8561 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8562 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8564 if (disable_discovery
> 0)
8567 ioc
->start_scan
= 1;
8568 rc
= mpt3sas_port_enable(ioc
);
8571 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
8575 * scsih_scan_finished - scsi lld callback for .scan_finished
8576 * @shost: SCSI host pointer
8577 * @time: elapsed time of the scan in jiffies
8579 * This function will be called periodicallyn until it returns 1 with the
8580 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8581 * we wait for firmware discovery to complete, then return 1.
8584 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8586 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8588 if (disable_discovery
> 0) {
8589 ioc
->is_driver_loading
= 0;
8590 ioc
->wait_for_discovery_to_complete
= 0;
8594 if (time
>= (300 * HZ
)) {
8595 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8597 "port enable: FAILED with timeout (timeout=300s)\n",
8599 ioc
->is_driver_loading
= 0;
8603 if (ioc
->start_scan
)
8606 if (ioc
->start_scan_failed
) {
8608 "port enable: FAILED with (ioc_status=0x%08x)\n",
8609 ioc
->name
, ioc
->start_scan_failed
);
8610 ioc
->is_driver_loading
= 0;
8611 ioc
->wait_for_discovery_to_complete
= 0;
8612 ioc
->remove_host
= 1;
8616 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
8617 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8619 if (ioc
->wait_for_discovery_to_complete
) {
8620 ioc
->wait_for_discovery_to_complete
= 0;
8621 _scsih_probe_devices(ioc
);
8623 mpt3sas_base_start_watchdog(ioc
);
8624 ioc
->is_driver_loading
= 0;
8628 /* shost template for SAS 2.0 HBA devices */
8629 static struct scsi_host_template mpt2sas_driver_template
= {
8630 .module
= THIS_MODULE
,
8631 .name
= "Fusion MPT SAS Host",
8632 .proc_name
= MPT2SAS_DRIVER_NAME
,
8633 .queuecommand
= scsih_qcmd
,
8634 .target_alloc
= scsih_target_alloc
,
8635 .slave_alloc
= scsih_slave_alloc
,
8636 .slave_configure
= scsih_slave_configure
,
8637 .target_destroy
= scsih_target_destroy
,
8638 .slave_destroy
= scsih_slave_destroy
,
8639 .scan_finished
= scsih_scan_finished
,
8640 .scan_start
= scsih_scan_start
,
8641 .change_queue_depth
= scsih_change_queue_depth
,
8642 .eh_abort_handler
= scsih_abort
,
8643 .eh_device_reset_handler
= scsih_dev_reset
,
8644 .eh_target_reset_handler
= scsih_target_reset
,
8645 .eh_host_reset_handler
= scsih_host_reset
,
8646 .bios_param
= scsih_bios_param
,
8649 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
8650 .max_sectors
= 32767,
8652 .use_clustering
= ENABLE_CLUSTERING
,
8653 .shost_attrs
= mpt3sas_host_attrs
,
8654 .sdev_attrs
= mpt3sas_dev_attrs
,
8655 .track_queue_depth
= 1,
8658 /* raid transport support for SAS 2.0 HBA devices */
8659 static struct raid_function_template mpt2sas_raid_functions
= {
8660 .cookie
= &mpt2sas_driver_template
,
8661 .is_raid
= scsih_is_raid
,
8662 .get_resync
= scsih_get_resync
,
8663 .get_state
= scsih_get_state
,
8666 /* shost template for SAS 3.0 HBA devices */
8667 static struct scsi_host_template mpt3sas_driver_template
= {
8668 .module
= THIS_MODULE
,
8669 .name
= "Fusion MPT SAS Host",
8670 .proc_name
= MPT3SAS_DRIVER_NAME
,
8671 .queuecommand
= scsih_qcmd
,
8672 .target_alloc
= scsih_target_alloc
,
8673 .slave_alloc
= scsih_slave_alloc
,
8674 .slave_configure
= scsih_slave_configure
,
8675 .target_destroy
= scsih_target_destroy
,
8676 .slave_destroy
= scsih_slave_destroy
,
8677 .scan_finished
= scsih_scan_finished
,
8678 .scan_start
= scsih_scan_start
,
8679 .change_queue_depth
= scsih_change_queue_depth
,
8680 .eh_abort_handler
= scsih_abort
,
8681 .eh_device_reset_handler
= scsih_dev_reset
,
8682 .eh_target_reset_handler
= scsih_target_reset
,
8683 .eh_host_reset_handler
= scsih_host_reset
,
8684 .bios_param
= scsih_bios_param
,
8687 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
8688 .max_sectors
= 32767,
8690 .use_clustering
= ENABLE_CLUSTERING
,
8691 .shost_attrs
= mpt3sas_host_attrs
,
8692 .sdev_attrs
= mpt3sas_dev_attrs
,
8693 .track_queue_depth
= 1,
8696 /* raid transport support for SAS 3.0 HBA devices */
8697 static struct raid_function_template mpt3sas_raid_functions
= {
8698 .cookie
= &mpt3sas_driver_template
,
8699 .is_raid
= scsih_is_raid
,
8700 .get_resync
= scsih_get_resync
,
8701 .get_state
= scsih_get_state
,
8705 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8706 * this device belongs to.
8707 * @pdev: PCI device struct
8709 * return MPI2_VERSION for SAS 2.0 HBA devices,
8710 * MPI25_VERSION for SAS 3.0 HBA devices, and
8711 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8714 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
8717 switch (pdev
->device
) {
8718 case MPI2_MFGPAGE_DEVID_SSS6200
:
8719 case MPI2_MFGPAGE_DEVID_SAS2004
:
8720 case MPI2_MFGPAGE_DEVID_SAS2008
:
8721 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
8722 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
8723 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
8724 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
8725 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
8726 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
8727 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
8728 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
8729 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
8730 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
8731 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
8732 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
8733 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
8734 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
8735 return MPI2_VERSION
;
8736 case MPI25_MFGPAGE_DEVID_SAS3004
:
8737 case MPI25_MFGPAGE_DEVID_SAS3008
:
8738 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
8739 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
8740 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
8741 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
8742 return MPI25_VERSION
;
8743 case MPI26_MFGPAGE_DEVID_SAS3216
:
8744 case MPI26_MFGPAGE_DEVID_SAS3224
:
8745 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
8746 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
8747 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
8748 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
8749 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
8750 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
8751 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
8752 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
8753 case MPI26_MFGPAGE_DEVID_SAS3508
:
8754 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
8755 case MPI26_MFGPAGE_DEVID_SAS3408
:
8756 case MPI26_MFGPAGE_DEVID_SAS3516
:
8757 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
8758 case MPI26_MFGPAGE_DEVID_SAS3416
:
8759 return MPI26_VERSION
;
8765 * _scsih_probe - attach and add scsi host
8766 * @pdev: PCI device struct
8767 * @id: pci device id
8769 * Returns 0 success, anything else error.
8772 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8774 struct MPT3SAS_ADAPTER
*ioc
;
8775 struct Scsi_Host
*shost
= NULL
;
8777 u16 hba_mpi_version
;
8779 /* Determine in which MPI version class this pci device belongs */
8780 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
8781 if (hba_mpi_version
== 0)
8784 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8785 * for other generation HBA's return with -ENODEV
8787 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
8790 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8791 * for other generation HBA's return with -ENODEV
8793 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
8794 || hba_mpi_version
== MPI26_VERSION
)))
8797 switch (hba_mpi_version
) {
8799 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
8800 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
8801 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8802 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
8803 sizeof(struct MPT3SAS_ADAPTER
));
8806 ioc
= shost_priv(shost
);
8807 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8808 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8809 ioc
->id
= mpt2_ids
++;
8810 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
8811 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8812 ioc
->is_warpdrive
= 1;
8813 ioc
->hide_ir_msg
= 1;
8815 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8819 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8820 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
8821 sizeof(struct MPT3SAS_ADAPTER
));
8824 ioc
= shost_priv(shost
);
8825 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8826 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8827 ioc
->id
= mpt3_ids
++;
8828 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
8829 switch (pdev
->device
) {
8830 case MPI26_MFGPAGE_DEVID_SAS3508
:
8831 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
8832 case MPI26_MFGPAGE_DEVID_SAS3408
:
8833 case MPI26_MFGPAGE_DEVID_SAS3516
:
8834 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
8835 case MPI26_MFGPAGE_DEVID_SAS3416
:
8836 ioc
->is_gen35_ioc
= 1;
8839 ioc
->is_gen35_ioc
= 0;
8841 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
8842 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
8843 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
8844 ioc
->combined_reply_queue
= 1;
8845 if (ioc
->is_gen35_ioc
)
8846 ioc
->combined_reply_index_count
=
8847 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
8849 ioc
->combined_reply_index_count
=
8850 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
8857 INIT_LIST_HEAD(&ioc
->list
);
8858 spin_lock(&gioc_lock
);
8859 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8860 spin_unlock(&gioc_lock
);
8863 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8864 ioc
->tm_cb_idx
= tm_cb_idx
;
8865 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8866 ioc
->base_cb_idx
= base_cb_idx
;
8867 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8868 ioc
->transport_cb_idx
= transport_cb_idx
;
8869 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8870 ioc
->config_cb_idx
= config_cb_idx
;
8871 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8872 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8873 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8874 ioc
->logging_level
= logging_level
;
8875 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8876 /* misc semaphores and spin locks */
8877 mutex_init(&ioc
->reset_in_progress_mutex
);
8878 /* initializing pci_access_mutex lock */
8879 mutex_init(&ioc
->pci_access_mutex
);
8880 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8881 spin_lock_init(&ioc
->scsi_lookup_lock
);
8882 spin_lock_init(&ioc
->sas_device_lock
);
8883 spin_lock_init(&ioc
->sas_node_lock
);
8884 spin_lock_init(&ioc
->fw_event_lock
);
8885 spin_lock_init(&ioc
->raid_device_lock
);
8886 spin_lock_init(&ioc
->diag_trigger_lock
);
8888 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8889 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8890 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8891 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8892 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8893 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8894 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8895 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
8896 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
8897 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8898 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8900 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
8902 /* init shost parameters */
8903 shost
->max_cmd_len
= 32;
8904 shost
->max_lun
= max_lun
;
8905 shost
->transportt
= mpt3sas_transport_template
;
8906 shost
->unique_id
= ioc
->id
;
8908 if (max_sectors
!= 0xFFFF) {
8909 if (max_sectors
< 64) {
8910 shost
->max_sectors
= 64;
8911 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8912 "for max_sectors, range is 64 to 32767. Assigning "
8913 "value of 64.\n", ioc
->name
, max_sectors
);
8914 } else if (max_sectors
> 32767) {
8915 shost
->max_sectors
= 32767;
8916 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8917 "for max_sectors, range is 64 to 32767. Assigning "
8918 "default value of 32767.\n", ioc
->name
,
8921 shost
->max_sectors
= max_sectors
& 0xFFFE;
8923 "The max_sectors value is set to %d\n",
8924 ioc
->name
, shost
->max_sectors
);
8928 /* register EEDP capabilities with SCSI layer */
8930 scsi_host_set_prot(shost
, prot_mask
);
8932 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8933 | SHOST_DIF_TYPE2_PROTECTION
8934 | SHOST_DIF_TYPE3_PROTECTION
);
8936 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8939 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8940 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
8941 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8942 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8943 if (!ioc
->firmware_event_thread
) {
8944 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8945 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8947 goto out_thread_fail
;
8950 ioc
->is_driver_loading
= 1;
8951 if ((mpt3sas_base_attach(ioc
))) {
8952 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8953 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8955 goto out_attach_fail
;
8958 if (ioc
->is_warpdrive
) {
8959 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8960 ioc
->hide_drives
= 0;
8961 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8962 ioc
->hide_drives
= 1;
8964 if (mpt3sas_get_num_volumes(ioc
))
8965 ioc
->hide_drives
= 1;
8967 ioc
->hide_drives
= 0;
8970 ioc
->hide_drives
= 0;
8972 rv
= scsi_add_host(shost
, &pdev
->dev
);
8974 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8975 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8976 goto out_add_shost_fail
;
8979 scsi_scan_host(shost
);
8982 mpt3sas_base_detach(ioc
);
8984 destroy_workqueue(ioc
->firmware_event_thread
);
8986 spin_lock(&gioc_lock
);
8987 list_del(&ioc
->list
);
8988 spin_unlock(&gioc_lock
);
8989 scsi_host_put(shost
);
8995 * scsih_suspend - power management suspend main entry point
8996 * @pdev: PCI device struct
8997 * @state: PM state change to (usually PCI_D3)
8999 * Returns 0 success, anything else error.
9002 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
9004 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9005 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9006 pci_power_t device_state
;
9008 mpt3sas_base_stop_watchdog(ioc
);
9009 flush_scheduled_work();
9010 scsi_block_requests(shost
);
9011 device_state
= pci_choose_state(pdev
, state
);
9013 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
9014 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
9016 pci_save_state(pdev
);
9017 mpt3sas_base_free_resources(ioc
);
9018 pci_set_power_state(pdev
, device_state
);
9023 * scsih_resume - power management resume main entry point
9024 * @pdev: PCI device struct
9026 * Returns 0 success, anything else error.
9029 scsih_resume(struct pci_dev
*pdev
)
9031 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9032 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9033 pci_power_t device_state
= pdev
->current_state
;
9037 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
9038 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
9040 pci_set_power_state(pdev
, PCI_D0
);
9041 pci_enable_wake(pdev
, PCI_D0
, 0);
9042 pci_restore_state(pdev
);
9044 r
= mpt3sas_base_map_resources(ioc
);
9048 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
9049 scsi_unblock_requests(shost
);
9050 mpt3sas_base_start_watchdog(ioc
);
9053 #endif /* CONFIG_PM */
9056 * scsih_pci_error_detected - Called when a PCI error is detected.
9057 * @pdev: PCI device struct
9058 * @state: PCI channel state
9060 * Description: Called when a PCI error is detected.
9063 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
9065 static pci_ers_result_t
9066 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
9068 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9069 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9071 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
9075 case pci_channel_io_normal
:
9076 return PCI_ERS_RESULT_CAN_RECOVER
;
9077 case pci_channel_io_frozen
:
9078 /* Fatal error, prepare for slot reset */
9079 ioc
->pci_error_recovery
= 1;
9080 scsi_block_requests(ioc
->shost
);
9081 mpt3sas_base_stop_watchdog(ioc
);
9082 mpt3sas_base_free_resources(ioc
);
9083 return PCI_ERS_RESULT_NEED_RESET
;
9084 case pci_channel_io_perm_failure
:
9085 /* Permanent error, prepare for device removal */
9086 ioc
->pci_error_recovery
= 1;
9087 mpt3sas_base_stop_watchdog(ioc
);
9088 _scsih_flush_running_cmds(ioc
);
9089 return PCI_ERS_RESULT_DISCONNECT
;
9091 return PCI_ERS_RESULT_NEED_RESET
;
9095 * scsih_pci_slot_reset - Called when PCI slot has been reset.
9096 * @pdev: PCI device struct
9098 * Description: This routine is called by the pci error recovery
9099 * code after the PCI slot has been reset, just before we
9100 * should resume normal operations.
9102 static pci_ers_result_t
9103 scsih_pci_slot_reset(struct pci_dev
*pdev
)
9105 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9106 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9109 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
9112 ioc
->pci_error_recovery
= 0;
9114 pci_restore_state(pdev
);
9115 rc
= mpt3sas_base_map_resources(ioc
);
9117 return PCI_ERS_RESULT_DISCONNECT
;
9119 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
9121 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
9122 (rc
== 0) ? "success" : "failed");
9125 return PCI_ERS_RESULT_RECOVERED
;
9127 return PCI_ERS_RESULT_DISCONNECT
;
9131 * scsih_pci_resume() - resume normal ops after PCI reset
9132 * @pdev: pointer to PCI device
9134 * Called when the error recovery driver tells us that its
9135 * OK to resume normal operation. Use completion to allow
9136 * halted scsi ops to resume.
9139 scsih_pci_resume(struct pci_dev
*pdev
)
9141 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9142 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9144 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
9146 pci_cleanup_aer_uncorrect_error_status(pdev
);
9147 mpt3sas_base_start_watchdog(ioc
);
9148 scsi_unblock_requests(ioc
->shost
);
9152 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
9153 * @pdev: pointer to PCI device
9155 static pci_ers_result_t
9156 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
9158 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9159 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9161 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
9164 /* TODO - dump whatever for debugging purposes */
9166 /* This called only if scsih_pci_error_detected returns
9167 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
9168 * works, no need to reset slot.
9170 return PCI_ERS_RESULT_RECOVERED
;
9174 * scsih__ncq_prio_supp - Check for NCQ command priority support
9175 * @sdev: scsi device struct
9177 * This is called when a user indicates they would like to enable
9178 * ncq command priorities. This works only on SATA devices.
9180 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
9183 bool ncq_prio_supp
= false;
9185 if (!scsi_device_supports_vpd(sdev
))
9186 return ncq_prio_supp
;
9188 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
9190 return ncq_prio_supp
;
9192 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
9193 ncq_prio_supp
= (buf
[213] >> 4) & 1;
9196 return ncq_prio_supp
;
9199 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9201 static const struct pci_device_id mpt3sas_pci_table
[] = {
9202 /* Spitfire ~ 2004 */
9203 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
9204 PCI_ANY_ID
, PCI_ANY_ID
},
9206 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
9207 PCI_ANY_ID
, PCI_ANY_ID
},
9208 /* Liberator ~ 2108 */
9209 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
9210 PCI_ANY_ID
, PCI_ANY_ID
},
9211 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
9212 PCI_ANY_ID
, PCI_ANY_ID
},
9213 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
9214 PCI_ANY_ID
, PCI_ANY_ID
},
9216 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
9217 PCI_ANY_ID
, PCI_ANY_ID
},
9218 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
9219 PCI_ANY_ID
, PCI_ANY_ID
},
9220 /* Thunderbolt ~ 2208 */
9221 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
9222 PCI_ANY_ID
, PCI_ANY_ID
},
9223 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
9224 PCI_ANY_ID
, PCI_ANY_ID
},
9225 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
9226 PCI_ANY_ID
, PCI_ANY_ID
},
9227 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
9228 PCI_ANY_ID
, PCI_ANY_ID
},
9229 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
9230 PCI_ANY_ID
, PCI_ANY_ID
},
9231 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
9232 PCI_ANY_ID
, PCI_ANY_ID
},
9233 /* Mustang ~ 2308 */
9234 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
9235 PCI_ANY_ID
, PCI_ANY_ID
},
9236 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
9237 PCI_ANY_ID
, PCI_ANY_ID
},
9238 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
9239 PCI_ANY_ID
, PCI_ANY_ID
},
9241 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
9242 PCI_ANY_ID
, PCI_ANY_ID
},
9243 /* Fury ~ 3004 and 3008 */
9244 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
9245 PCI_ANY_ID
, PCI_ANY_ID
},
9246 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
9247 PCI_ANY_ID
, PCI_ANY_ID
},
9248 /* Invader ~ 3108 */
9249 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
9250 PCI_ANY_ID
, PCI_ANY_ID
},
9251 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
9252 PCI_ANY_ID
, PCI_ANY_ID
},
9253 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
9254 PCI_ANY_ID
, PCI_ANY_ID
},
9255 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
9256 PCI_ANY_ID
, PCI_ANY_ID
},
9257 /* Cutlass ~ 3216 and 3224 */
9258 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
9259 PCI_ANY_ID
, PCI_ANY_ID
},
9260 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
9261 PCI_ANY_ID
, PCI_ANY_ID
},
9262 /* Intruder ~ 3316 and 3324 */
9263 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
9264 PCI_ANY_ID
, PCI_ANY_ID
},
9265 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
9266 PCI_ANY_ID
, PCI_ANY_ID
},
9267 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
9268 PCI_ANY_ID
, PCI_ANY_ID
},
9269 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
9270 PCI_ANY_ID
, PCI_ANY_ID
},
9271 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
9272 PCI_ANY_ID
, PCI_ANY_ID
},
9273 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
9274 PCI_ANY_ID
, PCI_ANY_ID
},
9275 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
9276 PCI_ANY_ID
, PCI_ANY_ID
},
9277 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
9278 PCI_ANY_ID
, PCI_ANY_ID
},
9279 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
9280 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
9281 PCI_ANY_ID
, PCI_ANY_ID
},
9282 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
9283 PCI_ANY_ID
, PCI_ANY_ID
},
9284 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
9285 PCI_ANY_ID
, PCI_ANY_ID
},
9286 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
9287 PCI_ANY_ID
, PCI_ANY_ID
},
9288 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
9289 PCI_ANY_ID
, PCI_ANY_ID
},
9290 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
9291 PCI_ANY_ID
, PCI_ANY_ID
},
9292 {0} /* Terminating entry */
9294 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
9296 static struct pci_error_handlers _mpt3sas_err_handler
= {
9297 .error_detected
= scsih_pci_error_detected
,
9298 .mmio_enabled
= scsih_pci_mmio_enabled
,
9299 .slot_reset
= scsih_pci_slot_reset
,
9300 .resume
= scsih_pci_resume
,
9303 static struct pci_driver mpt3sas_driver
= {
9304 .name
= MPT3SAS_DRIVER_NAME
,
9305 .id_table
= mpt3sas_pci_table
,
9306 .probe
= _scsih_probe
,
9307 .remove
= scsih_remove
,
9308 .shutdown
= scsih_shutdown
,
9309 .err_handler
= &_mpt3sas_err_handler
,
9311 .suspend
= scsih_suspend
,
9312 .resume
= scsih_resume
,
9317 * scsih_init - main entry point for this driver.
9319 * Returns 0 success, anything else error.
9327 mpt3sas_base_initialize_callback_handler();
9329 /* queuecommand callback hander */
9330 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
9332 /* task management callback handler */
9333 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
9335 /* base internal commands callback handler */
9336 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
9337 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
9338 mpt3sas_port_enable_done
);
9340 /* transport internal commands callback handler */
9341 transport_cb_idx
= mpt3sas_base_register_callback_handler(
9342 mpt3sas_transport_done
);
9344 /* scsih internal commands callback handler */
9345 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
9347 /* configuration page API internal commands callback handler */
9348 config_cb_idx
= mpt3sas_base_register_callback_handler(
9349 mpt3sas_config_done
);
9351 /* ctl module callback handler */
9352 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
9354 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
9355 _scsih_tm_tr_complete
);
9357 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
9358 _scsih_tm_volume_tr_complete
);
9360 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
9361 _scsih_sas_control_complete
);
9367 * scsih_exit - exit point for this driver (when it is a module).
9369 * Returns 0 success, anything else error.
9375 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
9376 mpt3sas_base_release_callback_handler(tm_cb_idx
);
9377 mpt3sas_base_release_callback_handler(base_cb_idx
);
9378 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
9379 mpt3sas_base_release_callback_handler(transport_cb_idx
);
9380 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
9381 mpt3sas_base_release_callback_handler(config_cb_idx
);
9382 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
9384 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
9385 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
9386 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
9388 /* raid transport support */
9389 if (hbas_to_enumerate
!= 1)
9390 raid_class_release(mpt3sas_raid_template
);
9391 if (hbas_to_enumerate
!= 2)
9392 raid_class_release(mpt2sas_raid_template
);
9393 sas_release_transport(mpt3sas_transport_template
);
9397 * _mpt3sas_init - main entry point for this driver.
9399 * Returns 0 success, anything else error.
9406 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
9407 MPT3SAS_DRIVER_VERSION
);
9409 mpt3sas_transport_template
=
9410 sas_attach_transport(&mpt3sas_transport_functions
);
9411 if (!mpt3sas_transport_template
)
9414 /* No need attach mpt3sas raid functions template
9415 * if hbas_to_enumarate value is one.
9417 if (hbas_to_enumerate
!= 1) {
9418 mpt3sas_raid_template
=
9419 raid_class_attach(&mpt3sas_raid_functions
);
9420 if (!mpt3sas_raid_template
) {
9421 sas_release_transport(mpt3sas_transport_template
);
9426 /* No need to attach mpt2sas raid functions template
9427 * if hbas_to_enumarate value is two
9429 if (hbas_to_enumerate
!= 2) {
9430 mpt2sas_raid_template
=
9431 raid_class_attach(&mpt2sas_raid_functions
);
9432 if (!mpt2sas_raid_template
) {
9433 sas_release_transport(mpt3sas_transport_template
);
9438 error
= scsih_init();
9444 mpt3sas_ctl_init(hbas_to_enumerate
);
9446 error
= pci_register_driver(&mpt3sas_driver
);
9454 * _mpt3sas_exit - exit point for this driver (when it is a module).
9460 pr_info("mpt3sas version %s unloading\n",
9461 MPT3SAS_DRIVER_VERSION
);
9463 pci_unregister_driver(&mpt3sas_driver
);
9465 mpt3sas_ctl_exit(hbas_to_enumerate
);
9470 module_init(_mpt3sas_init
);
9471 module_exit(_mpt3sas_exit
);