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
1079 * @ioc: per adapter object
1080 * @smid: system request message index
1082 * Returns the smid stored scmd pointer.
1083 * Then will derefrence the stored scmd pointer.
1085 static inline struct scsi_cmnd
*
1086 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1088 unsigned long flags
;
1089 struct scsi_cmnd
*scmd
;
1091 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1092 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
1093 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
1094 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1100 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1101 * @ioc: per adapter object
1102 * @smid: system request message index
1103 * @scmd: pointer to scsi command object
1104 * Context: This function will acquire ioc->scsi_lookup_lock.
1106 * This will search for a scmd pointer in the scsi_lookup array,
1107 * returning the revelent smid. A returned value of zero means invalid.
1110 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1114 unsigned long flags
;
1117 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1119 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1120 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1121 smid
= ioc
->scsi_lookup
[i
].smid
;
1126 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1131 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1132 * @ioc: per adapter object
1135 * Context: This function will acquire ioc->scsi_lookup_lock.
1137 * This will search for a matching channel:id in the scsi_lookup array,
1138 * returning 1 if found.
1141 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1145 unsigned long flags
;
1148 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1150 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1151 if (ioc
->scsi_lookup
[i
].scmd
&&
1152 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1153 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1159 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1164 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1165 * @ioc: per adapter object
1169 * Context: This function will acquire ioc->scsi_lookup_lock.
1171 * This will search for a matching channel:id:lun in the scsi_lookup array,
1172 * returning 1 if found.
1175 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1176 unsigned int lun
, int channel
)
1179 unsigned long flags
;
1182 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1184 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1185 if (ioc
->scsi_lookup
[i
].scmd
&&
1186 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1187 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1188 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1194 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1199 * scsih_change_queue_depth - setting device queue depth
1200 * @sdev: scsi device struct
1201 * @qdepth: requested queue depth
1203 * Returns queue depth.
1206 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1208 struct Scsi_Host
*shost
= sdev
->host
;
1210 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1211 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1212 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1213 struct _sas_device
*sas_device
;
1214 unsigned long flags
;
1216 max_depth
= shost
->can_queue
;
1218 /* limit max device queue for SATA to 32 */
1219 sas_device_priv_data
= sdev
->hostdata
;
1220 if (!sas_device_priv_data
)
1222 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1223 if (!sas_target_priv_data
)
1225 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1228 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1229 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1231 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1232 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1234 sas_device_put(sas_device
);
1236 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1240 if (!sdev
->tagged_supported
)
1242 if (qdepth
> max_depth
)
1244 return scsi_change_queue_depth(sdev
, qdepth
);
1248 * scsih_target_alloc - target add routine
1249 * @starget: scsi target struct
1251 * Returns 0 if ok. Any other return is assumed to be an error and
1252 * the device is ignored.
1255 scsih_target_alloc(struct scsi_target
*starget
)
1257 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1258 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1259 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1260 struct _sas_device
*sas_device
;
1261 struct _raid_device
*raid_device
;
1262 unsigned long flags
;
1263 struct sas_rphy
*rphy
;
1265 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1267 if (!sas_target_priv_data
)
1270 starget
->hostdata
= sas_target_priv_data
;
1271 sas_target_priv_data
->starget
= starget
;
1272 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1275 if (starget
->channel
== RAID_CHANNEL
) {
1276 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1277 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1280 sas_target_priv_data
->handle
= raid_device
->handle
;
1281 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1282 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1283 if (ioc
->is_warpdrive
)
1284 sas_target_priv_data
->raid_device
= raid_device
;
1285 raid_device
->starget
= starget
;
1287 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1291 /* sas/sata devices */
1292 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1293 rphy
= dev_to_rphy(starget
->dev
.parent
);
1294 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1295 rphy
->identify
.sas_address
);
1298 sas_target_priv_data
->handle
= sas_device
->handle
;
1299 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1300 sas_target_priv_data
->sdev
= sas_device
;
1301 sas_device
->starget
= starget
;
1302 sas_device
->id
= starget
->id
;
1303 sas_device
->channel
= starget
->channel
;
1304 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1305 sas_target_priv_data
->flags
|=
1306 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1307 if (sas_device
->fast_path
)
1308 sas_target_priv_data
->flags
|= MPT_TARGET_FASTPATH_IO
;
1310 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1316 * scsih_target_destroy - target destroy routine
1317 * @starget: scsi target struct
1322 scsih_target_destroy(struct scsi_target
*starget
)
1324 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1325 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1326 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1327 struct _sas_device
*sas_device
;
1328 struct _raid_device
*raid_device
;
1329 unsigned long flags
;
1331 sas_target_priv_data
= starget
->hostdata
;
1332 if (!sas_target_priv_data
)
1335 if (starget
->channel
== RAID_CHANNEL
) {
1336 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1337 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1340 raid_device
->starget
= NULL
;
1341 raid_device
->sdev
= NULL
;
1343 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1347 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1348 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1349 if (sas_device
&& (sas_device
->starget
== starget
) &&
1350 (sas_device
->id
== starget
->id
) &&
1351 (sas_device
->channel
== starget
->channel
))
1352 sas_device
->starget
= NULL
;
1356 * Corresponding get() is in _scsih_target_alloc()
1358 sas_target_priv_data
->sdev
= NULL
;
1359 sas_device_put(sas_device
);
1361 sas_device_put(sas_device
);
1363 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1366 kfree(sas_target_priv_data
);
1367 starget
->hostdata
= NULL
;
1371 * scsih_slave_alloc - device add routine
1372 * @sdev: scsi device struct
1374 * Returns 0 if ok. Any other return is assumed to be an error and
1375 * the device is ignored.
1378 scsih_slave_alloc(struct scsi_device
*sdev
)
1380 struct Scsi_Host
*shost
;
1381 struct MPT3SAS_ADAPTER
*ioc
;
1382 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1383 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1384 struct scsi_target
*starget
;
1385 struct _raid_device
*raid_device
;
1386 struct _sas_device
*sas_device
;
1387 unsigned long flags
;
1389 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1391 if (!sas_device_priv_data
)
1394 sas_device_priv_data
->lun
= sdev
->lun
;
1395 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1397 starget
= scsi_target(sdev
);
1398 sas_target_priv_data
= starget
->hostdata
;
1399 sas_target_priv_data
->num_luns
++;
1400 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1401 sdev
->hostdata
= sas_device_priv_data
;
1402 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1403 sdev
->no_uld_attach
= 1;
1405 shost
= dev_to_shost(&starget
->dev
);
1406 ioc
= shost_priv(shost
);
1407 if (starget
->channel
== RAID_CHANNEL
) {
1408 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1409 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1410 starget
->id
, starget
->channel
);
1412 raid_device
->sdev
= sdev
; /* raid is single lun */
1413 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1416 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1417 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1418 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1419 sas_target_priv_data
->sas_address
);
1420 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1421 sdev_printk(KERN_INFO
, sdev
,
1422 "%s : sas_device->starget set to starget @ %d\n",
1423 __func__
, __LINE__
);
1424 sas_device
->starget
= starget
;
1428 sas_device_put(sas_device
);
1430 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1437 * scsih_slave_destroy - device destroy routine
1438 * @sdev: scsi device struct
1443 scsih_slave_destroy(struct scsi_device
*sdev
)
1445 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1446 struct scsi_target
*starget
;
1447 struct Scsi_Host
*shost
;
1448 struct MPT3SAS_ADAPTER
*ioc
;
1449 struct _sas_device
*sas_device
;
1450 unsigned long flags
;
1452 if (!sdev
->hostdata
)
1455 starget
= scsi_target(sdev
);
1456 sas_target_priv_data
= starget
->hostdata
;
1457 sas_target_priv_data
->num_luns
--;
1459 shost
= dev_to_shost(&starget
->dev
);
1460 ioc
= shost_priv(shost
);
1462 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1463 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1464 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1465 sas_target_priv_data
);
1466 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1467 sas_device
->starget
= NULL
;
1470 sas_device_put(sas_device
);
1471 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1474 kfree(sdev
->hostdata
);
1475 sdev
->hostdata
= NULL
;
1479 * _scsih_display_sata_capabilities - sata capabilities
1480 * @ioc: per adapter object
1481 * @handle: device handle
1482 * @sdev: scsi device struct
1485 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1486 u16 handle
, struct scsi_device
*sdev
)
1488 Mpi2ConfigReply_t mpi_reply
;
1489 Mpi2SasDevicePage0_t sas_device_pg0
;
1494 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1495 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1496 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1497 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1501 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1502 MPI2_IOCSTATUS_MASK
;
1503 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1504 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1505 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1509 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1510 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1512 sdev_printk(KERN_INFO
, sdev
,
1513 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1514 "sw_preserve(%s)\n",
1515 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1516 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1517 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1519 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1520 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1521 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1525 * raid transport support -
1526 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1527 * unloading the driver followed by a load - I believe that the subroutine
1528 * raid_class_release() is not cleaning up properly.
1532 * scsih_is_raid - return boolean indicating device is raid volume
1533 * @dev the device struct object
1536 scsih_is_raid(struct device
*dev
)
1538 struct scsi_device
*sdev
= to_scsi_device(dev
);
1539 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1541 if (ioc
->is_warpdrive
)
1543 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1547 * scsih_get_resync - get raid volume resync percent complete
1548 * @dev the device struct object
1551 scsih_get_resync(struct device
*dev
)
1553 struct scsi_device
*sdev
= to_scsi_device(dev
);
1554 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1555 static struct _raid_device
*raid_device
;
1556 unsigned long flags
;
1557 Mpi2RaidVolPage0_t vol_pg0
;
1558 Mpi2ConfigReply_t mpi_reply
;
1559 u32 volume_status_flags
;
1560 u8 percent_complete
;
1563 percent_complete
= 0;
1565 if (ioc
->is_warpdrive
)
1568 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1569 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1572 handle
= raid_device
->handle
;
1573 percent_complete
= raid_device
->percent_complete
;
1575 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1580 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1581 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1582 sizeof(Mpi2RaidVolPage0_t
))) {
1583 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1584 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1585 percent_complete
= 0;
1589 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1590 if (!(volume_status_flags
&
1591 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1592 percent_complete
= 0;
1596 switch (ioc
->hba_mpi_version_belonged
) {
1598 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1602 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1608 * scsih_get_state - get raid volume level
1609 * @dev the device struct object
1612 scsih_get_state(struct device
*dev
)
1614 struct scsi_device
*sdev
= to_scsi_device(dev
);
1615 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1616 static struct _raid_device
*raid_device
;
1617 unsigned long flags
;
1618 Mpi2RaidVolPage0_t vol_pg0
;
1619 Mpi2ConfigReply_t mpi_reply
;
1621 enum raid_state state
= RAID_STATE_UNKNOWN
;
1624 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1625 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1628 handle
= raid_device
->handle
;
1629 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1634 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1635 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1636 sizeof(Mpi2RaidVolPage0_t
))) {
1637 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1638 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1642 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1643 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1644 state
= RAID_STATE_RESYNCING
;
1648 switch (vol_pg0
.VolumeState
) {
1649 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1650 case MPI2_RAID_VOL_STATE_ONLINE
:
1651 state
= RAID_STATE_ACTIVE
;
1653 case MPI2_RAID_VOL_STATE_DEGRADED
:
1654 state
= RAID_STATE_DEGRADED
;
1656 case MPI2_RAID_VOL_STATE_FAILED
:
1657 case MPI2_RAID_VOL_STATE_MISSING
:
1658 state
= RAID_STATE_OFFLINE
;
1662 switch (ioc
->hba_mpi_version_belonged
) {
1664 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1668 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1674 * _scsih_set_level - set raid level
1675 * @sdev: scsi device struct
1676 * @volume_type: volume type
1679 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
1680 struct scsi_device
*sdev
, u8 volume_type
)
1682 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1684 switch (volume_type
) {
1685 case MPI2_RAID_VOL_TYPE_RAID0
:
1686 level
= RAID_LEVEL_0
;
1688 case MPI2_RAID_VOL_TYPE_RAID10
:
1689 level
= RAID_LEVEL_10
;
1691 case MPI2_RAID_VOL_TYPE_RAID1E
:
1692 level
= RAID_LEVEL_1E
;
1694 case MPI2_RAID_VOL_TYPE_RAID1
:
1695 level
= RAID_LEVEL_1
;
1699 switch (ioc
->hba_mpi_version_belonged
) {
1701 raid_set_level(mpt2sas_raid_template
,
1702 &sdev
->sdev_gendev
, level
);
1706 raid_set_level(mpt3sas_raid_template
,
1707 &sdev
->sdev_gendev
, level
);
1714 * _scsih_get_volume_capabilities - volume capabilities
1715 * @ioc: per adapter object
1716 * @sas_device: the raid_device object
1718 * Returns 0 for success, else 1
1721 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1722 struct _raid_device
*raid_device
)
1724 Mpi2RaidVolPage0_t
*vol_pg0
;
1725 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1726 Mpi2SasDevicePage0_t sas_device_pg0
;
1727 Mpi2ConfigReply_t mpi_reply
;
1731 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1732 &num_pds
)) || !num_pds
) {
1733 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1734 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1739 raid_device
->num_pds
= num_pds
;
1740 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1741 sizeof(Mpi2RaidVol0PhysDisk_t
));
1742 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1744 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1745 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1750 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1751 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1752 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1753 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1759 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1761 /* figure out what the underlying devices are by
1762 * obtaining the device_info bits for the 1st device
1764 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1765 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1766 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1767 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1768 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1769 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1770 raid_device
->device_info
=
1771 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1780 * _scsih_enable_tlr - setting TLR flags
1781 * @ioc: per adapter object
1782 * @sdev: scsi device struct
1784 * Enabling Transaction Layer Retries for tape devices when
1785 * vpd page 0x90 is present
1789 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1793 if (sdev
->type
!= TYPE_TAPE
)
1796 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1799 sas_enable_tlr(sdev
);
1800 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1801 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1807 * scsih_slave_configure - device configure routine.
1808 * @sdev: scsi device struct
1810 * Returns 0 if ok. Any other return is assumed to be an error and
1811 * the device is ignored.
1814 scsih_slave_configure(struct scsi_device
*sdev
)
1816 struct Scsi_Host
*shost
= sdev
->host
;
1817 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1818 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1819 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1820 struct _sas_device
*sas_device
;
1821 struct _raid_device
*raid_device
;
1822 unsigned long flags
;
1827 u16 handle
, volume_handle
= 0;
1828 u64 volume_wwid
= 0;
1831 sas_device_priv_data
= sdev
->hostdata
;
1832 sas_device_priv_data
->configured_lun
= 1;
1833 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1834 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1835 handle
= sas_target_priv_data
->handle
;
1837 /* raid volume handling */
1838 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1840 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1841 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
1842 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1844 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1845 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1846 __LINE__
, __func__
));
1850 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1851 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1852 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1853 __LINE__
, __func__
));
1858 * WARPDRIVE: Initialize the required data for Direct IO
1860 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
1862 /* RAID Queue Depth Support
1863 * IS volume = underlying qdepth of drive type, either
1864 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1865 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1867 if (raid_device
->device_info
&
1868 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1869 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1872 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1873 if (raid_device
->device_info
&
1874 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1880 switch (raid_device
->volume_type
) {
1881 case MPI2_RAID_VOL_TYPE_RAID0
:
1884 case MPI2_RAID_VOL_TYPE_RAID1E
:
1885 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1886 if (ioc
->manu_pg10
.OEMIdentifier
&&
1887 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1888 MFG10_GF0_R10_DISPLAY
) &&
1889 !(raid_device
->num_pds
% 2))
1894 case MPI2_RAID_VOL_TYPE_RAID1
:
1895 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1898 case MPI2_RAID_VOL_TYPE_RAID10
:
1899 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1902 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1904 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1909 if (!ioc
->hide_ir_msg
)
1910 sdev_printk(KERN_INFO
, sdev
,
1911 "%s: handle(0x%04x), wwid(0x%016llx),"
1912 " pd_count(%d), type(%s)\n",
1913 r_level
, raid_device
->handle
,
1914 (unsigned long long)raid_device
->wwid
,
1915 raid_device
->num_pds
, ds
);
1917 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
1918 blk_queue_max_hw_sectors(sdev
->request_queue
,
1919 MPT3SAS_RAID_MAX_SECTORS
);
1920 sdev_printk(KERN_INFO
, sdev
,
1921 "Set queue's max_sector to: %u\n",
1922 MPT3SAS_RAID_MAX_SECTORS
);
1925 scsih_change_queue_depth(sdev
, qdepth
);
1927 /* raid transport support */
1928 if (!ioc
->is_warpdrive
)
1929 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
1933 /* non-raid handling */
1934 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1935 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1937 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1938 "failure at %s:%d/%s()!\n", ioc
->name
,
1939 __FILE__
, __LINE__
, __func__
));
1942 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1943 volume_handle
, &volume_wwid
)) {
1944 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1945 "failure at %s:%d/%s()!\n", ioc
->name
,
1946 __FILE__
, __LINE__
, __func__
));
1951 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1952 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1953 sas_device_priv_data
->sas_target
->sas_address
);
1955 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1956 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1957 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1962 sas_device
->volume_handle
= volume_handle
;
1963 sas_device
->volume_wwid
= volume_wwid
;
1964 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1965 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1967 if (sas_device
->device_info
&
1968 MPI2_SAS_DEVICE_INFO_SEP
) {
1969 sdev_printk(KERN_WARNING
, sdev
,
1970 "set ignore_delay_remove for handle(0x%04x)\n",
1971 sas_device_priv_data
->sas_target
->handle
);
1972 sas_device_priv_data
->ignore_delay_remove
= 1;
1977 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1978 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1980 else if (sas_device
->device_info
&
1981 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1985 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
1986 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1987 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
1988 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
1989 if (sas_device
->enclosure_handle
!= 0)
1990 sdev_printk(KERN_INFO
, sdev
,
1991 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1992 ds
, (unsigned long long)
1993 sas_device
->enclosure_logical_id
, sas_device
->slot
);
1994 if (sas_device
->connector_name
[0] != '\0')
1995 sdev_printk(KERN_INFO
, sdev
,
1996 "%s: enclosure level(0x%04x), connector name( %s)\n",
1997 ds
, sas_device
->enclosure_level
,
1998 sas_device
->connector_name
);
2000 sas_device_put(sas_device
);
2001 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2004 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2007 scsih_change_queue_depth(sdev
, qdepth
);
2010 sas_read_port_mode_page(sdev
);
2011 _scsih_enable_tlr(ioc
, sdev
);
2018 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2019 * @sdev: scsi device struct
2020 * @bdev: pointer to block device context
2021 * @capacity: device size (in 512 byte sectors)
2022 * @params: three element array to place output:
2023 * params[0] number of heads (max 255)
2024 * params[1] number of sectors (max 63)
2025 * params[2] number of cylinders
2030 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2031 sector_t capacity
, int params
[])
2041 dummy
= heads
* sectors
;
2042 cylinders
= capacity
;
2043 sector_div(cylinders
, dummy
);
2046 * Handle extended translation size for logical drives
2049 if ((ulong
)capacity
>= 0x200000) {
2052 dummy
= heads
* sectors
;
2053 cylinders
= capacity
;
2054 sector_div(cylinders
, dummy
);
2059 params
[1] = sectors
;
2060 params
[2] = cylinders
;
2066 * _scsih_response_code - translation of device response code
2067 * @ioc: per adapter object
2068 * @response_code: response code returned by the device
2073 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2077 switch (response_code
) {
2078 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2079 desc
= "task management request completed";
2081 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2082 desc
= "invalid frame";
2084 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2085 desc
= "task management request not supported";
2087 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2088 desc
= "task management request failed";
2090 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2091 desc
= "task management request succeeded";
2093 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2094 desc
= "invalid lun";
2097 desc
= "overlapped tag attempted";
2099 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2100 desc
= "task queued, however not sent to target";
2106 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2107 ioc
->name
, response_code
, desc
);
2111 * _scsih_tm_done - tm completion routine
2112 * @ioc: per adapter object
2113 * @smid: system request message index
2114 * @msix_index: MSIX table index supplied by the OS
2115 * @reply: reply message frame(lower 32bit addr)
2118 * The callback handler when using scsih_issue_tm.
2120 * Return 1 meaning mf should be freed from _base_interrupt
2121 * 0 means the mf is freed from this function.
2124 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2126 MPI2DefaultReply_t
*mpi_reply
;
2128 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2130 if (ioc
->tm_cmds
.smid
!= smid
)
2132 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2133 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2135 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2136 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2138 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2139 complete(&ioc
->tm_cmds
.done
);
2144 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2145 * @ioc: per adapter object
2146 * @handle: device handle
2148 * During taskmangement request, we need to freeze the device queue.
2151 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2153 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2154 struct scsi_device
*sdev
;
2157 shost_for_each_device(sdev
, ioc
->shost
) {
2160 sas_device_priv_data
= sdev
->hostdata
;
2161 if (!sas_device_priv_data
)
2163 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2164 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2166 ioc
->ignore_loginfos
= 1;
2172 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2173 * @ioc: per adapter object
2174 * @handle: device handle
2176 * During taskmangement request, we need to freeze the device queue.
2179 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2181 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2182 struct scsi_device
*sdev
;
2185 shost_for_each_device(sdev
, ioc
->shost
) {
2188 sas_device_priv_data
= sdev
->hostdata
;
2189 if (!sas_device_priv_data
)
2191 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2192 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2194 ioc
->ignore_loginfos
= 0;
2200 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2201 * @ioc: per adapter struct
2202 * @device_handle: device handle
2203 * @channel: the channel assigned by the OS
2204 * @id: the id assigned by the OS
2206 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2207 * @smid_task: smid assigned to the task
2208 * @timeout: timeout in seconds
2211 * A generic API for sending task management requests to firmware.
2213 * The callback index is set inside `ioc->tm_cb_idx`.
2215 * Return SUCCESS or FAILED.
2218 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2219 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2221 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2222 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2225 struct scsiio_tracker
*scsi_lookup
= NULL
;
2229 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2231 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2232 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2233 __func__
, ioc
->name
);
2237 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2238 ioc
->pci_error_recovery
) {
2239 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2240 __func__
, ioc
->name
);
2244 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2245 if (ioc_state
& MPI2_DOORBELL_USED
) {
2246 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2247 "unexpected doorbell active!\n", ioc
->name
));
2248 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2249 return (!rc
) ? SUCCESS
: FAILED
;
2252 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2253 mpt3sas_base_fault_info(ioc
, ioc_state
&
2254 MPI2_DOORBELL_DATA_MASK
);
2255 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2256 return (!rc
) ? SUCCESS
: FAILED
;
2259 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2261 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2262 ioc
->name
, __func__
);
2266 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2267 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2269 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2270 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2271 ioc
->name
, handle
, type
, smid_task
));
2272 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2273 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2274 ioc
->tm_cmds
.smid
= smid
;
2275 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2276 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2277 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2278 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2279 mpi_request
->TaskType
= type
;
2280 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2281 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2282 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2283 init_completion(&ioc
->tm_cmds
.done
);
2284 if ((type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) &&
2285 (scsi_lookup
->msix_io
< ioc
->reply_queue_count
))
2286 msix_task
= scsi_lookup
->msix_io
;
2289 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2290 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2291 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2292 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2293 ioc
->name
, __func__
);
2294 _debug_dump_mf(mpi_request
,
2295 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2296 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2297 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2299 rc
= (!rc
) ? SUCCESS
: FAILED
;
2304 /* sync IRQs in case those were busy during flush. */
2305 mpt3sas_base_sync_reply_irqs(ioc
);
2307 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2308 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2309 mpi_reply
= ioc
->tm_cmds
.reply
;
2310 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2311 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2312 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2313 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2314 le32_to_cpu(mpi_reply
->TerminationCount
)));
2315 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2316 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2317 if (mpi_reply
->IOCStatus
)
2318 _debug_dump_mf(mpi_request
,
2319 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2324 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2326 if (scsi_lookup
->scmd
== NULL
)
2331 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2332 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2337 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2338 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2339 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2344 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2353 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2354 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2358 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2359 uint channel
, uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2363 mutex_lock(&ioc
->tm_cmds
.mutex
);
2364 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, channel
, id
, lun
, type
,
2365 smid_task
, timeout
);
2366 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2372 * _scsih_tm_display_info - displays info about the device
2373 * @ioc: per adapter struct
2374 * @scmd: pointer to scsi command object
2376 * Called by task management callback handlers.
2379 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2381 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2382 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2383 struct _sas_device
*sas_device
= NULL
;
2384 unsigned long flags
;
2385 char *device_str
= NULL
;
2389 if (ioc
->hide_ir_msg
)
2390 device_str
= "WarpDrive";
2392 device_str
= "volume";
2394 scsi_print_command(scmd
);
2395 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2396 starget_printk(KERN_INFO
, starget
,
2397 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2398 device_str
, priv_target
->handle
,
2399 device_str
, (unsigned long long)priv_target
->sas_address
);
2401 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2402 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2404 if (priv_target
->flags
&
2405 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2406 starget_printk(KERN_INFO
, starget
,
2407 "volume handle(0x%04x), "
2408 "volume wwid(0x%016llx)\n",
2409 sas_device
->volume_handle
,
2410 (unsigned long long)sas_device
->volume_wwid
);
2412 starget_printk(KERN_INFO
, starget
,
2413 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2415 (unsigned long long)sas_device
->sas_address
,
2417 if (sas_device
->enclosure_handle
!= 0)
2418 starget_printk(KERN_INFO
, starget
,
2419 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2420 (unsigned long long)
2421 sas_device
->enclosure_logical_id
,
2423 if (sas_device
->connector_name
[0] != '\0')
2424 starget_printk(KERN_INFO
, starget
,
2425 "enclosure level(0x%04x),connector name(%s)\n",
2426 sas_device
->enclosure_level
,
2427 sas_device
->connector_name
);
2429 sas_device_put(sas_device
);
2431 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2436 * scsih_abort - eh threads main abort routine
2437 * @scmd: pointer to scsi command object
2439 * Returns SUCCESS if command aborted else FAILED
2442 scsih_abort(struct scsi_cmnd
*scmd
)
2444 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2445 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2450 sdev_printk(KERN_INFO
, scmd
->device
,
2451 "attempting task abort! scmd(%p)\n", scmd
);
2452 _scsih_tm_display_info(ioc
, scmd
);
2454 sas_device_priv_data
= scmd
->device
->hostdata
;
2455 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2456 sdev_printk(KERN_INFO
, scmd
->device
,
2457 "device been deleted! scmd(%p)\n", scmd
);
2458 scmd
->result
= DID_NO_CONNECT
<< 16;
2459 scmd
->scsi_done(scmd
);
2464 /* search for the command */
2465 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2467 scmd
->result
= DID_RESET
<< 16;
2472 /* for hidden raid components and volumes this is not supported */
2473 if (sas_device_priv_data
->sas_target
->flags
&
2474 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2475 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2476 scmd
->result
= DID_RESET
<< 16;
2481 mpt3sas_halt_firmware(ioc
);
2483 handle
= sas_device_priv_data
->sas_target
->handle
;
2484 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2485 scmd
->device
->id
, scmd
->device
->lun
,
2486 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
2489 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2490 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2495 * scsih_dev_reset - eh threads main device reset routine
2496 * @scmd: pointer to scsi command object
2498 * Returns SUCCESS if command aborted else FAILED
2501 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2503 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2504 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2505 struct _sas_device
*sas_device
= NULL
;
2509 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2510 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2512 sdev_printk(KERN_INFO
, scmd
->device
,
2513 "attempting device reset! scmd(%p)\n", scmd
);
2514 _scsih_tm_display_info(ioc
, scmd
);
2516 sas_device_priv_data
= scmd
->device
->hostdata
;
2517 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2518 sdev_printk(KERN_INFO
, scmd
->device
,
2519 "device been deleted! scmd(%p)\n", scmd
);
2520 scmd
->result
= DID_NO_CONNECT
<< 16;
2521 scmd
->scsi_done(scmd
);
2526 /* for hidden raid components obtain the volume_handle */
2528 if (sas_device_priv_data
->sas_target
->flags
&
2529 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2530 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2533 handle
= sas_device
->volume_handle
;
2535 handle
= sas_device_priv_data
->sas_target
->handle
;
2538 scmd
->result
= DID_RESET
<< 16;
2543 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2544 scmd
->device
->id
, scmd
->device
->lun
,
2545 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30);
2548 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2549 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2552 sas_device_put(sas_device
);
2558 * scsih_target_reset - eh threads main target reset routine
2559 * @scmd: pointer to scsi command object
2561 * Returns SUCCESS if command aborted else FAILED
2564 scsih_target_reset(struct scsi_cmnd
*scmd
)
2566 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2567 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2568 struct _sas_device
*sas_device
= NULL
;
2571 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2572 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2574 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2576 _scsih_tm_display_info(ioc
, scmd
);
2578 sas_device_priv_data
= scmd
->device
->hostdata
;
2579 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2580 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2582 scmd
->result
= DID_NO_CONNECT
<< 16;
2583 scmd
->scsi_done(scmd
);
2588 /* for hidden raid components obtain the volume_handle */
2590 if (sas_device_priv_data
->sas_target
->flags
&
2591 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2592 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2595 handle
= sas_device
->volume_handle
;
2597 handle
= sas_device_priv_data
->sas_target
->handle
;
2600 scmd
->result
= DID_RESET
<< 16;
2605 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2606 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2610 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2611 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2614 sas_device_put(sas_device
);
2621 * scsih_host_reset - eh threads main host reset routine
2622 * @scmd: pointer to scsi command object
2624 * Returns SUCCESS if command aborted else FAILED
2627 scsih_host_reset(struct scsi_cmnd
*scmd
)
2629 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2632 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
2634 scsi_print_command(scmd
);
2636 if (ioc
->is_driver_loading
) {
2637 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
2643 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2644 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2646 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2647 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2653 * _scsih_fw_event_add - insert and queue up fw_event
2654 * @ioc: per adapter object
2655 * @fw_event: object describing the event
2656 * Context: This function will acquire ioc->fw_event_lock.
2658 * This adds the firmware event object into link list, then queues it up to
2659 * be processed from user context.
2664 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2666 unsigned long flags
;
2668 if (ioc
->firmware_event_thread
== NULL
)
2671 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2672 fw_event_work_get(fw_event
);
2673 INIT_LIST_HEAD(&fw_event
->list
);
2674 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2675 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2676 fw_event_work_get(fw_event
);
2677 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2678 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2682 * _scsih_fw_event_del_from_list - delete fw_event from the list
2683 * @ioc: per adapter object
2684 * @fw_event: object describing the event
2685 * Context: This function will acquire ioc->fw_event_lock.
2687 * If the fw_event is on the fw_event_list, remove it and do a put.
2692 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2695 unsigned long flags
;
2697 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2698 if (!list_empty(&fw_event
->list
)) {
2699 list_del_init(&fw_event
->list
);
2700 fw_event_work_put(fw_event
);
2702 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2707 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2708 * @ioc: per adapter object
2709 * @event_data: trigger event data
2714 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2715 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2717 struct fw_event_work
*fw_event
;
2720 if (ioc
->is_driver_loading
)
2722 sz
= sizeof(*event_data
);
2723 fw_event
= alloc_fw_event_work(sz
);
2726 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2727 fw_event
->ioc
= ioc
;
2728 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2729 _scsih_fw_event_add(ioc
, fw_event
);
2730 fw_event_work_put(fw_event
);
2734 * _scsih_error_recovery_delete_devices - remove devices not responding
2735 * @ioc: per adapter object
2740 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2742 struct fw_event_work
*fw_event
;
2744 if (ioc
->is_driver_loading
)
2746 fw_event
= alloc_fw_event_work(0);
2749 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2750 fw_event
->ioc
= ioc
;
2751 _scsih_fw_event_add(ioc
, fw_event
);
2752 fw_event_work_put(fw_event
);
2756 * mpt3sas_port_enable_complete - port enable completed (fake event)
2757 * @ioc: per adapter object
2762 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2764 struct fw_event_work
*fw_event
;
2766 fw_event
= alloc_fw_event_work(0);
2769 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2770 fw_event
->ioc
= ioc
;
2771 _scsih_fw_event_add(ioc
, fw_event
);
2772 fw_event_work_put(fw_event
);
2775 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
2777 unsigned long flags
;
2778 struct fw_event_work
*fw_event
= NULL
;
2780 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2781 if (!list_empty(&ioc
->fw_event_list
)) {
2782 fw_event
= list_first_entry(&ioc
->fw_event_list
,
2783 struct fw_event_work
, list
);
2784 list_del_init(&fw_event
->list
);
2786 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2792 * _scsih_fw_event_cleanup_queue - cleanup event queue
2793 * @ioc: per adapter object
2795 * Walk the firmware event queue, either killing timers, or waiting
2796 * for outstanding events to complete
2801 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2803 struct fw_event_work
*fw_event
;
2805 if (list_empty(&ioc
->fw_event_list
) ||
2806 !ioc
->firmware_event_thread
|| in_interrupt())
2809 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
2811 * Wait on the fw_event to complete. If this returns 1, then
2812 * the event was never executed, and we need a put for the
2813 * reference the work had on the fw_event.
2815 * If it did execute, we wait for it to finish, and the put will
2816 * happen from _firmware_event_work()
2818 if (cancel_work_sync(&fw_event
->work
))
2819 fw_event_work_put(fw_event
);
2821 fw_event_work_put(fw_event
);
2826 * _scsih_internal_device_block - block the sdev device
2827 * @sdev: per device object
2828 * @sas_device_priv_data : per device driver private data
2830 * make sure device is blocked without error, if not
2834 _scsih_internal_device_block(struct scsi_device
*sdev
,
2835 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2839 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
2840 sas_device_priv_data
->sas_target
->handle
);
2841 sas_device_priv_data
->block
= 1;
2843 r
= scsi_internal_device_block(sdev
);
2845 sdev_printk(KERN_WARNING
, sdev
,
2846 "device_block failed with return(%d) for handle(0x%04x)\n",
2847 r
, sas_device_priv_data
->sas_target
->handle
);
2851 * _scsih_internal_device_unblock - unblock the sdev device
2852 * @sdev: per device object
2853 * @sas_device_priv_data : per device driver private data
2854 * make sure device is unblocked without error, if not retry
2855 * by blocking and then unblocking
2859 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
2860 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2864 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
2865 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
2866 sas_device_priv_data
->block
= 0;
2867 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2869 /* The device has been set to SDEV_RUNNING by SD layer during
2870 * device addition but the request queue is still stopped by
2871 * our earlier block call. We need to perform a block again
2872 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2874 sdev_printk(KERN_WARNING
, sdev
,
2875 "device_unblock failed with return(%d) for handle(0x%04x) "
2876 "performing a block followed by an unblock\n",
2877 r
, sas_device_priv_data
->sas_target
->handle
);
2878 sas_device_priv_data
->block
= 1;
2879 r
= scsi_internal_device_block(sdev
);
2881 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
2882 "failed with return(%d) for handle(0x%04x)\n",
2883 r
, sas_device_priv_data
->sas_target
->handle
);
2885 sas_device_priv_data
->block
= 0;
2886 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2888 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
2889 " failed with return(%d) for handle(0x%04x)\n",
2890 r
, sas_device_priv_data
->sas_target
->handle
);
2895 * _scsih_ublock_io_all_device - unblock every device
2896 * @ioc: per adapter object
2898 * change the device state from block to running
2901 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2903 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2904 struct scsi_device
*sdev
;
2906 shost_for_each_device(sdev
, ioc
->shost
) {
2907 sas_device_priv_data
= sdev
->hostdata
;
2908 if (!sas_device_priv_data
)
2910 if (!sas_device_priv_data
->block
)
2913 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2914 "device_running, handle(0x%04x)\n",
2915 sas_device_priv_data
->sas_target
->handle
));
2916 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
2922 * _scsih_ublock_io_device - prepare device to be deleted
2923 * @ioc: per adapter object
2924 * @sas_addr: sas address
2926 * unblock then put device in offline state
2929 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2931 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2932 struct scsi_device
*sdev
;
2934 shost_for_each_device(sdev
, ioc
->shost
) {
2935 sas_device_priv_data
= sdev
->hostdata
;
2936 if (!sas_device_priv_data
)
2938 if (sas_device_priv_data
->sas_target
->sas_address
2941 if (sas_device_priv_data
->block
)
2942 _scsih_internal_device_unblock(sdev
,
2943 sas_device_priv_data
);
2948 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2949 * @ioc: per adapter object
2950 * @handle: device handle
2952 * During device pull we need to appropriately set the sdev state.
2955 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2957 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2958 struct scsi_device
*sdev
;
2960 shost_for_each_device(sdev
, ioc
->shost
) {
2961 sas_device_priv_data
= sdev
->hostdata
;
2962 if (!sas_device_priv_data
)
2964 if (sas_device_priv_data
->block
)
2966 if (sas_device_priv_data
->ignore_delay_remove
) {
2967 sdev_printk(KERN_INFO
, sdev
,
2968 "%s skip device_block for SES handle(0x%04x)\n",
2969 __func__
, sas_device_priv_data
->sas_target
->handle
);
2972 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2977 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2978 * @ioc: per adapter object
2979 * @handle: device handle
2981 * During device pull we need to appropriately set the sdev state.
2984 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2986 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2987 struct scsi_device
*sdev
;
2988 struct _sas_device
*sas_device
;
2990 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
2994 shost_for_each_device(sdev
, ioc
->shost
) {
2995 sas_device_priv_data
= sdev
->hostdata
;
2996 if (!sas_device_priv_data
)
2998 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3000 if (sas_device_priv_data
->block
)
3002 if (sas_device
->pend_sas_rphy_add
)
3004 if (sas_device_priv_data
->ignore_delay_remove
) {
3005 sdev_printk(KERN_INFO
, sdev
,
3006 "%s skip device_block for SES handle(0x%04x)\n",
3007 __func__
, sas_device_priv_data
->sas_target
->handle
);
3010 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3013 sas_device_put(sas_device
);
3017 * _scsih_block_io_to_children_attached_to_ex
3018 * @ioc: per adapter object
3019 * @sas_expander: the sas_device object
3021 * This routine set sdev state to SDEV_BLOCK for all devices
3022 * attached to this expander. This function called when expander is
3026 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3027 struct _sas_node
*sas_expander
)
3029 struct _sas_port
*mpt3sas_port
;
3030 struct _sas_device
*sas_device
;
3031 struct _sas_node
*expander_sibling
;
3032 unsigned long flags
;
3037 list_for_each_entry(mpt3sas_port
,
3038 &sas_expander
->sas_port_list
, port_list
) {
3039 if (mpt3sas_port
->remote_identify
.device_type
==
3041 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3042 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3043 mpt3sas_port
->remote_identify
.sas_address
);
3045 set_bit(sas_device
->handle
,
3046 ioc
->blocking_handles
);
3047 sas_device_put(sas_device
);
3049 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3053 list_for_each_entry(mpt3sas_port
,
3054 &sas_expander
->sas_port_list
, port_list
) {
3056 if (mpt3sas_port
->remote_identify
.device_type
==
3057 SAS_EDGE_EXPANDER_DEVICE
||
3058 mpt3sas_port
->remote_identify
.device_type
==
3059 SAS_FANOUT_EXPANDER_DEVICE
) {
3061 mpt3sas_scsih_expander_find_by_sas_address(
3062 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3063 _scsih_block_io_to_children_attached_to_ex(ioc
,
3070 * _scsih_block_io_to_children_attached_directly
3071 * @ioc: per adapter object
3072 * @event_data: topology change event data
3074 * This routine set sdev state to SDEV_BLOCK for all devices
3075 * direct attached during device pull.
3078 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3079 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3085 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3086 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3089 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3090 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3091 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3092 _scsih_block_io_device(ioc
, handle
);
3097 * _scsih_tm_tr_send - send task management request
3098 * @ioc: per adapter object
3099 * @handle: device handle
3100 * Context: interrupt time.
3102 * This code is to initiate the device removal handshake protocol
3103 * with controller firmware. This function will issue target reset
3104 * using high priority request queue. It will send a sas iounit
3105 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3107 * This is designed to send muliple task management request at the same
3108 * time to the fifo. If the fifo is full, we will append the request,
3109 * and process it in a future completion.
3112 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3114 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3116 struct _sas_device
*sas_device
= NULL
;
3117 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3118 u64 sas_address
= 0;
3119 unsigned long flags
;
3120 struct _tr_list
*delayed_tr
;
3123 if (ioc
->remove_host
) {
3124 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3125 "%s: host has been removed: handle(0x%04x)\n",
3126 __func__
, ioc
->name
, handle
));
3128 } else if (ioc
->pci_error_recovery
) {
3129 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3130 "%s: host in pci error recovery: handle(0x%04x)\n",
3131 __func__
, ioc
->name
,
3135 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3136 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3137 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3138 "%s: host is not operational: handle(0x%04x)\n",
3139 __func__
, ioc
->name
,
3144 /* if PD, then return */
3145 if (test_bit(handle
, ioc
->pd_handles
))
3148 clear_bit(handle
, ioc
->pend_os_device_add
);
3150 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3151 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3152 if (sas_device
&& sas_device
->starget
&&
3153 sas_device
->starget
->hostdata
) {
3154 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3155 sas_target_priv_data
->deleted
= 1;
3156 sas_address
= sas_device
->sas_address
;
3158 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3160 if (sas_target_priv_data
) {
3161 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3162 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3164 (unsigned long long)sas_address
));
3165 if (sas_device
->enclosure_handle
!= 0)
3166 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3167 "setting delete flag:enclosure logical id(0x%016llx),"
3168 " slot(%d)\n", ioc
->name
, (unsigned long long)
3169 sas_device
->enclosure_logical_id
,
3171 if (sas_device
->connector_name
[0] != '\0')
3172 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3173 "setting delete flag: enclosure level(0x%04x),"
3174 " connector name( %s)\n", ioc
->name
,
3175 sas_device
->enclosure_level
,
3176 sas_device
->connector_name
));
3177 _scsih_ublock_io_device(ioc
, sas_address
);
3178 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3181 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3183 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3186 INIT_LIST_HEAD(&delayed_tr
->list
);
3187 delayed_tr
->handle
= handle
;
3188 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3189 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3190 "DELAYED:tr:handle(0x%04x), (open)\n",
3191 ioc
->name
, handle
));
3195 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3196 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3197 ioc
->name
, handle
, smid
,
3198 ioc
->tm_tr_cb_idx
));
3199 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3200 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3201 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3202 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3203 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3204 set_bit(handle
, ioc
->device_remove_in_progress
);
3205 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3206 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3210 sas_device_put(sas_device
);
3214 * _scsih_tm_tr_complete -
3215 * @ioc: per adapter object
3216 * @smid: system request message index
3217 * @msix_index: MSIX table index supplied by the OS
3218 * @reply: reply message frame(lower 32bit addr)
3219 * Context: interrupt time.
3221 * This is the target reset completion routine.
3222 * This code is part of the code to initiate the device removal
3223 * handshake protocol with controller firmware.
3224 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3226 * Return 1 meaning mf should be freed from _base_interrupt
3227 * 0 means the mf is freed from this function.
3230 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3234 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3235 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3236 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3237 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3240 struct _sc_list
*delayed_sc
;
3242 if (ioc
->remove_host
) {
3243 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3244 "%s: host has been removed\n", __func__
, ioc
->name
));
3246 } else if (ioc
->pci_error_recovery
) {
3247 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3248 "%s: host in pci error recovery\n", __func__
,
3252 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3253 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3254 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3255 "%s: host is not operational\n", __func__
, ioc
->name
));
3258 if (unlikely(!mpi_reply
)) {
3259 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3260 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3263 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3264 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3265 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3266 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3267 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3269 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3273 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3274 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3275 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3276 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3277 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3278 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3279 le32_to_cpu(mpi_reply
->TerminationCount
)));
3281 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3282 if (!smid_sas_ctrl
) {
3283 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3285 return _scsih_check_for_pending_tm(ioc
, smid
);
3286 INIT_LIST_HEAD(&delayed_sc
->list
);
3287 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3288 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3289 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3290 "DELAYED:sc:handle(0x%04x), (open)\n",
3291 ioc
->name
, handle
));
3292 return _scsih_check_for_pending_tm(ioc
, smid
);
3295 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3296 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3297 ioc
->name
, handle
, smid_sas_ctrl
,
3298 ioc
->tm_sas_control_cb_idx
));
3299 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3300 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3301 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3302 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3303 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3304 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3306 return _scsih_check_for_pending_tm(ioc
, smid
);
3311 * _scsih_sas_control_complete - completion routine
3312 * @ioc: per adapter object
3313 * @smid: system request message index
3314 * @msix_index: MSIX table index supplied by the OS
3315 * @reply: reply message frame(lower 32bit addr)
3316 * Context: interrupt time.
3318 * This is the sas iounit control completion routine.
3319 * This code is part of the code to initiate the device removal
3320 * handshake protocol with controller firmware.
3322 * Return 1 meaning mf should be freed from _base_interrupt
3323 * 0 means the mf is freed from this function.
3326 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3327 u8 msix_index
, u32 reply
)
3329 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3330 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3332 if (likely(mpi_reply
)) {
3333 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3334 "sc_complete:handle(0x%04x), (open) "
3335 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3336 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3337 le16_to_cpu(mpi_reply
->IOCStatus
),
3338 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3339 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3340 MPI2_IOCSTATUS_SUCCESS
) {
3341 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3342 ioc
->device_remove_in_progress
);
3345 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3346 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3348 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3352 * _scsih_tm_tr_volume_send - send target reset request for volumes
3353 * @ioc: per adapter object
3354 * @handle: device handle
3355 * Context: interrupt time.
3357 * This is designed to send muliple task management request at the same
3358 * time to the fifo. If the fifo is full, we will append the request,
3359 * and process it in a future completion.
3362 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3364 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3366 struct _tr_list
*delayed_tr
;
3368 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3369 ioc
->pci_error_recovery
) {
3370 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3371 "%s: host reset in progress!\n",
3372 __func__
, ioc
->name
));
3376 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3378 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3381 INIT_LIST_HEAD(&delayed_tr
->list
);
3382 delayed_tr
->handle
= handle
;
3383 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3384 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3385 "DELAYED:tr:handle(0x%04x), (open)\n",
3386 ioc
->name
, handle
));
3390 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3391 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3392 ioc
->name
, handle
, smid
,
3393 ioc
->tm_tr_volume_cb_idx
));
3394 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3395 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3396 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3397 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3398 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3399 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3403 * _scsih_tm_volume_tr_complete - target reset completion
3404 * @ioc: per adapter object
3405 * @smid: system request message index
3406 * @msix_index: MSIX table index supplied by the OS
3407 * @reply: reply message frame(lower 32bit addr)
3408 * Context: interrupt time.
3410 * Return 1 meaning mf should be freed from _base_interrupt
3411 * 0 means the mf is freed from this function.
3414 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3415 u8 msix_index
, u32 reply
)
3418 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3419 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3420 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3422 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3423 ioc
->pci_error_recovery
) {
3424 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3425 "%s: host reset in progress!\n",
3426 __func__
, ioc
->name
));
3429 if (unlikely(!mpi_reply
)) {
3430 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3431 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3435 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3436 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3437 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3438 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3439 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3441 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3445 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3446 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3447 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3448 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3449 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3450 le32_to_cpu(mpi_reply
->TerminationCount
)));
3452 return _scsih_check_for_pending_tm(ioc
, smid
);
3456 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3457 * @ioc: per adapter object
3458 * @smid: system request message index
3460 * @event_context: used to track events uniquely
3462 * Context - processed in interrupt context.
3465 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
3468 Mpi2EventAckRequest_t
*ack_request
;
3469 int i
= smid
- ioc
->internal_smid
;
3470 unsigned long flags
;
3472 /* Without releasing the smid just update the
3473 * call back index and reuse the same smid for
3474 * processing this delayed request
3476 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3477 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3478 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3480 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3481 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3482 ioc
->name
, le16_to_cpu(event
), smid
,
3484 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3485 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3486 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3487 ack_request
->Event
= event
;
3488 ack_request
->EventContext
= event_context
;
3489 ack_request
->VF_ID
= 0; /* TODO */
3490 ack_request
->VP_ID
= 0;
3491 ioc
->put_smid_default(ioc
, smid
);
3495 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3496 * sas_io_unit_ctrl messages
3497 * @ioc: per adapter object
3498 * @smid: system request message index
3499 * @handle: device handle
3501 * Context - processed in interrupt context.
3504 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
3505 u16 smid
, u16 handle
)
3507 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3509 int i
= smid
- ioc
->internal_smid
;
3510 unsigned long flags
;
3512 if (ioc
->remove_host
) {
3513 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3514 "%s: host has been removed\n",
3515 __func__
, ioc
->name
));
3517 } else if (ioc
->pci_error_recovery
) {
3518 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3519 "%s: host in pci error recovery\n",
3520 __func__
, ioc
->name
));
3523 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3524 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3525 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3526 "%s: host is not operational\n",
3527 __func__
, ioc
->name
));
3531 /* Without releasing the smid just update the
3532 * call back index and reuse the same smid for
3533 * processing this delayed request
3535 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3536 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
3537 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3539 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3540 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3541 ioc
->name
, le16_to_cpu(handle
), smid
,
3542 ioc
->tm_sas_control_cb_idx
));
3543 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3544 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3545 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3546 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3547 mpi_request
->DevHandle
= handle
;
3548 ioc
->put_smid_default(ioc
, smid
);
3552 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3553 * @ioc: per adapter object
3554 * @smid: system request message index
3556 * Context: Executed in interrupt context
3558 * This will check delayed internal messages list, and process the
3561 * Return 1 meaning mf should be freed from _base_interrupt
3562 * 0 means the mf is freed from this function.
3565 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3567 struct _sc_list
*delayed_sc
;
3568 struct _event_ack_list
*delayed_event_ack
;
3570 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
3571 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
3572 struct _event_ack_list
, list
);
3573 _scsih_issue_delayed_event_ack(ioc
, smid
,
3574 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
3575 list_del(&delayed_event_ack
->list
);
3576 kfree(delayed_event_ack
);
3580 if (!list_empty(&ioc
->delayed_sc_list
)) {
3581 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
3582 struct _sc_list
, list
);
3583 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
3584 delayed_sc
->handle
);
3585 list_del(&delayed_sc
->list
);
3593 * _scsih_check_for_pending_tm - check for pending task management
3594 * @ioc: per adapter object
3595 * @smid: system request message index
3597 * This will check delayed target reset list, and feed the
3600 * Return 1 meaning mf should be freed from _base_interrupt
3601 * 0 means the mf is freed from this function.
3604 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3606 struct _tr_list
*delayed_tr
;
3608 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3609 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3610 struct _tr_list
, list
);
3611 mpt3sas_base_free_smid(ioc
, smid
);
3612 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3613 list_del(&delayed_tr
->list
);
3618 if (!list_empty(&ioc
->delayed_tr_list
)) {
3619 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3620 struct _tr_list
, list
);
3621 mpt3sas_base_free_smid(ioc
, smid
);
3622 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3623 list_del(&delayed_tr
->list
);
3632 * _scsih_check_topo_delete_events - sanity check on topo events
3633 * @ioc: per adapter object
3634 * @event_data: the event data payload
3636 * This routine added to better handle cable breaker.
3638 * This handles the case where driver receives multiple expander
3639 * add and delete events in a single shot. When there is a delete event
3640 * the routine will void any pending add events waiting in the event queue.
3645 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3646 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3648 struct fw_event_work
*fw_event
;
3649 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3650 u16 expander_handle
;
3651 struct _sas_node
*sas_expander
;
3652 unsigned long flags
;
3656 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3657 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3660 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3661 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3662 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3663 _scsih_tm_tr_send(ioc
, handle
);
3666 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3667 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3668 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3671 if (event_data
->ExpStatus
==
3672 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3673 /* put expander attached devices into blocking state */
3674 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3675 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3677 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3678 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3680 handle
= find_first_bit(ioc
->blocking_handles
,
3681 ioc
->facts
.MaxDevHandle
);
3682 if (handle
< ioc
->facts
.MaxDevHandle
)
3683 _scsih_block_io_device(ioc
, handle
);
3684 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3685 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3686 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3688 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3691 /* mark ignore flag for pending events */
3692 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3693 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3694 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3697 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3698 fw_event
->event_data
;
3699 if (local_event_data
->ExpStatus
==
3700 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3701 local_event_data
->ExpStatus
==
3702 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3703 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3705 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3706 "setting ignoring flag\n", ioc
->name
));
3707 fw_event
->ignore
= 1;
3711 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3715 * _scsih_set_volume_delete_flag - setting volume delete flag
3716 * @ioc: per adapter object
3717 * @handle: device handle
3719 * This returns nothing.
3722 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3724 struct _raid_device
*raid_device
;
3725 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3726 unsigned long flags
;
3728 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3729 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
3730 if (raid_device
&& raid_device
->starget
&&
3731 raid_device
->starget
->hostdata
) {
3732 sas_target_priv_data
=
3733 raid_device
->starget
->hostdata
;
3734 sas_target_priv_data
->deleted
= 1;
3735 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3736 "setting delete flag: handle(0x%04x), "
3737 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3738 (unsigned long long) raid_device
->wwid
));
3740 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3744 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3745 * @handle: input handle
3746 * @a: handle for volume a
3747 * @b: handle for volume b
3749 * IR firmware only supports two raid volumes. The purpose of this
3750 * routine is to set the volume handle in either a or b. When the given
3751 * input handle is non-zero, or when a and b have not been set before.
3754 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3756 if (!handle
|| handle
== *a
|| handle
== *b
)
3765 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3766 * @ioc: per adapter object
3767 * @event_data: the event data payload
3768 * Context: interrupt time.
3770 * This routine will send target reset to volume, followed by target
3771 * resets to the PDs. This is called when a PD has been removed, or
3772 * volume has been deleted or removed. When the target reset is sent
3773 * to volume, the PD target resets need to be queued to start upon
3774 * completion of the volume target reset.
3779 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3780 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3782 Mpi2EventIrConfigElement_t
*element
;
3784 u16 handle
, volume_handle
, a
, b
;
3785 struct _tr_list
*delayed_tr
;
3790 if (ioc
->is_warpdrive
)
3793 /* Volume Resets for Deleted or Removed */
3794 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3795 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3796 if (le32_to_cpu(event_data
->Flags
) &
3797 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3799 if (element
->ReasonCode
==
3800 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3801 element
->ReasonCode
==
3802 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3803 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3804 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3805 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3809 /* Volume Resets for UNHIDE events */
3810 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3811 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3812 if (le32_to_cpu(event_data
->Flags
) &
3813 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3815 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3816 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3817 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3822 _scsih_tm_tr_volume_send(ioc
, a
);
3824 _scsih_tm_tr_volume_send(ioc
, b
);
3826 /* PD target resets */
3827 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3828 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3829 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3831 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3832 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3833 clear_bit(handle
, ioc
->pd_handles
);
3835 _scsih_tm_tr_send(ioc
, handle
);
3836 else if (volume_handle
== a
|| volume_handle
== b
) {
3837 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3838 BUG_ON(!delayed_tr
);
3839 INIT_LIST_HEAD(&delayed_tr
->list
);
3840 delayed_tr
->handle
= handle
;
3841 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3842 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3843 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3846 _scsih_tm_tr_send(ioc
, handle
);
3852 * _scsih_check_volume_delete_events - set delete flag for volumes
3853 * @ioc: per adapter object
3854 * @event_data: the event data payload
3855 * Context: interrupt time.
3857 * This will handle the case when the cable connected to entire volume is
3858 * pulled. We will take care of setting the deleted flag so normal IO will
3864 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3865 Mpi2EventDataIrVolume_t
*event_data
)
3869 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3871 state
= le32_to_cpu(event_data
->NewValue
);
3872 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3873 MPI2_RAID_VOL_STATE_FAILED
)
3874 _scsih_set_volume_delete_flag(ioc
,
3875 le16_to_cpu(event_data
->VolDevHandle
));
3879 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3880 * @ioc: per adapter object
3881 * @event_data: the temp threshold event data
3882 * Context: interrupt time.
3887 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
3888 Mpi2EventDataTemperature_t
*event_data
)
3890 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3891 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
3892 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3893 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3894 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3895 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3896 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3897 event_data
->SensorNum
);
3898 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
3899 ioc
->name
, event_data
->CurrentTemperature
);
3903 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
3905 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
3907 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
3911 return test_and_set_bit(0, &priv
->ata_command_pending
);
3913 clear_bit(0, &priv
->ata_command_pending
);
3918 * _scsih_flush_running_cmds - completing outstanding commands.
3919 * @ioc: per adapter object
3921 * The flushing out of all pending scmd commands following host reset,
3922 * where all IO is dropped to the floor.
3927 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3929 struct scsi_cmnd
*scmd
;
3933 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3934 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3938 _scsih_set_satl_pending(scmd
, false);
3939 mpt3sas_base_free_smid(ioc
, smid
);
3940 scsi_dma_unmap(scmd
);
3941 if (ioc
->pci_error_recovery
)
3942 scmd
->result
= DID_NO_CONNECT
<< 16;
3944 scmd
->result
= DID_RESET
<< 16;
3945 scmd
->scsi_done(scmd
);
3947 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3952 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3953 * @ioc: per adapter object
3954 * @scmd: pointer to scsi command object
3955 * @mpi_request: pointer to the SCSI_IO request message frame
3957 * Supporting protection 1 and 3.
3962 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3963 Mpi2SCSIIORequest_t
*mpi_request
)
3966 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3967 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3968 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3969 (Mpi25SCSIIORequest_t
*)mpi_request
;
3971 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3974 if (prot_op
== SCSI_PROT_READ_STRIP
)
3975 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3976 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3977 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3981 switch (prot_type
) {
3982 case SCSI_PROT_DIF_TYPE1
:
3983 case SCSI_PROT_DIF_TYPE2
:
3986 * enable ref/guard checking
3987 * auto increment ref tag
3989 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3990 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3991 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3992 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3993 cpu_to_be32(scsi_prot_ref_tag(scmd
));
3996 case SCSI_PROT_DIF_TYPE3
:
3999 * enable guard checking
4001 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4006 mpi_request_3v
->EEDPBlockSize
=
4007 cpu_to_le16(scmd
->device
->sector_size
);
4009 if (ioc
->is_gen35_ioc
)
4010 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4011 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4015 * _scsih_eedp_error_handling - return sense code for EEDP errors
4016 * @scmd: pointer to scsi command object
4017 * @ioc_status: ioc status
4022 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4026 switch (ioc_status
) {
4027 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4030 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4033 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4040 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4042 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4043 SAM_STAT_CHECK_CONDITION
;
4047 * scsih_qcmd - main scsi request entry point
4048 * @scmd: pointer to scsi command object
4049 * @done: function pointer to be invoked on completion
4051 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4053 * Returns 0 on success. If there's a failure, return either:
4054 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4055 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4058 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4060 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4061 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4062 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4063 struct _raid_device
*raid_device
;
4064 struct request
*rq
= scmd
->request
;
4066 Mpi2SCSIIORequest_t
*mpi_request
;
4071 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4072 scsi_print_command(scmd
);
4074 sas_device_priv_data
= scmd
->device
->hostdata
;
4075 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4076 scmd
->result
= DID_NO_CONNECT
<< 16;
4077 scmd
->scsi_done(scmd
);
4081 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
4082 scmd
->result
= DID_NO_CONNECT
<< 16;
4083 scmd
->scsi_done(scmd
);
4088 * Bug work around for firmware SATL handling. The loop
4089 * is based on atomic operations and ensures consistency
4090 * since we're lockless at this point
4093 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
)) {
4094 scmd
->result
= SAM_STAT_BUSY
;
4095 scmd
->scsi_done(scmd
);
4098 } while (_scsih_set_satl_pending(scmd
, true));
4100 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4102 /* invalid device handle */
4103 handle
= sas_target_priv_data
->handle
;
4104 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4105 scmd
->result
= DID_NO_CONNECT
<< 16;
4106 scmd
->scsi_done(scmd
);
4111 /* host recovery or link resets sent via IOCTLs */
4112 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4113 return SCSI_MLQUEUE_HOST_BUSY
;
4115 /* device has been deleted */
4116 else if (sas_target_priv_data
->deleted
) {
4117 scmd
->result
= DID_NO_CONNECT
<< 16;
4118 scmd
->scsi_done(scmd
);
4120 /* device busy with task management */
4121 } else if (sas_target_priv_data
->tm_busy
||
4122 sas_device_priv_data
->block
)
4123 return SCSI_MLQUEUE_DEVICE_BUSY
;
4125 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4126 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4127 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4128 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4130 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4133 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4134 /* NCQ Prio supported, make sure control indicated high priority */
4135 if (sas_device_priv_data
->ncq_prio_enable
) {
4136 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4137 if (class == IOPRIO_CLASS_RT
)
4138 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4140 /* Make sure Device is not raid volume.
4141 * We do not expose raid functionality to upper layer for warpdrive.
4143 if (!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
)
4144 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4145 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4147 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4149 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4150 ioc
->name
, __func__
);
4153 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4154 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
4155 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4157 if (scmd
->cmd_len
== 32)
4158 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4159 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4160 if (sas_device_priv_data
->sas_target
->flags
&
4161 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4162 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4164 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4165 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4166 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4167 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4168 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4169 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4170 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4171 mpi_request
->SenseBufferLowAddress
=
4172 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4173 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4174 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4176 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4178 if (mpi_request
->DataLength
) {
4179 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
4180 mpt3sas_base_free_smid(ioc
, smid
);
4184 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4186 raid_device
= sas_target_priv_data
->raid_device
;
4187 if (raid_device
&& raid_device
->direct_io_enabled
)
4188 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4191 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4192 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4193 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4194 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4195 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4197 ioc
->put_smid_scsi_io(ioc
, smid
,
4198 le16_to_cpu(mpi_request
->DevHandle
));
4200 ioc
->put_smid_default(ioc
, smid
);
4204 return SCSI_MLQUEUE_HOST_BUSY
;
4208 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4209 * @sense_buffer: sense data returned by target
4210 * @data: normalized skey/asc/ascq
4215 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4217 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4218 /* descriptor format */
4219 data
->skey
= sense_buffer
[1] & 0x0F;
4220 data
->asc
= sense_buffer
[2];
4221 data
->ascq
= sense_buffer
[3];
4224 data
->skey
= sense_buffer
[2] & 0x0F;
4225 data
->asc
= sense_buffer
[12];
4226 data
->ascq
= sense_buffer
[13];
4231 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4232 * @ioc: per adapter object
4233 * @scmd: pointer to scsi command object
4234 * @mpi_reply: reply mf payload returned from firmware
4236 * scsi_status - SCSI Status code returned from target device
4237 * scsi_state - state info associated with SCSI_IO determined by ioc
4238 * ioc_status - ioc supplied status info
4243 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4244 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4248 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4249 MPI2_IOCSTATUS_MASK
;
4250 u8 scsi_state
= mpi_reply
->SCSIState
;
4251 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4252 char *desc_ioc_state
= NULL
;
4253 char *desc_scsi_status
= NULL
;
4254 char *desc_scsi_state
= ioc
->tmp_string
;
4255 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4256 struct _sas_device
*sas_device
= NULL
;
4257 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4258 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4259 char *device_str
= NULL
;
4263 if (ioc
->hide_ir_msg
)
4264 device_str
= "WarpDrive";
4266 device_str
= "volume";
4268 if (log_info
== 0x31170000)
4271 switch (ioc_status
) {
4272 case MPI2_IOCSTATUS_SUCCESS
:
4273 desc_ioc_state
= "success";
4275 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4276 desc_ioc_state
= "invalid function";
4278 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4279 desc_ioc_state
= "scsi recovered error";
4281 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4282 desc_ioc_state
= "scsi invalid dev handle";
4284 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4285 desc_ioc_state
= "scsi device not there";
4287 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4288 desc_ioc_state
= "scsi data overrun";
4290 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4291 desc_ioc_state
= "scsi data underrun";
4293 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4294 desc_ioc_state
= "scsi io data error";
4296 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4297 desc_ioc_state
= "scsi protocol error";
4299 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4300 desc_ioc_state
= "scsi task terminated";
4302 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4303 desc_ioc_state
= "scsi residual mismatch";
4305 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4306 desc_ioc_state
= "scsi task mgmt failed";
4308 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4309 desc_ioc_state
= "scsi ioc terminated";
4311 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4312 desc_ioc_state
= "scsi ext terminated";
4314 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4315 desc_ioc_state
= "eedp guard error";
4317 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4318 desc_ioc_state
= "eedp ref tag error";
4320 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4321 desc_ioc_state
= "eedp app tag error";
4323 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4324 desc_ioc_state
= "insufficient power";
4327 desc_ioc_state
= "unknown";
4331 switch (scsi_status
) {
4332 case MPI2_SCSI_STATUS_GOOD
:
4333 desc_scsi_status
= "good";
4335 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4336 desc_scsi_status
= "check condition";
4338 case MPI2_SCSI_STATUS_CONDITION_MET
:
4339 desc_scsi_status
= "condition met";
4341 case MPI2_SCSI_STATUS_BUSY
:
4342 desc_scsi_status
= "busy";
4344 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4345 desc_scsi_status
= "intermediate";
4347 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4348 desc_scsi_status
= "intermediate condmet";
4350 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4351 desc_scsi_status
= "reservation conflict";
4353 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4354 desc_scsi_status
= "command terminated";
4356 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4357 desc_scsi_status
= "task set full";
4359 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4360 desc_scsi_status
= "aca active";
4362 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4363 desc_scsi_status
= "task aborted";
4366 desc_scsi_status
= "unknown";
4370 desc_scsi_state
[0] = '\0';
4372 desc_scsi_state
= " ";
4373 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4374 strcat(desc_scsi_state
, "response info ");
4375 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4376 strcat(desc_scsi_state
, "state terminated ");
4377 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4378 strcat(desc_scsi_state
, "no status ");
4379 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4380 strcat(desc_scsi_state
, "autosense failed ");
4381 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4382 strcat(desc_scsi_state
, "autosense valid ");
4384 scsi_print_command(scmd
);
4386 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4387 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4388 device_str
, (unsigned long long)priv_target
->sas_address
);
4390 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4393 "\tsas_address(0x%016llx), phy(%d)\n",
4394 ioc
->name
, (unsigned long long)
4395 sas_device
->sas_address
, sas_device
->phy
);
4396 if (sas_device
->enclosure_handle
!= 0)
4398 "\tenclosure_logical_id(0x%016llx),"
4399 "slot(%d)\n", ioc
->name
,
4400 (unsigned long long)
4401 sas_device
->enclosure_logical_id
,
4403 if (sas_device
->connector_name
[0])
4405 "\tenclosure level(0x%04x),"
4406 " connector name( %s)\n", ioc
->name
,
4407 sas_device
->enclosure_level
,
4408 sas_device
->connector_name
);
4410 sas_device_put(sas_device
);
4415 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4416 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4417 desc_ioc_state
, ioc_status
, smid
);
4419 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4420 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4421 scsi_get_resid(scmd
));
4423 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4424 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4425 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4427 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4428 ioc
->name
, desc_scsi_status
,
4429 scsi_status
, desc_scsi_state
, scsi_state
);
4431 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4432 struct sense_info data
;
4433 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4435 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4436 ioc
->name
, data
.skey
,
4437 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4440 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4441 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4442 response_bytes
= (u8
*)&response_info
;
4443 _scsih_response_code(ioc
, response_bytes
[0]);
4448 * _scsih_turn_on_pfa_led - illuminate PFA LED
4449 * @ioc: per adapter object
4450 * @handle: device handle
4456 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4458 Mpi2SepReply_t mpi_reply
;
4459 Mpi2SepRequest_t mpi_request
;
4460 struct _sas_device
*sas_device
;
4462 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4466 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4467 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4468 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4469 mpi_request
.SlotStatus
=
4470 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4471 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4472 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4473 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4474 &mpi_request
)) != 0) {
4475 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4476 __FILE__
, __LINE__
, __func__
);
4479 sas_device
->pfa_led_on
= 1;
4481 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4482 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4483 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4484 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4485 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4489 sas_device_put(sas_device
);
4493 * _scsih_turn_off_pfa_led - turn off Fault LED
4494 * @ioc: per adapter object
4495 * @sas_device: sas device whose PFA LED has to turned off
4501 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4502 struct _sas_device
*sas_device
)
4504 Mpi2SepReply_t mpi_reply
;
4505 Mpi2SepRequest_t mpi_request
;
4507 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4508 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4509 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4510 mpi_request
.SlotStatus
= 0;
4511 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4512 mpi_request
.DevHandle
= 0;
4513 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4514 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4515 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4516 &mpi_request
)) != 0) {
4517 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4518 __FILE__
, __LINE__
, __func__
);
4522 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4523 dewtprintk(ioc
, printk(MPT3SAS_FMT
4524 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4525 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4526 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4532 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4533 * @ioc: per adapter object
4534 * @handle: device handle
4535 * Context: interrupt.
4540 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4542 struct fw_event_work
*fw_event
;
4544 fw_event
= alloc_fw_event_work(0);
4547 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4548 fw_event
->device_handle
= handle
;
4549 fw_event
->ioc
= ioc
;
4550 _scsih_fw_event_add(ioc
, fw_event
);
4551 fw_event_work_put(fw_event
);
4555 * _scsih_smart_predicted_fault - process smart errors
4556 * @ioc: per adapter object
4557 * @handle: device handle
4558 * Context: interrupt.
4563 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4565 struct scsi_target
*starget
;
4566 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4567 Mpi2EventNotificationReply_t
*event_reply
;
4568 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4569 struct _sas_device
*sas_device
;
4571 unsigned long flags
;
4573 /* only handle non-raid devices */
4574 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4575 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
4579 starget
= sas_device
->starget
;
4580 sas_target_priv_data
= starget
->hostdata
;
4582 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4583 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
4586 if (sas_device
->enclosure_handle
!= 0)
4587 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4588 "enclosure logical id(0x%016llx), slot(%d)\n",
4589 (unsigned long long)sas_device
->enclosure_logical_id
,
4591 if (sas_device
->connector_name
[0] != '\0')
4592 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4593 "enclosure level(0x%04x), connector name( %s)\n",
4594 sas_device
->enclosure_level
,
4595 sas_device
->connector_name
);
4596 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4598 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4599 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4601 /* insert into event log */
4602 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4603 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4604 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4606 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4607 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4611 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4612 event_reply
->Event
=
4613 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4614 event_reply
->MsgLength
= sz
/4;
4615 event_reply
->EventDataLength
=
4616 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4617 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4618 event_reply
->EventData
;
4619 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4620 event_data
->ASC
= 0x5D;
4621 event_data
->DevHandle
= cpu_to_le16(handle
);
4622 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4623 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4627 sas_device_put(sas_device
);
4631 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4636 * _scsih_io_done - scsi request callback
4637 * @ioc: per adapter object
4638 * @smid: system request message index
4639 * @msix_index: MSIX table index supplied by the OS
4640 * @reply: reply message frame(lower 32bit addr)
4642 * Callback handler when using _scsih_qcmd.
4644 * Return 1 meaning mf should be freed from _base_interrupt
4645 * 0 means the mf is freed from this function.
4648 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4650 Mpi2SCSIIORequest_t
*mpi_request
;
4651 Mpi2SCSIIOReply_t
*mpi_reply
;
4652 struct scsi_cmnd
*scmd
;
4658 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4659 u32 response_code
= 0;
4660 unsigned long flags
;
4661 unsigned int sector_sz
;
4663 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4664 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4668 _scsih_set_satl_pending(scmd
, false);
4670 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4672 if (mpi_reply
== NULL
) {
4673 scmd
->result
= DID_OK
<< 16;
4677 sas_device_priv_data
= scmd
->device
->hostdata
;
4678 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4679 sas_device_priv_data
->sas_target
->deleted
) {
4680 scmd
->result
= DID_NO_CONNECT
<< 16;
4683 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4686 * WARPDRIVE: If direct_io is set then it is directIO,
4687 * the failed direct I/O should be redirected to volume
4689 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
4690 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4691 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4692 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4693 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4694 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4695 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
4696 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4697 mpi_request
->DevHandle
=
4698 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4699 ioc
->put_smid_scsi_io(ioc
, smid
,
4700 sas_device_priv_data
->sas_target
->handle
);
4703 /* turning off TLR */
4704 scsi_state
= mpi_reply
->SCSIState
;
4705 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4707 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4708 if (!sas_device_priv_data
->tlr_snoop_check
) {
4709 sas_device_priv_data
->tlr_snoop_check
++;
4710 if (!ioc
->is_warpdrive
&&
4711 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4712 sas_is_tlr_enabled(scmd
->device
) &&
4713 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4714 sas_disable_tlr(scmd
->device
);
4715 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4719 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4721 /* In case of bogus fw or device, we could end up having
4722 * unaligned partial completion. We can force alignment here,
4723 * then scsi-ml does not need to handle this misbehavior.
4725 sector_sz
= scmd
->device
->sector_size
;
4726 if (unlikely(scmd
->request
->cmd_type
== REQ_TYPE_FS
&& sector_sz
&&
4727 xfer_cnt
% sector_sz
)) {
4728 sdev_printk(KERN_INFO
, scmd
->device
,
4729 "unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4730 xfer_cnt
, sector_sz
);
4731 xfer_cnt
= round_down(xfer_cnt
, sector_sz
);
4734 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4735 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4736 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4739 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4740 scsi_status
= mpi_reply
->SCSIStatus
;
4742 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4743 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4744 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4745 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4746 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4749 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4750 struct sense_info data
;
4751 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4753 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4754 le32_to_cpu(mpi_reply
->SenseCount
));
4755 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4756 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4757 /* failure prediction threshold exceeded */
4758 if (data
.asc
== 0x5D)
4759 _scsih_smart_predicted_fault(ioc
,
4760 le16_to_cpu(mpi_reply
->DevHandle
));
4761 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4763 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4764 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4765 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4766 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4767 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4769 switch (ioc_status
) {
4770 case MPI2_IOCSTATUS_BUSY
:
4771 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4772 scmd
->result
= SAM_STAT_BUSY
;
4775 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4776 scmd
->result
= DID_NO_CONNECT
<< 16;
4779 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4780 if (sas_device_priv_data
->block
) {
4781 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4784 if (log_info
== 0x31110630) {
4785 if (scmd
->retries
> 2) {
4786 scmd
->result
= DID_NO_CONNECT
<< 16;
4787 scsi_device_set_state(scmd
->device
,
4790 scmd
->result
= DID_SOFT_ERROR
<< 16;
4791 scmd
->device
->expecting_cc_ua
= 1;
4794 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4795 scmd
->result
= DID_RESET
<< 16;
4798 scmd
->result
= DID_SOFT_ERROR
<< 16;
4800 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4801 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4802 scmd
->result
= DID_RESET
<< 16;
4805 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4806 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4807 scmd
->result
= DID_SOFT_ERROR
<< 16;
4809 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4812 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4813 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4815 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4818 if (xfer_cnt
< scmd
->underflow
) {
4819 if (scsi_status
== SAM_STAT_BUSY
)
4820 scmd
->result
= SAM_STAT_BUSY
;
4822 scmd
->result
= DID_SOFT_ERROR
<< 16;
4823 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4824 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4825 scmd
->result
= DID_SOFT_ERROR
<< 16;
4826 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4827 scmd
->result
= DID_RESET
<< 16;
4828 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4829 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4830 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4831 scmd
->result
= (DRIVER_SENSE
<< 24) |
4832 SAM_STAT_CHECK_CONDITION
;
4833 scmd
->sense_buffer
[0] = 0x70;
4834 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4835 scmd
->sense_buffer
[12] = 0x20;
4836 scmd
->sense_buffer
[13] = 0;
4840 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4841 scsi_set_resid(scmd
, 0);
4842 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4843 case MPI2_IOCSTATUS_SUCCESS
:
4844 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4845 if (response_code
==
4846 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4847 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4848 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4849 scmd
->result
= DID_SOFT_ERROR
<< 16;
4850 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4851 scmd
->result
= DID_RESET
<< 16;
4854 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4855 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4856 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4857 _scsih_eedp_error_handling(scmd
, ioc_status
);
4860 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4861 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4862 case MPI2_IOCSTATUS_INVALID_SGL
:
4863 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4864 case MPI2_IOCSTATUS_INVALID_FIELD
:
4865 case MPI2_IOCSTATUS_INVALID_STATE
:
4866 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4867 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4868 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4870 scmd
->result
= DID_SOFT_ERROR
<< 16;
4875 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4876 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4880 scsi_dma_unmap(scmd
);
4882 scmd
->scsi_done(scmd
);
4887 * _scsih_sas_host_refresh - refreshing sas host object contents
4888 * @ioc: per adapter object
4891 * During port enable, fw will send topology events for every device. Its
4892 * possible that the handles may change from the previous setting, so this
4893 * code keeping handles updating if changed.
4898 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4903 Mpi2ConfigReply_t mpi_reply
;
4904 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4905 u16 attached_handle
;
4908 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4909 "updating handles for sas_host(0x%016llx)\n",
4910 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4912 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4913 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4914 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4915 if (!sas_iounit_pg0
) {
4916 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4917 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4921 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4922 sas_iounit_pg0
, sz
)) != 0)
4924 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4925 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4927 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4928 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4930 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4931 PhyData
[0].ControllerDevHandle
);
4932 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4933 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4935 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4936 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4937 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4938 attached_handle
, i
, link_rate
);
4941 kfree(sas_iounit_pg0
);
4945 * _scsih_sas_host_add - create sas host object
4946 * @ioc: per adapter object
4948 * Creating host side data object, stored in ioc->sas_hba
4953 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4956 Mpi2ConfigReply_t mpi_reply
;
4957 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4958 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4959 Mpi2SasPhyPage0_t phy_pg0
;
4960 Mpi2SasDevicePage0_t sas_device_pg0
;
4961 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4964 u8 device_missing_delay
;
4967 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
4969 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4970 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4973 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
4974 sizeof(struct _sas_phy
), GFP_KERNEL
);
4975 if (!ioc
->sas_hba
.phy
) {
4976 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4977 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4980 ioc
->sas_hba
.num_phys
= num_phys
;
4982 /* sas_iounit page 0 */
4983 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4984 sizeof(Mpi2SasIOUnit0PhyData_t
));
4985 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4986 if (!sas_iounit_pg0
) {
4987 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4988 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4991 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4992 sas_iounit_pg0
, sz
))) {
4993 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4994 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4997 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4998 MPI2_IOCSTATUS_MASK
;
4999 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5000 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5001 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5005 /* sas_iounit page 1 */
5006 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5007 sizeof(Mpi2SasIOUnit1PhyData_t
));
5008 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5009 if (!sas_iounit_pg1
) {
5010 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5011 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5014 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5015 sas_iounit_pg1
, sz
))) {
5016 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5017 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5020 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5021 MPI2_IOCSTATUS_MASK
;
5022 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5023 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5024 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5028 ioc
->io_missing_delay
=
5029 sas_iounit_pg1
->IODeviceMissingDelay
;
5030 device_missing_delay
=
5031 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5032 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5033 ioc
->device_missing_delay
= (device_missing_delay
&
5034 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5036 ioc
->device_missing_delay
= device_missing_delay
&
5037 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5039 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5040 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5041 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5043 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5044 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5047 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5048 MPI2_IOCSTATUS_MASK
;
5049 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5050 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5051 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5056 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5057 PhyData
[0].ControllerDevHandle
);
5058 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5059 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5060 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5061 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5063 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5064 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5065 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5066 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5069 ioc
->sas_hba
.enclosure_handle
=
5070 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5071 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5073 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5074 ioc
->name
, ioc
->sas_hba
.handle
,
5075 (unsigned long long) ioc
->sas_hba
.sas_address
,
5076 ioc
->sas_hba
.num_phys
) ;
5078 if (ioc
->sas_hba
.enclosure_handle
) {
5079 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5080 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5081 ioc
->sas_hba
.enclosure_handle
)))
5082 ioc
->sas_hba
.enclosure_logical_id
=
5083 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5087 kfree(sas_iounit_pg1
);
5088 kfree(sas_iounit_pg0
);
5092 * _scsih_expander_add - creating expander object
5093 * @ioc: per adapter object
5094 * @handle: expander handle
5096 * Creating expander object, stored in ioc->sas_expander_list.
5098 * Return 0 for success, else error.
5101 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5103 struct _sas_node
*sas_expander
;
5104 Mpi2ConfigReply_t mpi_reply
;
5105 Mpi2ExpanderPage0_t expander_pg0
;
5106 Mpi2ExpanderPage1_t expander_pg1
;
5107 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5110 u64 sas_address
, sas_address_parent
= 0;
5112 unsigned long flags
;
5113 struct _sas_port
*mpt3sas_port
= NULL
;
5120 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5123 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5124 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5125 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5126 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5130 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5131 MPI2_IOCSTATUS_MASK
;
5132 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5133 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5134 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5138 /* handle out of order topology events */
5139 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5140 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5142 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5143 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5146 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5147 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5148 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5149 sas_address_parent
);
5150 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5151 if (!sas_expander
) {
5152 rc
= _scsih_expander_add(ioc
, parent_handle
);
5158 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5159 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5160 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5162 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5167 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5169 if (!sas_expander
) {
5170 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5171 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5175 sas_expander
->handle
= handle
;
5176 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5177 sas_expander
->sas_address_parent
= sas_address_parent
;
5178 sas_expander
->sas_address
= sas_address
;
5180 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5181 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5182 handle
, parent_handle
, (unsigned long long)
5183 sas_expander
->sas_address
, sas_expander
->num_phys
);
5185 if (!sas_expander
->num_phys
)
5187 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5188 sizeof(struct _sas_phy
), GFP_KERNEL
);
5189 if (!sas_expander
->phy
) {
5190 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5191 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5196 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5197 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5198 sas_address_parent
);
5199 if (!mpt3sas_port
) {
5200 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5201 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5205 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5207 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5208 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5209 &expander_pg1
, i
, handle
))) {
5210 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5211 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5215 sas_expander
->phy
[i
].handle
= handle
;
5216 sas_expander
->phy
[i
].phy_id
= i
;
5218 if ((mpt3sas_transport_add_expander_phy(ioc
,
5219 &sas_expander
->phy
[i
], expander_pg1
,
5220 sas_expander
->parent_dev
))) {
5221 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5222 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5228 if (sas_expander
->enclosure_handle
) {
5229 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5230 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5231 sas_expander
->enclosure_handle
)))
5232 sas_expander
->enclosure_logical_id
=
5233 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5236 _scsih_expander_node_add(ioc
, sas_expander
);
5242 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5243 sas_address_parent
);
5244 kfree(sas_expander
);
5249 * mpt3sas_expander_remove - removing expander object
5250 * @ioc: per adapter object
5251 * @sas_address: expander sas_address
5256 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5258 struct _sas_node
*sas_expander
;
5259 unsigned long flags
;
5261 if (ioc
->shost_recovery
)
5264 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5265 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5268 list_del(&sas_expander
->list
);
5269 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5271 _scsih_expander_node_remove(ioc
, sas_expander
);
5275 * _scsih_done - internal SCSI_IO callback handler.
5276 * @ioc: per adapter object
5277 * @smid: system request message index
5278 * @msix_index: MSIX table index supplied by the OS
5279 * @reply: reply message frame(lower 32bit addr)
5281 * Callback handler when sending internal generated SCSI_IO.
5282 * The callback index passed is `ioc->scsih_cb_idx`
5284 * Return 1 meaning mf should be freed from _base_interrupt
5285 * 0 means the mf is freed from this function.
5288 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5290 MPI2DefaultReply_t
*mpi_reply
;
5292 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5293 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5295 if (ioc
->scsih_cmds
.smid
!= smid
)
5297 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5299 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5300 mpi_reply
->MsgLength
*4);
5301 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5303 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5304 complete(&ioc
->scsih_cmds
.done
);
5311 #define MPT3_MAX_LUNS (255)
5315 * _scsih_check_access_status - check access flags
5316 * @ioc: per adapter object
5317 * @sas_address: sas address
5318 * @handle: sas device handle
5319 * @access_flags: errors returned during discovery of the device
5321 * Return 0 for success, else failure
5324 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5325 u16 handle
, u8 access_status
)
5330 switch (access_status
) {
5331 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5332 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5335 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5336 desc
= "sata capability failed";
5338 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5339 desc
= "sata affiliation conflict";
5341 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5342 desc
= "route not addressable";
5344 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5345 desc
= "smp error not addressable";
5347 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5348 desc
= "device blocked";
5350 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5351 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5352 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5353 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5354 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5355 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5356 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5357 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5358 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5359 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5360 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5361 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5362 desc
= "sata initialization failed";
5373 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5374 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5379 * _scsih_check_device - checking device responsiveness
5380 * @ioc: per adapter object
5381 * @parent_sas_address: sas address of parent expander or sas host
5382 * @handle: attached device handle
5383 * @phy_numberv: phy number
5384 * @link_rate: new link rate
5389 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5390 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5392 Mpi2ConfigReply_t mpi_reply
;
5393 Mpi2SasDevicePage0_t sas_device_pg0
;
5394 struct _sas_device
*sas_device
;
5396 unsigned long flags
;
5398 struct scsi_target
*starget
;
5399 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5403 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5404 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5407 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5408 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5411 /* wide port handling ~ we need only handle device once for the phy that
5412 * is matched in sas device page zero
5414 if (phy_number
!= sas_device_pg0
.PhyNum
)
5417 /* check if this is end device */
5418 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5419 if (!(_scsih_is_end_device(device_info
)))
5422 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5423 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5424 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5430 if (unlikely(sas_device
->handle
!= handle
)) {
5431 starget
= sas_device
->starget
;
5432 sas_target_priv_data
= starget
->hostdata
;
5433 starget_printk(KERN_INFO
, starget
,
5434 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5435 sas_device
->handle
, handle
);
5436 sas_target_priv_data
->handle
= handle
;
5437 sas_device
->handle
= handle
;
5438 if (le16_to_cpu(sas_device_pg0
.Flags
) &
5439 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5440 sas_device
->enclosure_level
=
5441 sas_device_pg0
.EnclosureLevel
;
5442 memcpy(sas_device
->connector_name
,
5443 sas_device_pg0
.ConnectorName
, 4);
5444 sas_device
->connector_name
[4] = '\0';
5446 sas_device
->enclosure_level
= 0;
5447 sas_device
->connector_name
[0] = '\0';
5451 /* check if device is present */
5452 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5453 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5455 "device is not present handle(0x%04x), flags!!!\n",
5460 /* check if there were any issues with discovery */
5461 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5462 sas_device_pg0
.AccessStatus
))
5465 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5466 _scsih_ublock_io_device(ioc
, sas_address
);
5469 sas_device_put(sas_device
);
5473 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5475 sas_device_put(sas_device
);
5479 * _scsih_add_device - creating sas device object
5480 * @ioc: per adapter object
5481 * @handle: sas device handle
5482 * @phy_num: phy number end device attached to
5483 * @is_pd: is this hidden raid component
5485 * Creating end device object, stored in ioc->sas_device_list.
5487 * Returns 0 for success, non-zero for failure.
5490 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
5493 Mpi2ConfigReply_t mpi_reply
;
5494 Mpi2SasDevicePage0_t sas_device_pg0
;
5495 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5496 struct _sas_device
*sas_device
;
5501 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5502 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5503 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5504 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5508 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5509 MPI2_IOCSTATUS_MASK
;
5510 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5511 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5512 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5516 /* check if this is end device */
5517 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5518 if (!(_scsih_is_end_device(device_info
)))
5520 set_bit(handle
, ioc
->pend_os_device_add
);
5521 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5523 /* check if device is present */
5524 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5525 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5526 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5531 /* check if there were any issues with discovery */
5532 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5533 sas_device_pg0
.AccessStatus
))
5536 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
5539 clear_bit(handle
, ioc
->pend_os_device_add
);
5540 sas_device_put(sas_device
);
5544 sas_device
= kzalloc(sizeof(struct _sas_device
),
5547 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5548 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5552 kref_init(&sas_device
->refcount
);
5553 sas_device
->handle
= handle
;
5554 if (_scsih_get_sas_address(ioc
,
5555 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5556 &sas_device
->sas_address_parent
) != 0)
5557 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5558 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5559 sas_device
->enclosure_handle
=
5560 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5561 if (sas_device
->enclosure_handle
!= 0)
5563 le16_to_cpu(sas_device_pg0
.Slot
);
5564 sas_device
->device_info
= device_info
;
5565 sas_device
->sas_address
= sas_address
;
5566 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5567 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5568 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5570 if (le16_to_cpu(sas_device_pg0
.Flags
)
5571 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5572 sas_device
->enclosure_level
=
5573 sas_device_pg0
.EnclosureLevel
;
5574 memcpy(sas_device
->connector_name
,
5575 sas_device_pg0
.ConnectorName
, 4);
5576 sas_device
->connector_name
[4] = '\0';
5578 sas_device
->enclosure_level
= 0;
5579 sas_device
->connector_name
[0] = '\0';
5581 /* get enclosure_logical_id */
5582 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5583 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5584 sas_device
->enclosure_handle
)))
5585 sas_device
->enclosure_logical_id
=
5586 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5588 /* get device name */
5589 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5591 if (ioc
->wait_for_discovery_to_complete
)
5592 _scsih_sas_device_init_add(ioc
, sas_device
);
5594 _scsih_sas_device_add(ioc
, sas_device
);
5596 sas_device_put(sas_device
);
5601 * _scsih_remove_device - removing sas device object
5602 * @ioc: per adapter object
5603 * @sas_device_delete: the sas_device object
5608 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5609 struct _sas_device
*sas_device
)
5611 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5613 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5614 (sas_device
->pfa_led_on
)) {
5615 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5616 sas_device
->pfa_led_on
= 0;
5618 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5619 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5620 ioc
->name
, __func__
,
5621 sas_device
->handle
, (unsigned long long)
5622 sas_device
->sas_address
));
5623 if (sas_device
->enclosure_handle
!= 0)
5624 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5625 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5626 ioc
->name
, __func__
,
5627 (unsigned long long)sas_device
->enclosure_logical_id
,
5629 if (sas_device
->connector_name
[0] != '\0')
5630 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5631 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5632 ioc
->name
, __func__
,
5633 sas_device
->enclosure_level
,
5634 sas_device
->connector_name
));
5636 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5637 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5638 sas_target_priv_data
->deleted
= 1;
5639 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5640 sas_target_priv_data
->handle
=
5641 MPT3SAS_INVALID_DEVICE_HANDLE
;
5644 if (!ioc
->hide_drives
)
5645 mpt3sas_transport_port_remove(ioc
,
5646 sas_device
->sas_address
,
5647 sas_device
->sas_address_parent
);
5650 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5651 ioc
->name
, sas_device
->handle
,
5652 (unsigned long long) sas_device
->sas_address
);
5653 if (sas_device
->enclosure_handle
!= 0)
5655 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5657 (unsigned long long)sas_device
->enclosure_logical_id
,
5659 if (sas_device
->connector_name
[0] != '\0')
5661 "removing enclosure level(0x%04x), connector name( %s)\n",
5662 ioc
->name
, sas_device
->enclosure_level
,
5663 sas_device
->connector_name
);
5665 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5666 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5667 ioc
->name
, __func__
,
5668 sas_device
->handle
, (unsigned long long)
5669 sas_device
->sas_address
));
5670 if (sas_device
->enclosure_handle
!= 0)
5671 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5672 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5673 ioc
->name
, __func__
,
5674 (unsigned long long)sas_device
->enclosure_logical_id
,
5676 if (sas_device
->connector_name
[0] != '\0')
5677 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5678 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5679 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5680 sas_device
->connector_name
));
5684 * _scsih_sas_topology_change_event_debug - debug for topology event
5685 * @ioc: per adapter object
5686 * @event_data: event data payload
5690 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5691 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5697 char *status_str
= NULL
;
5698 u8 link_rate
, prev_link_rate
;
5700 switch (event_data
->ExpStatus
) {
5701 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5704 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5705 status_str
= "remove";
5707 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5709 status_str
= "responding";
5711 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5712 status_str
= "remove delay";
5715 status_str
= "unknown status";
5718 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5719 ioc
->name
, status_str
);
5720 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5721 "start_phy(%02d), count(%d)\n",
5722 le16_to_cpu(event_data
->ExpanderDevHandle
),
5723 le16_to_cpu(event_data
->EnclosureHandle
),
5724 event_data
->StartPhyNum
, event_data
->NumEntries
);
5725 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5726 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5729 phy_number
= event_data
->StartPhyNum
+ i
;
5730 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5731 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5732 switch (reason_code
) {
5733 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5734 status_str
= "target add";
5736 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5737 status_str
= "target remove";
5739 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5740 status_str
= "delay target remove";
5742 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5743 status_str
= "link rate change";
5745 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5746 status_str
= "target responding";
5749 status_str
= "unknown";
5752 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5753 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5754 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5755 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5756 handle
, status_str
, link_rate
, prev_link_rate
);
5762 * _scsih_sas_topology_change_event - handle topology changes
5763 * @ioc: per adapter object
5764 * @fw_event: The fw_event_work object
5769 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5770 struct fw_event_work
*fw_event
)
5773 u16 parent_handle
, handle
;
5775 u8 phy_number
, max_phys
;
5776 struct _sas_node
*sas_expander
;
5778 unsigned long flags
;
5779 u8 link_rate
, prev_link_rate
;
5780 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5781 (Mpi2EventDataSasTopologyChangeList_t
*)
5782 fw_event
->event_data
;
5784 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5785 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5787 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5790 if (!ioc
->sas_hba
.num_phys
)
5791 _scsih_sas_host_add(ioc
);
5793 _scsih_sas_host_refresh(ioc
);
5795 if (fw_event
->ignore
) {
5796 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5797 "ignoring expander event\n", ioc
->name
));
5801 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5803 /* handle expander add */
5804 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5805 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5808 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5809 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5812 sas_address
= sas_expander
->sas_address
;
5813 max_phys
= sas_expander
->num_phys
;
5814 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5815 sas_address
= ioc
->sas_hba
.sas_address
;
5816 max_phys
= ioc
->sas_hba
.num_phys
;
5818 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5821 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5823 /* handle siblings events */
5824 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5825 if (fw_event
->ignore
) {
5826 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5827 "ignoring expander event\n", ioc
->name
));
5830 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5832 phy_number
= event_data
->StartPhyNum
+ i
;
5833 if (phy_number
>= max_phys
)
5835 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5836 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5837 if ((event_data
->PHY
[i
].PhyStatus
&
5838 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5839 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5841 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5844 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5845 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5846 switch (reason_code
) {
5847 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5849 if (ioc
->shost_recovery
)
5852 if (link_rate
== prev_link_rate
)
5855 mpt3sas_transport_update_links(ioc
, sas_address
,
5856 handle
, phy_number
, link_rate
);
5858 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5861 _scsih_check_device(ioc
, sas_address
, handle
,
5862 phy_number
, link_rate
);
5864 if (!test_bit(handle
, ioc
->pend_os_device_add
))
5868 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5870 if (ioc
->shost_recovery
)
5873 mpt3sas_transport_update_links(ioc
, sas_address
,
5874 handle
, phy_number
, link_rate
);
5876 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5879 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5881 _scsih_device_remove_by_handle(ioc
, handle
);
5886 /* handle expander removal */
5887 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5889 mpt3sas_expander_remove(ioc
, sas_address
);
5895 * _scsih_sas_device_status_change_event_debug - debug for device event
5896 * @event_data: event data payload
5902 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5903 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5905 char *reason_str
= NULL
;
5907 switch (event_data
->ReasonCode
) {
5908 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5909 reason_str
= "smart data";
5911 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5912 reason_str
= "unsupported device discovered";
5914 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5915 reason_str
= "internal device reset";
5917 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5918 reason_str
= "internal task abort";
5920 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5921 reason_str
= "internal task abort set";
5923 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5924 reason_str
= "internal clear task set";
5926 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5927 reason_str
= "internal query task";
5929 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5930 reason_str
= "sata init failure";
5932 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5933 reason_str
= "internal device reset complete";
5935 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5936 reason_str
= "internal task abort complete";
5938 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5939 reason_str
= "internal async notification";
5941 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5942 reason_str
= "expander reduced functionality";
5944 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5945 reason_str
= "expander reduced functionality complete";
5948 reason_str
= "unknown reason";
5951 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5952 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5953 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5954 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5955 le16_to_cpu(event_data
->TaskTag
));
5956 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5957 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5958 event_data
->ASC
, event_data
->ASCQ
);
5963 * _scsih_sas_device_status_change_event - handle device status change
5964 * @ioc: per adapter object
5965 * @fw_event: The fw_event_work object
5971 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5972 struct fw_event_work
*fw_event
)
5974 struct MPT3SAS_TARGET
*target_priv_data
;
5975 struct _sas_device
*sas_device
;
5977 unsigned long flags
;
5978 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5979 (Mpi2EventDataSasDeviceStatusChange_t
*)
5980 fw_event
->event_data
;
5982 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5983 _scsih_sas_device_status_change_event_debug(ioc
,
5986 /* In MPI Revision K (0xC), the internal device reset complete was
5987 * implemented, so avoid setting tm_busy flag for older firmware.
5989 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5992 if (event_data
->ReasonCode
!=
5993 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5994 event_data
->ReasonCode
!=
5995 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5998 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5999 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6000 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6003 if (!sas_device
|| !sas_device
->starget
)
6006 target_priv_data
= sas_device
->starget
->hostdata
;
6007 if (!target_priv_data
)
6010 if (event_data
->ReasonCode
==
6011 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6012 target_priv_data
->tm_busy
= 1;
6014 target_priv_data
->tm_busy
= 0;
6018 sas_device_put(sas_device
);
6020 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6025 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
6027 * @ioc: per adapter object
6028 * @event_data: event data payload
6034 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6035 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
6037 char *reason_str
= NULL
;
6039 switch (event_data
->ReasonCode
) {
6040 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
6041 reason_str
= "enclosure add";
6043 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
6044 reason_str
= "enclosure remove";
6047 reason_str
= "unknown reason";
6051 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
6052 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
6053 " number slots(%d)\n", ioc
->name
, reason_str
,
6054 le16_to_cpu(event_data
->EnclosureHandle
),
6055 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
6056 le16_to_cpu(event_data
->StartSlot
));
6060 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
6061 * @ioc: per adapter object
6062 * @fw_event: The fw_event_work object
6068 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6069 struct fw_event_work
*fw_event
)
6071 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6072 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
6073 (Mpi2EventDataSasEnclDevStatusChange_t
*)
6074 fw_event
->event_data
);
6078 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6079 * @ioc: per adapter object
6080 * @fw_event: The fw_event_work object
6086 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
6087 struct fw_event_work
*fw_event
)
6089 struct scsi_cmnd
*scmd
;
6090 struct scsi_device
*sdev
;
6093 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6094 u32 termination_count
;
6096 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
6097 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
6098 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6099 fw_event
->event_data
;
6101 unsigned long flags
;
6104 u8 task_abort_retries
;
6106 mutex_lock(&ioc
->tm_cmds
.mutex
);
6108 "%s: enter: phy number(%d), width(%d)\n",
6109 ioc
->name
, __func__
, event_data
->PhyNum
,
6110 event_data
->PortWidth
);
6112 _scsih_block_io_all_device(ioc
);
6114 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6115 mpi_reply
= ioc
->tm_cmds
.reply
;
6116 broadcast_aen_retry
:
6118 /* sanity checks for retrying this loop */
6119 if (max_retries
++ == 5) {
6120 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
6121 ioc
->name
, __func__
));
6123 } else if (max_retries
> 1)
6124 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
6125 ioc
->name
, __func__
, max_retries
- 1));
6127 termination_count
= 0;
6129 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
6130 if (ioc
->shost_recovery
)
6132 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
6135 sdev
= scmd
->device
;
6136 sas_device_priv_data
= sdev
->hostdata
;
6137 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
6139 /* skip hidden raid components */
6140 if (sas_device_priv_data
->sas_target
->flags
&
6141 MPT_TARGET_FLAGS_RAID_COMPONENT
)
6144 if (sas_device_priv_data
->sas_target
->flags
&
6145 MPT_TARGET_FLAGS_VOLUME
)
6148 handle
= sas_device_priv_data
->sas_target
->handle
;
6149 lun
= sas_device_priv_data
->lun
;
6152 if (ioc
->shost_recovery
)
6155 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6156 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
6157 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
6159 sdev_printk(KERN_WARNING
, sdev
,
6160 "mpt3sas_scsih_issue_tm: FAILED when sending "
6161 "QUERY_TASK: scmd(%p)\n", scmd
);
6162 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6163 goto broadcast_aen_retry
;
6165 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
6166 & MPI2_IOCSTATUS_MASK
;
6167 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6168 sdev_printk(KERN_WARNING
, sdev
,
6169 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6171 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6172 goto broadcast_aen_retry
;
6175 /* see if IO is still owned by IOC and target */
6176 if (mpi_reply
->ResponseCode
==
6177 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
6178 mpi_reply
->ResponseCode
==
6179 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
6180 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6183 task_abort_retries
= 0;
6185 if (task_abort_retries
++ == 60) {
6186 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6187 "%s: ABORT_TASK: giving up\n", ioc
->name
,
6189 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6190 goto broadcast_aen_retry
;
6193 if (ioc
->shost_recovery
)
6196 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
6197 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
,
6200 sdev_printk(KERN_WARNING
, sdev
,
6201 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6202 "scmd(%p)\n", scmd
);
6206 if (task_abort_retries
> 1)
6207 sdev_printk(KERN_WARNING
, sdev
,
6208 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6210 task_abort_retries
- 1, scmd
);
6212 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
6213 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6216 if (ioc
->broadcast_aen_pending
) {
6217 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6218 "%s: loop back due to pending AEN\n",
6219 ioc
->name
, __func__
));
6220 ioc
->broadcast_aen_pending
= 0;
6221 goto broadcast_aen_retry
;
6225 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6228 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6229 "%s - exit, query_count = %d termination_count = %d\n",
6230 ioc
->name
, __func__
, query_count
, termination_count
));
6232 ioc
->broadcast_aen_busy
= 0;
6233 if (!ioc
->shost_recovery
)
6234 _scsih_ublock_io_all_device(ioc
);
6235 mutex_unlock(&ioc
->tm_cmds
.mutex
);
6239 * _scsih_sas_discovery_event - handle discovery events
6240 * @ioc: per adapter object
6241 * @fw_event: The fw_event_work object
6247 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
6248 struct fw_event_work
*fw_event
)
6250 Mpi2EventDataSasDiscovery_t
*event_data
=
6251 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
6253 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
6254 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
6255 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
6257 if (event_data
->DiscoveryStatus
)
6258 pr_info("discovery_status(0x%08x)",
6259 le32_to_cpu(event_data
->DiscoveryStatus
));
6263 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
6264 !ioc
->sas_hba
.num_phys
) {
6265 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6266 /* Wait for the reset to complete */
6267 while (ioc
->shost_recovery
)
6270 _scsih_sas_host_add(ioc
);
6275 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6276 * @ioc: per adapter object
6277 * @handle: device handle for physical disk
6278 * @phys_disk_num: physical disk number
6280 * Return 0 for success, else failure.
6283 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
6285 Mpi2RaidActionRequest_t
*mpi_request
;
6286 Mpi2RaidActionReply_t
*mpi_reply
;
6293 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
6296 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6298 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
6299 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
6300 ioc
->name
, __func__
);
6304 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
6306 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6308 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
6309 ioc
->name
, __func__
);
6310 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6315 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
6316 ioc
->scsih_cmds
.smid
= smid
;
6317 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6319 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6320 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
6321 mpi_request
->PhysDiskNum
= phys_disk_num
;
6323 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
6324 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
6325 handle
, phys_disk_num
));
6327 init_completion(&ioc
->scsih_cmds
.done
);
6328 ioc
->put_smid_default(ioc
, smid
);
6329 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6331 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
6332 pr_err(MPT3SAS_FMT
"%s: timeout\n",
6333 ioc
->name
, __func__
);
6334 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
6340 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
6342 mpi_reply
= ioc
->scsih_cmds
.reply
;
6343 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
6344 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
6345 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
6348 ioc_status
&= MPI2_IOCSTATUS_MASK
;
6349 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6350 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6351 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6352 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
6356 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6357 "IR RAID_ACTION: completed successfully\n",
6362 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6363 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6366 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
6371 * _scsih_reprobe_lun - reprobing lun
6372 * @sdev: scsi device struct
6373 * @no_uld_attach: sdev->no_uld_attach flag setting
6377 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6379 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6380 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6381 sdev
->no_uld_attach
? "hiding" : "exposing");
6382 WARN_ON(scsi_device_reprobe(sdev
));
6386 * _scsih_sas_volume_add - add new volume
6387 * @ioc: per adapter object
6388 * @element: IR config element data
6394 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
6395 Mpi2EventIrConfigElement_t
*element
)
6397 struct _raid_device
*raid_device
;
6398 unsigned long flags
;
6400 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6403 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6406 "failure at %s:%d/%s()!\n", ioc
->name
,
6407 __FILE__
, __LINE__
, __func__
);
6411 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6412 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6413 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6418 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6421 "failure at %s:%d/%s()!\n", ioc
->name
,
6422 __FILE__
, __LINE__
, __func__
);
6426 raid_device
->id
= ioc
->sas_id
++;
6427 raid_device
->channel
= RAID_CHANNEL
;
6428 raid_device
->handle
= handle
;
6429 raid_device
->wwid
= wwid
;
6430 _scsih_raid_device_add(ioc
, raid_device
);
6431 if (!ioc
->wait_for_discovery_to_complete
) {
6432 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6433 raid_device
->id
, 0);
6435 _scsih_raid_device_remove(ioc
, raid_device
);
6437 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6438 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6439 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6444 * _scsih_sas_volume_delete - delete volume
6445 * @ioc: per adapter object
6446 * @handle: volume device handle
6452 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6454 struct _raid_device
*raid_device
;
6455 unsigned long flags
;
6456 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6457 struct scsi_target
*starget
= NULL
;
6459 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6460 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6462 if (raid_device
->starget
) {
6463 starget
= raid_device
->starget
;
6464 sas_target_priv_data
= starget
->hostdata
;
6465 sas_target_priv_data
->deleted
= 1;
6467 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
6468 ioc
->name
, raid_device
->handle
,
6469 (unsigned long long) raid_device
->wwid
);
6470 list_del(&raid_device
->list
);
6473 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6475 scsi_remove_target(&starget
->dev
);
6479 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6480 * @ioc: per adapter object
6481 * @element: IR config element data
6487 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6488 Mpi2EventIrConfigElement_t
*element
)
6490 struct _sas_device
*sas_device
;
6491 struct scsi_target
*starget
= NULL
;
6492 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6493 unsigned long flags
;
6494 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6496 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6497 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6499 sas_device
->volume_handle
= 0;
6500 sas_device
->volume_wwid
= 0;
6501 clear_bit(handle
, ioc
->pd_handles
);
6502 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6503 starget
= sas_device
->starget
;
6504 sas_target_priv_data
= starget
->hostdata
;
6505 sas_target_priv_data
->flags
&=
6506 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6509 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6513 /* exposing raid component */
6515 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6517 sas_device_put(sas_device
);
6521 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6522 * @ioc: per adapter object
6523 * @element: IR config element data
6529 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6530 Mpi2EventIrConfigElement_t
*element
)
6532 struct _sas_device
*sas_device
;
6533 struct scsi_target
*starget
= NULL
;
6534 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6535 unsigned long flags
;
6536 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6537 u16 volume_handle
= 0;
6538 u64 volume_wwid
= 0;
6540 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6542 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6545 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6546 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6548 set_bit(handle
, ioc
->pd_handles
);
6549 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6550 starget
= sas_device
->starget
;
6551 sas_target_priv_data
= starget
->hostdata
;
6552 sas_target_priv_data
->flags
|=
6553 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6554 sas_device
->volume_handle
= volume_handle
;
6555 sas_device
->volume_wwid
= volume_wwid
;
6558 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6562 /* hiding raid component */
6563 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6566 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6568 sas_device_put(sas_device
);
6572 * _scsih_sas_pd_delete - delete pd component
6573 * @ioc: per adapter object
6574 * @element: IR config element data
6580 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6581 Mpi2EventIrConfigElement_t
*element
)
6583 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6585 _scsih_device_remove_by_handle(ioc
, handle
);
6589 * _scsih_sas_pd_add - remove pd component
6590 * @ioc: per adapter object
6591 * @element: IR config element data
6597 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6598 Mpi2EventIrConfigElement_t
*element
)
6600 struct _sas_device
*sas_device
;
6601 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6602 Mpi2ConfigReply_t mpi_reply
;
6603 Mpi2SasDevicePage0_t sas_device_pg0
;
6608 set_bit(handle
, ioc
->pd_handles
);
6610 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6612 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6613 sas_device_put(sas_device
);
6617 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6618 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6619 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6620 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6624 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6625 MPI2_IOCSTATUS_MASK
;
6626 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6627 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6628 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6632 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6633 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6634 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6635 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6637 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6638 _scsih_add_device(ioc
, handle
, 0, 1);
6642 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6643 * @ioc: per adapter object
6644 * @event_data: event data payload
6650 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6651 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6653 Mpi2EventIrConfigElement_t
*element
;
6656 char *reason_str
= NULL
, *element_str
= NULL
;
6658 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6660 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6661 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6662 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6663 "foreign" : "native", event_data
->NumElements
);
6664 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6665 switch (element
->ReasonCode
) {
6666 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6669 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6670 reason_str
= "remove";
6672 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6673 reason_str
= "no change";
6675 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6676 reason_str
= "hide";
6678 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6679 reason_str
= "unhide";
6681 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6682 reason_str
= "volume_created";
6684 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6685 reason_str
= "volume_deleted";
6687 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6688 reason_str
= "pd_created";
6690 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6691 reason_str
= "pd_deleted";
6694 reason_str
= "unknown reason";
6697 element_type
= le16_to_cpu(element
->ElementFlags
) &
6698 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6699 switch (element_type
) {
6700 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6701 element_str
= "volume";
6703 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6704 element_str
= "phys disk";
6706 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6707 element_str
= "hot spare";
6710 element_str
= "unknown element";
6713 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6714 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6715 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6716 le16_to_cpu(element
->PhysDiskDevHandle
),
6717 element
->PhysDiskNum
);
6722 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6723 * @ioc: per adapter object
6724 * @fw_event: The fw_event_work object
6730 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6731 struct fw_event_work
*fw_event
)
6733 Mpi2EventIrConfigElement_t
*element
;
6736 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6737 (Mpi2EventDataIrConfigChangeList_t
*)
6738 fw_event
->event_data
;
6740 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6741 (!ioc
->hide_ir_msg
))
6742 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6744 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6745 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6747 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6748 if (ioc
->shost_recovery
&&
6749 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
6750 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6751 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6752 _scsih_ir_fastpath(ioc
,
6753 le16_to_cpu(element
->PhysDiskDevHandle
),
6754 element
->PhysDiskNum
);
6759 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6761 switch (element
->ReasonCode
) {
6762 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6763 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6764 if (!foreign_config
)
6765 _scsih_sas_volume_add(ioc
, element
);
6767 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6768 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6769 if (!foreign_config
)
6770 _scsih_sas_volume_delete(ioc
,
6771 le16_to_cpu(element
->VolDevHandle
));
6773 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6774 if (!ioc
->is_warpdrive
)
6775 _scsih_sas_pd_hide(ioc
, element
);
6777 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6778 if (!ioc
->is_warpdrive
)
6779 _scsih_sas_pd_expose(ioc
, element
);
6781 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6782 if (!ioc
->is_warpdrive
)
6783 _scsih_sas_pd_add(ioc
, element
);
6785 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6786 if (!ioc
->is_warpdrive
)
6787 _scsih_sas_pd_delete(ioc
, element
);
6794 * _scsih_sas_ir_volume_event - IR volume event
6795 * @ioc: per adapter object
6796 * @fw_event: The fw_event_work object
6802 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6803 struct fw_event_work
*fw_event
)
6806 unsigned long flags
;
6807 struct _raid_device
*raid_device
;
6811 Mpi2EventDataIrVolume_t
*event_data
=
6812 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6814 if (ioc
->shost_recovery
)
6817 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6820 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6821 state
= le32_to_cpu(event_data
->NewValue
);
6822 if (!ioc
->hide_ir_msg
)
6823 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6824 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6825 ioc
->name
, __func__
, handle
,
6826 le32_to_cpu(event_data
->PreviousValue
), state
));
6828 case MPI2_RAID_VOL_STATE_MISSING
:
6829 case MPI2_RAID_VOL_STATE_FAILED
:
6830 _scsih_sas_volume_delete(ioc
, handle
);
6833 case MPI2_RAID_VOL_STATE_ONLINE
:
6834 case MPI2_RAID_VOL_STATE_DEGRADED
:
6835 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6837 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6838 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6839 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6844 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6847 "failure at %s:%d/%s()!\n", ioc
->name
,
6848 __FILE__
, __LINE__
, __func__
);
6852 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6855 "failure at %s:%d/%s()!\n", ioc
->name
,
6856 __FILE__
, __LINE__
, __func__
);
6860 raid_device
->id
= ioc
->sas_id
++;
6861 raid_device
->channel
= RAID_CHANNEL
;
6862 raid_device
->handle
= handle
;
6863 raid_device
->wwid
= wwid
;
6864 _scsih_raid_device_add(ioc
, raid_device
);
6865 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6866 raid_device
->id
, 0);
6868 _scsih_raid_device_remove(ioc
, raid_device
);
6871 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6878 * _scsih_sas_ir_physical_disk_event - PD event
6879 * @ioc: per adapter object
6880 * @fw_event: The fw_event_work object
6886 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6887 struct fw_event_work
*fw_event
)
6889 u16 handle
, parent_handle
;
6891 struct _sas_device
*sas_device
;
6892 Mpi2ConfigReply_t mpi_reply
;
6893 Mpi2SasDevicePage0_t sas_device_pg0
;
6895 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6896 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6899 if (ioc
->shost_recovery
)
6902 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6905 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6906 state
= le32_to_cpu(event_data
->NewValue
);
6908 if (!ioc
->hide_ir_msg
)
6909 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6910 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6911 ioc
->name
, __func__
, handle
,
6912 le32_to_cpu(event_data
->PreviousValue
), state
));
6915 case MPI2_RAID_PD_STATE_ONLINE
:
6916 case MPI2_RAID_PD_STATE_DEGRADED
:
6917 case MPI2_RAID_PD_STATE_REBUILDING
:
6918 case MPI2_RAID_PD_STATE_OPTIMAL
:
6919 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6921 if (!ioc
->is_warpdrive
)
6922 set_bit(handle
, ioc
->pd_handles
);
6924 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6926 sas_device_put(sas_device
);
6930 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6931 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6933 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6934 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6938 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6939 MPI2_IOCSTATUS_MASK
;
6940 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6941 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6942 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6946 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6947 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6948 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6949 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6951 _scsih_add_device(ioc
, handle
, 0, 1);
6955 case MPI2_RAID_PD_STATE_OFFLINE
:
6956 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6957 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6964 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6965 * @ioc: per adapter object
6966 * @event_data: event data payload
6972 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6973 Mpi2EventDataIrOperationStatus_t
*event_data
)
6975 char *reason_str
= NULL
;
6977 switch (event_data
->RAIDOperation
) {
6978 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6979 reason_str
= "resync";
6981 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6982 reason_str
= "online capacity expansion";
6984 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6985 reason_str
= "consistency check";
6987 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6988 reason_str
= "background init";
6990 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6991 reason_str
= "make data consistent";
6998 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6999 "\thandle(0x%04x), percent complete(%d)\n",
7000 ioc
->name
, reason_str
,
7001 le16_to_cpu(event_data
->VolDevHandle
),
7002 event_data
->PercentComplete
);
7006 * _scsih_sas_ir_operation_status_event - handle RAID operation events
7007 * @ioc: per adapter object
7008 * @fw_event: The fw_event_work object
7014 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
7015 struct fw_event_work
*fw_event
)
7017 Mpi2EventDataIrOperationStatus_t
*event_data
=
7018 (Mpi2EventDataIrOperationStatus_t
*)
7019 fw_event
->event_data
;
7020 static struct _raid_device
*raid_device
;
7021 unsigned long flags
;
7024 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
7025 (!ioc
->hide_ir_msg
))
7026 _scsih_sas_ir_operation_status_event_debug(ioc
,
7029 /* code added for raid transport support */
7030 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
7032 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7033 handle
= le16_to_cpu(event_data
->VolDevHandle
);
7034 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7036 raid_device
->percent_complete
=
7037 event_data
->PercentComplete
;
7038 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7043 * _scsih_prep_device_scan - initialize parameters prior to device scan
7044 * @ioc: per adapter object
7046 * Set the deleted flag prior to device scan. If the device is found during
7047 * the scan, then we clear the deleted flag.
7050 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
7052 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7053 struct scsi_device
*sdev
;
7055 shost_for_each_device(sdev
, ioc
->shost
) {
7056 sas_device_priv_data
= sdev
->hostdata
;
7057 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
7058 sas_device_priv_data
->sas_target
->deleted
= 1;
7063 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
7064 * @ioc: per adapter object
7065 * @sas_device_pg0: SAS Device page 0
7067 * After host reset, find out whether devices are still responding.
7068 * Used in _scsih_remove_unresponsive_sas_devices.
7073 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
7074 Mpi2SasDevicePage0_t
*sas_device_pg0
)
7076 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7077 struct scsi_target
*starget
;
7078 struct _sas_device
*sas_device
;
7079 unsigned long flags
;
7081 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7082 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
7083 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
7084 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
7085 sas_device
->responding
= 1;
7086 starget
= sas_device
->starget
;
7087 if (starget
&& starget
->hostdata
) {
7088 sas_target_priv_data
= starget
->hostdata
;
7089 sas_target_priv_data
->tm_busy
= 0;
7090 sas_target_priv_data
->deleted
= 0;
7092 sas_target_priv_data
= NULL
;
7094 starget_printk(KERN_INFO
, starget
,
7095 "handle(0x%04x), sas_addr(0x%016llx)\n",
7096 sas_device_pg0
->DevHandle
,
7097 (unsigned long long)
7098 sas_device
->sas_address
);
7100 if (sas_device
->enclosure_handle
!= 0)
7101 starget_printk(KERN_INFO
, starget
,
7102 "enclosure logical id(0x%016llx),"
7104 (unsigned long long)
7105 sas_device
->enclosure_logical_id
,
7108 if (sas_device_pg0
->Flags
&
7109 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
7110 sas_device
->enclosure_level
=
7111 sas_device_pg0
->EnclosureLevel
;
7112 memcpy(&sas_device
->connector_name
[0],
7113 &sas_device_pg0
->ConnectorName
[0], 4);
7115 sas_device
->enclosure_level
= 0;
7116 sas_device
->connector_name
[0] = '\0';
7119 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
7121 pr_info("\thandle changed from(0x%04x)!!!\n",
7122 sas_device
->handle
);
7123 sas_device
->handle
= sas_device_pg0
->DevHandle
;
7124 if (sas_target_priv_data
)
7125 sas_target_priv_data
->handle
=
7126 sas_device_pg0
->DevHandle
;
7131 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7135 * _scsih_search_responding_sas_devices -
7136 * @ioc: per adapter object
7138 * After host reset, find out whether devices are still responding.
7144 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7146 Mpi2SasDevicePage0_t sas_device_pg0
;
7147 Mpi2ConfigReply_t mpi_reply
;
7152 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
7154 if (list_empty(&ioc
->sas_device_list
))
7158 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7159 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7161 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7162 MPI2_IOCSTATUS_MASK
;
7163 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7165 handle
= sas_device_pg0
.DevHandle
=
7166 le16_to_cpu(sas_device_pg0
.DevHandle
);
7167 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
7168 if (!(_scsih_is_end_device(device_info
)))
7170 sas_device_pg0
.SASAddress
=
7171 le64_to_cpu(sas_device_pg0
.SASAddress
);
7172 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
7173 sas_device_pg0
.Flags
= le16_to_cpu(sas_device_pg0
.Flags
);
7174 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
7178 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
7183 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7184 * @ioc: per adapter object
7185 * @wwid: world wide identifier for raid volume
7186 * @handle: device handle
7188 * After host reset, find out whether devices are still responding.
7189 * Used in _scsih_remove_unresponsive_raid_devices.
7194 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
7197 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7198 struct scsi_target
*starget
;
7199 struct _raid_device
*raid_device
;
7200 unsigned long flags
;
7202 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7203 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
7204 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
7205 starget
= raid_device
->starget
;
7206 if (starget
&& starget
->hostdata
) {
7207 sas_target_priv_data
= starget
->hostdata
;
7208 sas_target_priv_data
->deleted
= 0;
7210 sas_target_priv_data
= NULL
;
7211 raid_device
->responding
= 1;
7212 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7213 starget_printk(KERN_INFO
, raid_device
->starget
,
7214 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
7215 (unsigned long long)raid_device
->wwid
);
7218 * WARPDRIVE: The handles of the PDs might have changed
7219 * across the host reset so re-initialize the
7220 * required data for Direct IO
7222 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
7223 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7224 if (raid_device
->handle
== handle
) {
7225 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
7229 pr_info("\thandle changed from(0x%04x)!!!\n",
7230 raid_device
->handle
);
7231 raid_device
->handle
= handle
;
7232 if (sas_target_priv_data
)
7233 sas_target_priv_data
->handle
= handle
;
7234 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7238 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7242 * _scsih_search_responding_raid_devices -
7243 * @ioc: per adapter object
7245 * After host reset, find out whether devices are still responding.
7251 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
7253 Mpi2RaidVolPage1_t volume_pg1
;
7254 Mpi2RaidVolPage0_t volume_pg0
;
7255 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7256 Mpi2ConfigReply_t mpi_reply
;
7261 if (!ioc
->ir_firmware
)
7264 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
7267 if (list_empty(&ioc
->raid_device_list
))
7271 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7272 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7273 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7274 MPI2_IOCSTATUS_MASK
;
7275 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7277 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7279 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7280 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7281 sizeof(Mpi2RaidVolPage0_t
)))
7284 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7285 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7286 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
7287 _scsih_mark_responding_raid_device(ioc
,
7288 le64_to_cpu(volume_pg1
.WWID
), handle
);
7291 /* refresh the pd_handles */
7292 if (!ioc
->is_warpdrive
) {
7293 phys_disk_num
= 0xFF;
7294 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
7295 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7296 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7298 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7299 MPI2_IOCSTATUS_MASK
;
7300 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7302 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7303 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7304 set_bit(handle
, ioc
->pd_handles
);
7308 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
7313 * _scsih_mark_responding_expander - mark a expander as responding
7314 * @ioc: per adapter object
7315 * @sas_address: sas address
7318 * After host reset, find out whether devices are still responding.
7319 * Used in _scsih_remove_unresponsive_expanders.
7324 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
7327 struct _sas_node
*sas_expander
;
7328 unsigned long flags
;
7331 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7332 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
7333 if (sas_expander
->sas_address
!= sas_address
)
7335 sas_expander
->responding
= 1;
7336 if (sas_expander
->handle
== handle
)
7338 pr_info("\texpander(0x%016llx): handle changed" \
7339 " from(0x%04x) to (0x%04x)!!!\n",
7340 (unsigned long long)sas_expander
->sas_address
,
7341 sas_expander
->handle
, handle
);
7342 sas_expander
->handle
= handle
;
7343 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
7344 sas_expander
->phy
[i
].handle
= handle
;
7348 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7352 * _scsih_search_responding_expanders -
7353 * @ioc: per adapter object
7355 * After host reset, find out whether devices are still responding.
7361 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
7363 Mpi2ExpanderPage0_t expander_pg0
;
7364 Mpi2ConfigReply_t mpi_reply
;
7369 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
7371 if (list_empty(&ioc
->sas_expander_list
))
7375 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7376 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7378 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7379 MPI2_IOCSTATUS_MASK
;
7380 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7383 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7384 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7385 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7387 (unsigned long long)sas_address
);
7388 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7392 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
7396 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7397 * @ioc: per adapter object
7402 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7404 struct _sas_device
*sas_device
, *sas_device_next
;
7405 struct _sas_node
*sas_expander
, *sas_expander_next
;
7406 struct _raid_device
*raid_device
, *raid_device_next
;
7407 struct list_head tmp_list
;
7408 unsigned long flags
;
7411 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
7414 /* removing unresponding end devices */
7415 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
7418 * Iterate, pulling off devices marked as non-responding. We become the
7419 * owner for the reference the list had on any object we prune.
7421 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7422 list_for_each_entry_safe(sas_device
, sas_device_next
,
7423 &ioc
->sas_device_list
, list
) {
7424 if (!sas_device
->responding
)
7425 list_move_tail(&sas_device
->list
, &head
);
7427 sas_device
->responding
= 0;
7429 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7432 * Now, uninitialize and remove the unresponding devices we pruned.
7434 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
7435 _scsih_remove_device(ioc
, sas_device
);
7436 list_del_init(&sas_device
->list
);
7437 sas_device_put(sas_device
);
7440 /* removing unresponding volumes */
7441 if (ioc
->ir_firmware
) {
7442 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
7444 list_for_each_entry_safe(raid_device
, raid_device_next
,
7445 &ioc
->raid_device_list
, list
) {
7446 if (!raid_device
->responding
)
7447 _scsih_sas_volume_delete(ioc
,
7448 raid_device
->handle
);
7450 raid_device
->responding
= 0;
7454 /* removing unresponding expanders */
7455 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
7457 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7458 INIT_LIST_HEAD(&tmp_list
);
7459 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7460 &ioc
->sas_expander_list
, list
) {
7461 if (!sas_expander
->responding
)
7462 list_move_tail(&sas_expander
->list
, &tmp_list
);
7464 sas_expander
->responding
= 0;
7466 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7467 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7469 list_del(&sas_expander
->list
);
7470 _scsih_expander_node_remove(ioc
, sas_expander
);
7473 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
7476 /* unblock devices */
7477 _scsih_ublock_io_all_device(ioc
);
7481 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
7482 struct _sas_node
*sas_expander
, u16 handle
)
7484 Mpi2ExpanderPage1_t expander_pg1
;
7485 Mpi2ConfigReply_t mpi_reply
;
7488 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7489 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7490 &expander_pg1
, i
, handle
))) {
7491 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7492 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7496 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7497 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7498 expander_pg1
.NegotiatedLinkRate
>> 4);
7503 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7504 * @ioc: per adapter object
7509 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
7511 Mpi2ExpanderPage0_t expander_pg0
;
7512 Mpi2SasDevicePage0_t sas_device_pg0
;
7513 Mpi2RaidVolPage1_t volume_pg1
;
7514 Mpi2RaidVolPage0_t volume_pg0
;
7515 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7516 Mpi2EventIrConfigElement_t element
;
7517 Mpi2ConfigReply_t mpi_reply
;
7520 u16 handle
, parent_handle
;
7522 struct _sas_device
*sas_device
;
7523 struct _sas_node
*expander_device
;
7524 static struct _raid_device
*raid_device
;
7526 unsigned long flags
;
7528 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7530 _scsih_sas_host_refresh(ioc
);
7532 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7536 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7537 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7538 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7539 MPI2_IOCSTATUS_MASK
;
7540 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7541 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7542 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7543 ioc
->name
, ioc_status
,
7544 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7547 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7548 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7549 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7550 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7551 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7552 if (expander_device
)
7553 _scsih_refresh_expander_links(ioc
, expander_device
,
7556 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7557 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7558 handle
, (unsigned long long)
7559 le64_to_cpu(expander_pg0
.SASAddress
));
7560 _scsih_expander_add(ioc
, handle
);
7561 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7562 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7563 handle
, (unsigned long long)
7564 le64_to_cpu(expander_pg0
.SASAddress
));
7568 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7571 if (!ioc
->ir_firmware
)
7574 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7577 phys_disk_num
= 0xFF;
7578 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7579 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7581 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7582 MPI2_IOCSTATUS_MASK
;
7583 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7584 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7585 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7586 ioc
->name
, ioc_status
,
7587 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7590 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7591 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7592 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7594 sas_device_put(sas_device
);
7597 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7598 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7601 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7602 MPI2_IOCSTATUS_MASK
;
7603 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7604 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7605 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7606 ioc
->name
, ioc_status
,
7607 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7610 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7611 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7613 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7614 " handle (0x%04x), sas_addr(0x%016llx)\n",
7615 ioc
->name
, handle
, (unsigned long long)
7616 le64_to_cpu(sas_device_pg0
.SASAddress
));
7617 mpt3sas_transport_update_links(ioc
, sas_address
,
7618 handle
, sas_device_pg0
.PhyNum
,
7619 MPI2_SAS_NEG_LINK_RATE_1_5
);
7620 set_bit(handle
, ioc
->pd_handles
);
7622 /* This will retry adding the end device.
7623 * _scsih_add_device() will decide on retries and
7624 * return "1" when it should be retried
7626 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7630 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7631 " handle (0x%04x), sas_addr(0x%016llx)\n",
7632 ioc
->name
, handle
, (unsigned long long)
7633 le64_to_cpu(sas_device_pg0
.SASAddress
));
7637 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7640 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7644 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7645 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7646 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7647 MPI2_IOCSTATUS_MASK
;
7648 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7649 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7650 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7651 ioc
->name
, ioc_status
,
7652 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7655 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7656 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7657 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7658 le64_to_cpu(volume_pg1
.WWID
));
7659 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7662 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7663 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7664 sizeof(Mpi2RaidVolPage0_t
)))
7666 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7667 MPI2_IOCSTATUS_MASK
;
7668 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7669 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7670 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7671 ioc
->name
, ioc_status
,
7672 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7675 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7676 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7677 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7678 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7679 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7680 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7682 "\tBEFORE adding volume: handle (0x%04x)\n",
7683 ioc
->name
, volume_pg1
.DevHandle
);
7684 _scsih_sas_volume_add(ioc
, &element
);
7686 "\tAFTER adding volume: handle (0x%04x)\n",
7687 ioc
->name
, volume_pg1
.DevHandle
);
7691 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7696 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7701 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7702 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7704 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7705 MPI2_IOCSTATUS_MASK
;
7706 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7707 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7708 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7709 ioc
->name
, ioc_status
,
7710 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7713 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7714 if (!(_scsih_is_end_device(
7715 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7717 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
7718 le64_to_cpu(sas_device_pg0
.SASAddress
));
7720 sas_device_put(sas_device
);
7723 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7724 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7725 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7726 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7727 handle
, (unsigned long long)
7728 le64_to_cpu(sas_device_pg0
.SASAddress
));
7729 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7730 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7732 /* This will retry adding the end device.
7733 * _scsih_add_device() will decide on retries and
7734 * return "1" when it should be retried
7736 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7740 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7741 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7742 handle
, (unsigned long long)
7743 le64_to_cpu(sas_device_pg0
.SASAddress
));
7746 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7749 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7752 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7753 * @ioc: per adapter object
7754 * @reset_phase: phase
7756 * The handler for doing any required cleanup or initialization.
7758 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7759 * MPT3_IOC_DONE_RESET
7764 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7766 switch (reset_phase
) {
7767 case MPT3_IOC_PRE_RESET
:
7768 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7769 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7771 case MPT3_IOC_AFTER_RESET
:
7772 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7773 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7774 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7775 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7776 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7777 complete(&ioc
->scsih_cmds
.done
);
7779 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7780 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7781 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7782 complete(&ioc
->tm_cmds
.done
);
7785 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
7786 memset(ioc
->device_remove_in_progress
, 0,
7787 ioc
->device_remove_in_progress_sz
);
7788 _scsih_fw_event_cleanup_queue(ioc
);
7789 _scsih_flush_running_cmds(ioc
);
7791 case MPT3_IOC_DONE_RESET
:
7792 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7793 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7794 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7795 !ioc
->sas_hba
.num_phys
)) {
7796 _scsih_prep_device_scan(ioc
);
7797 _scsih_search_responding_sas_devices(ioc
);
7798 _scsih_search_responding_raid_devices(ioc
);
7799 _scsih_search_responding_expanders(ioc
);
7800 _scsih_error_recovery_delete_devices(ioc
);
7807 * _mpt3sas_fw_work - delayed task for processing firmware events
7808 * @ioc: per adapter object
7809 * @fw_event: The fw_event_work object
7815 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7817 _scsih_fw_event_del_from_list(ioc
, fw_event
);
7819 /* the queue is being flushed so ignore this event */
7820 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
7821 fw_event_work_put(fw_event
);
7825 switch (fw_event
->event
) {
7826 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7827 mpt3sas_process_trigger_data(ioc
,
7828 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7829 fw_event
->event_data
);
7831 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7832 while (scsi_host_in_recovery(ioc
->shost
) ||
7833 ioc
->shost_recovery
) {
7835 * If we're unloading, bail. Otherwise, this can become
7838 if (ioc
->remove_host
)
7842 _scsih_remove_unresponding_sas_devices(ioc
);
7843 _scsih_scan_for_devices_after_reset(ioc
);
7845 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7846 ioc
->start_scan
= 0;
7847 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7848 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7850 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7851 "port enable: complete from worker thread\n",
7854 case MPT3SAS_TURN_ON_PFA_LED
:
7855 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7857 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7858 _scsih_sas_topology_change_event(ioc
, fw_event
);
7860 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7861 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7863 case MPI2_EVENT_SAS_DISCOVERY
:
7864 _scsih_sas_discovery_event(ioc
, fw_event
);
7866 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7867 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7869 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7870 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7873 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7874 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7876 case MPI2_EVENT_IR_VOLUME
:
7877 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7879 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7880 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7882 case MPI2_EVENT_IR_OPERATION_STATUS
:
7883 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7887 fw_event_work_put(fw_event
);
7891 * _firmware_event_work
7892 * @ioc: per adapter object
7893 * @work: The fw_event_work object
7896 * wrappers for the work thread handling firmware events
7902 _firmware_event_work(struct work_struct
*work
)
7904 struct fw_event_work
*fw_event
= container_of(work
,
7905 struct fw_event_work
, work
);
7907 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7911 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7912 * @ioc: per adapter object
7913 * @msix_index: MSIX table index supplied by the OS
7914 * @reply: reply message frame(lower 32bit addr)
7915 * Context: interrupt.
7917 * This function merely adds a new work task into ioc->firmware_event_thread.
7918 * The tasks are worked from _firmware_event_work in user context.
7920 * Return 1 meaning mf should be freed from _base_interrupt
7921 * 0 means the mf is freed from this function.
7924 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7927 struct fw_event_work
*fw_event
;
7928 Mpi2EventNotificationReply_t
*mpi_reply
;
7931 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
7933 /* events turned off due to host reset or driver unloading */
7934 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7937 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7939 if (unlikely(!mpi_reply
)) {
7940 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7941 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7945 event
= le16_to_cpu(mpi_reply
->Event
);
7947 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7948 mpt3sas_trigger_event(ioc
, event
, 0);
7952 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7954 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7955 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7956 mpi_reply
->EventData
;
7958 if (baen_data
->Primitive
!=
7959 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7962 if (ioc
->broadcast_aen_busy
) {
7963 ioc
->broadcast_aen_pending
++;
7966 ioc
->broadcast_aen_busy
= 1;
7970 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7971 _scsih_check_topo_delete_events(ioc
,
7972 (Mpi2EventDataSasTopologyChangeList_t
*)
7973 mpi_reply
->EventData
);
7975 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7976 _scsih_check_ir_config_unhide_events(ioc
,
7977 (Mpi2EventDataIrConfigChangeList_t
*)
7978 mpi_reply
->EventData
);
7980 case MPI2_EVENT_IR_VOLUME
:
7981 _scsih_check_volume_delete_events(ioc
,
7982 (Mpi2EventDataIrVolume_t
*)
7983 mpi_reply
->EventData
);
7985 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7987 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7990 if (!ioc
->is_warpdrive
)
7993 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7994 mpi_reply
->EventData
;
7995 log_code
= (u32
*)log_entry
->LogData
;
7997 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7998 != MPT2_WARPDRIVE_LOGENTRY
)
8001 switch (le32_to_cpu(*log_code
)) {
8002 case MPT2_WARPDRIVE_LC_SSDT
:
8003 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
8004 "IO Throttling has occurred in the WarpDrive "
8005 "subsystem. Check WarpDrive documentation for "
8006 "additional details.\n", ioc
->name
);
8008 case MPT2_WARPDRIVE_LC_SSDLW
:
8009 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
8010 "Program/Erase Cycles for the WarpDrive subsystem "
8011 "in degraded range. Check WarpDrive documentation "
8012 "for additional details.\n", ioc
->name
);
8014 case MPT2_WARPDRIVE_LC_SSDLF
:
8015 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
8016 "There are no Program/Erase Cycles for the "
8017 "WarpDrive subsystem. The storage device will be "
8018 "in read-only mode. Check WarpDrive documentation "
8019 "for additional details.\n", ioc
->name
);
8021 case MPT2_WARPDRIVE_LC_BRMF
:
8022 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
8023 "The Backup Rail Monitor has failed on the "
8024 "WarpDrive subsystem. Check WarpDrive "
8025 "documentation for additional details.\n",
8032 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
8033 case MPI2_EVENT_IR_OPERATION_STATUS
:
8034 case MPI2_EVENT_SAS_DISCOVERY
:
8035 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
8036 case MPI2_EVENT_IR_PHYSICAL_DISK
:
8039 case MPI2_EVENT_TEMP_THRESHOLD
:
8040 _scsih_temp_threshold_events(ioc
,
8041 (Mpi2EventDataTemperature_t
*)
8042 mpi_reply
->EventData
);
8044 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
8045 ActiveCableEventData
=
8046 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
8047 if (ActiveCableEventData
->ReasonCode
==
8048 MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
) {
8049 pr_info(MPT3SAS_FMT
"Currently an active cable with ReceptacleID %d",
8050 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
8051 pr_info("cannot be powered and devices connected to this active cable");
8052 pr_info("will not be seen. This active cable");
8053 pr_info("requires %d mW of power",
8054 ActiveCableEventData
->ActiveCablePowerRequirement
);
8058 default: /* ignore the rest */
8062 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
8063 fw_event
= alloc_fw_event_work(sz
);
8065 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8066 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8070 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
8071 fw_event
->ioc
= ioc
;
8072 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
8073 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
8074 fw_event
->event
= event
;
8075 _scsih_fw_event_add(ioc
, fw_event
);
8076 fw_event_work_put(fw_event
);
8081 * _scsih_expander_node_remove - removing expander device from list.
8082 * @ioc: per adapter object
8083 * @sas_expander: the sas_device object
8084 * Context: Calling function should acquire ioc->sas_node_lock.
8086 * Removing object and freeing associated memory from the
8087 * ioc->sas_expander_list.
8092 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
8093 struct _sas_node
*sas_expander
)
8095 struct _sas_port
*mpt3sas_port
, *next
;
8097 /* remove sibling ports attached to this expander */
8098 list_for_each_entry_safe(mpt3sas_port
, next
,
8099 &sas_expander
->sas_port_list
, port_list
) {
8100 if (ioc
->shost_recovery
)
8102 if (mpt3sas_port
->remote_identify
.device_type
==
8104 mpt3sas_device_remove_by_sas_address(ioc
,
8105 mpt3sas_port
->remote_identify
.sas_address
);
8106 else if (mpt3sas_port
->remote_identify
.device_type
==
8107 SAS_EDGE_EXPANDER_DEVICE
||
8108 mpt3sas_port
->remote_identify
.device_type
==
8109 SAS_FANOUT_EXPANDER_DEVICE
)
8110 mpt3sas_expander_remove(ioc
,
8111 mpt3sas_port
->remote_identify
.sas_address
);
8114 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
8115 sas_expander
->sas_address_parent
);
8118 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8120 sas_expander
->handle
, (unsigned long long)
8121 sas_expander
->sas_address
);
8123 kfree(sas_expander
->phy
);
8124 kfree(sas_expander
);
8128 * _scsih_ir_shutdown - IR shutdown notification
8129 * @ioc: per adapter object
8131 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8132 * the host system is shutting down.
8137 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
8139 Mpi2RaidActionRequest_t
*mpi_request
;
8140 Mpi2RaidActionReply_t
*mpi_reply
;
8143 /* is IR firmware build loaded ? */
8144 if (!ioc
->ir_firmware
)
8147 /* are there any volumes ? */
8148 if (list_empty(&ioc
->raid_device_list
))
8151 mutex_lock(&ioc
->scsih_cmds
.mutex
);
8153 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
8154 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
8155 ioc
->name
, __func__
);
8158 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
8160 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
8162 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
8163 ioc
->name
, __func__
);
8164 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8168 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
8169 ioc
->scsih_cmds
.smid
= smid
;
8170 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
8172 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
8173 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
8175 if (!ioc
->hide_ir_msg
)
8176 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
8177 init_completion(&ioc
->scsih_cmds
.done
);
8178 ioc
->put_smid_default(ioc
, smid
);
8179 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
8181 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
8182 pr_err(MPT3SAS_FMT
"%s: timeout\n",
8183 ioc
->name
, __func__
);
8187 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
8188 mpi_reply
= ioc
->scsih_cmds
.reply
;
8189 if (!ioc
->hide_ir_msg
)
8190 pr_info(MPT3SAS_FMT
"IR shutdown "
8191 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8192 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
8193 le32_to_cpu(mpi_reply
->IOCLogInfo
));
8197 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8198 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
8202 * scsih_remove - detach and remove add host
8203 * @pdev: PCI device struct
8205 * Routine called when unloading the driver.
8208 static void scsih_remove(struct pci_dev
*pdev
)
8210 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8211 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8212 struct _sas_port
*mpt3sas_port
, *next_port
;
8213 struct _raid_device
*raid_device
, *next
;
8214 struct MPT3SAS_TARGET
*sas_target_priv_data
;
8215 struct workqueue_struct
*wq
;
8216 unsigned long flags
;
8218 ioc
->remove_host
= 1;
8219 _scsih_fw_event_cleanup_queue(ioc
);
8221 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8222 wq
= ioc
->firmware_event_thread
;
8223 ioc
->firmware_event_thread
= NULL
;
8224 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8226 destroy_workqueue(wq
);
8228 /* release all the volumes */
8229 _scsih_ir_shutdown(ioc
);
8230 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
8232 if (raid_device
->starget
) {
8233 sas_target_priv_data
=
8234 raid_device
->starget
->hostdata
;
8235 sas_target_priv_data
->deleted
= 1;
8236 scsi_remove_target(&raid_device
->starget
->dev
);
8238 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
8239 ioc
->name
, raid_device
->handle
,
8240 (unsigned long long) raid_device
->wwid
);
8241 _scsih_raid_device_remove(ioc
, raid_device
);
8244 /* free ports attached to the sas_host */
8245 list_for_each_entry_safe(mpt3sas_port
, next_port
,
8246 &ioc
->sas_hba
.sas_port_list
, port_list
) {
8247 if (mpt3sas_port
->remote_identify
.device_type
==
8249 mpt3sas_device_remove_by_sas_address(ioc
,
8250 mpt3sas_port
->remote_identify
.sas_address
);
8251 else if (mpt3sas_port
->remote_identify
.device_type
==
8252 SAS_EDGE_EXPANDER_DEVICE
||
8253 mpt3sas_port
->remote_identify
.device_type
==
8254 SAS_FANOUT_EXPANDER_DEVICE
)
8255 mpt3sas_expander_remove(ioc
,
8256 mpt3sas_port
->remote_identify
.sas_address
);
8259 /* free phys attached to the sas_host */
8260 if (ioc
->sas_hba
.num_phys
) {
8261 kfree(ioc
->sas_hba
.phy
);
8262 ioc
->sas_hba
.phy
= NULL
;
8263 ioc
->sas_hba
.num_phys
= 0;
8266 sas_remove_host(shost
);
8267 scsi_remove_host(shost
);
8268 mpt3sas_base_detach(ioc
);
8269 spin_lock(&gioc_lock
);
8270 list_del(&ioc
->list
);
8271 spin_unlock(&gioc_lock
);
8272 scsi_host_put(shost
);
8276 * scsih_shutdown - routine call during system shutdown
8277 * @pdev: PCI device struct
8282 scsih_shutdown(struct pci_dev
*pdev
)
8284 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8285 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8286 struct workqueue_struct
*wq
;
8287 unsigned long flags
;
8289 ioc
->remove_host
= 1;
8290 _scsih_fw_event_cleanup_queue(ioc
);
8292 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8293 wq
= ioc
->firmware_event_thread
;
8294 ioc
->firmware_event_thread
= NULL
;
8295 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8297 destroy_workqueue(wq
);
8299 _scsih_ir_shutdown(ioc
);
8300 mpt3sas_base_detach(ioc
);
8305 * _scsih_probe_boot_devices - reports 1st device
8306 * @ioc: per adapter object
8308 * If specified in bios page 2, this routine reports the 1st
8309 * device scsi-ml or sas transport for persistent boot device
8310 * purposes. Please refer to function _scsih_determine_boot_device()
8313 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
8317 struct _sas_device
*sas_device
;
8318 struct _raid_device
*raid_device
;
8320 u64 sas_address_parent
;
8322 unsigned long flags
;
8325 /* no Bios, return immediately */
8326 if (!ioc
->bios_pg3
.BiosVersion
)
8331 if (ioc
->req_boot_device
.device
) {
8332 device
= ioc
->req_boot_device
.device
;
8333 is_raid
= ioc
->req_boot_device
.is_raid
;
8334 } else if (ioc
->req_alt_boot_device
.device
) {
8335 device
= ioc
->req_alt_boot_device
.device
;
8336 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
8337 } else if (ioc
->current_boot_device
.device
) {
8338 device
= ioc
->current_boot_device
.device
;
8339 is_raid
= ioc
->current_boot_device
.is_raid
;
8346 raid_device
= device
;
8347 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8348 raid_device
->id
, 0);
8350 _scsih_raid_device_remove(ioc
, raid_device
);
8352 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8353 sas_device
= device
;
8354 handle
= sas_device
->handle
;
8355 sas_address_parent
= sas_device
->sas_address_parent
;
8356 sas_address
= sas_device
->sas_address
;
8357 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8358 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8360 if (ioc
->hide_drives
)
8362 if (!mpt3sas_transport_port_add(ioc
, handle
,
8363 sas_address_parent
)) {
8364 _scsih_sas_device_remove(ioc
, sas_device
);
8365 } else if (!sas_device
->starget
) {
8366 if (!ioc
->is_driver_loading
) {
8367 mpt3sas_transport_port_remove(ioc
,
8369 sas_address_parent
);
8370 _scsih_sas_device_remove(ioc
, sas_device
);
8377 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8378 * @ioc: per adapter object
8380 * Called during initial loading of the driver.
8383 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
8385 struct _raid_device
*raid_device
, *raid_next
;
8388 list_for_each_entry_safe(raid_device
, raid_next
,
8389 &ioc
->raid_device_list
, list
) {
8390 if (raid_device
->starget
)
8392 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8393 raid_device
->id
, 0);
8395 _scsih_raid_device_remove(ioc
, raid_device
);
8399 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
8401 struct _sas_device
*sas_device
= NULL
;
8402 unsigned long flags
;
8404 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8405 if (!list_empty(&ioc
->sas_device_init_list
)) {
8406 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
8407 struct _sas_device
, list
);
8408 sas_device_get(sas_device
);
8410 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8415 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
8416 struct _sas_device
*sas_device
)
8418 unsigned long flags
;
8420 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8423 * Since we dropped the lock during the call to port_add(), we need to
8424 * be careful here that somebody else didn't move or delete this item
8425 * while we were busy with other things.
8427 * If it was on the list, we need a put() for the reference the list
8428 * had. Either way, we need a get() for the destination list.
8430 if (!list_empty(&sas_device
->list
)) {
8431 list_del_init(&sas_device
->list
);
8432 sas_device_put(sas_device
);
8435 sas_device_get(sas_device
);
8436 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8438 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8442 * _scsih_probe_sas - reporting sas devices to sas transport
8443 * @ioc: per adapter object
8445 * Called during initial loading of the driver.
8448 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
8450 struct _sas_device
*sas_device
;
8452 if (ioc
->hide_drives
)
8455 while ((sas_device
= get_next_sas_device(ioc
))) {
8456 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
8457 sas_device
->sas_address_parent
)) {
8458 _scsih_sas_device_remove(ioc
, sas_device
);
8459 sas_device_put(sas_device
);
8461 } else if (!sas_device
->starget
) {
8463 * When asyn scanning is enabled, its not possible to
8464 * remove devices while scanning is turned on due to an
8465 * oops in scsi_sysfs_add_sdev()->add_device()->
8466 * sysfs_addrm_start()
8468 if (!ioc
->is_driver_loading
) {
8469 mpt3sas_transport_port_remove(ioc
,
8470 sas_device
->sas_address
,
8471 sas_device
->sas_address_parent
);
8472 _scsih_sas_device_remove(ioc
, sas_device
);
8473 sas_device_put(sas_device
);
8477 sas_device_make_active(ioc
, sas_device
);
8478 sas_device_put(sas_device
);
8483 * _scsih_probe_devices - probing for devices
8484 * @ioc: per adapter object
8486 * Called during initial loading of the driver.
8489 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
8491 u16 volume_mapping_flags
;
8493 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8494 return; /* return when IOC doesn't support initiator mode */
8496 _scsih_probe_boot_devices(ioc
);
8498 if (ioc
->ir_firmware
) {
8499 volume_mapping_flags
=
8500 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8501 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8502 if (volume_mapping_flags
==
8503 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8504 _scsih_probe_raid(ioc
);
8505 _scsih_probe_sas(ioc
);
8507 _scsih_probe_sas(ioc
);
8508 _scsih_probe_raid(ioc
);
8511 _scsih_probe_sas(ioc
);
8515 * scsih_scan_start - scsi lld callback for .scan_start
8516 * @shost: SCSI host pointer
8518 * The shost has the ability to discover targets on its own instead
8519 * of scanning the entire bus. In our implemention, we will kick off
8520 * firmware discovery.
8523 scsih_scan_start(struct Scsi_Host
*shost
)
8525 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8527 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8528 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8530 if (disable_discovery
> 0)
8533 ioc
->start_scan
= 1;
8534 rc
= mpt3sas_port_enable(ioc
);
8537 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
8541 * scsih_scan_finished - scsi lld callback for .scan_finished
8542 * @shost: SCSI host pointer
8543 * @time: elapsed time of the scan in jiffies
8545 * This function will be called periodicallyn until it returns 1 with the
8546 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8547 * we wait for firmware discovery to complete, then return 1.
8550 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8552 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8554 if (disable_discovery
> 0) {
8555 ioc
->is_driver_loading
= 0;
8556 ioc
->wait_for_discovery_to_complete
= 0;
8560 if (time
>= (300 * HZ
)) {
8561 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8563 "port enable: FAILED with timeout (timeout=300s)\n",
8565 ioc
->is_driver_loading
= 0;
8569 if (ioc
->start_scan
)
8572 if (ioc
->start_scan_failed
) {
8574 "port enable: FAILED with (ioc_status=0x%08x)\n",
8575 ioc
->name
, ioc
->start_scan_failed
);
8576 ioc
->is_driver_loading
= 0;
8577 ioc
->wait_for_discovery_to_complete
= 0;
8578 ioc
->remove_host
= 1;
8582 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
8583 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8585 if (ioc
->wait_for_discovery_to_complete
) {
8586 ioc
->wait_for_discovery_to_complete
= 0;
8587 _scsih_probe_devices(ioc
);
8589 mpt3sas_base_start_watchdog(ioc
);
8590 ioc
->is_driver_loading
= 0;
8594 /* shost template for SAS 2.0 HBA devices */
8595 static struct scsi_host_template mpt2sas_driver_template
= {
8596 .module
= THIS_MODULE
,
8597 .name
= "Fusion MPT SAS Host",
8598 .proc_name
= MPT2SAS_DRIVER_NAME
,
8599 .queuecommand
= scsih_qcmd
,
8600 .target_alloc
= scsih_target_alloc
,
8601 .slave_alloc
= scsih_slave_alloc
,
8602 .slave_configure
= scsih_slave_configure
,
8603 .target_destroy
= scsih_target_destroy
,
8604 .slave_destroy
= scsih_slave_destroy
,
8605 .scan_finished
= scsih_scan_finished
,
8606 .scan_start
= scsih_scan_start
,
8607 .change_queue_depth
= scsih_change_queue_depth
,
8608 .eh_abort_handler
= scsih_abort
,
8609 .eh_device_reset_handler
= scsih_dev_reset
,
8610 .eh_target_reset_handler
= scsih_target_reset
,
8611 .eh_host_reset_handler
= scsih_host_reset
,
8612 .bios_param
= scsih_bios_param
,
8615 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
8616 .max_sectors
= 32767,
8618 .use_clustering
= ENABLE_CLUSTERING
,
8619 .shost_attrs
= mpt3sas_host_attrs
,
8620 .sdev_attrs
= mpt3sas_dev_attrs
,
8621 .track_queue_depth
= 1,
8624 /* raid transport support for SAS 2.0 HBA devices */
8625 static struct raid_function_template mpt2sas_raid_functions
= {
8626 .cookie
= &mpt2sas_driver_template
,
8627 .is_raid
= scsih_is_raid
,
8628 .get_resync
= scsih_get_resync
,
8629 .get_state
= scsih_get_state
,
8632 /* shost template for SAS 3.0 HBA devices */
8633 static struct scsi_host_template mpt3sas_driver_template
= {
8634 .module
= THIS_MODULE
,
8635 .name
= "Fusion MPT SAS Host",
8636 .proc_name
= MPT3SAS_DRIVER_NAME
,
8637 .queuecommand
= scsih_qcmd
,
8638 .target_alloc
= scsih_target_alloc
,
8639 .slave_alloc
= scsih_slave_alloc
,
8640 .slave_configure
= scsih_slave_configure
,
8641 .target_destroy
= scsih_target_destroy
,
8642 .slave_destroy
= scsih_slave_destroy
,
8643 .scan_finished
= scsih_scan_finished
,
8644 .scan_start
= scsih_scan_start
,
8645 .change_queue_depth
= scsih_change_queue_depth
,
8646 .eh_abort_handler
= scsih_abort
,
8647 .eh_device_reset_handler
= scsih_dev_reset
,
8648 .eh_target_reset_handler
= scsih_target_reset
,
8649 .eh_host_reset_handler
= scsih_host_reset
,
8650 .bios_param
= scsih_bios_param
,
8653 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
8654 .max_sectors
= 32767,
8656 .use_clustering
= ENABLE_CLUSTERING
,
8657 .shost_attrs
= mpt3sas_host_attrs
,
8658 .sdev_attrs
= mpt3sas_dev_attrs
,
8659 .track_queue_depth
= 1,
8662 /* raid transport support for SAS 3.0 HBA devices */
8663 static struct raid_function_template mpt3sas_raid_functions
= {
8664 .cookie
= &mpt3sas_driver_template
,
8665 .is_raid
= scsih_is_raid
,
8666 .get_resync
= scsih_get_resync
,
8667 .get_state
= scsih_get_state
,
8671 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8672 * this device belongs to.
8673 * @pdev: PCI device struct
8675 * return MPI2_VERSION for SAS 2.0 HBA devices,
8676 * MPI25_VERSION for SAS 3.0 HBA devices, and
8677 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8680 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
8683 switch (pdev
->device
) {
8684 case MPI2_MFGPAGE_DEVID_SSS6200
:
8685 case MPI2_MFGPAGE_DEVID_SAS2004
:
8686 case MPI2_MFGPAGE_DEVID_SAS2008
:
8687 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
8688 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
8689 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
8690 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
8691 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
8692 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
8693 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
8694 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
8695 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
8696 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
8697 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
8698 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
8699 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
8700 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
8701 return MPI2_VERSION
;
8702 case MPI25_MFGPAGE_DEVID_SAS3004
:
8703 case MPI25_MFGPAGE_DEVID_SAS3008
:
8704 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
8705 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
8706 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
8707 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
8708 return MPI25_VERSION
;
8709 case MPI26_MFGPAGE_DEVID_SAS3216
:
8710 case MPI26_MFGPAGE_DEVID_SAS3224
:
8711 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
8712 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
8713 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
8714 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
8715 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
8716 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
8717 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
8718 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
8719 case MPI26_MFGPAGE_DEVID_SAS3508
:
8720 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
8721 case MPI26_MFGPAGE_DEVID_SAS3408
:
8722 case MPI26_MFGPAGE_DEVID_SAS3516
:
8723 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
8724 case MPI26_MFGPAGE_DEVID_SAS3416
:
8725 return MPI26_VERSION
;
8731 * _scsih_probe - attach and add scsi host
8732 * @pdev: PCI device struct
8733 * @id: pci device id
8735 * Returns 0 success, anything else error.
8738 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8740 struct MPT3SAS_ADAPTER
*ioc
;
8741 struct Scsi_Host
*shost
= NULL
;
8743 u16 hba_mpi_version
;
8745 /* Determine in which MPI version class this pci device belongs */
8746 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
8747 if (hba_mpi_version
== 0)
8750 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8751 * for other generation HBA's return with -ENODEV
8753 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
8756 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8757 * for other generation HBA's return with -ENODEV
8759 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
8760 || hba_mpi_version
== MPI26_VERSION
)))
8763 switch (hba_mpi_version
) {
8765 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
8766 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
8767 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8768 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
8769 sizeof(struct MPT3SAS_ADAPTER
));
8772 ioc
= shost_priv(shost
);
8773 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8774 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8775 ioc
->id
= mpt2_ids
++;
8776 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
8777 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8778 ioc
->is_warpdrive
= 1;
8779 ioc
->hide_ir_msg
= 1;
8781 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8785 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8786 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
8787 sizeof(struct MPT3SAS_ADAPTER
));
8790 ioc
= shost_priv(shost
);
8791 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8792 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8793 ioc
->id
= mpt3_ids
++;
8794 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
8795 switch (pdev
->device
) {
8796 case MPI26_MFGPAGE_DEVID_SAS3508
:
8797 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
8798 case MPI26_MFGPAGE_DEVID_SAS3408
:
8799 case MPI26_MFGPAGE_DEVID_SAS3516
:
8800 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
8801 case MPI26_MFGPAGE_DEVID_SAS3416
:
8802 ioc
->is_gen35_ioc
= 1;
8805 ioc
->is_gen35_ioc
= 0;
8807 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
8808 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
8809 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
8810 ioc
->combined_reply_queue
= 1;
8811 if (ioc
->is_gen35_ioc
)
8812 ioc
->combined_reply_index_count
=
8813 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
8815 ioc
->combined_reply_index_count
=
8816 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
8823 INIT_LIST_HEAD(&ioc
->list
);
8824 spin_lock(&gioc_lock
);
8825 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8826 spin_unlock(&gioc_lock
);
8829 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8830 ioc
->tm_cb_idx
= tm_cb_idx
;
8831 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8832 ioc
->base_cb_idx
= base_cb_idx
;
8833 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8834 ioc
->transport_cb_idx
= transport_cb_idx
;
8835 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8836 ioc
->config_cb_idx
= config_cb_idx
;
8837 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8838 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8839 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8840 ioc
->logging_level
= logging_level
;
8841 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8842 /* misc semaphores and spin locks */
8843 mutex_init(&ioc
->reset_in_progress_mutex
);
8844 /* initializing pci_access_mutex lock */
8845 mutex_init(&ioc
->pci_access_mutex
);
8846 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8847 spin_lock_init(&ioc
->scsi_lookup_lock
);
8848 spin_lock_init(&ioc
->sas_device_lock
);
8849 spin_lock_init(&ioc
->sas_node_lock
);
8850 spin_lock_init(&ioc
->fw_event_lock
);
8851 spin_lock_init(&ioc
->raid_device_lock
);
8852 spin_lock_init(&ioc
->diag_trigger_lock
);
8854 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8855 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8856 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8857 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8858 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8859 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8860 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8861 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
8862 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
8863 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8864 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8866 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
8868 /* init shost parameters */
8869 shost
->max_cmd_len
= 32;
8870 shost
->max_lun
= max_lun
;
8871 shost
->transportt
= mpt3sas_transport_template
;
8872 shost
->unique_id
= ioc
->id
;
8874 if (max_sectors
!= 0xFFFF) {
8875 if (max_sectors
< 64) {
8876 shost
->max_sectors
= 64;
8877 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8878 "for max_sectors, range is 64 to 32767. Assigning "
8879 "value of 64.\n", ioc
->name
, max_sectors
);
8880 } else if (max_sectors
> 32767) {
8881 shost
->max_sectors
= 32767;
8882 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8883 "for max_sectors, range is 64 to 32767. Assigning "
8884 "default value of 32767.\n", ioc
->name
,
8887 shost
->max_sectors
= max_sectors
& 0xFFFE;
8889 "The max_sectors value is set to %d\n",
8890 ioc
->name
, shost
->max_sectors
);
8894 /* register EEDP capabilities with SCSI layer */
8896 scsi_host_set_prot(shost
, prot_mask
);
8898 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8899 | SHOST_DIF_TYPE2_PROTECTION
8900 | SHOST_DIF_TYPE3_PROTECTION
);
8902 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8905 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8906 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
8907 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8908 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8909 if (!ioc
->firmware_event_thread
) {
8910 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8911 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8913 goto out_thread_fail
;
8916 ioc
->is_driver_loading
= 1;
8917 if ((mpt3sas_base_attach(ioc
))) {
8918 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8919 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8921 goto out_attach_fail
;
8924 if (ioc
->is_warpdrive
) {
8925 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8926 ioc
->hide_drives
= 0;
8927 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8928 ioc
->hide_drives
= 1;
8930 if (mpt3sas_get_num_volumes(ioc
))
8931 ioc
->hide_drives
= 1;
8933 ioc
->hide_drives
= 0;
8936 ioc
->hide_drives
= 0;
8938 rv
= scsi_add_host(shost
, &pdev
->dev
);
8940 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8941 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8942 goto out_add_shost_fail
;
8945 scsi_scan_host(shost
);
8948 mpt3sas_base_detach(ioc
);
8950 destroy_workqueue(ioc
->firmware_event_thread
);
8952 spin_lock(&gioc_lock
);
8953 list_del(&ioc
->list
);
8954 spin_unlock(&gioc_lock
);
8955 scsi_host_put(shost
);
8961 * scsih_suspend - power management suspend main entry point
8962 * @pdev: PCI device struct
8963 * @state: PM state change to (usually PCI_D3)
8965 * Returns 0 success, anything else error.
8968 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8970 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8971 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8972 pci_power_t device_state
;
8974 mpt3sas_base_stop_watchdog(ioc
);
8975 flush_scheduled_work();
8976 scsi_block_requests(shost
);
8977 device_state
= pci_choose_state(pdev
, state
);
8979 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8980 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8982 pci_save_state(pdev
);
8983 mpt3sas_base_free_resources(ioc
);
8984 pci_set_power_state(pdev
, device_state
);
8989 * scsih_resume - power management resume main entry point
8990 * @pdev: PCI device struct
8992 * Returns 0 success, anything else error.
8995 scsih_resume(struct pci_dev
*pdev
)
8997 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8998 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8999 pci_power_t device_state
= pdev
->current_state
;
9003 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
9004 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
9006 pci_set_power_state(pdev
, PCI_D0
);
9007 pci_enable_wake(pdev
, PCI_D0
, 0);
9008 pci_restore_state(pdev
);
9010 r
= mpt3sas_base_map_resources(ioc
);
9014 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
9015 scsi_unblock_requests(shost
);
9016 mpt3sas_base_start_watchdog(ioc
);
9019 #endif /* CONFIG_PM */
9022 * scsih_pci_error_detected - Called when a PCI error is detected.
9023 * @pdev: PCI device struct
9024 * @state: PCI channel state
9026 * Description: Called when a PCI error is detected.
9029 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
9031 static pci_ers_result_t
9032 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
9034 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9035 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9037 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
9041 case pci_channel_io_normal
:
9042 return PCI_ERS_RESULT_CAN_RECOVER
;
9043 case pci_channel_io_frozen
:
9044 /* Fatal error, prepare for slot reset */
9045 ioc
->pci_error_recovery
= 1;
9046 scsi_block_requests(ioc
->shost
);
9047 mpt3sas_base_stop_watchdog(ioc
);
9048 mpt3sas_base_free_resources(ioc
);
9049 return PCI_ERS_RESULT_NEED_RESET
;
9050 case pci_channel_io_perm_failure
:
9051 /* Permanent error, prepare for device removal */
9052 ioc
->pci_error_recovery
= 1;
9053 mpt3sas_base_stop_watchdog(ioc
);
9054 _scsih_flush_running_cmds(ioc
);
9055 return PCI_ERS_RESULT_DISCONNECT
;
9057 return PCI_ERS_RESULT_NEED_RESET
;
9061 * scsih_pci_slot_reset - Called when PCI slot has been reset.
9062 * @pdev: PCI device struct
9064 * Description: This routine is called by the pci error recovery
9065 * code after the PCI slot has been reset, just before we
9066 * should resume normal operations.
9068 static pci_ers_result_t
9069 scsih_pci_slot_reset(struct pci_dev
*pdev
)
9071 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9072 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9075 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
9078 ioc
->pci_error_recovery
= 0;
9080 pci_restore_state(pdev
);
9081 rc
= mpt3sas_base_map_resources(ioc
);
9083 return PCI_ERS_RESULT_DISCONNECT
;
9085 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
9087 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
9088 (rc
== 0) ? "success" : "failed");
9091 return PCI_ERS_RESULT_RECOVERED
;
9093 return PCI_ERS_RESULT_DISCONNECT
;
9097 * scsih_pci_resume() - resume normal ops after PCI reset
9098 * @pdev: pointer to PCI device
9100 * Called when the error recovery driver tells us that its
9101 * OK to resume normal operation. Use completion to allow
9102 * halted scsi ops to resume.
9105 scsih_pci_resume(struct pci_dev
*pdev
)
9107 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9108 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9110 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
9112 pci_cleanup_aer_uncorrect_error_status(pdev
);
9113 mpt3sas_base_start_watchdog(ioc
);
9114 scsi_unblock_requests(ioc
->shost
);
9118 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
9119 * @pdev: pointer to PCI device
9121 static pci_ers_result_t
9122 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
9124 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9125 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9127 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
9130 /* TODO - dump whatever for debugging purposes */
9132 /* This called only if scsih_pci_error_detected returns
9133 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
9134 * works, no need to reset slot.
9136 return PCI_ERS_RESULT_RECOVERED
;
9140 * scsih__ncq_prio_supp - Check for NCQ command priority support
9141 * @sdev: scsi device struct
9143 * This is called when a user indicates they would like to enable
9144 * ncq command priorities. This works only on SATA devices.
9146 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
9149 bool ncq_prio_supp
= false;
9151 if (!scsi_device_supports_vpd(sdev
))
9152 return ncq_prio_supp
;
9154 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
9156 return ncq_prio_supp
;
9158 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
9159 ncq_prio_supp
= (buf
[213] >> 4) & 1;
9162 return ncq_prio_supp
;
9165 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9167 static const struct pci_device_id mpt3sas_pci_table
[] = {
9168 /* Spitfire ~ 2004 */
9169 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
9170 PCI_ANY_ID
, PCI_ANY_ID
},
9172 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
9173 PCI_ANY_ID
, PCI_ANY_ID
},
9174 /* Liberator ~ 2108 */
9175 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
9176 PCI_ANY_ID
, PCI_ANY_ID
},
9177 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
9178 PCI_ANY_ID
, PCI_ANY_ID
},
9179 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
9180 PCI_ANY_ID
, PCI_ANY_ID
},
9182 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
9183 PCI_ANY_ID
, PCI_ANY_ID
},
9184 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
9185 PCI_ANY_ID
, PCI_ANY_ID
},
9186 /* Thunderbolt ~ 2208 */
9187 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
9188 PCI_ANY_ID
, PCI_ANY_ID
},
9189 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
9190 PCI_ANY_ID
, PCI_ANY_ID
},
9191 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
9192 PCI_ANY_ID
, PCI_ANY_ID
},
9193 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
9194 PCI_ANY_ID
, PCI_ANY_ID
},
9195 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
9196 PCI_ANY_ID
, PCI_ANY_ID
},
9197 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
9198 PCI_ANY_ID
, PCI_ANY_ID
},
9199 /* Mustang ~ 2308 */
9200 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
9201 PCI_ANY_ID
, PCI_ANY_ID
},
9202 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
9203 PCI_ANY_ID
, PCI_ANY_ID
},
9204 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
9205 PCI_ANY_ID
, PCI_ANY_ID
},
9207 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
9208 PCI_ANY_ID
, PCI_ANY_ID
},
9209 /* Fury ~ 3004 and 3008 */
9210 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
9211 PCI_ANY_ID
, PCI_ANY_ID
},
9212 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
9213 PCI_ANY_ID
, PCI_ANY_ID
},
9214 /* Invader ~ 3108 */
9215 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
9216 PCI_ANY_ID
, PCI_ANY_ID
},
9217 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
9218 PCI_ANY_ID
, PCI_ANY_ID
},
9219 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
9220 PCI_ANY_ID
, PCI_ANY_ID
},
9221 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
9222 PCI_ANY_ID
, PCI_ANY_ID
},
9223 /* Cutlass ~ 3216 and 3224 */
9224 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
9225 PCI_ANY_ID
, PCI_ANY_ID
},
9226 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
9227 PCI_ANY_ID
, PCI_ANY_ID
},
9228 /* Intruder ~ 3316 and 3324 */
9229 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
9230 PCI_ANY_ID
, PCI_ANY_ID
},
9231 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
9232 PCI_ANY_ID
, PCI_ANY_ID
},
9233 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
9234 PCI_ANY_ID
, PCI_ANY_ID
},
9235 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
9236 PCI_ANY_ID
, PCI_ANY_ID
},
9237 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
9238 PCI_ANY_ID
, PCI_ANY_ID
},
9239 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
9240 PCI_ANY_ID
, PCI_ANY_ID
},
9241 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
9242 PCI_ANY_ID
, PCI_ANY_ID
},
9243 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
9244 PCI_ANY_ID
, PCI_ANY_ID
},
9245 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
9246 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
9247 PCI_ANY_ID
, PCI_ANY_ID
},
9248 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
9249 PCI_ANY_ID
, PCI_ANY_ID
},
9250 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
9251 PCI_ANY_ID
, PCI_ANY_ID
},
9252 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
9253 PCI_ANY_ID
, PCI_ANY_ID
},
9254 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
9255 PCI_ANY_ID
, PCI_ANY_ID
},
9256 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
9257 PCI_ANY_ID
, PCI_ANY_ID
},
9258 {0} /* Terminating entry */
9260 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
9262 static struct pci_error_handlers _mpt3sas_err_handler
= {
9263 .error_detected
= scsih_pci_error_detected
,
9264 .mmio_enabled
= scsih_pci_mmio_enabled
,
9265 .slot_reset
= scsih_pci_slot_reset
,
9266 .resume
= scsih_pci_resume
,
9269 static struct pci_driver mpt3sas_driver
= {
9270 .name
= MPT3SAS_DRIVER_NAME
,
9271 .id_table
= mpt3sas_pci_table
,
9272 .probe
= _scsih_probe
,
9273 .remove
= scsih_remove
,
9274 .shutdown
= scsih_shutdown
,
9275 .err_handler
= &_mpt3sas_err_handler
,
9277 .suspend
= scsih_suspend
,
9278 .resume
= scsih_resume
,
9283 * scsih_init - main entry point for this driver.
9285 * Returns 0 success, anything else error.
9293 mpt3sas_base_initialize_callback_handler();
9295 /* queuecommand callback hander */
9296 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
9298 /* task management callback handler */
9299 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
9301 /* base internal commands callback handler */
9302 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
9303 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
9304 mpt3sas_port_enable_done
);
9306 /* transport internal commands callback handler */
9307 transport_cb_idx
= mpt3sas_base_register_callback_handler(
9308 mpt3sas_transport_done
);
9310 /* scsih internal commands callback handler */
9311 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
9313 /* configuration page API internal commands callback handler */
9314 config_cb_idx
= mpt3sas_base_register_callback_handler(
9315 mpt3sas_config_done
);
9317 /* ctl module callback handler */
9318 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
9320 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
9321 _scsih_tm_tr_complete
);
9323 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
9324 _scsih_tm_volume_tr_complete
);
9326 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
9327 _scsih_sas_control_complete
);
9333 * scsih_exit - exit point for this driver (when it is a module).
9335 * Returns 0 success, anything else error.
9341 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
9342 mpt3sas_base_release_callback_handler(tm_cb_idx
);
9343 mpt3sas_base_release_callback_handler(base_cb_idx
);
9344 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
9345 mpt3sas_base_release_callback_handler(transport_cb_idx
);
9346 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
9347 mpt3sas_base_release_callback_handler(config_cb_idx
);
9348 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
9350 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
9351 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
9352 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
9354 /* raid transport support */
9355 if (hbas_to_enumerate
!= 1)
9356 raid_class_release(mpt3sas_raid_template
);
9357 if (hbas_to_enumerate
!= 2)
9358 raid_class_release(mpt2sas_raid_template
);
9359 sas_release_transport(mpt3sas_transport_template
);
9363 * _mpt3sas_init - main entry point for this driver.
9365 * Returns 0 success, anything else error.
9372 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
9373 MPT3SAS_DRIVER_VERSION
);
9375 mpt3sas_transport_template
=
9376 sas_attach_transport(&mpt3sas_transport_functions
);
9377 if (!mpt3sas_transport_template
)
9380 /* No need attach mpt3sas raid functions template
9381 * if hbas_to_enumarate value is one.
9383 if (hbas_to_enumerate
!= 1) {
9384 mpt3sas_raid_template
=
9385 raid_class_attach(&mpt3sas_raid_functions
);
9386 if (!mpt3sas_raid_template
) {
9387 sas_release_transport(mpt3sas_transport_template
);
9392 /* No need to attach mpt2sas raid functions template
9393 * if hbas_to_enumarate value is two
9395 if (hbas_to_enumerate
!= 2) {
9396 mpt2sas_raid_template
=
9397 raid_class_attach(&mpt2sas_raid_functions
);
9398 if (!mpt2sas_raid_template
) {
9399 sas_release_transport(mpt3sas_transport_template
);
9404 error
= scsih_init();
9410 mpt3sas_ctl_init(hbas_to_enumerate
);
9412 error
= pci_register_driver(&mpt3sas_driver
);
9420 * _mpt3sas_exit - exit point for this driver (when it is a module).
9426 pr_info("mpt3sas version %s unloading\n",
9427 MPT3SAS_DRIVER_VERSION
);
9429 pci_unregister_driver(&mpt3sas_driver
);
9431 mpt3sas_ctl_exit(hbas_to_enumerate
);
9436 module_init(_mpt3sas_init
);
9437 module_exit(_mpt3sas_exit
);