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/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <asm/unaligned.h>
59 #include "mpt3sas_base.h"
61 #define RAID_CHANNEL 1
63 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
64 struct _sas_node
*sas_expander
);
65 static void _firmware_event_work(struct work_struct
*work
);
67 static void _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
68 struct _sas_device
*sas_device
);
69 static int _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
70 u8 retry_count
, u8 is_pd
);
72 static u8
_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
);
74 /* global parameters */
75 LIST_HEAD(mpt3sas_ioc_list
);
76 /* global ioc lock for list operations */
77 DEFINE_SPINLOCK(gioc_lock
);
79 MODULE_AUTHOR(MPT3SAS_AUTHOR
);
80 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION
);
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(MPT3SAS_DRIVER_VERSION
);
83 MODULE_ALIAS("mpt2sas");
85 /* local parameters */
86 static u8 scsi_io_cb_idx
= -1;
87 static u8 tm_cb_idx
= -1;
88 static u8 ctl_cb_idx
= -1;
89 static u8 base_cb_idx
= -1;
90 static u8 port_enable_cb_idx
= -1;
91 static u8 transport_cb_idx
= -1;
92 static u8 scsih_cb_idx
= -1;
93 static u8 config_cb_idx
= -1;
97 static u8 tm_tr_cb_idx
= -1 ;
98 static u8 tm_tr_volume_cb_idx
= -1 ;
99 static u8 tm_sas_control_cb_idx
= -1;
101 /* command line options */
102 static u32 logging_level
;
103 MODULE_PARM_DESC(logging_level
,
104 " bits for enabling additional logging info (default=0)");
107 static ushort max_sectors
= 0xFFFF;
108 module_param(max_sectors
, ushort
, 0);
109 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
112 static int missing_delay
[2] = {-1, -1};
113 module_param_array(missing_delay
, int, NULL
, 0);
114 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
116 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
117 #define MPT3SAS_MAX_LUN (16895)
118 static u64 max_lun
= MPT3SAS_MAX_LUN
;
119 module_param(max_lun
, ullong
, 0);
120 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
122 static ushort hbas_to_enumerate
;
123 module_param(hbas_to_enumerate
, ushort
, 0);
124 MODULE_PARM_DESC(hbas_to_enumerate
,
125 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
126 1 - enumerates only SAS 2.0 generation HBAs\n \
127 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
129 /* diag_buffer_enable is bitwise
131 * bit 1 set = SNAPSHOT
132 * bit 2 set = EXTENDED
134 * Either bit can be set, or both
136 static int diag_buffer_enable
= -1;
137 module_param(diag_buffer_enable
, int, 0);
138 MODULE_PARM_DESC(diag_buffer_enable
,
139 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
140 static int disable_discovery
= -1;
141 module_param(disable_discovery
, int, 0);
142 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
145 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
146 static int prot_mask
= -1;
147 module_param(prot_mask
, int, 0);
148 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
151 /* raid transport support */
152 struct raid_template
*mpt3sas_raid_template
;
153 struct raid_template
*mpt2sas_raid_template
;
157 * struct sense_info - common structure for obtaining sense keys
159 * @asc: additional sense code
160 * @ascq: additional sense code qualifier
168 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
169 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
170 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
171 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
172 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
174 * struct fw_event_work - firmware event struct
175 * @list: link list framework
176 * @work: work object (ioc->fault_reset_work_q)
177 * @cancel_pending_work: flag set during reset handling
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 mpt2_ioc.h
184 * @event_data: reply event data payload follows
186 * This object stored on ioc->fw_event_list.
188 struct fw_event_work
{
189 struct list_head list
;
190 struct work_struct work
;
191 u8 cancel_pending_work
;
192 struct delayed_work delayed_work
;
194 struct MPT3SAS_ADAPTER
*ioc
;
200 struct kref refcount
;
201 char event_data
[0] __aligned(4);
204 static void fw_event_work_free(struct kref
*r
)
206 kfree(container_of(r
, struct fw_event_work
, refcount
));
209 static void fw_event_work_get(struct fw_event_work
*fw_work
)
211 kref_get(&fw_work
->refcount
);
214 static void fw_event_work_put(struct fw_event_work
*fw_work
)
216 kref_put(&fw_work
->refcount
, fw_event_work_free
);
219 static struct fw_event_work
*alloc_fw_event_work(int len
)
221 struct fw_event_work
*fw_event
;
223 fw_event
= kzalloc(sizeof(*fw_event
) + len
, GFP_ATOMIC
);
227 kref_init(&fw_event
->refcount
);
232 * struct _scsi_io_transfer - scsi io transfer
233 * @handle: sas device handle (assigned by firmware)
234 * @is_raid: flag set for hidden raid components
235 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
236 * @data_length: data transfer length
237 * @data_dma: dma pointer to data
240 * @cdb_length: cdb length
242 * @timeout: timeout for this command
243 * @VF_ID: virtual function id
244 * @VP_ID: virtual port id
245 * @valid_reply: flag set for reply message
246 * @sense_length: sense length
247 * @ioc_status: ioc status
248 * @scsi_state: scsi state
249 * @scsi_status: scsi staus
250 * @log_info: log information
251 * @transfer_length: data length transfer when there is a reply message
253 * Used for sending internal scsi commands to devices within this module.
254 * Refer to _scsi_send_scsi_io().
256 struct _scsi_io_transfer
{
259 enum dma_data_direction dir
;
262 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
270 /* the following bits are only valid when 'valid_reply = 1' */
280 * _scsih_set_debug_level - global setting of ioc->logging_level.
282 * Note: The logging levels are defined in mpt3sas_debug.h.
285 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
287 int ret
= param_set_int(val
, kp
);
288 struct MPT3SAS_ADAPTER
*ioc
;
293 pr_info("setting logging_level(0x%08x)\n", logging_level
);
294 spin_lock(&gioc_lock
);
295 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
296 ioc
->logging_level
= logging_level
;
297 spin_unlock(&gioc_lock
);
300 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
301 &logging_level
, 0644);
304 * _scsih_srch_boot_sas_address - search based on sas_address
305 * @sas_address: sas address
306 * @boot_device: boot device object from bios page 2
308 * Returns 1 when there's a match, 0 means no match.
311 _scsih_srch_boot_sas_address(u64 sas_address
,
312 Mpi2BootDeviceSasWwid_t
*boot_device
)
314 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
318 * _scsih_srch_boot_device_name - search based on device name
319 * @device_name: device name specified in INDENTIFY fram
320 * @boot_device: boot device object from bios page 2
322 * Returns 1 when there's a match, 0 means no match.
325 _scsih_srch_boot_device_name(u64 device_name
,
326 Mpi2BootDeviceDeviceName_t
*boot_device
)
328 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
332 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
333 * @enclosure_logical_id: enclosure logical id
334 * @slot_number: slot number
335 * @boot_device: boot device object from bios page 2
337 * Returns 1 when there's a match, 0 means no match.
340 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
341 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
343 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
344 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
345 SlotNumber
)) ? 1 : 0;
349 * _scsih_is_boot_device - search for matching boot device.
350 * @sas_address: sas address
351 * @device_name: device name specified in INDENTIFY fram
352 * @enclosure_logical_id: enclosure logical id
353 * @slot_number: slot number
354 * @form: specifies boot device form
355 * @boot_device: boot device object from bios page 2
357 * Returns 1 when there's a match, 0 means no match.
360 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
361 u64 enclosure_logical_id
, u16 slot
, u8 form
,
362 Mpi2BiosPage2BootDevice_t
*boot_device
)
367 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
370 rc
= _scsih_srch_boot_sas_address(
371 sas_address
, &boot_device
->SasWwid
);
373 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
374 if (!enclosure_logical_id
)
376 rc
= _scsih_srch_boot_encl_slot(
377 enclosure_logical_id
,
378 slot
, &boot_device
->EnclosureSlot
);
380 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
383 rc
= _scsih_srch_boot_device_name(
384 device_name
, &boot_device
->DeviceName
);
386 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
394 * _scsih_get_sas_address - set the sas_address for given device handle
395 * @handle: device handle
396 * @sas_address: sas address
398 * Returns 0 success, non-zero when failure
401 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
404 Mpi2SasDevicePage0_t sas_device_pg0
;
405 Mpi2ConfigReply_t mpi_reply
;
410 if (handle
<= ioc
->sas_hba
.num_phys
) {
411 *sas_address
= ioc
->sas_hba
.sas_address
;
415 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
416 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
417 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
418 __FILE__
, __LINE__
, __func__
);
422 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
423 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
424 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
428 /* we hit this becuase the given parent handle doesn't exist */
429 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
432 /* else error case */
434 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
435 ioc
->name
, handle
, ioc_status
,
436 __FILE__
, __LINE__
, __func__
);
441 * _scsih_determine_boot_device - determine boot device.
442 * @ioc: per adapter object
443 * @device: either sas_device or raid_device object
444 * @is_raid: [flag] 1 = raid object, 0 = sas object
446 * Determines whether this device should be first reported device to
447 * to scsi-ml or sas transport, this purpose is for persistent boot device.
448 * There are primary, alternate, and current entries in bios page 2. The order
449 * priority is primary, alternate, then current. This routine saves
450 * the corresponding device object and is_raid flag in the ioc object.
451 * The saved data to be used later in _scsih_probe_boot_devices().
454 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
,
455 void *device
, u8 is_raid
)
457 struct _sas_device
*sas_device
;
458 struct _raid_device
*raid_device
;
461 u64 enclosure_logical_id
;
464 /* only process this function when driver loads */
465 if (!ioc
->is_driver_loading
)
468 /* no Bios, return immediately */
469 if (!ioc
->bios_pg3
.BiosVersion
)
474 sas_address
= sas_device
->sas_address
;
475 device_name
= sas_device
->device_name
;
476 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
477 slot
= sas_device
->slot
;
479 raid_device
= device
;
480 sas_address
= raid_device
->wwid
;
482 enclosure_logical_id
= 0;
486 if (!ioc
->req_boot_device
.device
) {
487 if (_scsih_is_boot_device(sas_address
, device_name
,
488 enclosure_logical_id
, slot
,
489 (ioc
->bios_pg2
.ReqBootDeviceForm
&
490 MPI2_BIOSPAGE2_FORM_MASK
),
491 &ioc
->bios_pg2
.RequestedBootDevice
)) {
492 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
493 "%s: req_boot_device(0x%016llx)\n",
495 (unsigned long long)sas_address
));
496 ioc
->req_boot_device
.device
= device
;
497 ioc
->req_boot_device
.is_raid
= is_raid
;
501 if (!ioc
->req_alt_boot_device
.device
) {
502 if (_scsih_is_boot_device(sas_address
, device_name
,
503 enclosure_logical_id
, slot
,
504 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
505 MPI2_BIOSPAGE2_FORM_MASK
),
506 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
507 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
508 "%s: req_alt_boot_device(0x%016llx)\n",
510 (unsigned long long)sas_address
));
511 ioc
->req_alt_boot_device
.device
= device
;
512 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
516 if (!ioc
->current_boot_device
.device
) {
517 if (_scsih_is_boot_device(sas_address
, device_name
,
518 enclosure_logical_id
, slot
,
519 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
520 MPI2_BIOSPAGE2_FORM_MASK
),
521 &ioc
->bios_pg2
.CurrentBootDevice
)) {
522 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
523 "%s: current_boot_device(0x%016llx)\n",
525 (unsigned long long)sas_address
));
526 ioc
->current_boot_device
.device
= device
;
527 ioc
->current_boot_device
.is_raid
= is_raid
;
532 static struct _sas_device
*
533 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
534 struct MPT3SAS_TARGET
*tgt_priv
)
536 struct _sas_device
*ret
;
538 assert_spin_locked(&ioc
->sas_device_lock
);
540 ret
= tgt_priv
->sdev
;
547 static struct _sas_device
*
548 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
549 struct MPT3SAS_TARGET
*tgt_priv
)
551 struct _sas_device
*ret
;
554 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
555 ret
= __mpt3sas_get_sdev_from_target(ioc
, tgt_priv
);
556 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
563 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
566 struct _sas_device
*sas_device
;
568 assert_spin_locked(&ioc
->sas_device_lock
);
570 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
571 if (sas_device
->sas_address
== sas_address
)
574 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
575 if (sas_device
->sas_address
== sas_address
)
581 sas_device_get(sas_device
);
586 * mpt3sas_get_sdev_by_addr - sas device search
587 * @ioc: per adapter object
588 * @sas_address: sas address
589 * Context: Calling function should acquire ioc->sas_device_lock
591 * This searches for sas_device based on sas_address, then return sas_device
595 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
598 struct _sas_device
*sas_device
;
601 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
602 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
604 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
609 static struct _sas_device
*
610 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
612 struct _sas_device
*sas_device
;
614 assert_spin_locked(&ioc
->sas_device_lock
);
616 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
617 if (sas_device
->handle
== handle
)
620 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
621 if (sas_device
->handle
== handle
)
627 sas_device_get(sas_device
);
632 * mpt3sas_get_sdev_by_handle - sas device search
633 * @ioc: per adapter object
634 * @handle: sas device handle (assigned by firmware)
635 * Context: Calling function should acquire ioc->sas_device_lock
637 * This searches for sas_device based on sas_address, then return sas_device
640 static struct _sas_device
*
641 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
643 struct _sas_device
*sas_device
;
646 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
647 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
648 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
654 * _scsih_sas_device_remove - remove sas_device from list.
655 * @ioc: per adapter object
656 * @sas_device: the sas_device object
657 * Context: This function will acquire ioc->sas_device_lock.
659 * If sas_device is on the list, remove it and decrement its reference count.
662 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
663 struct _sas_device
*sas_device
)
670 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
671 ioc
->name
, sas_device
->handle
,
672 (unsigned long long) sas_device
->sas_address
);
674 if (sas_device
->enclosure_handle
!= 0)
676 "removing enclosure logical id(0x%016llx), slot(%d)\n",
677 ioc
->name
, (unsigned long long)
678 sas_device
->enclosure_logical_id
, sas_device
->slot
);
680 if (sas_device
->connector_name
[0] != '\0')
682 "removing enclosure level(0x%04x), connector name( %s)\n",
683 ioc
->name
, sas_device
->enclosure_level
,
684 sas_device
->connector_name
);
687 * The lock serializes access to the list, but we still need to verify
688 * that nobody removed the entry while we were waiting on the lock.
690 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
691 if (!list_empty(&sas_device
->list
)) {
692 list_del_init(&sas_device
->list
);
693 sas_device_put(sas_device
);
695 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
699 * _scsih_device_remove_by_handle - removing device object by handle
700 * @ioc: per adapter object
701 * @handle: device handle
706 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
708 struct _sas_device
*sas_device
;
711 if (ioc
->shost_recovery
)
714 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
715 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
717 list_del_init(&sas_device
->list
);
718 sas_device_put(sas_device
);
720 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
722 _scsih_remove_device(ioc
, sas_device
);
723 sas_device_put(sas_device
);
728 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
729 * @ioc: per adapter object
730 * @sas_address: device sas_address
735 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
738 struct _sas_device
*sas_device
;
741 if (ioc
->shost_recovery
)
744 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
745 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
, sas_address
);
747 list_del_init(&sas_device
->list
);
748 sas_device_put(sas_device
);
750 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
752 _scsih_remove_device(ioc
, sas_device
);
753 sas_device_put(sas_device
);
758 * _scsih_sas_device_add - insert sas_device to the list.
759 * @ioc: per adapter object
760 * @sas_device: the sas_device object
761 * Context: This function will acquire ioc->sas_device_lock.
763 * Adding new object to the ioc->sas_device_list.
766 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
767 struct _sas_device
*sas_device
)
771 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
772 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
773 ioc
->name
, __func__
, sas_device
->handle
,
774 (unsigned long long)sas_device
->sas_address
));
776 if (sas_device
->enclosure_handle
!= 0)
777 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
778 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
779 ioc
->name
, __func__
, (unsigned long long)
780 sas_device
->enclosure_logical_id
, sas_device
->slot
));
782 if (sas_device
->connector_name
[0] != '\0')
783 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
784 "%s: enclosure level(0x%04x), connector name( %s)\n",
786 sas_device
->enclosure_level
, sas_device
->connector_name
));
788 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
789 sas_device_get(sas_device
);
790 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
791 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
793 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
794 sas_device
->sas_address_parent
)) {
795 _scsih_sas_device_remove(ioc
, sas_device
);
796 } else if (!sas_device
->starget
) {
798 * When asyn scanning is enabled, its not possible to remove
799 * devices while scanning is turned on due to an oops in
800 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
802 if (!ioc
->is_driver_loading
) {
803 mpt3sas_transport_port_remove(ioc
,
804 sas_device
->sas_address
,
805 sas_device
->sas_address_parent
);
806 _scsih_sas_device_remove(ioc
, sas_device
);
812 * _scsih_sas_device_init_add - insert sas_device to the list.
813 * @ioc: per adapter object
814 * @sas_device: the sas_device object
815 * Context: This function will acquire ioc->sas_device_lock.
817 * Adding new object at driver load time to the ioc->sas_device_init_list.
820 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
821 struct _sas_device
*sas_device
)
825 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
826 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
827 __func__
, sas_device
->handle
,
828 (unsigned long long)sas_device
->sas_address
));
830 if (sas_device
->enclosure_handle
!= 0)
831 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
832 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
833 ioc
->name
, __func__
, (unsigned long long)
834 sas_device
->enclosure_logical_id
, sas_device
->slot
));
836 if (sas_device
->connector_name
[0] != '\0')
837 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
838 "%s: enclosure level(0x%04x), connector name( %s)\n",
839 ioc
->name
, __func__
, sas_device
->enclosure_level
,
840 sas_device
->connector_name
));
842 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
843 sas_device_get(sas_device
);
844 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
845 _scsih_determine_boot_device(ioc
, sas_device
, 0);
846 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
850 * _scsih_raid_device_find_by_id - raid device search
851 * @ioc: per adapter object
852 * @id: sas device target id
853 * @channel: sas device channel
854 * Context: Calling function should acquire ioc->raid_device_lock
856 * This searches for raid_device based on target id, then return raid_device
859 static struct _raid_device
*
860 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
862 struct _raid_device
*raid_device
, *r
;
865 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
866 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
877 * mpt3sas_raid_device_find_by_handle - raid device search
878 * @ioc: per adapter object
879 * @handle: sas device handle (assigned by firmware)
880 * Context: Calling function should acquire ioc->raid_device_lock
882 * This searches for raid_device based on handle, then return raid_device
885 struct _raid_device
*
886 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
888 struct _raid_device
*raid_device
, *r
;
891 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
892 if (raid_device
->handle
!= handle
)
903 * _scsih_raid_device_find_by_wwid - raid device search
904 * @ioc: per adapter object
905 * @handle: sas device handle (assigned by firmware)
906 * Context: Calling function should acquire ioc->raid_device_lock
908 * This searches for raid_device based on wwid, then return raid_device
911 static struct _raid_device
*
912 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
914 struct _raid_device
*raid_device
, *r
;
917 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
918 if (raid_device
->wwid
!= wwid
)
929 * _scsih_raid_device_add - add raid_device object
930 * @ioc: per adapter object
931 * @raid_device: raid_device object
933 * This is added to the raid_device_list link list.
936 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
937 struct _raid_device
*raid_device
)
941 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
942 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
943 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
945 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
946 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
947 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
951 * _scsih_raid_device_remove - delete raid_device object
952 * @ioc: per adapter object
953 * @raid_device: raid_device object
957 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
958 struct _raid_device
*raid_device
)
962 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
963 list_del(&raid_device
->list
);
965 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
969 * mpt3sas_scsih_expander_find_by_handle - expander device search
970 * @ioc: per adapter object
971 * @handle: expander handle (assigned by firmware)
972 * Context: Calling function should acquire ioc->sas_device_lock
974 * This searches for expander device based on handle, then returns the
978 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
980 struct _sas_node
*sas_expander
, *r
;
983 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
984 if (sas_expander
->handle
!= handle
)
994 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
995 * @ioc: per adapter object
996 * @sas_address: sas address
997 * Context: Calling function should acquire ioc->sas_node_lock.
999 * This searches for expander device based on sas_address, then returns the
1003 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1006 struct _sas_node
*sas_expander
, *r
;
1009 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1010 if (sas_expander
->sas_address
!= sas_address
)
1020 * _scsih_expander_node_add - insert expander device to the list.
1021 * @ioc: per adapter object
1022 * @sas_expander: the sas_device object
1023 * Context: This function will acquire ioc->sas_node_lock.
1025 * Adding new object to the ioc->sas_expander_list.
1030 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1031 struct _sas_node
*sas_expander
)
1033 unsigned long flags
;
1035 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1036 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1037 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1041 * _scsih_is_end_device - determines if device is an end device
1042 * @device_info: bitfield providing information about the device.
1045 * Returns 1 if end device.
1048 _scsih_is_end_device(u32 device_info
)
1050 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1051 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1052 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1053 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1060 * _scsih_scsi_lookup_get - returns scmd entry
1061 * @ioc: per adapter object
1062 * @smid: system request message index
1064 * Returns the smid stored scmd pointer.
1066 static struct scsi_cmnd
*
1067 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1069 return ioc
->scsi_lookup
[smid
- 1].scmd
;
1073 * _scsih_scsi_lookup_get_clear - returns scmd entry
1074 * @ioc: per adapter object
1075 * @smid: system request message index
1077 * Returns the smid stored scmd pointer.
1078 * Then will derefrence the stored scmd pointer.
1080 static inline struct scsi_cmnd
*
1081 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1083 unsigned long flags
;
1084 struct scsi_cmnd
*scmd
;
1086 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1087 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
1088 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
1089 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1095 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1096 * @ioc: per adapter object
1097 * @smid: system request message index
1098 * @scmd: pointer to scsi command object
1099 * Context: This function will acquire ioc->scsi_lookup_lock.
1101 * This will search for a scmd pointer in the scsi_lookup array,
1102 * returning the revelent smid. A returned value of zero means invalid.
1105 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1109 unsigned long flags
;
1112 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1114 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1115 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1116 smid
= ioc
->scsi_lookup
[i
].smid
;
1121 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1126 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1127 * @ioc: per adapter object
1130 * Context: This function will acquire ioc->scsi_lookup_lock.
1132 * This will search for a matching channel:id in the scsi_lookup array,
1133 * returning 1 if found.
1136 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1140 unsigned long flags
;
1143 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1145 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1146 if (ioc
->scsi_lookup
[i
].scmd
&&
1147 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1148 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1154 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1159 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1160 * @ioc: per adapter object
1164 * Context: This function will acquire ioc->scsi_lookup_lock.
1166 * This will search for a matching channel:id:lun in the scsi_lookup array,
1167 * returning 1 if found.
1170 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1171 unsigned int lun
, int channel
)
1174 unsigned long flags
;
1177 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1179 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1180 if (ioc
->scsi_lookup
[i
].scmd
&&
1181 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1182 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1183 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1189 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1194 * scsih_change_queue_depth - setting device queue depth
1195 * @sdev: scsi device struct
1196 * @qdepth: requested queue depth
1198 * Returns queue depth.
1201 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1203 struct Scsi_Host
*shost
= sdev
->host
;
1205 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1206 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1207 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1208 struct _sas_device
*sas_device
;
1209 unsigned long flags
;
1211 max_depth
= shost
->can_queue
;
1213 /* limit max device queue for SATA to 32 */
1214 sas_device_priv_data
= sdev
->hostdata
;
1215 if (!sas_device_priv_data
)
1217 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1218 if (!sas_target_priv_data
)
1220 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1223 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1224 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1226 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1227 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1229 sas_device_put(sas_device
);
1231 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1235 if (!sdev
->tagged_supported
)
1237 if (qdepth
> max_depth
)
1239 return scsi_change_queue_depth(sdev
, qdepth
);
1243 * scsih_target_alloc - target add routine
1244 * @starget: scsi target struct
1246 * Returns 0 if ok. Any other return is assumed to be an error and
1247 * the device is ignored.
1250 scsih_target_alloc(struct scsi_target
*starget
)
1252 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1253 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1254 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1255 struct _sas_device
*sas_device
;
1256 struct _raid_device
*raid_device
;
1257 unsigned long flags
;
1258 struct sas_rphy
*rphy
;
1260 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1262 if (!sas_target_priv_data
)
1265 starget
->hostdata
= sas_target_priv_data
;
1266 sas_target_priv_data
->starget
= starget
;
1267 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1270 if (starget
->channel
== RAID_CHANNEL
) {
1271 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1272 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1275 sas_target_priv_data
->handle
= raid_device
->handle
;
1276 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1277 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1278 sas_target_priv_data
->raid_device
= raid_device
;
1279 if (ioc
->is_warpdrive
)
1280 raid_device
->starget
= starget
;
1282 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1286 /* sas/sata devices */
1287 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1288 rphy
= dev_to_rphy(starget
->dev
.parent
);
1289 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1290 rphy
->identify
.sas_address
);
1293 sas_target_priv_data
->handle
= sas_device
->handle
;
1294 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1295 sas_target_priv_data
->sdev
= sas_device
;
1296 sas_device
->starget
= starget
;
1297 sas_device
->id
= starget
->id
;
1298 sas_device
->channel
= starget
->channel
;
1299 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1300 sas_target_priv_data
->flags
|=
1301 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1302 if (sas_device
->fast_path
)
1303 sas_target_priv_data
->flags
|= MPT_TARGET_FASTPATH_IO
;
1305 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1311 * scsih_target_destroy - target destroy routine
1312 * @starget: scsi target struct
1317 scsih_target_destroy(struct scsi_target
*starget
)
1319 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1320 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1321 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1322 struct _sas_device
*sas_device
;
1323 struct _raid_device
*raid_device
;
1324 unsigned long flags
;
1325 struct sas_rphy
*rphy
;
1327 sas_target_priv_data
= starget
->hostdata
;
1328 if (!sas_target_priv_data
)
1331 if (starget
->channel
== RAID_CHANNEL
) {
1332 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1333 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1336 raid_device
->starget
= NULL
;
1337 raid_device
->sdev
= NULL
;
1339 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1343 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1344 rphy
= dev_to_rphy(starget
->dev
.parent
);
1345 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1346 if (sas_device
&& (sas_device
->starget
== starget
) &&
1347 (sas_device
->id
== starget
->id
) &&
1348 (sas_device
->channel
== starget
->channel
))
1349 sas_device
->starget
= NULL
;
1353 * Corresponding get() is in _scsih_target_alloc()
1355 sas_target_priv_data
->sdev
= NULL
;
1356 sas_device_put(sas_device
);
1358 sas_device_put(sas_device
);
1360 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1363 kfree(sas_target_priv_data
);
1364 starget
->hostdata
= NULL
;
1368 * scsih_slave_alloc - device add routine
1369 * @sdev: scsi device struct
1371 * Returns 0 if ok. Any other return is assumed to be an error and
1372 * the device is ignored.
1375 scsih_slave_alloc(struct scsi_device
*sdev
)
1377 struct Scsi_Host
*shost
;
1378 struct MPT3SAS_ADAPTER
*ioc
;
1379 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1380 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1381 struct scsi_target
*starget
;
1382 struct _raid_device
*raid_device
;
1383 struct _sas_device
*sas_device
;
1384 unsigned long flags
;
1386 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1388 if (!sas_device_priv_data
)
1391 sas_device_priv_data
->lun
= sdev
->lun
;
1392 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1394 starget
= scsi_target(sdev
);
1395 sas_target_priv_data
= starget
->hostdata
;
1396 sas_target_priv_data
->num_luns
++;
1397 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1398 sdev
->hostdata
= sas_device_priv_data
;
1399 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1400 sdev
->no_uld_attach
= 1;
1402 shost
= dev_to_shost(&starget
->dev
);
1403 ioc
= shost_priv(shost
);
1404 if (starget
->channel
== RAID_CHANNEL
) {
1405 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1406 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1407 starget
->id
, starget
->channel
);
1409 raid_device
->sdev
= sdev
; /* raid is single lun */
1410 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1413 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1414 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1415 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1416 sas_target_priv_data
->sas_address
);
1417 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1418 sdev_printk(KERN_INFO
, sdev
,
1419 "%s : sas_device->starget set to starget @ %d\n",
1420 __func__
, __LINE__
);
1421 sas_device
->starget
= starget
;
1425 sas_device_put(sas_device
);
1427 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1434 * scsih_slave_destroy - device destroy routine
1435 * @sdev: scsi device struct
1440 scsih_slave_destroy(struct scsi_device
*sdev
)
1442 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1443 struct scsi_target
*starget
;
1444 struct Scsi_Host
*shost
;
1445 struct MPT3SAS_ADAPTER
*ioc
;
1446 struct _sas_device
*sas_device
;
1447 unsigned long flags
;
1449 if (!sdev
->hostdata
)
1452 starget
= scsi_target(sdev
);
1453 sas_target_priv_data
= starget
->hostdata
;
1454 sas_target_priv_data
->num_luns
--;
1456 shost
= dev_to_shost(&starget
->dev
);
1457 ioc
= shost_priv(shost
);
1459 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1460 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1461 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1462 sas_target_priv_data
);
1463 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1464 sas_device
->starget
= NULL
;
1467 sas_device_put(sas_device
);
1468 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1471 kfree(sdev
->hostdata
);
1472 sdev
->hostdata
= NULL
;
1476 * _scsih_display_sata_capabilities - sata capabilities
1477 * @ioc: per adapter object
1478 * @handle: device handle
1479 * @sdev: scsi device struct
1482 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1483 u16 handle
, struct scsi_device
*sdev
)
1485 Mpi2ConfigReply_t mpi_reply
;
1486 Mpi2SasDevicePage0_t sas_device_pg0
;
1491 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1492 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1493 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1494 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1498 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1499 MPI2_IOCSTATUS_MASK
;
1500 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1501 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1502 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1506 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1507 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1509 sdev_printk(KERN_INFO
, sdev
,
1510 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1511 "sw_preserve(%s)\n",
1512 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1513 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1514 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1516 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1517 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1518 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1522 * raid transport support -
1523 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1524 * unloading the driver followed by a load - I beleive that the subroutine
1525 * raid_class_release() is not cleaning up properly.
1529 * scsih_is_raid - return boolean indicating device is raid volume
1530 * @dev the device struct object
1533 scsih_is_raid(struct device
*dev
)
1535 struct scsi_device
*sdev
= to_scsi_device(dev
);
1536 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1538 if (ioc
->is_warpdrive
)
1540 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1544 * scsih_get_resync - get raid volume resync percent complete
1545 * @dev the device struct object
1548 scsih_get_resync(struct device
*dev
)
1550 struct scsi_device
*sdev
= to_scsi_device(dev
);
1551 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1552 static struct _raid_device
*raid_device
;
1553 unsigned long flags
;
1554 Mpi2RaidVolPage0_t vol_pg0
;
1555 Mpi2ConfigReply_t mpi_reply
;
1556 u32 volume_status_flags
;
1557 u8 percent_complete
;
1560 percent_complete
= 0;
1562 if (ioc
->is_warpdrive
)
1565 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1566 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1569 handle
= raid_device
->handle
;
1570 percent_complete
= raid_device
->percent_complete
;
1572 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1577 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1578 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1579 sizeof(Mpi2RaidVolPage0_t
))) {
1580 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1581 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1582 percent_complete
= 0;
1586 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1587 if (!(volume_status_flags
&
1588 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1589 percent_complete
= 0;
1592 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
1593 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1594 if (ioc
->hba_mpi_version_belonged
== MPI25_VERSION
)
1595 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1599 * scsih_get_state - get raid volume level
1600 * @dev the device struct object
1603 scsih_get_state(struct device
*dev
)
1605 struct scsi_device
*sdev
= to_scsi_device(dev
);
1606 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1607 static struct _raid_device
*raid_device
;
1608 unsigned long flags
;
1609 Mpi2RaidVolPage0_t vol_pg0
;
1610 Mpi2ConfigReply_t mpi_reply
;
1612 enum raid_state state
= RAID_STATE_UNKNOWN
;
1615 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1616 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1619 handle
= raid_device
->handle
;
1620 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1625 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1626 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1627 sizeof(Mpi2RaidVolPage0_t
))) {
1628 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1629 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1633 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1634 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1635 state
= RAID_STATE_RESYNCING
;
1639 switch (vol_pg0
.VolumeState
) {
1640 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1641 case MPI2_RAID_VOL_STATE_ONLINE
:
1642 state
= RAID_STATE_ACTIVE
;
1644 case MPI2_RAID_VOL_STATE_DEGRADED
:
1645 state
= RAID_STATE_DEGRADED
;
1647 case MPI2_RAID_VOL_STATE_FAILED
:
1648 case MPI2_RAID_VOL_STATE_MISSING
:
1649 state
= RAID_STATE_OFFLINE
;
1653 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
1654 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1655 if (ioc
->hba_mpi_version_belonged
== MPI25_VERSION
)
1656 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1660 * _scsih_set_level - set raid level
1661 * @sdev: scsi device struct
1662 * @volume_type: volume type
1665 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
1666 struct scsi_device
*sdev
, u8 volume_type
)
1668 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1670 switch (volume_type
) {
1671 case MPI2_RAID_VOL_TYPE_RAID0
:
1672 level
= RAID_LEVEL_0
;
1674 case MPI2_RAID_VOL_TYPE_RAID10
:
1675 level
= RAID_LEVEL_10
;
1677 case MPI2_RAID_VOL_TYPE_RAID1E
:
1678 level
= RAID_LEVEL_1E
;
1680 case MPI2_RAID_VOL_TYPE_RAID1
:
1681 level
= RAID_LEVEL_1
;
1685 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
1686 raid_set_level(mpt2sas_raid_template
,
1687 &sdev
->sdev_gendev
, level
);
1688 if (ioc
->hba_mpi_version_belonged
== MPI25_VERSION
)
1689 raid_set_level(mpt3sas_raid_template
,
1690 &sdev
->sdev_gendev
, level
);
1695 * _scsih_get_volume_capabilities - volume capabilities
1696 * @ioc: per adapter object
1697 * @sas_device: the raid_device object
1699 * Returns 0 for success, else 1
1702 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1703 struct _raid_device
*raid_device
)
1705 Mpi2RaidVolPage0_t
*vol_pg0
;
1706 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1707 Mpi2SasDevicePage0_t sas_device_pg0
;
1708 Mpi2ConfigReply_t mpi_reply
;
1712 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1713 &num_pds
)) || !num_pds
) {
1714 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1715 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1720 raid_device
->num_pds
= num_pds
;
1721 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1722 sizeof(Mpi2RaidVol0PhysDisk_t
));
1723 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1725 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1726 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1731 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1732 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1733 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1734 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1740 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1742 /* figure out what the underlying devices are by
1743 * obtaining the device_info bits for the 1st device
1745 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1746 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1747 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1748 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1749 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1750 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1751 raid_device
->device_info
=
1752 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1761 * _scsih_enable_tlr - setting TLR flags
1762 * @ioc: per adapter object
1763 * @sdev: scsi device struct
1765 * Enabling Transaction Layer Retries for tape devices when
1766 * vpd page 0x90 is present
1770 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1774 if (sdev
->type
!= TYPE_TAPE
)
1777 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1780 sas_enable_tlr(sdev
);
1781 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1782 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1788 * scsih_slave_configure - device configure routine.
1789 * @sdev: scsi device struct
1791 * Returns 0 if ok. Any other return is assumed to be an error and
1792 * the device is ignored.
1795 scsih_slave_configure(struct scsi_device
*sdev
)
1797 struct Scsi_Host
*shost
= sdev
->host
;
1798 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1799 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1800 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1801 struct _sas_device
*sas_device
;
1802 struct _raid_device
*raid_device
;
1803 unsigned long flags
;
1808 u16 handle
, volume_handle
= 0;
1809 u64 volume_wwid
= 0;
1812 sas_device_priv_data
= sdev
->hostdata
;
1813 sas_device_priv_data
->configured_lun
= 1;
1814 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1815 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1816 handle
= sas_target_priv_data
->handle
;
1818 /* raid volume handling */
1819 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1821 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1822 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
1823 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1825 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1826 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1827 __LINE__
, __func__
));
1831 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1832 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1833 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1834 __LINE__
, __func__
));
1839 * WARPDRIVE: Initialize the required data for Direct IO
1841 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
1843 /* RAID Queue Depth Support
1844 * IS volume = underlying qdepth of drive type, either
1845 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1846 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1848 if (raid_device
->device_info
&
1849 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1850 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1853 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1854 if (raid_device
->device_info
&
1855 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1861 switch (raid_device
->volume_type
) {
1862 case MPI2_RAID_VOL_TYPE_RAID0
:
1865 case MPI2_RAID_VOL_TYPE_RAID1E
:
1866 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1867 if (ioc
->manu_pg10
.OEMIdentifier
&&
1868 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1869 MFG10_GF0_R10_DISPLAY
) &&
1870 !(raid_device
->num_pds
% 2))
1875 case MPI2_RAID_VOL_TYPE_RAID1
:
1876 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1879 case MPI2_RAID_VOL_TYPE_RAID10
:
1880 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1883 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1885 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1890 if (!ioc
->hide_ir_msg
)
1891 sdev_printk(KERN_INFO
, sdev
,
1892 "%s: handle(0x%04x), wwid(0x%016llx),"
1893 " pd_count(%d), type(%s)\n",
1894 r_level
, raid_device
->handle
,
1895 (unsigned long long)raid_device
->wwid
,
1896 raid_device
->num_pds
, ds
);
1898 scsih_change_queue_depth(sdev
, qdepth
);
1900 /* raid transport support */
1901 if (!ioc
->is_warpdrive
)
1902 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
1906 /* non-raid handling */
1907 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1908 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1910 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1911 "failure at %s:%d/%s()!\n", ioc
->name
,
1912 __FILE__
, __LINE__
, __func__
));
1915 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1916 volume_handle
, &volume_wwid
)) {
1917 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1918 "failure at %s:%d/%s()!\n", ioc
->name
,
1919 __FILE__
, __LINE__
, __func__
));
1924 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1925 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1926 sas_device_priv_data
->sas_target
->sas_address
);
1928 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1929 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1930 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1935 sas_device
->volume_handle
= volume_handle
;
1936 sas_device
->volume_wwid
= volume_wwid
;
1937 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1938 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1942 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1943 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1945 else if (sas_device
->device_info
&
1946 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1950 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
1951 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1952 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
1953 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
1954 if (sas_device
->enclosure_handle
!= 0)
1955 sdev_printk(KERN_INFO
, sdev
,
1956 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1957 ds
, (unsigned long long)
1958 sas_device
->enclosure_logical_id
, sas_device
->slot
);
1959 if (sas_device
->connector_name
[0] != '\0')
1960 sdev_printk(KERN_INFO
, sdev
,
1961 "%s: enclosure level(0x%04x), connector name( %s)\n",
1962 ds
, sas_device
->enclosure_level
,
1963 sas_device
->connector_name
);
1965 sas_device_put(sas_device
);
1966 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1969 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
1972 scsih_change_queue_depth(sdev
, qdepth
);
1975 sas_read_port_mode_page(sdev
);
1976 _scsih_enable_tlr(ioc
, sdev
);
1983 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1984 * @sdev: scsi device struct
1985 * @bdev: pointer to block device context
1986 * @capacity: device size (in 512 byte sectors)
1987 * @params: three element array to place output:
1988 * params[0] number of heads (max 255)
1989 * params[1] number of sectors (max 63)
1990 * params[2] number of cylinders
1995 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1996 sector_t capacity
, int params
[])
2006 dummy
= heads
* sectors
;
2007 cylinders
= capacity
;
2008 sector_div(cylinders
, dummy
);
2011 * Handle extended translation size for logical drives
2014 if ((ulong
)capacity
>= 0x200000) {
2017 dummy
= heads
* sectors
;
2018 cylinders
= capacity
;
2019 sector_div(cylinders
, dummy
);
2024 params
[1] = sectors
;
2025 params
[2] = cylinders
;
2031 * _scsih_response_code - translation of device response code
2032 * @ioc: per adapter object
2033 * @response_code: response code returned by the device
2038 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2042 switch (response_code
) {
2043 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2044 desc
= "task management request completed";
2046 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2047 desc
= "invalid frame";
2049 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2050 desc
= "task management request not supported";
2052 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2053 desc
= "task management request failed";
2055 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2056 desc
= "task management request succeeded";
2058 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2059 desc
= "invalid lun";
2062 desc
= "overlapped tag attempted";
2064 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2065 desc
= "task queued, however not sent to target";
2071 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2072 ioc
->name
, response_code
, desc
);
2076 * _scsih_tm_done - tm completion routine
2077 * @ioc: per adapter object
2078 * @smid: system request message index
2079 * @msix_index: MSIX table index supplied by the OS
2080 * @reply: reply message frame(lower 32bit addr)
2083 * The callback handler when using scsih_issue_tm.
2085 * Return 1 meaning mf should be freed from _base_interrupt
2086 * 0 means the mf is freed from this function.
2089 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2091 MPI2DefaultReply_t
*mpi_reply
;
2093 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2095 if (ioc
->tm_cmds
.smid
!= smid
)
2097 mpt3sas_base_flush_reply_queues(ioc
);
2098 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2099 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2101 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2102 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2104 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2105 complete(&ioc
->tm_cmds
.done
);
2110 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2111 * @ioc: per adapter object
2112 * @handle: device handle
2114 * During taskmangement request, we need to freeze the device queue.
2117 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2119 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2120 struct scsi_device
*sdev
;
2123 shost_for_each_device(sdev
, ioc
->shost
) {
2126 sas_device_priv_data
= sdev
->hostdata
;
2127 if (!sas_device_priv_data
)
2129 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2130 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2132 ioc
->ignore_loginfos
= 1;
2138 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2139 * @ioc: per adapter object
2140 * @handle: device handle
2142 * During taskmangement request, we need to freeze the device queue.
2145 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2147 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2148 struct scsi_device
*sdev
;
2151 shost_for_each_device(sdev
, ioc
->shost
) {
2154 sas_device_priv_data
= sdev
->hostdata
;
2155 if (!sas_device_priv_data
)
2157 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2158 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2160 ioc
->ignore_loginfos
= 0;
2166 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2167 * @ioc: per adapter struct
2168 * @device_handle: device handle
2169 * @channel: the channel assigned by the OS
2170 * @id: the id assigned by the OS
2172 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2173 * @smid_task: smid assigned to the task
2174 * @timeout: timeout in seconds
2175 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2178 * A generic API for sending task management requests to firmware.
2180 * The callback index is set inside `ioc->tm_cb_idx`.
2182 * Return SUCCESS or FAILED.
2185 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2186 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2187 enum mutex_type m_type
)
2189 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2190 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2193 unsigned long timeleft
;
2194 struct scsiio_tracker
*scsi_lookup
= NULL
;
2197 if (m_type
== TM_MUTEX_ON
)
2198 mutex_lock(&ioc
->tm_cmds
.mutex
);
2199 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2200 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2201 __func__
, ioc
->name
);
2206 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2207 ioc
->pci_error_recovery
) {
2208 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2209 __func__
, ioc
->name
);
2214 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2215 if (ioc_state
& MPI2_DOORBELL_USED
) {
2216 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2217 "unexpected doorbell active!\n", ioc
->name
));
2218 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2220 rc
= (!rc
) ? SUCCESS
: FAILED
;
2224 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2225 mpt3sas_base_fault_info(ioc
, ioc_state
&
2226 MPI2_DOORBELL_DATA_MASK
);
2227 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2229 rc
= (!rc
) ? SUCCESS
: FAILED
;
2233 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2235 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2236 ioc
->name
, __func__
);
2241 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2242 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2244 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2245 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2246 ioc
->name
, handle
, type
, smid_task
));
2247 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2248 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2249 ioc
->tm_cmds
.smid
= smid
;
2250 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2251 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2252 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2253 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2254 mpi_request
->TaskType
= type
;
2255 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2256 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2257 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2258 init_completion(&ioc
->tm_cmds
.done
);
2259 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
2260 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2261 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2262 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2263 ioc
->name
, __func__
);
2264 _debug_dump_mf(mpi_request
,
2265 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2266 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2267 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2269 rc
= (!rc
) ? SUCCESS
: FAILED
;
2270 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2271 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2276 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2277 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2278 mpi_reply
= ioc
->tm_cmds
.reply
;
2279 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2280 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2281 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2282 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2283 le32_to_cpu(mpi_reply
->TerminationCount
)));
2284 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2285 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2286 if (mpi_reply
->IOCStatus
)
2287 _debug_dump_mf(mpi_request
,
2288 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2293 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2295 if (scsi_lookup
->scmd
== NULL
)
2300 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2301 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2306 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2307 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2308 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2313 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2321 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2322 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2323 if (m_type
== TM_MUTEX_ON
)
2324 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2329 if (m_type
== TM_MUTEX_ON
)
2330 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2335 * _scsih_tm_display_info - displays info about the device
2336 * @ioc: per adapter struct
2337 * @scmd: pointer to scsi command object
2339 * Called by task management callback handlers.
2342 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2344 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2345 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2346 struct _sas_device
*sas_device
= NULL
;
2347 unsigned long flags
;
2348 char *device_str
= NULL
;
2352 if (ioc
->hide_ir_msg
)
2353 device_str
= "WarpDrive";
2355 device_str
= "volume";
2357 scsi_print_command(scmd
);
2358 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2359 starget_printk(KERN_INFO
, starget
,
2360 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2361 device_str
, priv_target
->handle
,
2362 device_str
, (unsigned long long)priv_target
->sas_address
);
2364 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2365 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2367 if (priv_target
->flags
&
2368 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2369 starget_printk(KERN_INFO
, starget
,
2370 "volume handle(0x%04x), "
2371 "volume wwid(0x%016llx)\n",
2372 sas_device
->volume_handle
,
2373 (unsigned long long)sas_device
->volume_wwid
);
2375 starget_printk(KERN_INFO
, starget
,
2376 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2378 (unsigned long long)sas_device
->sas_address
,
2380 if (sas_device
->enclosure_handle
!= 0)
2381 starget_printk(KERN_INFO
, starget
,
2382 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2383 (unsigned long long)
2384 sas_device
->enclosure_logical_id
,
2386 if (sas_device
->connector_name
)
2387 starget_printk(KERN_INFO
, starget
,
2388 "enclosure level(0x%04x),connector name(%s)\n",
2389 sas_device
->enclosure_level
,
2390 sas_device
->connector_name
);
2392 sas_device_put(sas_device
);
2394 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2399 * scsih_abort - eh threads main abort routine
2400 * @scmd: pointer to scsi command object
2402 * Returns SUCCESS if command aborted else FAILED
2405 scsih_abort(struct scsi_cmnd
*scmd
)
2407 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2408 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2413 sdev_printk(KERN_INFO
, scmd
->device
,
2414 "attempting task abort! scmd(%p)\n", scmd
);
2415 _scsih_tm_display_info(ioc
, scmd
);
2417 sas_device_priv_data
= scmd
->device
->hostdata
;
2418 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2419 sdev_printk(KERN_INFO
, scmd
->device
,
2420 "device been deleted! scmd(%p)\n", scmd
);
2421 scmd
->result
= DID_NO_CONNECT
<< 16;
2422 scmd
->scsi_done(scmd
);
2427 /* search for the command */
2428 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2430 scmd
->result
= DID_RESET
<< 16;
2435 /* for hidden raid components and volumes this is not supported */
2436 if (sas_device_priv_data
->sas_target
->flags
&
2437 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2438 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2439 scmd
->result
= DID_RESET
<< 16;
2444 mpt3sas_halt_firmware(ioc
);
2446 handle
= sas_device_priv_data
->sas_target
->handle
;
2447 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2448 scmd
->device
->id
, scmd
->device
->lun
,
2449 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, TM_MUTEX_ON
);
2452 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2453 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2458 * scsih_dev_reset - eh threads main device reset routine
2459 * @scmd: pointer to scsi command object
2461 * Returns SUCCESS if command aborted else FAILED
2464 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2466 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2467 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2468 struct _sas_device
*sas_device
= NULL
;
2472 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2473 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2475 sdev_printk(KERN_INFO
, scmd
->device
,
2476 "attempting device reset! scmd(%p)\n", scmd
);
2477 _scsih_tm_display_info(ioc
, scmd
);
2479 sas_device_priv_data
= scmd
->device
->hostdata
;
2480 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2481 sdev_printk(KERN_INFO
, scmd
->device
,
2482 "device been deleted! scmd(%p)\n", scmd
);
2483 scmd
->result
= DID_NO_CONNECT
<< 16;
2484 scmd
->scsi_done(scmd
);
2489 /* for hidden raid components obtain the volume_handle */
2491 if (sas_device_priv_data
->sas_target
->flags
&
2492 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2493 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2496 handle
= sas_device
->volume_handle
;
2498 handle
= sas_device_priv_data
->sas_target
->handle
;
2501 scmd
->result
= DID_RESET
<< 16;
2506 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2507 scmd
->device
->id
, scmd
->device
->lun
,
2508 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, TM_MUTEX_ON
);
2511 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2512 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2515 sas_device_put(sas_device
);
2521 * scsih_target_reset - eh threads main target reset routine
2522 * @scmd: pointer to scsi command object
2524 * Returns SUCCESS if command aborted else FAILED
2527 scsih_target_reset(struct scsi_cmnd
*scmd
)
2529 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2530 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2531 struct _sas_device
*sas_device
= NULL
;
2534 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2535 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2537 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2539 _scsih_tm_display_info(ioc
, scmd
);
2541 sas_device_priv_data
= scmd
->device
->hostdata
;
2542 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2543 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2545 scmd
->result
= DID_NO_CONNECT
<< 16;
2546 scmd
->scsi_done(scmd
);
2551 /* for hidden raid components obtain the volume_handle */
2553 if (sas_device_priv_data
->sas_target
->flags
&
2554 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2555 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2558 handle
= sas_device
->volume_handle
;
2560 handle
= sas_device_priv_data
->sas_target
->handle
;
2563 scmd
->result
= DID_RESET
<< 16;
2568 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2569 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2573 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2574 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2577 sas_device_put(sas_device
);
2584 * scsih_host_reset - eh threads main host reset routine
2585 * @scmd: pointer to scsi command object
2587 * Returns SUCCESS if command aborted else FAILED
2590 scsih_host_reset(struct scsi_cmnd
*scmd
)
2592 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2595 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
2597 scsi_print_command(scmd
);
2599 if (ioc
->is_driver_loading
) {
2600 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
2606 retval
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2608 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2610 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2611 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2617 * _scsih_fw_event_add - insert and queue up fw_event
2618 * @ioc: per adapter object
2619 * @fw_event: object describing the event
2620 * Context: This function will acquire ioc->fw_event_lock.
2622 * This adds the firmware event object into link list, then queues it up to
2623 * be processed from user context.
2628 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2630 unsigned long flags
;
2632 if (ioc
->firmware_event_thread
== NULL
)
2635 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2636 fw_event_work_get(fw_event
);
2637 INIT_LIST_HEAD(&fw_event
->list
);
2638 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2639 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2640 fw_event_work_get(fw_event
);
2641 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2642 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2646 * _scsih_fw_event_del_from_list - delete fw_event from the list
2647 * @ioc: per adapter object
2648 * @fw_event: object describing the event
2649 * Context: This function will acquire ioc->fw_event_lock.
2651 * If the fw_event is on the fw_event_list, remove it and do a put.
2656 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2659 unsigned long flags
;
2661 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2662 if (!list_empty(&fw_event
->list
)) {
2663 list_del_init(&fw_event
->list
);
2664 fw_event_work_put(fw_event
);
2666 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2671 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2672 * @ioc: per adapter object
2673 * @event_data: trigger event data
2678 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2679 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2681 struct fw_event_work
*fw_event
;
2684 if (ioc
->is_driver_loading
)
2686 sz
= sizeof(*event_data
);
2687 fw_event
= alloc_fw_event_work(sz
);
2690 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2691 fw_event
->ioc
= ioc
;
2692 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2693 _scsih_fw_event_add(ioc
, fw_event
);
2694 fw_event_work_put(fw_event
);
2698 * _scsih_error_recovery_delete_devices - remove devices not responding
2699 * @ioc: per adapter object
2704 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2706 struct fw_event_work
*fw_event
;
2708 if (ioc
->is_driver_loading
)
2710 fw_event
= alloc_fw_event_work(0);
2713 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2714 fw_event
->ioc
= ioc
;
2715 _scsih_fw_event_add(ioc
, fw_event
);
2716 fw_event_work_put(fw_event
);
2720 * mpt3sas_port_enable_complete - port enable completed (fake event)
2721 * @ioc: per adapter object
2726 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2728 struct fw_event_work
*fw_event
;
2730 fw_event
= alloc_fw_event_work(0);
2733 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2734 fw_event
->ioc
= ioc
;
2735 _scsih_fw_event_add(ioc
, fw_event
);
2736 fw_event_work_put(fw_event
);
2739 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
2741 unsigned long flags
;
2742 struct fw_event_work
*fw_event
= NULL
;
2744 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2745 if (!list_empty(&ioc
->fw_event_list
)) {
2746 fw_event
= list_first_entry(&ioc
->fw_event_list
,
2747 struct fw_event_work
, list
);
2748 list_del_init(&fw_event
->list
);
2750 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2756 * _scsih_fw_event_cleanup_queue - cleanup event queue
2757 * @ioc: per adapter object
2759 * Walk the firmware event queue, either killing timers, or waiting
2760 * for outstanding events to complete
2765 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2767 struct fw_event_work
*fw_event
;
2769 if (list_empty(&ioc
->fw_event_list
) ||
2770 !ioc
->firmware_event_thread
|| in_interrupt())
2773 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
2775 * Wait on the fw_event to complete. If this returns 1, then
2776 * the event was never executed, and we need a put for the
2777 * reference the delayed_work had on the fw_event.
2779 * If it did execute, we wait for it to finish, and the put will
2780 * happen from _firmware_event_work()
2782 if (cancel_delayed_work_sync(&fw_event
->delayed_work
))
2783 fw_event_work_put(fw_event
);
2785 fw_event_work_put(fw_event
);
2790 * _scsih_internal_device_block - block the sdev device
2791 * @sdev: per device object
2792 * @sas_device_priv_data : per device driver private data
2794 * make sure device is blocked without error, if not
2798 _scsih_internal_device_block(struct scsi_device
*sdev
,
2799 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2803 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
2804 sas_device_priv_data
->sas_target
->handle
);
2805 sas_device_priv_data
->block
= 1;
2807 r
= scsi_internal_device_block(sdev
);
2809 sdev_printk(KERN_WARNING
, sdev
,
2810 "device_block failed with return(%d) for handle(0x%04x)\n",
2811 sas_device_priv_data
->sas_target
->handle
, r
);
2815 * _scsih_internal_device_unblock - unblock the sdev device
2816 * @sdev: per device object
2817 * @sas_device_priv_data : per device driver private data
2818 * make sure device is unblocked without error, if not retry
2819 * by blocking and then unblocking
2823 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
2824 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2828 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
2829 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
2830 sas_device_priv_data
->block
= 0;
2831 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2833 /* The device has been set to SDEV_RUNNING by SD layer during
2834 * device addition but the request queue is still stopped by
2835 * our earlier block call. We need to perform a block again
2836 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2838 sdev_printk(KERN_WARNING
, sdev
,
2839 "device_unblock failed with return(%d) for handle(0x%04x) "
2840 "performing a block followed by an unblock\n",
2841 sas_device_priv_data
->sas_target
->handle
, r
);
2842 sas_device_priv_data
->block
= 1;
2843 r
= scsi_internal_device_block(sdev
);
2845 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
2846 "failed with return(%d) for handle(0x%04x)\n",
2847 sas_device_priv_data
->sas_target
->handle
, r
);
2849 sas_device_priv_data
->block
= 0;
2850 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2852 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
2853 " failed with return(%d) for handle(0x%04x)\n",
2854 sas_device_priv_data
->sas_target
->handle
, r
);
2859 * _scsih_ublock_io_all_device - unblock every device
2860 * @ioc: per adapter object
2862 * change the device state from block to running
2865 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2867 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2868 struct scsi_device
*sdev
;
2870 shost_for_each_device(sdev
, ioc
->shost
) {
2871 sas_device_priv_data
= sdev
->hostdata
;
2872 if (!sas_device_priv_data
)
2874 if (!sas_device_priv_data
->block
)
2877 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2878 "device_running, handle(0x%04x)\n",
2879 sas_device_priv_data
->sas_target
->handle
));
2880 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
2886 * _scsih_ublock_io_device - prepare device to be deleted
2887 * @ioc: per adapter object
2888 * @sas_addr: sas address
2890 * unblock then put device in offline state
2893 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2895 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2896 struct scsi_device
*sdev
;
2898 shost_for_each_device(sdev
, ioc
->shost
) {
2899 sas_device_priv_data
= sdev
->hostdata
;
2900 if (!sas_device_priv_data
)
2902 if (sas_device_priv_data
->sas_target
->sas_address
2905 if (sas_device_priv_data
->block
)
2906 _scsih_internal_device_unblock(sdev
,
2907 sas_device_priv_data
);
2912 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2913 * @ioc: per adapter object
2914 * @handle: device handle
2916 * During device pull we need to appropiately set the sdev state.
2919 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2921 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2922 struct scsi_device
*sdev
;
2924 shost_for_each_device(sdev
, ioc
->shost
) {
2925 sas_device_priv_data
= sdev
->hostdata
;
2926 if (!sas_device_priv_data
)
2928 if (sas_device_priv_data
->block
)
2930 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2935 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2936 * @ioc: per adapter object
2937 * @handle: device handle
2939 * During device pull we need to appropiately set the sdev state.
2942 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2944 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2945 struct scsi_device
*sdev
;
2946 struct _sas_device
*sas_device
;
2948 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
2952 shost_for_each_device(sdev
, ioc
->shost
) {
2953 sas_device_priv_data
= sdev
->hostdata
;
2954 if (!sas_device_priv_data
)
2956 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
2958 if (sas_device_priv_data
->block
)
2960 if (sas_device
->pend_sas_rphy_add
)
2962 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2965 sas_device_put(sas_device
);
2969 * _scsih_block_io_to_children_attached_to_ex
2970 * @ioc: per adapter object
2971 * @sas_expander: the sas_device object
2973 * This routine set sdev state to SDEV_BLOCK for all devices
2974 * attached to this expander. This function called when expander is
2978 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
2979 struct _sas_node
*sas_expander
)
2981 struct _sas_port
*mpt3sas_port
;
2982 struct _sas_device
*sas_device
;
2983 struct _sas_node
*expander_sibling
;
2984 unsigned long flags
;
2989 list_for_each_entry(mpt3sas_port
,
2990 &sas_expander
->sas_port_list
, port_list
) {
2991 if (mpt3sas_port
->remote_identify
.device_type
==
2993 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2994 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
2995 mpt3sas_port
->remote_identify
.sas_address
);
2997 set_bit(sas_device
->handle
,
2998 ioc
->blocking_handles
);
2999 sas_device_put(sas_device
);
3001 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3005 list_for_each_entry(mpt3sas_port
,
3006 &sas_expander
->sas_port_list
, port_list
) {
3008 if (mpt3sas_port
->remote_identify
.device_type
==
3009 SAS_EDGE_EXPANDER_DEVICE
||
3010 mpt3sas_port
->remote_identify
.device_type
==
3011 SAS_FANOUT_EXPANDER_DEVICE
) {
3013 mpt3sas_scsih_expander_find_by_sas_address(
3014 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3015 _scsih_block_io_to_children_attached_to_ex(ioc
,
3022 * _scsih_block_io_to_children_attached_directly
3023 * @ioc: per adapter object
3024 * @event_data: topology change event data
3026 * This routine set sdev state to SDEV_BLOCK for all devices
3027 * direct attached during device pull.
3030 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3031 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3037 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3038 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3041 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3042 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3043 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3044 _scsih_block_io_device(ioc
, handle
);
3049 * _scsih_tm_tr_send - send task management request
3050 * @ioc: per adapter object
3051 * @handle: device handle
3052 * Context: interrupt time.
3054 * This code is to initiate the device removal handshake protocol
3055 * with controller firmware. This function will issue target reset
3056 * using high priority request queue. It will send a sas iounit
3057 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3059 * This is designed to send muliple task management request at the same
3060 * time to the fifo. If the fifo is full, we will append the request,
3061 * and process it in a future completion.
3064 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3066 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3068 struct _sas_device
*sas_device
= NULL
;
3069 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3070 u64 sas_address
= 0;
3071 unsigned long flags
;
3072 struct _tr_list
*delayed_tr
;
3075 if (ioc
->remove_host
) {
3076 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3077 "%s: host has been removed: handle(0x%04x)\n",
3078 __func__
, ioc
->name
, handle
));
3080 } else if (ioc
->pci_error_recovery
) {
3081 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3082 "%s: host in pci error recovery: handle(0x%04x)\n",
3083 __func__
, ioc
->name
,
3087 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3088 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3089 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3090 "%s: host is not operational: handle(0x%04x)\n",
3091 __func__
, ioc
->name
,
3096 /* if PD, then return */
3097 if (test_bit(handle
, ioc
->pd_handles
))
3100 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3101 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3102 if (sas_device
&& sas_device
->starget
&&
3103 sas_device
->starget
->hostdata
) {
3104 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3105 sas_target_priv_data
->deleted
= 1;
3106 sas_address
= sas_device
->sas_address
;
3108 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3110 if (sas_target_priv_data
) {
3111 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3112 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3114 (unsigned long long)sas_address
));
3115 if (sas_device
->enclosure_handle
!= 0)
3116 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3117 "setting delete flag:enclosure logical id(0x%016llx),"
3118 " slot(%d)\n", ioc
->name
, (unsigned long long)
3119 sas_device
->enclosure_logical_id
,
3121 if (sas_device
->connector_name
)
3122 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3123 "setting delete flag: enclosure level(0x%04x),"
3124 " connector name( %s)\n", ioc
->name
,
3125 sas_device
->enclosure_level
,
3126 sas_device
->connector_name
));
3127 _scsih_ublock_io_device(ioc
, sas_address
);
3128 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3131 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3133 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3136 INIT_LIST_HEAD(&delayed_tr
->list
);
3137 delayed_tr
->handle
= handle
;
3138 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3139 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3140 "DELAYED:tr:handle(0x%04x), (open)\n",
3141 ioc
->name
, handle
));
3145 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3146 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3147 ioc
->name
, handle
, smid
,
3148 ioc
->tm_tr_cb_idx
));
3149 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3150 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3151 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3152 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3153 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3154 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
3155 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3159 sas_device_put(sas_device
);
3163 * _scsih_tm_tr_complete -
3164 * @ioc: per adapter object
3165 * @smid: system request message index
3166 * @msix_index: MSIX table index supplied by the OS
3167 * @reply: reply message frame(lower 32bit addr)
3168 * Context: interrupt time.
3170 * This is the target reset completion routine.
3171 * This code is part of the code to initiate the device removal
3172 * handshake protocol with controller firmware.
3173 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3175 * Return 1 meaning mf should be freed from _base_interrupt
3176 * 0 means the mf is freed from this function.
3179 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3183 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3184 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3185 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3186 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3190 if (ioc
->remove_host
) {
3191 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3192 "%s: host has been removed\n", __func__
, ioc
->name
));
3194 } else if (ioc
->pci_error_recovery
) {
3195 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3196 "%s: host in pci error recovery\n", __func__
,
3200 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3201 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3202 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3203 "%s: host is not operational\n", __func__
, ioc
->name
));
3206 if (unlikely(!mpi_reply
)) {
3207 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3208 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3211 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3212 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3213 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3214 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3215 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3217 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3221 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3222 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3223 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3224 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3225 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3226 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3227 le32_to_cpu(mpi_reply
->TerminationCount
)));
3229 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3230 if (!smid_sas_ctrl
) {
3231 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3232 ioc
->name
, __func__
);
3236 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3237 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3238 ioc
->name
, handle
, smid_sas_ctrl
,
3239 ioc
->tm_sas_control_cb_idx
));
3240 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3241 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3242 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3243 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3244 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3245 mpt3sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3247 return _scsih_check_for_pending_tm(ioc
, smid
);
3252 * _scsih_sas_control_complete - completion routine
3253 * @ioc: per adapter object
3254 * @smid: system request message index
3255 * @msix_index: MSIX table index supplied by the OS
3256 * @reply: reply message frame(lower 32bit addr)
3257 * Context: interrupt time.
3259 * This is the sas iounit control completion routine.
3260 * This code is part of the code to initiate the device removal
3261 * handshake protocol with controller firmware.
3263 * Return 1 meaning mf should be freed from _base_interrupt
3264 * 0 means the mf is freed from this function.
3267 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3268 u8 msix_index
, u32 reply
)
3270 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3271 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3273 if (likely(mpi_reply
)) {
3274 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3275 "sc_complete:handle(0x%04x), (open) "
3276 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3277 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3278 le16_to_cpu(mpi_reply
->IOCStatus
),
3279 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3281 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3282 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3288 * _scsih_tm_tr_volume_send - send target reset request for volumes
3289 * @ioc: per adapter object
3290 * @handle: device handle
3291 * Context: interrupt time.
3293 * This is designed to send muliple task management request at the same
3294 * time to the fifo. If the fifo is full, we will append the request,
3295 * and process it in a future completion.
3298 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3300 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3302 struct _tr_list
*delayed_tr
;
3304 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3305 ioc
->pci_error_recovery
) {
3306 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3307 "%s: host reset in progress!\n",
3308 __func__
, ioc
->name
));
3312 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3314 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3317 INIT_LIST_HEAD(&delayed_tr
->list
);
3318 delayed_tr
->handle
= handle
;
3319 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3320 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3321 "DELAYED:tr:handle(0x%04x), (open)\n",
3322 ioc
->name
, handle
));
3326 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3327 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3328 ioc
->name
, handle
, smid
,
3329 ioc
->tm_tr_volume_cb_idx
));
3330 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3331 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3332 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3333 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3334 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3335 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
3339 * _scsih_tm_volume_tr_complete - target reset completion
3340 * @ioc: per adapter object
3341 * @smid: system request message index
3342 * @msix_index: MSIX table index supplied by the OS
3343 * @reply: reply message frame(lower 32bit addr)
3344 * Context: interrupt time.
3346 * Return 1 meaning mf should be freed from _base_interrupt
3347 * 0 means the mf is freed from this function.
3350 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3351 u8 msix_index
, u32 reply
)
3354 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3355 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3356 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3358 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3359 ioc
->pci_error_recovery
) {
3360 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3361 "%s: host reset in progress!\n",
3362 __func__
, ioc
->name
));
3365 if (unlikely(!mpi_reply
)) {
3366 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3367 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3371 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3372 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3373 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3374 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3375 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3377 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3381 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3382 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3383 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3384 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3385 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3386 le32_to_cpu(mpi_reply
->TerminationCount
)));
3388 return _scsih_check_for_pending_tm(ioc
, smid
);
3393 * _scsih_check_for_pending_tm - check for pending task management
3394 * @ioc: per adapter object
3395 * @smid: system request message index
3397 * This will check delayed target reset list, and feed the
3400 * Return 1 meaning mf should be freed from _base_interrupt
3401 * 0 means the mf is freed from this function.
3404 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3406 struct _tr_list
*delayed_tr
;
3408 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3409 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3410 struct _tr_list
, list
);
3411 mpt3sas_base_free_smid(ioc
, smid
);
3412 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3413 list_del(&delayed_tr
->list
);
3418 if (!list_empty(&ioc
->delayed_tr_list
)) {
3419 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3420 struct _tr_list
, list
);
3421 mpt3sas_base_free_smid(ioc
, smid
);
3422 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3423 list_del(&delayed_tr
->list
);
3432 * _scsih_check_topo_delete_events - sanity check on topo events
3433 * @ioc: per adapter object
3434 * @event_data: the event data payload
3436 * This routine added to better handle cable breaker.
3438 * This handles the case where driver receives multiple expander
3439 * add and delete events in a single shot. When there is a delete event
3440 * the routine will void any pending add events waiting in the event queue.
3445 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3446 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3448 struct fw_event_work
*fw_event
;
3449 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3450 u16 expander_handle
;
3451 struct _sas_node
*sas_expander
;
3452 unsigned long flags
;
3456 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3457 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3460 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3461 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3462 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3463 _scsih_tm_tr_send(ioc
, handle
);
3466 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3467 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3468 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3471 if (event_data
->ExpStatus
==
3472 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3473 /* put expander attached devices into blocking state */
3474 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3475 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3477 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3478 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3480 handle
= find_first_bit(ioc
->blocking_handles
,
3481 ioc
->facts
.MaxDevHandle
);
3482 if (handle
< ioc
->facts
.MaxDevHandle
)
3483 _scsih_block_io_device(ioc
, handle
);
3484 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3485 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3486 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3488 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3491 /* mark ignore flag for pending events */
3492 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3493 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3494 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3497 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3498 fw_event
->event_data
;
3499 if (local_event_data
->ExpStatus
==
3500 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3501 local_event_data
->ExpStatus
==
3502 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3503 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3505 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3506 "setting ignoring flag\n", ioc
->name
));
3507 fw_event
->ignore
= 1;
3511 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3515 * _scsih_set_volume_delete_flag - setting volume delete flag
3516 * @ioc: per adapter object
3517 * @handle: device handle
3519 * This returns nothing.
3522 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3524 struct _raid_device
*raid_device
;
3525 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3526 unsigned long flags
;
3528 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3529 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
3530 if (raid_device
&& raid_device
->starget
&&
3531 raid_device
->starget
->hostdata
) {
3532 sas_target_priv_data
=
3533 raid_device
->starget
->hostdata
;
3534 sas_target_priv_data
->deleted
= 1;
3535 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3536 "setting delete flag: handle(0x%04x), "
3537 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3538 (unsigned long long) raid_device
->wwid
));
3540 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3544 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3545 * @handle: input handle
3546 * @a: handle for volume a
3547 * @b: handle for volume b
3549 * IR firmware only supports two raid volumes. The purpose of this
3550 * routine is to set the volume handle in either a or b. When the given
3551 * input handle is non-zero, or when a and b have not been set before.
3554 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3556 if (!handle
|| handle
== *a
|| handle
== *b
)
3565 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3566 * @ioc: per adapter object
3567 * @event_data: the event data payload
3568 * Context: interrupt time.
3570 * This routine will send target reset to volume, followed by target
3571 * resets to the PDs. This is called when a PD has been removed, or
3572 * volume has been deleted or removed. When the target reset is sent
3573 * to volume, the PD target resets need to be queued to start upon
3574 * completion of the volume target reset.
3579 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3580 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3582 Mpi2EventIrConfigElement_t
*element
;
3584 u16 handle
, volume_handle
, a
, b
;
3585 struct _tr_list
*delayed_tr
;
3590 if (ioc
->is_warpdrive
)
3593 /* Volume Resets for Deleted or Removed */
3594 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3595 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3596 if (le32_to_cpu(event_data
->Flags
) &
3597 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3599 if (element
->ReasonCode
==
3600 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3601 element
->ReasonCode
==
3602 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3603 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3604 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3605 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3609 /* Volume Resets for UNHIDE events */
3610 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3611 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3612 if (le32_to_cpu(event_data
->Flags
) &
3613 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3615 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3616 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3617 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3622 _scsih_tm_tr_volume_send(ioc
, a
);
3624 _scsih_tm_tr_volume_send(ioc
, b
);
3626 /* PD target resets */
3627 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3628 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3629 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3631 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3632 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3633 clear_bit(handle
, ioc
->pd_handles
);
3635 _scsih_tm_tr_send(ioc
, handle
);
3636 else if (volume_handle
== a
|| volume_handle
== b
) {
3637 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3638 BUG_ON(!delayed_tr
);
3639 INIT_LIST_HEAD(&delayed_tr
->list
);
3640 delayed_tr
->handle
= handle
;
3641 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3642 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3643 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3646 _scsih_tm_tr_send(ioc
, handle
);
3652 * _scsih_check_volume_delete_events - set delete flag for volumes
3653 * @ioc: per adapter object
3654 * @event_data: the event data payload
3655 * Context: interrupt time.
3657 * This will handle the case when the cable connected to entire volume is
3658 * pulled. We will take care of setting the deleted flag so normal IO will
3664 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3665 Mpi2EventDataIrVolume_t
*event_data
)
3669 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3671 state
= le32_to_cpu(event_data
->NewValue
);
3672 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3673 MPI2_RAID_VOL_STATE_FAILED
)
3674 _scsih_set_volume_delete_flag(ioc
,
3675 le16_to_cpu(event_data
->VolDevHandle
));
3679 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3680 * @ioc: per adapter object
3681 * @event_data: the temp threshold event data
3682 * Context: interrupt time.
3687 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
3688 Mpi2EventDataTemperature_t
*event_data
)
3690 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3691 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
3692 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3693 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3694 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3695 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3696 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3697 event_data
->SensorNum
);
3698 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
3699 ioc
->name
, event_data
->CurrentTemperature
);
3704 * _scsih_flush_running_cmds - completing outstanding commands.
3705 * @ioc: per adapter object
3707 * The flushing out of all pending scmd commands following host reset,
3708 * where all IO is dropped to the floor.
3713 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3715 struct scsi_cmnd
*scmd
;
3719 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3720 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3724 mpt3sas_base_free_smid(ioc
, smid
);
3725 scsi_dma_unmap(scmd
);
3726 if (ioc
->pci_error_recovery
)
3727 scmd
->result
= DID_NO_CONNECT
<< 16;
3729 scmd
->result
= DID_RESET
<< 16;
3730 scmd
->scsi_done(scmd
);
3732 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3737 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3738 * @ioc: per adapter object
3739 * @scmd: pointer to scsi command object
3740 * @mpi_request: pointer to the SCSI_IO reqest message frame
3742 * Supporting protection 1 and 3.
3747 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3748 Mpi2SCSIIORequest_t
*mpi_request
)
3751 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3752 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3753 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3754 (Mpi25SCSIIORequest_t
*)mpi_request
;
3756 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3759 if (prot_op
== SCSI_PROT_READ_STRIP
)
3760 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3761 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3762 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3766 switch (prot_type
) {
3767 case SCSI_PROT_DIF_TYPE1
:
3768 case SCSI_PROT_DIF_TYPE2
:
3771 * enable ref/guard checking
3772 * auto increment ref tag
3774 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3775 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3776 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3777 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3778 cpu_to_be32(scsi_get_lba(scmd
));
3781 case SCSI_PROT_DIF_TYPE3
:
3784 * enable guard checking
3786 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3791 mpi_request_3v
->EEDPBlockSize
=
3792 cpu_to_le16(scmd
->device
->sector_size
);
3793 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3797 * _scsih_eedp_error_handling - return sense code for EEDP errors
3798 * @scmd: pointer to scsi command object
3799 * @ioc_status: ioc status
3804 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3808 switch (ioc_status
) {
3809 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3812 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3815 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3822 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
3824 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
3825 SAM_STAT_CHECK_CONDITION
;
3831 * scsih_qcmd - main scsi request entry point
3832 * @scmd: pointer to scsi command object
3833 * @done: function pointer to be invoked on completion
3835 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3837 * Returns 0 on success. If there's a failure, return either:
3838 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3839 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3842 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
3844 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3845 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3846 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3847 struct _raid_device
*raid_device
;
3848 Mpi2SCSIIORequest_t
*mpi_request
;
3853 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
3854 scsi_print_command(scmd
);
3856 sas_device_priv_data
= scmd
->device
->hostdata
;
3857 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3858 scmd
->result
= DID_NO_CONNECT
<< 16;
3859 scmd
->scsi_done(scmd
);
3863 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3864 scmd
->result
= DID_NO_CONNECT
<< 16;
3865 scmd
->scsi_done(scmd
);
3869 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3871 /* invalid device handle */
3872 handle
= sas_target_priv_data
->handle
;
3873 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
3874 scmd
->result
= DID_NO_CONNECT
<< 16;
3875 scmd
->scsi_done(scmd
);
3880 /* host recovery or link resets sent via IOCTLs */
3881 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3882 return SCSI_MLQUEUE_HOST_BUSY
;
3884 /* device has been deleted */
3885 else if (sas_target_priv_data
->deleted
) {
3886 scmd
->result
= DID_NO_CONNECT
<< 16;
3887 scmd
->scsi_done(scmd
);
3889 /* device busy with task managment */
3890 } else if (sas_target_priv_data
->tm_busy
||
3891 sas_device_priv_data
->block
)
3892 return SCSI_MLQUEUE_DEVICE_BUSY
;
3894 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3895 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3896 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3897 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3899 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3902 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3904 /* Make sure Device is not raid volume.
3905 * We do not expose raid functionality to upper layer for warpdrive.
3907 if (!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
)
3908 && (sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) &&
3909 scmd
->cmd_len
!= 32)
3910 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3912 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3914 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3915 ioc
->name
, __func__
);
3918 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3919 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3920 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
3922 if (scmd
->cmd_len
== 32)
3923 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3924 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3925 if (sas_device_priv_data
->sas_target
->flags
&
3926 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3927 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3929 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3930 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3931 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3932 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3933 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3934 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3935 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3936 mpi_request
->SenseBufferLowAddress
=
3937 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
3938 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3939 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3941 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3943 if (mpi_request
->DataLength
) {
3944 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
3945 mpt3sas_base_free_smid(ioc
, smid
);
3949 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3951 raid_device
= sas_target_priv_data
->raid_device
;
3952 if (raid_device
&& raid_device
->direct_io_enabled
)
3953 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
3956 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
3957 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
3958 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
3959 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
3960 mpt3sas_base_put_smid_fast_path(ioc
, smid
, handle
);
3962 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
3963 le16_to_cpu(mpi_request
->DevHandle
));
3965 mpt3sas_base_put_smid_default(ioc
, smid
);
3969 return SCSI_MLQUEUE_HOST_BUSY
;
3973 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3974 * @sense_buffer: sense data returned by target
3975 * @data: normalized skey/asc/ascq
3980 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3982 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3983 /* descriptor format */
3984 data
->skey
= sense_buffer
[1] & 0x0F;
3985 data
->asc
= sense_buffer
[2];
3986 data
->ascq
= sense_buffer
[3];
3989 data
->skey
= sense_buffer
[2] & 0x0F;
3990 data
->asc
= sense_buffer
[12];
3991 data
->ascq
= sense_buffer
[13];
3996 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3997 * @ioc: per adapter object
3998 * @scmd: pointer to scsi command object
3999 * @mpi_reply: reply mf payload returned from firmware
4001 * scsi_status - SCSI Status code returned from target device
4002 * scsi_state - state info associated with SCSI_IO determined by ioc
4003 * ioc_status - ioc supplied status info
4008 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4009 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4013 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4014 MPI2_IOCSTATUS_MASK
;
4015 u8 scsi_state
= mpi_reply
->SCSIState
;
4016 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4017 char *desc_ioc_state
= NULL
;
4018 char *desc_scsi_status
= NULL
;
4019 char *desc_scsi_state
= ioc
->tmp_string
;
4020 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4021 struct _sas_device
*sas_device
= NULL
;
4022 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4023 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4024 char *device_str
= NULL
;
4028 if (ioc
->hide_ir_msg
)
4029 device_str
= "WarpDrive";
4031 device_str
= "volume";
4033 if (log_info
== 0x31170000)
4036 switch (ioc_status
) {
4037 case MPI2_IOCSTATUS_SUCCESS
:
4038 desc_ioc_state
= "success";
4040 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4041 desc_ioc_state
= "invalid function";
4043 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4044 desc_ioc_state
= "scsi recovered error";
4046 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4047 desc_ioc_state
= "scsi invalid dev handle";
4049 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4050 desc_ioc_state
= "scsi device not there";
4052 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4053 desc_ioc_state
= "scsi data overrun";
4055 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4056 desc_ioc_state
= "scsi data underrun";
4058 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4059 desc_ioc_state
= "scsi io data error";
4061 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4062 desc_ioc_state
= "scsi protocol error";
4064 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4065 desc_ioc_state
= "scsi task terminated";
4067 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4068 desc_ioc_state
= "scsi residual mismatch";
4070 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4071 desc_ioc_state
= "scsi task mgmt failed";
4073 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4074 desc_ioc_state
= "scsi ioc terminated";
4076 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4077 desc_ioc_state
= "scsi ext terminated";
4079 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4080 desc_ioc_state
= "eedp guard error";
4082 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4083 desc_ioc_state
= "eedp ref tag error";
4085 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4086 desc_ioc_state
= "eedp app tag error";
4089 desc_ioc_state
= "unknown";
4093 switch (scsi_status
) {
4094 case MPI2_SCSI_STATUS_GOOD
:
4095 desc_scsi_status
= "good";
4097 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4098 desc_scsi_status
= "check condition";
4100 case MPI2_SCSI_STATUS_CONDITION_MET
:
4101 desc_scsi_status
= "condition met";
4103 case MPI2_SCSI_STATUS_BUSY
:
4104 desc_scsi_status
= "busy";
4106 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4107 desc_scsi_status
= "intermediate";
4109 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4110 desc_scsi_status
= "intermediate condmet";
4112 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4113 desc_scsi_status
= "reservation conflict";
4115 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4116 desc_scsi_status
= "command terminated";
4118 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4119 desc_scsi_status
= "task set full";
4121 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4122 desc_scsi_status
= "aca active";
4124 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4125 desc_scsi_status
= "task aborted";
4128 desc_scsi_status
= "unknown";
4132 desc_scsi_state
[0] = '\0';
4134 desc_scsi_state
= " ";
4135 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4136 strcat(desc_scsi_state
, "response info ");
4137 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4138 strcat(desc_scsi_state
, "state terminated ");
4139 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4140 strcat(desc_scsi_state
, "no status ");
4141 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4142 strcat(desc_scsi_state
, "autosense failed ");
4143 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4144 strcat(desc_scsi_state
, "autosense valid ");
4146 scsi_print_command(scmd
);
4148 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4149 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4150 device_str
, (unsigned long long)priv_target
->sas_address
);
4152 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4155 "\tsas_address(0x%016llx), phy(%d)\n",
4156 ioc
->name
, (unsigned long long)
4157 sas_device
->sas_address
, sas_device
->phy
);
4158 if (sas_device
->enclosure_handle
!= 0)
4160 "\tenclosure_logical_id(0x%016llx),"
4161 "slot(%d)\n", ioc
->name
,
4162 (unsigned long long)
4163 sas_device
->enclosure_logical_id
,
4165 if (sas_device
->connector_name
[0])
4167 "\tenclosure level(0x%04x),"
4168 " connector name( %s)\n", ioc
->name
,
4169 sas_device
->enclosure_level
,
4170 sas_device
->connector_name
);
4172 sas_device_put(sas_device
);
4177 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4178 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4179 desc_ioc_state
, ioc_status
, smid
);
4181 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4182 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4183 scsi_get_resid(scmd
));
4185 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4186 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4187 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4189 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4190 ioc
->name
, desc_scsi_status
,
4191 scsi_status
, desc_scsi_state
, scsi_state
);
4193 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4194 struct sense_info data
;
4195 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4197 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4198 ioc
->name
, data
.skey
,
4199 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4202 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4203 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4204 response_bytes
= (u8
*)&response_info
;
4205 _scsih_response_code(ioc
, response_bytes
[0]);
4210 * _scsih_turn_on_pfa_led - illuminate PFA LED
4211 * @ioc: per adapter object
4212 * @handle: device handle
4218 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4220 Mpi2SepReply_t mpi_reply
;
4221 Mpi2SepRequest_t mpi_request
;
4222 struct _sas_device
*sas_device
;
4224 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4228 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4229 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4230 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4231 mpi_request
.SlotStatus
=
4232 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4233 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4234 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4235 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4236 &mpi_request
)) != 0) {
4237 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4238 __FILE__
, __LINE__
, __func__
);
4241 sas_device
->pfa_led_on
= 1;
4243 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4244 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4245 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4246 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4247 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4251 sas_device_put(sas_device
);
4255 * _scsih_turn_off_pfa_led - turn off Fault LED
4256 * @ioc: per adapter object
4257 * @sas_device: sas device whose PFA LED has to turned off
4263 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4264 struct _sas_device
*sas_device
)
4266 Mpi2SepReply_t mpi_reply
;
4267 Mpi2SepRequest_t mpi_request
;
4269 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4270 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4271 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4272 mpi_request
.SlotStatus
= 0;
4273 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4274 mpi_request
.DevHandle
= 0;
4275 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4276 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4277 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4278 &mpi_request
)) != 0) {
4279 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4280 __FILE__
, __LINE__
, __func__
);
4284 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4285 dewtprintk(ioc
, printk(MPT3SAS_FMT
4286 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4287 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4288 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4294 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4295 * @ioc: per adapter object
4296 * @handle: device handle
4297 * Context: interrupt.
4302 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4304 struct fw_event_work
*fw_event
;
4306 fw_event
= alloc_fw_event_work(0);
4309 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4310 fw_event
->device_handle
= handle
;
4311 fw_event
->ioc
= ioc
;
4312 _scsih_fw_event_add(ioc
, fw_event
);
4313 fw_event_work_put(fw_event
);
4317 * _scsih_smart_predicted_fault - process smart errors
4318 * @ioc: per adapter object
4319 * @handle: device handle
4320 * Context: interrupt.
4325 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4327 struct scsi_target
*starget
;
4328 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4329 Mpi2EventNotificationReply_t
*event_reply
;
4330 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4331 struct _sas_device
*sas_device
;
4333 unsigned long flags
;
4335 /* only handle non-raid devices */
4336 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4337 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
4341 starget
= sas_device
->starget
;
4342 sas_target_priv_data
= starget
->hostdata
;
4344 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4345 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
4348 if (sas_device
->enclosure_handle
!= 0)
4349 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4350 "enclosure logical id(0x%016llx), slot(%d)\n",
4351 (unsigned long long)sas_device
->enclosure_logical_id
,
4353 if (sas_device
->connector_name
[0] != '\0')
4354 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4355 "enclosure level(0x%04x), connector name( %s)\n",
4356 sas_device
->enclosure_level
,
4357 sas_device
->connector_name
);
4358 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4360 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4361 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4363 /* insert into event log */
4364 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4365 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4366 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4368 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4369 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4373 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4374 event_reply
->Event
=
4375 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4376 event_reply
->MsgLength
= sz
/4;
4377 event_reply
->EventDataLength
=
4378 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4379 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4380 event_reply
->EventData
;
4381 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4382 event_data
->ASC
= 0x5D;
4383 event_data
->DevHandle
= cpu_to_le16(handle
);
4384 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4385 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4389 sas_device_put(sas_device
);
4393 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4398 * _scsih_io_done - scsi request callback
4399 * @ioc: per adapter object
4400 * @smid: system request message index
4401 * @msix_index: MSIX table index supplied by the OS
4402 * @reply: reply message frame(lower 32bit addr)
4404 * Callback handler when using _scsih_qcmd.
4406 * Return 1 meaning mf should be freed from _base_interrupt
4407 * 0 means the mf is freed from this function.
4410 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4412 Mpi2SCSIIORequest_t
*mpi_request
;
4413 Mpi2SCSIIOReply_t
*mpi_reply
;
4414 struct scsi_cmnd
*scmd
;
4420 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4421 u32 response_code
= 0;
4422 unsigned long flags
;
4424 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4425 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4429 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4431 if (mpi_reply
== NULL
) {
4432 scmd
->result
= DID_OK
<< 16;
4436 sas_device_priv_data
= scmd
->device
->hostdata
;
4437 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4438 sas_device_priv_data
->sas_target
->deleted
) {
4439 scmd
->result
= DID_NO_CONNECT
<< 16;
4442 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4445 * WARPDRIVE: If direct_io is set then it is directIO,
4446 * the failed direct I/O should be redirected to volume
4448 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
4449 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4450 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4451 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4452 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4453 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4454 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
4455 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4456 mpi_request
->DevHandle
=
4457 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4458 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
4459 sas_device_priv_data
->sas_target
->handle
);
4462 /* turning off TLR */
4463 scsi_state
= mpi_reply
->SCSIState
;
4464 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4466 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4467 if (!sas_device_priv_data
->tlr_snoop_check
) {
4468 sas_device_priv_data
->tlr_snoop_check
++;
4469 if (!ioc
->is_warpdrive
&&
4470 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4471 sas_is_tlr_enabled(scmd
->device
) &&
4472 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4473 sas_disable_tlr(scmd
->device
);
4474 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4478 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4479 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4480 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4481 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4484 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4485 scsi_status
= mpi_reply
->SCSIStatus
;
4487 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4488 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4489 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4490 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4491 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4494 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4495 struct sense_info data
;
4496 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4498 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4499 le32_to_cpu(mpi_reply
->SenseCount
));
4500 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4501 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4502 /* failure prediction threshold exceeded */
4503 if (data
.asc
== 0x5D)
4504 _scsih_smart_predicted_fault(ioc
,
4505 le16_to_cpu(mpi_reply
->DevHandle
));
4506 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4508 if (!(ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4509 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4510 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4511 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4512 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4514 switch (ioc_status
) {
4515 case MPI2_IOCSTATUS_BUSY
:
4516 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4517 scmd
->result
= SAM_STAT_BUSY
;
4520 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4521 scmd
->result
= DID_NO_CONNECT
<< 16;
4524 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4525 if (sas_device_priv_data
->block
) {
4526 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4529 if (log_info
== 0x31110630) {
4530 if (scmd
->retries
> 2) {
4531 scmd
->result
= DID_NO_CONNECT
<< 16;
4532 scsi_device_set_state(scmd
->device
,
4535 scmd
->result
= DID_SOFT_ERROR
<< 16;
4536 scmd
->device
->expecting_cc_ua
= 1;
4539 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4540 scmd
->result
= DID_RESET
<< 16;
4543 scmd
->result
= DID_SOFT_ERROR
<< 16;
4545 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4546 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4547 scmd
->result
= DID_RESET
<< 16;
4550 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4551 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4552 scmd
->result
= DID_SOFT_ERROR
<< 16;
4554 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4557 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4558 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4560 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4563 if (xfer_cnt
< scmd
->underflow
) {
4564 if (scsi_status
== SAM_STAT_BUSY
)
4565 scmd
->result
= SAM_STAT_BUSY
;
4567 scmd
->result
= DID_SOFT_ERROR
<< 16;
4568 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4569 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4570 scmd
->result
= DID_SOFT_ERROR
<< 16;
4571 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4572 scmd
->result
= DID_RESET
<< 16;
4573 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4574 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4575 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4576 scmd
->result
= (DRIVER_SENSE
<< 24) |
4577 SAM_STAT_CHECK_CONDITION
;
4578 scmd
->sense_buffer
[0] = 0x70;
4579 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4580 scmd
->sense_buffer
[12] = 0x20;
4581 scmd
->sense_buffer
[13] = 0;
4585 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4586 scsi_set_resid(scmd
, 0);
4587 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4588 case MPI2_IOCSTATUS_SUCCESS
:
4589 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4590 if (response_code
==
4591 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4592 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4593 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4594 scmd
->result
= DID_SOFT_ERROR
<< 16;
4595 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4596 scmd
->result
= DID_RESET
<< 16;
4599 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4600 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4601 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4602 _scsih_eedp_error_handling(scmd
, ioc_status
);
4605 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4606 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4607 case MPI2_IOCSTATUS_INVALID_SGL
:
4608 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4609 case MPI2_IOCSTATUS_INVALID_FIELD
:
4610 case MPI2_IOCSTATUS_INVALID_STATE
:
4611 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4612 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4614 scmd
->result
= DID_SOFT_ERROR
<< 16;
4619 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4620 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4624 scsi_dma_unmap(scmd
);
4626 scmd
->scsi_done(scmd
);
4631 * _scsih_sas_host_refresh - refreshing sas host object contents
4632 * @ioc: per adapter object
4635 * During port enable, fw will send topology events for every device. Its
4636 * possible that the handles may change from the previous setting, so this
4637 * code keeping handles updating if changed.
4642 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4647 Mpi2ConfigReply_t mpi_reply
;
4648 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4649 u16 attached_handle
;
4652 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4653 "updating handles for sas_host(0x%016llx)\n",
4654 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4656 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4657 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4658 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4659 if (!sas_iounit_pg0
) {
4660 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4661 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4665 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4666 sas_iounit_pg0
, sz
)) != 0)
4668 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4669 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4671 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4672 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4674 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4675 PhyData
[0].ControllerDevHandle
);
4676 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4677 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4679 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4680 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4681 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4682 attached_handle
, i
, link_rate
);
4685 kfree(sas_iounit_pg0
);
4689 * _scsih_sas_host_add - create sas host object
4690 * @ioc: per adapter object
4692 * Creating host side data object, stored in ioc->sas_hba
4697 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4700 Mpi2ConfigReply_t mpi_reply
;
4701 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4702 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4703 Mpi2SasPhyPage0_t phy_pg0
;
4704 Mpi2SasDevicePage0_t sas_device_pg0
;
4705 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4708 u8 device_missing_delay
;
4710 mpt3sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4711 if (!ioc
->sas_hba
.num_phys
) {
4712 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4713 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4717 /* sas_iounit page 0 */
4718 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4719 sizeof(Mpi2SasIOUnit0PhyData_t
));
4720 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4721 if (!sas_iounit_pg0
) {
4722 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4723 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4726 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4727 sas_iounit_pg0
, sz
))) {
4728 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4729 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4732 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4733 MPI2_IOCSTATUS_MASK
;
4734 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4735 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4736 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4740 /* sas_iounit page 1 */
4741 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4742 sizeof(Mpi2SasIOUnit1PhyData_t
));
4743 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4744 if (!sas_iounit_pg1
) {
4745 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4746 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4749 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4750 sas_iounit_pg1
, sz
))) {
4751 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4752 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4755 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4756 MPI2_IOCSTATUS_MASK
;
4757 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4758 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4759 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4763 ioc
->io_missing_delay
=
4764 sas_iounit_pg1
->IODeviceMissingDelay
;
4765 device_missing_delay
=
4766 sas_iounit_pg1
->ReportDeviceMissingDelay
;
4767 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4768 ioc
->device_missing_delay
= (device_missing_delay
&
4769 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4771 ioc
->device_missing_delay
= device_missing_delay
&
4772 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4774 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4775 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4776 sizeof(struct _sas_phy
), GFP_KERNEL
);
4777 if (!ioc
->sas_hba
.phy
) {
4778 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4779 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4782 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4783 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4785 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4786 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4789 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4790 MPI2_IOCSTATUS_MASK
;
4791 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4792 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4793 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4798 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4799 PhyData
[0].ControllerDevHandle
);
4800 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4801 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4802 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4803 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4805 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4806 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4807 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4808 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4811 ioc
->sas_hba
.enclosure_handle
=
4812 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4813 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4815 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4816 ioc
->name
, ioc
->sas_hba
.handle
,
4817 (unsigned long long) ioc
->sas_hba
.sas_address
,
4818 ioc
->sas_hba
.num_phys
) ;
4820 if (ioc
->sas_hba
.enclosure_handle
) {
4821 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4822 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4823 ioc
->sas_hba
.enclosure_handle
)))
4824 ioc
->sas_hba
.enclosure_logical_id
=
4825 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4829 kfree(sas_iounit_pg1
);
4830 kfree(sas_iounit_pg0
);
4834 * _scsih_expander_add - creating expander object
4835 * @ioc: per adapter object
4836 * @handle: expander handle
4838 * Creating expander object, stored in ioc->sas_expander_list.
4840 * Return 0 for success, else error.
4843 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4845 struct _sas_node
*sas_expander
;
4846 Mpi2ConfigReply_t mpi_reply
;
4847 Mpi2ExpanderPage0_t expander_pg0
;
4848 Mpi2ExpanderPage1_t expander_pg1
;
4849 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4852 u64 sas_address
, sas_address_parent
= 0;
4854 unsigned long flags
;
4855 struct _sas_port
*mpt3sas_port
= NULL
;
4862 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4865 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4866 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4867 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4868 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4872 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4873 MPI2_IOCSTATUS_MASK
;
4874 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4875 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4876 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4880 /* handle out of order topology events */
4881 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4882 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4884 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4885 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4888 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4889 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4890 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4891 sas_address_parent
);
4892 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4893 if (!sas_expander
) {
4894 rc
= _scsih_expander_add(ioc
, parent_handle
);
4900 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4901 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4902 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4904 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4909 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4911 if (!sas_expander
) {
4912 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4913 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4917 sas_expander
->handle
= handle
;
4918 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4919 sas_expander
->sas_address_parent
= sas_address_parent
;
4920 sas_expander
->sas_address
= sas_address
;
4922 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
4923 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4924 handle
, parent_handle
, (unsigned long long)
4925 sas_expander
->sas_address
, sas_expander
->num_phys
);
4927 if (!sas_expander
->num_phys
)
4929 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4930 sizeof(struct _sas_phy
), GFP_KERNEL
);
4931 if (!sas_expander
->phy
) {
4932 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4933 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4938 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4939 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
4940 sas_address_parent
);
4941 if (!mpt3sas_port
) {
4942 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4943 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4947 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
4949 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4950 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4951 &expander_pg1
, i
, handle
))) {
4952 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4953 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4957 sas_expander
->phy
[i
].handle
= handle
;
4958 sas_expander
->phy
[i
].phy_id
= i
;
4960 if ((mpt3sas_transport_add_expander_phy(ioc
,
4961 &sas_expander
->phy
[i
], expander_pg1
,
4962 sas_expander
->parent_dev
))) {
4963 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4964 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4970 if (sas_expander
->enclosure_handle
) {
4971 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4972 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4973 sas_expander
->enclosure_handle
)))
4974 sas_expander
->enclosure_logical_id
=
4975 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4978 _scsih_expander_node_add(ioc
, sas_expander
);
4984 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4985 sas_address_parent
);
4986 kfree(sas_expander
);
4991 * mpt3sas_expander_remove - removing expander object
4992 * @ioc: per adapter object
4993 * @sas_address: expander sas_address
4998 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5000 struct _sas_node
*sas_expander
;
5001 unsigned long flags
;
5003 if (ioc
->shost_recovery
)
5006 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5007 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5010 list_del(&sas_expander
->list
);
5011 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5013 _scsih_expander_node_remove(ioc
, sas_expander
);
5017 * _scsih_done - internal SCSI_IO callback handler.
5018 * @ioc: per adapter object
5019 * @smid: system request message index
5020 * @msix_index: MSIX table index supplied by the OS
5021 * @reply: reply message frame(lower 32bit addr)
5023 * Callback handler when sending internal generated SCSI_IO.
5024 * The callback index passed is `ioc->scsih_cb_idx`
5026 * Return 1 meaning mf should be freed from _base_interrupt
5027 * 0 means the mf is freed from this function.
5030 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5032 MPI2DefaultReply_t
*mpi_reply
;
5034 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5035 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5037 if (ioc
->scsih_cmds
.smid
!= smid
)
5039 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5041 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5042 mpi_reply
->MsgLength
*4);
5043 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5045 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5046 complete(&ioc
->scsih_cmds
.done
);
5053 #define MPT3_MAX_LUNS (255)
5057 * _scsih_check_access_status - check access flags
5058 * @ioc: per adapter object
5059 * @sas_address: sas address
5060 * @handle: sas device handle
5061 * @access_flags: errors returned during discovery of the device
5063 * Return 0 for success, else failure
5066 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5067 u16 handle
, u8 access_status
)
5072 switch (access_status
) {
5073 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5074 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5077 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5078 desc
= "sata capability failed";
5080 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5081 desc
= "sata affiliation conflict";
5083 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5084 desc
= "route not addressable";
5086 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5087 desc
= "smp error not addressable";
5089 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5090 desc
= "device blocked";
5092 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5093 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5094 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5103 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5104 desc
= "sata initialization failed";
5115 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5116 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5121 * _scsih_check_device - checking device responsiveness
5122 * @ioc: per adapter object
5123 * @parent_sas_address: sas address of parent expander or sas host
5124 * @handle: attached device handle
5125 * @phy_numberv: phy number
5126 * @link_rate: new link rate
5131 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5132 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5134 Mpi2ConfigReply_t mpi_reply
;
5135 Mpi2SasDevicePage0_t sas_device_pg0
;
5136 struct _sas_device
*sas_device
;
5138 unsigned long flags
;
5140 struct scsi_target
*starget
;
5141 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5145 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5146 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5149 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5150 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5153 /* wide port handling ~ we need only handle device once for the phy that
5154 * is matched in sas device page zero
5156 if (phy_number
!= sas_device_pg0
.PhyNum
)
5159 /* check if this is end device */
5160 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5161 if (!(_scsih_is_end_device(device_info
)))
5164 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5165 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5166 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5172 if (unlikely(sas_device
->handle
!= handle
)) {
5173 starget
= sas_device
->starget
;
5174 sas_target_priv_data
= starget
->hostdata
;
5175 starget_printk(KERN_INFO
, starget
,
5176 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5177 sas_device
->handle
, handle
);
5178 sas_target_priv_data
->handle
= handle
;
5179 sas_device
->handle
= handle
;
5180 if (sas_device_pg0
.Flags
&
5181 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5182 sas_device
->enclosure_level
=
5183 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5184 memcpy(&sas_device
->connector_name
[0],
5185 &sas_device_pg0
.ConnectorName
[0], 4);
5187 sas_device
->enclosure_level
= 0;
5188 sas_device
->connector_name
[0] = '\0';
5192 /* check if device is present */
5193 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5194 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5196 "device is not present handle(0x%04x), flags!!!\n",
5201 /* check if there were any issues with discovery */
5202 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5203 sas_device_pg0
.AccessStatus
))
5206 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5207 _scsih_ublock_io_device(ioc
, sas_address
);
5210 sas_device_put(sas_device
);
5214 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5216 sas_device_put(sas_device
);
5220 * _scsih_add_device - creating sas device object
5221 * @ioc: per adapter object
5222 * @handle: sas device handle
5223 * @phy_num: phy number end device attached to
5224 * @is_pd: is this hidden raid component
5226 * Creating end device object, stored in ioc->sas_device_list.
5228 * Returns 0 for success, non-zero for failure.
5231 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
5234 Mpi2ConfigReply_t mpi_reply
;
5235 Mpi2SasDevicePage0_t sas_device_pg0
;
5236 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5237 struct _sas_device
*sas_device
;
5242 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5243 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5244 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5245 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5249 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5250 MPI2_IOCSTATUS_MASK
;
5251 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5252 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5253 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5257 /* check if this is end device */
5258 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5259 if (!(_scsih_is_end_device(device_info
)))
5261 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5263 /* check if device is present */
5264 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5265 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5266 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5271 /* check if there were any issues with discovery */
5272 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5273 sas_device_pg0
.AccessStatus
))
5276 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
5279 sas_device_put(sas_device
);
5283 sas_device
= kzalloc(sizeof(struct _sas_device
),
5286 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5287 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5291 kref_init(&sas_device
->refcount
);
5292 sas_device
->handle
= handle
;
5293 if (_scsih_get_sas_address(ioc
,
5294 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5295 &sas_device
->sas_address_parent
) != 0)
5296 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5297 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5298 sas_device
->enclosure_handle
=
5299 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5300 if (sas_device
->enclosure_handle
!= 0)
5302 le16_to_cpu(sas_device_pg0
.Slot
);
5303 sas_device
->device_info
= device_info
;
5304 sas_device
->sas_address
= sas_address
;
5305 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5306 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5307 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5309 if (sas_device_pg0
.Flags
& MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5310 sas_device
->enclosure_level
=
5311 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5312 memcpy(&sas_device
->connector_name
[0],
5313 &sas_device_pg0
.ConnectorName
[0], 4);
5315 sas_device
->enclosure_level
= 0;
5316 sas_device
->connector_name
[0] = '\0';
5318 /* get enclosure_logical_id */
5319 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5320 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5321 sas_device
->enclosure_handle
)))
5322 sas_device
->enclosure_logical_id
=
5323 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5325 /* get device name */
5326 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5328 if (ioc
->wait_for_discovery_to_complete
)
5329 _scsih_sas_device_init_add(ioc
, sas_device
);
5331 _scsih_sas_device_add(ioc
, sas_device
);
5333 sas_device_put(sas_device
);
5338 * _scsih_remove_device - removing sas device object
5339 * @ioc: per adapter object
5340 * @sas_device_delete: the sas_device object
5345 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5346 struct _sas_device
*sas_device
)
5348 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5350 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5351 (sas_device
->pfa_led_on
)) {
5352 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5353 sas_device
->pfa_led_on
= 0;
5355 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5356 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5357 ioc
->name
, __func__
,
5358 sas_device
->handle
, (unsigned long long)
5359 sas_device
->sas_address
));
5360 if (sas_device
->enclosure_handle
!= 0)
5361 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5362 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5363 ioc
->name
, __func__
,
5364 (unsigned long long)sas_device
->enclosure_logical_id
,
5366 if (sas_device
->connector_name
[0] != '\0')
5367 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5368 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5369 ioc
->name
, __func__
,
5370 sas_device
->enclosure_level
,
5371 sas_device
->connector_name
));
5373 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5374 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5375 sas_target_priv_data
->deleted
= 1;
5376 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5377 sas_target_priv_data
->handle
=
5378 MPT3SAS_INVALID_DEVICE_HANDLE
;
5381 if (!ioc
->hide_drives
)
5382 mpt3sas_transport_port_remove(ioc
,
5383 sas_device
->sas_address
,
5384 sas_device
->sas_address_parent
);
5387 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5388 ioc
->name
, sas_device
->handle
,
5389 (unsigned long long) sas_device
->sas_address
);
5390 if (sas_device
->enclosure_handle
!= 0)
5392 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5394 (unsigned long long)sas_device
->enclosure_logical_id
,
5396 if (sas_device
->connector_name
[0] != '\0')
5398 "removing enclosure level(0x%04x), connector name( %s)\n",
5399 ioc
->name
, sas_device
->enclosure_level
,
5400 sas_device
->connector_name
);
5402 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5403 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5404 ioc
->name
, __func__
,
5405 sas_device
->handle
, (unsigned long long)
5406 sas_device
->sas_address
));
5407 if (sas_device
->enclosure_handle
!= 0)
5408 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5409 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5410 ioc
->name
, __func__
,
5411 (unsigned long long)sas_device
->enclosure_logical_id
,
5413 if (sas_device
->connector_name
[0] != '\0')
5414 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5415 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5416 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5417 sas_device
->connector_name
));
5421 * _scsih_sas_topology_change_event_debug - debug for topology event
5422 * @ioc: per adapter object
5423 * @event_data: event data payload
5427 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5428 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5434 char *status_str
= NULL
;
5435 u8 link_rate
, prev_link_rate
;
5437 switch (event_data
->ExpStatus
) {
5438 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5441 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5442 status_str
= "remove";
5444 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5446 status_str
= "responding";
5448 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5449 status_str
= "remove delay";
5452 status_str
= "unknown status";
5455 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5456 ioc
->name
, status_str
);
5457 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5458 "start_phy(%02d), count(%d)\n",
5459 le16_to_cpu(event_data
->ExpanderDevHandle
),
5460 le16_to_cpu(event_data
->EnclosureHandle
),
5461 event_data
->StartPhyNum
, event_data
->NumEntries
);
5462 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5463 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5466 phy_number
= event_data
->StartPhyNum
+ i
;
5467 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5468 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5469 switch (reason_code
) {
5470 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5471 status_str
= "target add";
5473 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5474 status_str
= "target remove";
5476 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5477 status_str
= "delay target remove";
5479 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5480 status_str
= "link rate change";
5482 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5483 status_str
= "target responding";
5486 status_str
= "unknown";
5489 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5490 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5491 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5492 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5493 handle
, status_str
, link_rate
, prev_link_rate
);
5499 * _scsih_sas_topology_change_event - handle topology changes
5500 * @ioc: per adapter object
5501 * @fw_event: The fw_event_work object
5506 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5507 struct fw_event_work
*fw_event
)
5510 u16 parent_handle
, handle
;
5512 u8 phy_number
, max_phys
;
5513 struct _sas_node
*sas_expander
;
5515 unsigned long flags
;
5516 u8 link_rate
, prev_link_rate
;
5517 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5518 (Mpi2EventDataSasTopologyChangeList_t
*)
5519 fw_event
->event_data
;
5521 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5522 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5524 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5527 if (!ioc
->sas_hba
.num_phys
)
5528 _scsih_sas_host_add(ioc
);
5530 _scsih_sas_host_refresh(ioc
);
5532 if (fw_event
->ignore
) {
5533 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5534 "ignoring expander event\n", ioc
->name
));
5538 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5540 /* handle expander add */
5541 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5542 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5545 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5546 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5549 sas_address
= sas_expander
->sas_address
;
5550 max_phys
= sas_expander
->num_phys
;
5551 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5552 sas_address
= ioc
->sas_hba
.sas_address
;
5553 max_phys
= ioc
->sas_hba
.num_phys
;
5555 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5558 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5560 /* handle siblings events */
5561 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5562 if (fw_event
->ignore
) {
5563 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5564 "ignoring expander event\n", ioc
->name
));
5567 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5569 phy_number
= event_data
->StartPhyNum
+ i
;
5570 if (phy_number
>= max_phys
)
5572 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5573 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5574 if ((event_data
->PHY
[i
].PhyStatus
&
5575 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5576 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5578 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5581 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5582 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5583 switch (reason_code
) {
5584 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5586 if (ioc
->shost_recovery
)
5589 if (link_rate
== prev_link_rate
)
5592 mpt3sas_transport_update_links(ioc
, sas_address
,
5593 handle
, phy_number
, link_rate
);
5595 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5598 _scsih_check_device(ioc
, sas_address
, handle
,
5599 phy_number
, link_rate
);
5602 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5604 if (ioc
->shost_recovery
)
5607 mpt3sas_transport_update_links(ioc
, sas_address
,
5608 handle
, phy_number
, link_rate
);
5610 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5613 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5615 _scsih_device_remove_by_handle(ioc
, handle
);
5620 /* handle expander removal */
5621 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5623 mpt3sas_expander_remove(ioc
, sas_address
);
5629 * _scsih_sas_device_status_change_event_debug - debug for device event
5630 * @event_data: event data payload
5636 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5637 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5639 char *reason_str
= NULL
;
5641 switch (event_data
->ReasonCode
) {
5642 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5643 reason_str
= "smart data";
5645 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5646 reason_str
= "unsupported device discovered";
5648 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5649 reason_str
= "internal device reset";
5651 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5652 reason_str
= "internal task abort";
5654 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5655 reason_str
= "internal task abort set";
5657 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5658 reason_str
= "internal clear task set";
5660 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5661 reason_str
= "internal query task";
5663 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5664 reason_str
= "sata init failure";
5666 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5667 reason_str
= "internal device reset complete";
5669 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5670 reason_str
= "internal task abort complete";
5672 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5673 reason_str
= "internal async notification";
5675 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5676 reason_str
= "expander reduced functionality";
5678 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5679 reason_str
= "expander reduced functionality complete";
5682 reason_str
= "unknown reason";
5685 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5686 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5687 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5688 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5689 le16_to_cpu(event_data
->TaskTag
));
5690 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5691 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5692 event_data
->ASC
, event_data
->ASCQ
);
5697 * _scsih_sas_device_status_change_event - handle device status change
5698 * @ioc: per adapter object
5699 * @fw_event: The fw_event_work object
5705 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5706 struct fw_event_work
*fw_event
)
5708 struct MPT3SAS_TARGET
*target_priv_data
;
5709 struct _sas_device
*sas_device
;
5711 unsigned long flags
;
5712 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5713 (Mpi2EventDataSasDeviceStatusChange_t
*)
5714 fw_event
->event_data
;
5716 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5717 _scsih_sas_device_status_change_event_debug(ioc
,
5720 /* In MPI Revision K (0xC), the internal device reset complete was
5721 * implemented, so avoid setting tm_busy flag for older firmware.
5723 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5726 if (event_data
->ReasonCode
!=
5727 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5728 event_data
->ReasonCode
!=
5729 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5732 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5733 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5734 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5737 if (!sas_device
|| !sas_device
->starget
)
5740 target_priv_data
= sas_device
->starget
->hostdata
;
5741 if (!target_priv_data
)
5744 if (event_data
->ReasonCode
==
5745 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5746 target_priv_data
->tm_busy
= 1;
5748 target_priv_data
->tm_busy
= 0;
5752 sas_device_put(sas_device
);
5754 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5759 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5761 * @ioc: per adapter object
5762 * @event_data: event data payload
5768 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5769 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5771 char *reason_str
= NULL
;
5773 switch (event_data
->ReasonCode
) {
5774 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5775 reason_str
= "enclosure add";
5777 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5778 reason_str
= "enclosure remove";
5781 reason_str
= "unknown reason";
5785 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
5786 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5787 " number slots(%d)\n", ioc
->name
, reason_str
,
5788 le16_to_cpu(event_data
->EnclosureHandle
),
5789 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5790 le16_to_cpu(event_data
->StartSlot
));
5794 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5795 * @ioc: per adapter object
5796 * @fw_event: The fw_event_work object
5802 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5803 struct fw_event_work
*fw_event
)
5805 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5806 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5807 (Mpi2EventDataSasEnclDevStatusChange_t
*)
5808 fw_event
->event_data
);
5812 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5813 * @ioc: per adapter object
5814 * @fw_event: The fw_event_work object
5820 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
5821 struct fw_event_work
*fw_event
)
5823 struct scsi_cmnd
*scmd
;
5824 struct scsi_device
*sdev
;
5827 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5828 u32 termination_count
;
5830 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5831 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
5832 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5833 fw_event
->event_data
;
5835 unsigned long flags
;
5838 u8 task_abort_retries
;
5840 mutex_lock(&ioc
->tm_cmds
.mutex
);
5842 "%s: enter: phy number(%d), width(%d)\n",
5843 ioc
->name
, __func__
, event_data
->PhyNum
,
5844 event_data
->PortWidth
);
5846 _scsih_block_io_all_device(ioc
);
5848 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5849 mpi_reply
= ioc
->tm_cmds
.reply
;
5850 broadcast_aen_retry
:
5852 /* sanity checks for retrying this loop */
5853 if (max_retries
++ == 5) {
5854 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
5855 ioc
->name
, __func__
));
5857 } else if (max_retries
> 1)
5858 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
5859 ioc
->name
, __func__
, max_retries
- 1));
5861 termination_count
= 0;
5863 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5864 if (ioc
->shost_recovery
)
5866 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5869 sdev
= scmd
->device
;
5870 sas_device_priv_data
= sdev
->hostdata
;
5871 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5873 /* skip hidden raid components */
5874 if (sas_device_priv_data
->sas_target
->flags
&
5875 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5878 if (sas_device_priv_data
->sas_target
->flags
&
5879 MPT_TARGET_FLAGS_VOLUME
)
5882 handle
= sas_device_priv_data
->sas_target
->handle
;
5883 lun
= sas_device_priv_data
->lun
;
5886 if (ioc
->shost_recovery
)
5889 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5890 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5891 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
5894 sdev_printk(KERN_WARNING
, sdev
,
5895 "mpt3sas_scsih_issue_tm: FAILED when sending "
5896 "QUERY_TASK: scmd(%p)\n", scmd
);
5897 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5898 goto broadcast_aen_retry
;
5900 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5901 & MPI2_IOCSTATUS_MASK
;
5902 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5903 sdev_printk(KERN_WARNING
, sdev
,
5904 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5906 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5907 goto broadcast_aen_retry
;
5910 /* see if IO is still owned by IOC and target */
5911 if (mpi_reply
->ResponseCode
==
5912 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5913 mpi_reply
->ResponseCode
==
5914 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5915 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5918 task_abort_retries
= 0;
5920 if (task_abort_retries
++ == 60) {
5921 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5922 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5924 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5925 goto broadcast_aen_retry
;
5928 if (ioc
->shost_recovery
)
5931 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5932 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5935 sdev_printk(KERN_WARNING
, sdev
,
5936 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5937 "scmd(%p)\n", scmd
);
5941 if (task_abort_retries
> 1)
5942 sdev_printk(KERN_WARNING
, sdev
,
5943 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5945 task_abort_retries
- 1, scmd
);
5947 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5948 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5951 if (ioc
->broadcast_aen_pending
) {
5952 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5953 "%s: loop back due to pending AEN\n",
5954 ioc
->name
, __func__
));
5955 ioc
->broadcast_aen_pending
= 0;
5956 goto broadcast_aen_retry
;
5960 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5963 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5964 "%s - exit, query_count = %d termination_count = %d\n",
5965 ioc
->name
, __func__
, query_count
, termination_count
));
5967 ioc
->broadcast_aen_busy
= 0;
5968 if (!ioc
->shost_recovery
)
5969 _scsih_ublock_io_all_device(ioc
);
5970 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5974 * _scsih_sas_discovery_event - handle discovery events
5975 * @ioc: per adapter object
5976 * @fw_event: The fw_event_work object
5982 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
5983 struct fw_event_work
*fw_event
)
5985 Mpi2EventDataSasDiscovery_t
*event_data
=
5986 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
5988 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5989 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
5990 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5992 if (event_data
->DiscoveryStatus
)
5993 pr_info("discovery_status(0x%08x)",
5994 le32_to_cpu(event_data
->DiscoveryStatus
));
5998 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5999 !ioc
->sas_hba
.num_phys
) {
6000 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6001 /* Wait for the reset to complete */
6002 while (ioc
->shost_recovery
)
6005 _scsih_sas_host_add(ioc
);
6010 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6011 * @ioc: per adapter object
6012 * @handle: device handle for physical disk
6013 * @phys_disk_num: physical disk number
6015 * Return 0 for success, else failure.
6018 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
6020 Mpi2RaidActionRequest_t
*mpi_request
;
6021 Mpi2RaidActionReply_t
*mpi_reply
;
6028 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
6031 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6033 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
6034 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
6035 ioc
->name
, __func__
);
6039 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
6041 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6043 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
6044 ioc
->name
, __func__
);
6045 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6050 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
6051 ioc
->scsih_cmds
.smid
= smid
;
6052 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6054 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6055 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
6056 mpi_request
->PhysDiskNum
= phys_disk_num
;
6058 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
6059 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
6060 handle
, phys_disk_num
));
6062 init_completion(&ioc
->scsih_cmds
.done
);
6063 mpt3sas_base_put_smid_default(ioc
, smid
);
6064 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6066 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
6067 pr_err(MPT3SAS_FMT
"%s: timeout\n",
6068 ioc
->name
, __func__
);
6069 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
6075 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
6077 mpi_reply
= ioc
->scsih_cmds
.reply
;
6078 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
6079 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
6080 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
6083 ioc_status
&= MPI2_IOCSTATUS_MASK
;
6084 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6085 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6086 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6087 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
6091 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6092 "IR RAID_ACTION: completed successfully\n",
6097 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6098 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6101 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
6107 * _scsih_reprobe_lun - reprobing lun
6108 * @sdev: scsi device struct
6109 * @no_uld_attach: sdev->no_uld_attach flag setting
6113 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6116 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6117 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6118 sdev
->no_uld_attach
? "hidding" : "exposing");
6119 rc
= scsi_device_reprobe(sdev
);
6123 * _scsih_sas_volume_add - add new volume
6124 * @ioc: per adapter object
6125 * @element: IR config element data
6131 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
6132 Mpi2EventIrConfigElement_t
*element
)
6134 struct _raid_device
*raid_device
;
6135 unsigned long flags
;
6137 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6140 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6143 "failure at %s:%d/%s()!\n", ioc
->name
,
6144 __FILE__
, __LINE__
, __func__
);
6148 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6149 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6150 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6155 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6158 "failure at %s:%d/%s()!\n", ioc
->name
,
6159 __FILE__
, __LINE__
, __func__
);
6163 raid_device
->id
= ioc
->sas_id
++;
6164 raid_device
->channel
= RAID_CHANNEL
;
6165 raid_device
->handle
= handle
;
6166 raid_device
->wwid
= wwid
;
6167 _scsih_raid_device_add(ioc
, raid_device
);
6168 if (!ioc
->wait_for_discovery_to_complete
) {
6169 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6170 raid_device
->id
, 0);
6172 _scsih_raid_device_remove(ioc
, raid_device
);
6174 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6175 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6176 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6181 * _scsih_sas_volume_delete - delete volume
6182 * @ioc: per adapter object
6183 * @handle: volume device handle
6189 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6191 struct _raid_device
*raid_device
;
6192 unsigned long flags
;
6193 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6194 struct scsi_target
*starget
= NULL
;
6196 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6197 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6199 if (raid_device
->starget
) {
6200 starget
= raid_device
->starget
;
6201 sas_target_priv_data
= starget
->hostdata
;
6202 sas_target_priv_data
->deleted
= 1;
6204 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
6205 ioc
->name
, raid_device
->handle
,
6206 (unsigned long long) raid_device
->wwid
);
6207 list_del(&raid_device
->list
);
6210 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6212 scsi_remove_target(&starget
->dev
);
6216 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6217 * @ioc: per adapter object
6218 * @element: IR config element data
6224 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6225 Mpi2EventIrConfigElement_t
*element
)
6227 struct _sas_device
*sas_device
;
6228 struct scsi_target
*starget
= NULL
;
6229 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6230 unsigned long flags
;
6231 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6233 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6234 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6236 sas_device
->volume_handle
= 0;
6237 sas_device
->volume_wwid
= 0;
6238 clear_bit(handle
, ioc
->pd_handles
);
6239 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6240 starget
= sas_device
->starget
;
6241 sas_target_priv_data
= starget
->hostdata
;
6242 sas_target_priv_data
->flags
&=
6243 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6246 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6250 /* exposing raid component */
6252 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6254 sas_device_put(sas_device
);
6258 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6259 * @ioc: per adapter object
6260 * @element: IR config element data
6266 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6267 Mpi2EventIrConfigElement_t
*element
)
6269 struct _sas_device
*sas_device
;
6270 struct scsi_target
*starget
= NULL
;
6271 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6272 unsigned long flags
;
6273 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6274 u16 volume_handle
= 0;
6275 u64 volume_wwid
= 0;
6277 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6279 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6282 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6283 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6285 set_bit(handle
, ioc
->pd_handles
);
6286 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6287 starget
= sas_device
->starget
;
6288 sas_target_priv_data
= starget
->hostdata
;
6289 sas_target_priv_data
->flags
|=
6290 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6291 sas_device
->volume_handle
= volume_handle
;
6292 sas_device
->volume_wwid
= volume_wwid
;
6295 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6299 /* hiding raid component */
6300 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6303 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6305 sas_device_put(sas_device
);
6309 * _scsih_sas_pd_delete - delete pd component
6310 * @ioc: per adapter object
6311 * @element: IR config element data
6317 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6318 Mpi2EventIrConfigElement_t
*element
)
6320 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6322 _scsih_device_remove_by_handle(ioc
, handle
);
6326 * _scsih_sas_pd_add - remove pd component
6327 * @ioc: per adapter object
6328 * @element: IR config element data
6334 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6335 Mpi2EventIrConfigElement_t
*element
)
6337 struct _sas_device
*sas_device
;
6338 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6339 Mpi2ConfigReply_t mpi_reply
;
6340 Mpi2SasDevicePage0_t sas_device_pg0
;
6345 set_bit(handle
, ioc
->pd_handles
);
6347 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6349 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6350 sas_device_put(sas_device
);
6354 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6355 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6356 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6357 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6361 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6362 MPI2_IOCSTATUS_MASK
;
6363 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6364 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6365 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6369 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6370 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6371 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6372 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6374 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6375 _scsih_add_device(ioc
, handle
, 0, 1);
6379 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6380 * @ioc: per adapter object
6381 * @event_data: event data payload
6387 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6388 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6390 Mpi2EventIrConfigElement_t
*element
;
6393 char *reason_str
= NULL
, *element_str
= NULL
;
6395 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6397 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6398 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6399 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6400 "foreign" : "native", event_data
->NumElements
);
6401 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6402 switch (element
->ReasonCode
) {
6403 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6406 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6407 reason_str
= "remove";
6409 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6410 reason_str
= "no change";
6412 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6413 reason_str
= "hide";
6415 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6416 reason_str
= "unhide";
6418 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6419 reason_str
= "volume_created";
6421 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6422 reason_str
= "volume_deleted";
6424 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6425 reason_str
= "pd_created";
6427 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6428 reason_str
= "pd_deleted";
6431 reason_str
= "unknown reason";
6434 element_type
= le16_to_cpu(element
->ElementFlags
) &
6435 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6436 switch (element_type
) {
6437 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6438 element_str
= "volume";
6440 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6441 element_str
= "phys disk";
6443 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6444 element_str
= "hot spare";
6447 element_str
= "unknown element";
6450 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6451 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6452 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6453 le16_to_cpu(element
->PhysDiskDevHandle
),
6454 element
->PhysDiskNum
);
6459 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6460 * @ioc: per adapter object
6461 * @fw_event: The fw_event_work object
6467 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6468 struct fw_event_work
*fw_event
)
6470 Mpi2EventIrConfigElement_t
*element
;
6473 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6474 (Mpi2EventDataIrConfigChangeList_t
*)
6475 fw_event
->event_data
;
6477 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6478 (!ioc
->hide_ir_msg
))
6479 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6481 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6482 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6484 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6485 if (ioc
->shost_recovery
&&
6486 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
6487 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6488 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6489 _scsih_ir_fastpath(ioc
,
6490 le16_to_cpu(element
->PhysDiskDevHandle
),
6491 element
->PhysDiskNum
);
6496 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6498 switch (element
->ReasonCode
) {
6499 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6500 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6501 if (!foreign_config
)
6502 _scsih_sas_volume_add(ioc
, element
);
6504 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6505 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6506 if (!foreign_config
)
6507 _scsih_sas_volume_delete(ioc
,
6508 le16_to_cpu(element
->VolDevHandle
));
6510 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6511 if (!ioc
->is_warpdrive
)
6512 _scsih_sas_pd_hide(ioc
, element
);
6514 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6515 if (!ioc
->is_warpdrive
)
6516 _scsih_sas_pd_expose(ioc
, element
);
6518 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6519 if (!ioc
->is_warpdrive
)
6520 _scsih_sas_pd_add(ioc
, element
);
6522 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6523 if (!ioc
->is_warpdrive
)
6524 _scsih_sas_pd_delete(ioc
, element
);
6531 * _scsih_sas_ir_volume_event - IR volume event
6532 * @ioc: per adapter object
6533 * @fw_event: The fw_event_work object
6539 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6540 struct fw_event_work
*fw_event
)
6543 unsigned long flags
;
6544 struct _raid_device
*raid_device
;
6548 Mpi2EventDataIrVolume_t
*event_data
=
6549 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6551 if (ioc
->shost_recovery
)
6554 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6557 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6558 state
= le32_to_cpu(event_data
->NewValue
);
6559 if (!ioc
->hide_ir_msg
)
6560 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6561 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6562 ioc
->name
, __func__
, handle
,
6563 le32_to_cpu(event_data
->PreviousValue
), state
));
6565 case MPI2_RAID_VOL_STATE_MISSING
:
6566 case MPI2_RAID_VOL_STATE_FAILED
:
6567 _scsih_sas_volume_delete(ioc
, handle
);
6570 case MPI2_RAID_VOL_STATE_ONLINE
:
6571 case MPI2_RAID_VOL_STATE_DEGRADED
:
6572 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6574 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6575 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6576 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6581 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6584 "failure at %s:%d/%s()!\n", ioc
->name
,
6585 __FILE__
, __LINE__
, __func__
);
6589 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6592 "failure at %s:%d/%s()!\n", ioc
->name
,
6593 __FILE__
, __LINE__
, __func__
);
6597 raid_device
->id
= ioc
->sas_id
++;
6598 raid_device
->channel
= RAID_CHANNEL
;
6599 raid_device
->handle
= handle
;
6600 raid_device
->wwid
= wwid
;
6601 _scsih_raid_device_add(ioc
, raid_device
);
6602 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6603 raid_device
->id
, 0);
6605 _scsih_raid_device_remove(ioc
, raid_device
);
6608 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6615 * _scsih_sas_ir_physical_disk_event - PD event
6616 * @ioc: per adapter object
6617 * @fw_event: The fw_event_work object
6623 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6624 struct fw_event_work
*fw_event
)
6626 u16 handle
, parent_handle
;
6628 struct _sas_device
*sas_device
;
6629 Mpi2ConfigReply_t mpi_reply
;
6630 Mpi2SasDevicePage0_t sas_device_pg0
;
6632 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6633 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6636 if (ioc
->shost_recovery
)
6639 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6642 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6643 state
= le32_to_cpu(event_data
->NewValue
);
6645 if (!ioc
->hide_ir_msg
)
6646 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6647 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6648 ioc
->name
, __func__
, handle
,
6649 le32_to_cpu(event_data
->PreviousValue
), state
));
6652 case MPI2_RAID_PD_STATE_ONLINE
:
6653 case MPI2_RAID_PD_STATE_DEGRADED
:
6654 case MPI2_RAID_PD_STATE_REBUILDING
:
6655 case MPI2_RAID_PD_STATE_OPTIMAL
:
6656 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6658 if (!ioc
->is_warpdrive
)
6659 set_bit(handle
, ioc
->pd_handles
);
6661 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6663 sas_device_put(sas_device
);
6667 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6668 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6670 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6671 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6675 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6676 MPI2_IOCSTATUS_MASK
;
6677 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6678 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6679 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6683 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6684 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6685 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6686 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6688 _scsih_add_device(ioc
, handle
, 0, 1);
6692 case MPI2_RAID_PD_STATE_OFFLINE
:
6693 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6694 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6701 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6702 * @ioc: per adapter object
6703 * @event_data: event data payload
6709 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6710 Mpi2EventDataIrOperationStatus_t
*event_data
)
6712 char *reason_str
= NULL
;
6714 switch (event_data
->RAIDOperation
) {
6715 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6716 reason_str
= "resync";
6718 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6719 reason_str
= "online capacity expansion";
6721 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6722 reason_str
= "consistency check";
6724 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6725 reason_str
= "background init";
6727 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6728 reason_str
= "make data consistent";
6735 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6736 "\thandle(0x%04x), percent complete(%d)\n",
6737 ioc
->name
, reason_str
,
6738 le16_to_cpu(event_data
->VolDevHandle
),
6739 event_data
->PercentComplete
);
6743 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6744 * @ioc: per adapter object
6745 * @fw_event: The fw_event_work object
6751 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
6752 struct fw_event_work
*fw_event
)
6754 Mpi2EventDataIrOperationStatus_t
*event_data
=
6755 (Mpi2EventDataIrOperationStatus_t
*)
6756 fw_event
->event_data
;
6757 static struct _raid_device
*raid_device
;
6758 unsigned long flags
;
6761 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6762 (!ioc
->hide_ir_msg
))
6763 _scsih_sas_ir_operation_status_event_debug(ioc
,
6766 /* code added for raid transport support */
6767 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6769 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6770 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6771 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6773 raid_device
->percent_complete
=
6774 event_data
->PercentComplete
;
6775 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6780 * _scsih_prep_device_scan - initialize parameters prior to device scan
6781 * @ioc: per adapter object
6783 * Set the deleted flag prior to device scan. If the device is found during
6784 * the scan, then we clear the deleted flag.
6787 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
6789 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6790 struct scsi_device
*sdev
;
6792 shost_for_each_device(sdev
, ioc
->shost
) {
6793 sas_device_priv_data
= sdev
->hostdata
;
6794 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6795 sas_device_priv_data
->sas_target
->deleted
= 1;
6800 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6801 * @ioc: per adapter object
6802 * @sas_device_pg0: SAS Device page 0
6804 * After host reset, find out whether devices are still responding.
6805 * Used in _scsih_remove_unresponsive_sas_devices.
6810 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
6811 Mpi2SasDevicePage0_t
*sas_device_pg0
)
6813 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
6814 struct scsi_target
*starget
;
6815 struct _sas_device
*sas_device
;
6816 unsigned long flags
;
6818 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6819 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6820 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
6821 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
6822 sas_device
->responding
= 1;
6823 starget
= sas_device
->starget
;
6824 if (starget
&& starget
->hostdata
) {
6825 sas_target_priv_data
= starget
->hostdata
;
6826 sas_target_priv_data
->tm_busy
= 0;
6827 sas_target_priv_data
->deleted
= 0;
6829 sas_target_priv_data
= NULL
;
6831 starget_printk(KERN_INFO
, starget
,
6832 "handle(0x%04x), sas_addr(0x%016llx)\n",
6833 sas_device_pg0
->DevHandle
,
6834 (unsigned long long)
6835 sas_device
->sas_address
);
6837 if (sas_device
->enclosure_handle
!= 0)
6838 starget_printk(KERN_INFO
, starget
,
6839 "enclosure logical id(0x%016llx),"
6841 (unsigned long long)
6842 sas_device
->enclosure_logical_id
,
6845 if (sas_device_pg0
->Flags
&
6846 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6847 sas_device
->enclosure_level
=
6848 le16_to_cpu(sas_device_pg0
->EnclosureLevel
);
6849 memcpy(&sas_device
->connector_name
[0],
6850 &sas_device_pg0
->ConnectorName
[0], 4);
6852 sas_device
->enclosure_level
= 0;
6853 sas_device
->connector_name
[0] = '\0';
6856 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
6858 pr_info("\thandle changed from(0x%04x)!!!\n",
6859 sas_device
->handle
);
6860 sas_device
->handle
= sas_device_pg0
->DevHandle
;
6861 if (sas_target_priv_data
)
6862 sas_target_priv_data
->handle
=
6863 sas_device_pg0
->DevHandle
;
6868 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6872 * _scsih_search_responding_sas_devices -
6873 * @ioc: per adapter object
6875 * After host reset, find out whether devices are still responding.
6881 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
6883 Mpi2SasDevicePage0_t sas_device_pg0
;
6884 Mpi2ConfigReply_t mpi_reply
;
6889 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
6891 if (list_empty(&ioc
->sas_device_list
))
6895 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6896 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6898 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6899 MPI2_IOCSTATUS_MASK
;
6900 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6902 handle
= sas_device_pg0
.DevHandle
=
6903 le16_to_cpu(sas_device_pg0
.DevHandle
);
6904 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6905 if (!(_scsih_is_end_device(device_info
)))
6907 sas_device_pg0
.SASAddress
=
6908 le64_to_cpu(sas_device_pg0
.SASAddress
);
6909 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6910 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
6914 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
6919 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6920 * @ioc: per adapter object
6921 * @wwid: world wide identifier for raid volume
6922 * @handle: device handle
6924 * After host reset, find out whether devices are still responding.
6925 * Used in _scsih_remove_unresponsive_raid_devices.
6930 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6933 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
6934 struct scsi_target
*starget
;
6935 struct _raid_device
*raid_device
;
6936 unsigned long flags
;
6938 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6939 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6940 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6941 starget
= raid_device
->starget
;
6942 if (starget
&& starget
->hostdata
) {
6943 sas_target_priv_data
= starget
->hostdata
;
6944 sas_target_priv_data
->deleted
= 0;
6946 sas_target_priv_data
= NULL
;
6947 raid_device
->responding
= 1;
6948 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6949 starget_printk(KERN_INFO
, raid_device
->starget
,
6950 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6951 (unsigned long long)raid_device
->wwid
);
6954 * WARPDRIVE: The handles of the PDs might have changed
6955 * across the host reset so re-initialize the
6956 * required data for Direct IO
6958 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
6959 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6960 if (raid_device
->handle
== handle
) {
6961 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
6965 pr_info("\thandle changed from(0x%04x)!!!\n",
6966 raid_device
->handle
);
6967 raid_device
->handle
= handle
;
6968 if (sas_target_priv_data
)
6969 sas_target_priv_data
->handle
= handle
;
6970 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6974 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6978 * _scsih_search_responding_raid_devices -
6979 * @ioc: per adapter object
6981 * After host reset, find out whether devices are still responding.
6987 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
6989 Mpi2RaidVolPage1_t volume_pg1
;
6990 Mpi2RaidVolPage0_t volume_pg0
;
6991 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6992 Mpi2ConfigReply_t mpi_reply
;
6997 if (!ioc
->ir_firmware
)
7000 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
7003 if (list_empty(&ioc
->raid_device_list
))
7007 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7008 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7009 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7010 MPI2_IOCSTATUS_MASK
;
7011 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7013 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7015 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7016 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7017 sizeof(Mpi2RaidVolPage0_t
)))
7020 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7021 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7022 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
7023 _scsih_mark_responding_raid_device(ioc
,
7024 le64_to_cpu(volume_pg1
.WWID
), handle
);
7027 /* refresh the pd_handles */
7028 if (!ioc
->is_warpdrive
) {
7029 phys_disk_num
= 0xFF;
7030 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
7031 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7032 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7034 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7035 MPI2_IOCSTATUS_MASK
;
7036 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7038 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7039 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7040 set_bit(handle
, ioc
->pd_handles
);
7044 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
7049 * _scsih_mark_responding_expander - mark a expander as responding
7050 * @ioc: per adapter object
7051 * @sas_address: sas address
7054 * After host reset, find out whether devices are still responding.
7055 * Used in _scsih_remove_unresponsive_expanders.
7060 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
7063 struct _sas_node
*sas_expander
;
7064 unsigned long flags
;
7067 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7068 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
7069 if (sas_expander
->sas_address
!= sas_address
)
7071 sas_expander
->responding
= 1;
7072 if (sas_expander
->handle
== handle
)
7074 pr_info("\texpander(0x%016llx): handle changed" \
7075 " from(0x%04x) to (0x%04x)!!!\n",
7076 (unsigned long long)sas_expander
->sas_address
,
7077 sas_expander
->handle
, handle
);
7078 sas_expander
->handle
= handle
;
7079 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
7080 sas_expander
->phy
[i
].handle
= handle
;
7084 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7088 * _scsih_search_responding_expanders -
7089 * @ioc: per adapter object
7091 * After host reset, find out whether devices are still responding.
7097 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
7099 Mpi2ExpanderPage0_t expander_pg0
;
7100 Mpi2ConfigReply_t mpi_reply
;
7105 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
7107 if (list_empty(&ioc
->sas_expander_list
))
7111 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7112 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7114 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7115 MPI2_IOCSTATUS_MASK
;
7116 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7119 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7120 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7121 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7123 (unsigned long long)sas_address
);
7124 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7128 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
7132 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7133 * @ioc: per adapter object
7138 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7140 struct _sas_device
*sas_device
, *sas_device_next
;
7141 struct _sas_node
*sas_expander
, *sas_expander_next
;
7142 struct _raid_device
*raid_device
, *raid_device_next
;
7143 struct list_head tmp_list
;
7144 unsigned long flags
;
7147 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
7150 /* removing unresponding end devices */
7151 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
7154 * Iterate, pulling off devices marked as non-responding. We become the
7155 * owner for the reference the list had on any object we prune.
7157 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7158 list_for_each_entry_safe(sas_device
, sas_device_next
,
7159 &ioc
->sas_device_list
, list
) {
7160 if (!sas_device
->responding
)
7161 list_move_tail(&sas_device
->list
, &head
);
7163 sas_device
->responding
= 0;
7165 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7168 * Now, uninitialize and remove the unresponding devices we pruned.
7170 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
7171 _scsih_remove_device(ioc
, sas_device
);
7172 list_del_init(&sas_device
->list
);
7173 sas_device_put(sas_device
);
7176 /* removing unresponding volumes */
7177 if (ioc
->ir_firmware
) {
7178 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
7180 list_for_each_entry_safe(raid_device
, raid_device_next
,
7181 &ioc
->raid_device_list
, list
) {
7182 if (!raid_device
->responding
)
7183 _scsih_sas_volume_delete(ioc
,
7184 raid_device
->handle
);
7186 raid_device
->responding
= 0;
7190 /* removing unresponding expanders */
7191 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
7193 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7194 INIT_LIST_HEAD(&tmp_list
);
7195 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7196 &ioc
->sas_expander_list
, list
) {
7197 if (!sas_expander
->responding
)
7198 list_move_tail(&sas_expander
->list
, &tmp_list
);
7200 sas_expander
->responding
= 0;
7202 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7203 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7205 list_del(&sas_expander
->list
);
7206 _scsih_expander_node_remove(ioc
, sas_expander
);
7209 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
7212 /* unblock devices */
7213 _scsih_ublock_io_all_device(ioc
);
7217 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
7218 struct _sas_node
*sas_expander
, u16 handle
)
7220 Mpi2ExpanderPage1_t expander_pg1
;
7221 Mpi2ConfigReply_t mpi_reply
;
7224 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7225 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7226 &expander_pg1
, i
, handle
))) {
7227 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7228 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7232 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7233 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7234 expander_pg1
.NegotiatedLinkRate
>> 4);
7239 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7240 * @ioc: per adapter object
7245 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
7247 Mpi2ExpanderPage0_t expander_pg0
;
7248 Mpi2SasDevicePage0_t sas_device_pg0
;
7249 Mpi2RaidVolPage1_t volume_pg1
;
7250 Mpi2RaidVolPage0_t volume_pg0
;
7251 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7252 Mpi2EventIrConfigElement_t element
;
7253 Mpi2ConfigReply_t mpi_reply
;
7256 u16 handle
, parent_handle
;
7258 struct _sas_device
*sas_device
;
7259 struct _sas_node
*expander_device
;
7260 static struct _raid_device
*raid_device
;
7262 unsigned long flags
;
7264 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7266 _scsih_sas_host_refresh(ioc
);
7268 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7272 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7273 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7274 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7275 MPI2_IOCSTATUS_MASK
;
7276 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7277 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7278 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7279 ioc
->name
, ioc_status
,
7280 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7283 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7284 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7285 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7286 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7287 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7288 if (expander_device
)
7289 _scsih_refresh_expander_links(ioc
, expander_device
,
7292 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7293 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7294 handle
, (unsigned long long)
7295 le64_to_cpu(expander_pg0
.SASAddress
));
7296 _scsih_expander_add(ioc
, handle
);
7297 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7298 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7299 handle
, (unsigned long long)
7300 le64_to_cpu(expander_pg0
.SASAddress
));
7304 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7307 if (!ioc
->ir_firmware
)
7310 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7313 phys_disk_num
= 0xFF;
7314 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7315 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7317 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7318 MPI2_IOCSTATUS_MASK
;
7319 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7320 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7321 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7322 ioc
->name
, ioc_status
,
7323 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7326 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7327 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7328 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7330 sas_device_put(sas_device
);
7333 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7334 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7337 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7338 MPI2_IOCSTATUS_MASK
;
7339 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7340 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7341 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7342 ioc
->name
, ioc_status
,
7343 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7346 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7347 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7349 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7350 " handle (0x%04x), sas_addr(0x%016llx)\n",
7351 ioc
->name
, handle
, (unsigned long long)
7352 le64_to_cpu(sas_device_pg0
.SASAddress
));
7353 mpt3sas_transport_update_links(ioc
, sas_address
,
7354 handle
, sas_device_pg0
.PhyNum
,
7355 MPI2_SAS_NEG_LINK_RATE_1_5
);
7356 set_bit(handle
, ioc
->pd_handles
);
7358 /* This will retry adding the end device.
7359 * _scsih_add_device() will decide on retries and
7360 * return "1" when it should be retried
7362 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7366 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7367 " handle (0x%04x), sas_addr(0x%016llx)\n",
7368 ioc
->name
, handle
, (unsigned long long)
7369 le64_to_cpu(sas_device_pg0
.SASAddress
));
7373 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7376 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7380 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7381 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7382 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7383 MPI2_IOCSTATUS_MASK
;
7384 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7385 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7386 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7387 ioc
->name
, ioc_status
,
7388 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7391 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7392 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7393 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7394 le64_to_cpu(volume_pg1
.WWID
));
7395 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7398 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7399 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7400 sizeof(Mpi2RaidVolPage0_t
)))
7402 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7403 MPI2_IOCSTATUS_MASK
;
7404 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7405 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7406 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7407 ioc
->name
, ioc_status
,
7408 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7411 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7412 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7413 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7414 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7415 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7416 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7418 "\tBEFORE adding volume: handle (0x%04x)\n",
7419 ioc
->name
, volume_pg1
.DevHandle
);
7420 _scsih_sas_volume_add(ioc
, &element
);
7422 "\tAFTER adding volume: handle (0x%04x)\n",
7423 ioc
->name
, volume_pg1
.DevHandle
);
7427 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7432 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7437 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7438 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7440 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7441 MPI2_IOCSTATUS_MASK
;
7442 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7443 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7444 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7445 ioc
->name
, ioc_status
,
7446 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7449 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7450 if (!(_scsih_is_end_device(
7451 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7453 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
7454 le64_to_cpu(sas_device_pg0
.SASAddress
));
7456 sas_device_put(sas_device
);
7459 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7460 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7461 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7462 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7463 handle
, (unsigned long long)
7464 le64_to_cpu(sas_device_pg0
.SASAddress
));
7465 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7466 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7468 /* This will retry adding the end device.
7469 * _scsih_add_device() will decide on retries and
7470 * return "1" when it should be retried
7472 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7476 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7477 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7478 handle
, (unsigned long long)
7479 le64_to_cpu(sas_device_pg0
.SASAddress
));
7482 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7485 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7488 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7489 * @ioc: per adapter object
7490 * @reset_phase: phase
7492 * The handler for doing any required cleanup or initialization.
7494 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7495 * MPT3_IOC_DONE_RESET
7500 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7502 switch (reset_phase
) {
7503 case MPT3_IOC_PRE_RESET
:
7504 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7505 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7507 case MPT3_IOC_AFTER_RESET
:
7508 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7509 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7510 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7511 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7512 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7513 complete(&ioc
->scsih_cmds
.done
);
7515 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7516 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7517 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7518 complete(&ioc
->tm_cmds
.done
);
7521 _scsih_fw_event_cleanup_queue(ioc
);
7522 _scsih_flush_running_cmds(ioc
);
7524 case MPT3_IOC_DONE_RESET
:
7525 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7526 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7527 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7528 !ioc
->sas_hba
.num_phys
)) {
7529 _scsih_prep_device_scan(ioc
);
7530 _scsih_search_responding_sas_devices(ioc
);
7531 _scsih_search_responding_raid_devices(ioc
);
7532 _scsih_search_responding_expanders(ioc
);
7533 _scsih_error_recovery_delete_devices(ioc
);
7540 * _mpt3sas_fw_work - delayed task for processing firmware events
7541 * @ioc: per adapter object
7542 * @fw_event: The fw_event_work object
7548 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7550 _scsih_fw_event_del_from_list(ioc
, fw_event
);
7552 /* the queue is being flushed so ignore this event */
7553 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
7554 fw_event_work_put(fw_event
);
7558 switch (fw_event
->event
) {
7559 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7560 mpt3sas_process_trigger_data(ioc
,
7561 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7562 fw_event
->event_data
);
7564 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7565 while (scsi_host_in_recovery(ioc
->shost
) ||
7566 ioc
->shost_recovery
) {
7568 * If we're unloading, bail. Otherwise, this can become
7571 if (ioc
->remove_host
)
7575 _scsih_remove_unresponding_sas_devices(ioc
);
7576 _scsih_scan_for_devices_after_reset(ioc
);
7578 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7579 ioc
->start_scan
= 0;
7580 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7581 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7583 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7584 "port enable: complete from worker thread\n",
7587 case MPT3SAS_TURN_ON_PFA_LED
:
7588 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7590 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7591 _scsih_sas_topology_change_event(ioc
, fw_event
);
7593 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7594 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7596 case MPI2_EVENT_SAS_DISCOVERY
:
7597 _scsih_sas_discovery_event(ioc
, fw_event
);
7599 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7600 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7602 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7603 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7606 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7607 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7609 case MPI2_EVENT_IR_VOLUME
:
7610 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7612 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7613 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7615 case MPI2_EVENT_IR_OPERATION_STATUS
:
7616 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7620 fw_event_work_put(fw_event
);
7624 * _firmware_event_work
7625 * @ioc: per adapter object
7626 * @work: The fw_event_work object
7629 * wrappers for the work thread handling firmware events
7635 _firmware_event_work(struct work_struct
*work
)
7637 struct fw_event_work
*fw_event
= container_of(work
,
7638 struct fw_event_work
, work
);
7640 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7644 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7645 * @ioc: per adapter object
7646 * @msix_index: MSIX table index supplied by the OS
7647 * @reply: reply message frame(lower 32bit addr)
7648 * Context: interrupt.
7650 * This function merely adds a new work task into ioc->firmware_event_thread.
7651 * The tasks are worked from _firmware_event_work in user context.
7653 * Return 1 meaning mf should be freed from _base_interrupt
7654 * 0 means the mf is freed from this function.
7657 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7660 struct fw_event_work
*fw_event
;
7661 Mpi2EventNotificationReply_t
*mpi_reply
;
7665 /* events turned off due to host reset or driver unloading */
7666 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7669 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7671 if (unlikely(!mpi_reply
)) {
7672 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7673 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7677 event
= le16_to_cpu(mpi_reply
->Event
);
7679 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7680 mpt3sas_trigger_event(ioc
, event
, 0);
7684 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7686 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7687 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7688 mpi_reply
->EventData
;
7690 if (baen_data
->Primitive
!=
7691 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7694 if (ioc
->broadcast_aen_busy
) {
7695 ioc
->broadcast_aen_pending
++;
7698 ioc
->broadcast_aen_busy
= 1;
7702 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7703 _scsih_check_topo_delete_events(ioc
,
7704 (Mpi2EventDataSasTopologyChangeList_t
*)
7705 mpi_reply
->EventData
);
7707 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7708 _scsih_check_ir_config_unhide_events(ioc
,
7709 (Mpi2EventDataIrConfigChangeList_t
*)
7710 mpi_reply
->EventData
);
7712 case MPI2_EVENT_IR_VOLUME
:
7713 _scsih_check_volume_delete_events(ioc
,
7714 (Mpi2EventDataIrVolume_t
*)
7715 mpi_reply
->EventData
);
7717 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7719 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7722 if (!ioc
->is_warpdrive
)
7725 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7726 mpi_reply
->EventData
;
7727 log_code
= (u32
*)log_entry
->LogData
;
7729 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7730 != MPT2_WARPDRIVE_LOGENTRY
)
7733 switch (le32_to_cpu(*log_code
)) {
7734 case MPT2_WARPDRIVE_LC_SSDT
:
7735 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7736 "IO Throttling has occurred in the WarpDrive "
7737 "subsystem. Check WarpDrive documentation for "
7738 "additional details.\n", ioc
->name
);
7740 case MPT2_WARPDRIVE_LC_SSDLW
:
7741 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7742 "Program/Erase Cycles for the WarpDrive subsystem "
7743 "in degraded range. Check WarpDrive documentation "
7744 "for additional details.\n", ioc
->name
);
7746 case MPT2_WARPDRIVE_LC_SSDLF
:
7747 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7748 "There are no Program/Erase Cycles for the "
7749 "WarpDrive subsystem. The storage device will be "
7750 "in read-only mode. Check WarpDrive documentation "
7751 "for additional details.\n", ioc
->name
);
7753 case MPT2_WARPDRIVE_LC_BRMF
:
7754 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7755 "The Backup Rail Monitor has failed on the "
7756 "WarpDrive subsystem. Check WarpDrive "
7757 "documentation for additional details.\n",
7764 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7765 case MPI2_EVENT_IR_OPERATION_STATUS
:
7766 case MPI2_EVENT_SAS_DISCOVERY
:
7767 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7768 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7771 case MPI2_EVENT_TEMP_THRESHOLD
:
7772 _scsih_temp_threshold_events(ioc
,
7773 (Mpi2EventDataTemperature_t
*)
7774 mpi_reply
->EventData
);
7777 default: /* ignore the rest */
7781 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7782 fw_event
= alloc_fw_event_work(sz
);
7784 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7785 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7789 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
7790 fw_event
->ioc
= ioc
;
7791 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7792 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7793 fw_event
->event
= event
;
7794 _scsih_fw_event_add(ioc
, fw_event
);
7795 fw_event_work_put(fw_event
);
7800 * _scsih_expander_node_remove - removing expander device from list.
7801 * @ioc: per adapter object
7802 * @sas_expander: the sas_device object
7803 * Context: Calling function should acquire ioc->sas_node_lock.
7805 * Removing object and freeing associated memory from the
7806 * ioc->sas_expander_list.
7811 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
7812 struct _sas_node
*sas_expander
)
7814 struct _sas_port
*mpt3sas_port
, *next
;
7816 /* remove sibling ports attached to this expander */
7817 list_for_each_entry_safe(mpt3sas_port
, next
,
7818 &sas_expander
->sas_port_list
, port_list
) {
7819 if (ioc
->shost_recovery
)
7821 if (mpt3sas_port
->remote_identify
.device_type
==
7823 mpt3sas_device_remove_by_sas_address(ioc
,
7824 mpt3sas_port
->remote_identify
.sas_address
);
7825 else if (mpt3sas_port
->remote_identify
.device_type
==
7826 SAS_EDGE_EXPANDER_DEVICE
||
7827 mpt3sas_port
->remote_identify
.device_type
==
7828 SAS_FANOUT_EXPANDER_DEVICE
)
7829 mpt3sas_expander_remove(ioc
,
7830 mpt3sas_port
->remote_identify
.sas_address
);
7833 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7834 sas_expander
->sas_address_parent
);
7837 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7839 sas_expander
->handle
, (unsigned long long)
7840 sas_expander
->sas_address
);
7842 kfree(sas_expander
->phy
);
7843 kfree(sas_expander
);
7847 * _scsih_ir_shutdown - IR shutdown notification
7848 * @ioc: per adapter object
7850 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7851 * the host system is shutting down.
7856 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
7858 Mpi2RaidActionRequest_t
*mpi_request
;
7859 Mpi2RaidActionReply_t
*mpi_reply
;
7862 /* is IR firmware build loaded ? */
7863 if (!ioc
->ir_firmware
)
7866 /* are there any volumes ? */
7867 if (list_empty(&ioc
->raid_device_list
))
7870 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7872 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7873 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7874 ioc
->name
, __func__
);
7877 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7879 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7881 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7882 ioc
->name
, __func__
);
7883 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7887 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7888 ioc
->scsih_cmds
.smid
= smid
;
7889 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7891 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7892 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7894 if (!ioc
->hide_ir_msg
)
7895 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
7896 init_completion(&ioc
->scsih_cmds
.done
);
7897 mpt3sas_base_put_smid_default(ioc
, smid
);
7898 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7900 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7901 pr_err(MPT3SAS_FMT
"%s: timeout\n",
7902 ioc
->name
, __func__
);
7906 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7907 mpi_reply
= ioc
->scsih_cmds
.reply
;
7908 if (!ioc
->hide_ir_msg
)
7909 pr_info(MPT3SAS_FMT
"IR shutdown "
7910 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7911 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7912 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7916 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7917 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7921 * scsih_remove - detach and remove add host
7922 * @pdev: PCI device struct
7924 * Routine called when unloading the driver.
7927 void scsih_remove(struct pci_dev
*pdev
)
7929 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7930 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7931 struct _sas_port
*mpt3sas_port
, *next_port
;
7932 struct _raid_device
*raid_device
, *next
;
7933 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7934 struct workqueue_struct
*wq
;
7935 unsigned long flags
;
7937 ioc
->remove_host
= 1;
7938 _scsih_fw_event_cleanup_queue(ioc
);
7940 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7941 wq
= ioc
->firmware_event_thread
;
7942 ioc
->firmware_event_thread
= NULL
;
7943 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7945 destroy_workqueue(wq
);
7947 /* release all the volumes */
7948 _scsih_ir_shutdown(ioc
);
7949 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7951 if (raid_device
->starget
) {
7952 sas_target_priv_data
=
7953 raid_device
->starget
->hostdata
;
7954 sas_target_priv_data
->deleted
= 1;
7955 scsi_remove_target(&raid_device
->starget
->dev
);
7957 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7958 ioc
->name
, raid_device
->handle
,
7959 (unsigned long long) raid_device
->wwid
);
7960 _scsih_raid_device_remove(ioc
, raid_device
);
7963 /* free ports attached to the sas_host */
7964 list_for_each_entry_safe(mpt3sas_port
, next_port
,
7965 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7966 if (mpt3sas_port
->remote_identify
.device_type
==
7968 mpt3sas_device_remove_by_sas_address(ioc
,
7969 mpt3sas_port
->remote_identify
.sas_address
);
7970 else if (mpt3sas_port
->remote_identify
.device_type
==
7971 SAS_EDGE_EXPANDER_DEVICE
||
7972 mpt3sas_port
->remote_identify
.device_type
==
7973 SAS_FANOUT_EXPANDER_DEVICE
)
7974 mpt3sas_expander_remove(ioc
,
7975 mpt3sas_port
->remote_identify
.sas_address
);
7978 /* free phys attached to the sas_host */
7979 if (ioc
->sas_hba
.num_phys
) {
7980 kfree(ioc
->sas_hba
.phy
);
7981 ioc
->sas_hba
.phy
= NULL
;
7982 ioc
->sas_hba
.num_phys
= 0;
7985 sas_remove_host(shost
);
7986 scsi_remove_host(shost
);
7987 mpt3sas_base_detach(ioc
);
7988 spin_lock(&gioc_lock
);
7989 list_del(&ioc
->list
);
7990 spin_unlock(&gioc_lock
);
7991 scsi_host_put(shost
);
7995 * scsih_shutdown - routine call during system shutdown
7996 * @pdev: PCI device struct
8001 scsih_shutdown(struct pci_dev
*pdev
)
8003 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8004 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8005 struct workqueue_struct
*wq
;
8006 unsigned long flags
;
8008 ioc
->remove_host
= 1;
8009 _scsih_fw_event_cleanup_queue(ioc
);
8011 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8012 wq
= ioc
->firmware_event_thread
;
8013 ioc
->firmware_event_thread
= NULL
;
8014 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8016 destroy_workqueue(wq
);
8018 _scsih_ir_shutdown(ioc
);
8019 mpt3sas_base_detach(ioc
);
8024 * _scsih_probe_boot_devices - reports 1st device
8025 * @ioc: per adapter object
8027 * If specified in bios page 2, this routine reports the 1st
8028 * device scsi-ml or sas transport for persistent boot device
8029 * purposes. Please refer to function _scsih_determine_boot_device()
8032 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
8036 struct _sas_device
*sas_device
;
8037 struct _raid_device
*raid_device
;
8039 u64 sas_address_parent
;
8041 unsigned long flags
;
8044 /* no Bios, return immediately */
8045 if (!ioc
->bios_pg3
.BiosVersion
)
8050 if (ioc
->req_boot_device
.device
) {
8051 device
= ioc
->req_boot_device
.device
;
8052 is_raid
= ioc
->req_boot_device
.is_raid
;
8053 } else if (ioc
->req_alt_boot_device
.device
) {
8054 device
= ioc
->req_alt_boot_device
.device
;
8055 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
8056 } else if (ioc
->current_boot_device
.device
) {
8057 device
= ioc
->current_boot_device
.device
;
8058 is_raid
= ioc
->current_boot_device
.is_raid
;
8065 raid_device
= device
;
8066 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8067 raid_device
->id
, 0);
8069 _scsih_raid_device_remove(ioc
, raid_device
);
8071 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8072 sas_device
= device
;
8073 handle
= sas_device
->handle
;
8074 sas_address_parent
= sas_device
->sas_address_parent
;
8075 sas_address
= sas_device
->sas_address
;
8076 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8077 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8079 if (ioc
->hide_drives
)
8081 if (!mpt3sas_transport_port_add(ioc
, handle
,
8082 sas_address_parent
)) {
8083 _scsih_sas_device_remove(ioc
, sas_device
);
8084 } else if (!sas_device
->starget
) {
8085 if (!ioc
->is_driver_loading
) {
8086 mpt3sas_transport_port_remove(ioc
,
8088 sas_address_parent
);
8089 _scsih_sas_device_remove(ioc
, sas_device
);
8096 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8097 * @ioc: per adapter object
8099 * Called during initial loading of the driver.
8102 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
8104 struct _raid_device
*raid_device
, *raid_next
;
8107 list_for_each_entry_safe(raid_device
, raid_next
,
8108 &ioc
->raid_device_list
, list
) {
8109 if (raid_device
->starget
)
8111 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8112 raid_device
->id
, 0);
8114 _scsih_raid_device_remove(ioc
, raid_device
);
8118 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
8120 struct _sas_device
*sas_device
= NULL
;
8121 unsigned long flags
;
8123 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8124 if (!list_empty(&ioc
->sas_device_init_list
)) {
8125 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
8126 struct _sas_device
, list
);
8127 sas_device_get(sas_device
);
8129 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8134 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
8135 struct _sas_device
*sas_device
)
8137 unsigned long flags
;
8139 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8142 * Since we dropped the lock during the call to port_add(), we need to
8143 * be careful here that somebody else didn't move or delete this item
8144 * while we were busy with other things.
8146 * If it was on the list, we need a put() for the reference the list
8147 * had. Either way, we need a get() for the destination list.
8149 if (!list_empty(&sas_device
->list
)) {
8150 list_del_init(&sas_device
->list
);
8151 sas_device_put(sas_device
);
8154 sas_device_get(sas_device
);
8155 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8157 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8161 * _scsih_probe_sas - reporting sas devices to sas transport
8162 * @ioc: per adapter object
8164 * Called during initial loading of the driver.
8167 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
8169 struct _sas_device
*sas_device
;
8171 if (ioc
->hide_drives
)
8174 while ((sas_device
= get_next_sas_device(ioc
))) {
8175 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
8176 sas_device
->sas_address_parent
)) {
8177 _scsih_sas_device_remove(ioc
, sas_device
);
8178 sas_device_put(sas_device
);
8180 } else if (!sas_device
->starget
) {
8182 * When asyn scanning is enabled, its not possible to
8183 * remove devices while scanning is turned on due to an
8184 * oops in scsi_sysfs_add_sdev()->add_device()->
8185 * sysfs_addrm_start()
8187 if (!ioc
->is_driver_loading
) {
8188 mpt3sas_transport_port_remove(ioc
,
8189 sas_device
->sas_address
,
8190 sas_device
->sas_address_parent
);
8191 _scsih_sas_device_remove(ioc
, sas_device
);
8192 sas_device_put(sas_device
);
8196 sas_device_make_active(ioc
, sas_device
);
8197 sas_device_put(sas_device
);
8202 * _scsih_probe_devices - probing for devices
8203 * @ioc: per adapter object
8205 * Called during initial loading of the driver.
8208 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
8210 u16 volume_mapping_flags
;
8212 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8213 return; /* return when IOC doesn't support initiator mode */
8215 _scsih_probe_boot_devices(ioc
);
8217 if (ioc
->ir_firmware
) {
8218 volume_mapping_flags
=
8219 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8220 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8221 if (volume_mapping_flags
==
8222 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8223 _scsih_probe_raid(ioc
);
8224 _scsih_probe_sas(ioc
);
8226 _scsih_probe_sas(ioc
);
8227 _scsih_probe_raid(ioc
);
8230 _scsih_probe_sas(ioc
);
8234 * scsih_scan_start - scsi lld callback for .scan_start
8235 * @shost: SCSI host pointer
8237 * The shost has the ability to discover targets on its own instead
8238 * of scanning the entire bus. In our implemention, we will kick off
8239 * firmware discovery.
8242 scsih_scan_start(struct Scsi_Host
*shost
)
8244 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8246 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8247 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8249 if (disable_discovery
> 0)
8252 ioc
->start_scan
= 1;
8253 rc
= mpt3sas_port_enable(ioc
);
8256 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
8260 * scsih_scan_finished - scsi lld callback for .scan_finished
8261 * @shost: SCSI host pointer
8262 * @time: elapsed time of the scan in jiffies
8264 * This function will be called periodicallyn until it returns 1 with the
8265 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8266 * we wait for firmware discovery to complete, then return 1.
8269 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8271 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8273 if (disable_discovery
> 0) {
8274 ioc
->is_driver_loading
= 0;
8275 ioc
->wait_for_discovery_to_complete
= 0;
8279 if (time
>= (300 * HZ
)) {
8280 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8282 "port enable: FAILED with timeout (timeout=300s)\n",
8284 ioc
->is_driver_loading
= 0;
8288 if (ioc
->start_scan
)
8291 if (ioc
->start_scan_failed
) {
8293 "port enable: FAILED with (ioc_status=0x%08x)\n",
8294 ioc
->name
, ioc
->start_scan_failed
);
8295 ioc
->is_driver_loading
= 0;
8296 ioc
->wait_for_discovery_to_complete
= 0;
8297 ioc
->remove_host
= 1;
8301 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
8302 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8304 if (ioc
->wait_for_discovery_to_complete
) {
8305 ioc
->wait_for_discovery_to_complete
= 0;
8306 _scsih_probe_devices(ioc
);
8308 mpt3sas_base_start_watchdog(ioc
);
8309 ioc
->is_driver_loading
= 0;
8313 /* shost template for SAS 2.0 HBA devices */
8314 static struct scsi_host_template mpt2sas_driver_template
= {
8315 .module
= THIS_MODULE
,
8316 .name
= "Fusion MPT SAS Host",
8317 .proc_name
= MPT2SAS_DRIVER_NAME
,
8318 .queuecommand
= scsih_qcmd
,
8319 .target_alloc
= scsih_target_alloc
,
8320 .slave_alloc
= scsih_slave_alloc
,
8321 .slave_configure
= scsih_slave_configure
,
8322 .target_destroy
= scsih_target_destroy
,
8323 .slave_destroy
= scsih_slave_destroy
,
8324 .scan_finished
= scsih_scan_finished
,
8325 .scan_start
= scsih_scan_start
,
8326 .change_queue_depth
= scsih_change_queue_depth
,
8327 .eh_abort_handler
= scsih_abort
,
8328 .eh_device_reset_handler
= scsih_dev_reset
,
8329 .eh_target_reset_handler
= scsih_target_reset
,
8330 .eh_host_reset_handler
= scsih_host_reset
,
8331 .bios_param
= scsih_bios_param
,
8334 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
8335 .max_sectors
= 32767,
8337 .use_clustering
= ENABLE_CLUSTERING
,
8338 .shost_attrs
= mpt3sas_host_attrs
,
8339 .sdev_attrs
= mpt3sas_dev_attrs
,
8340 .track_queue_depth
= 1,
8343 /* raid transport support for SAS 2.0 HBA devices */
8344 static struct raid_function_template mpt2sas_raid_functions
= {
8345 .cookie
= &mpt2sas_driver_template
,
8346 .is_raid
= scsih_is_raid
,
8347 .get_resync
= scsih_get_resync
,
8348 .get_state
= scsih_get_state
,
8351 /* shost template for SAS 3.0 HBA devices */
8352 static struct scsi_host_template mpt3sas_driver_template
= {
8353 .module
= THIS_MODULE
,
8354 .name
= "Fusion MPT SAS Host",
8355 .proc_name
= MPT3SAS_DRIVER_NAME
,
8356 .queuecommand
= scsih_qcmd
,
8357 .target_alloc
= scsih_target_alloc
,
8358 .slave_alloc
= scsih_slave_alloc
,
8359 .slave_configure
= scsih_slave_configure
,
8360 .target_destroy
= scsih_target_destroy
,
8361 .slave_destroy
= scsih_slave_destroy
,
8362 .scan_finished
= scsih_scan_finished
,
8363 .scan_start
= scsih_scan_start
,
8364 .change_queue_depth
= scsih_change_queue_depth
,
8365 .eh_abort_handler
= scsih_abort
,
8366 .eh_device_reset_handler
= scsih_dev_reset
,
8367 .eh_target_reset_handler
= scsih_target_reset
,
8368 .eh_host_reset_handler
= scsih_host_reset
,
8369 .bios_param
= scsih_bios_param
,
8372 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
8373 .max_sectors
= 32767,
8375 .use_clustering
= ENABLE_CLUSTERING
,
8376 .shost_attrs
= mpt3sas_host_attrs
,
8377 .sdev_attrs
= mpt3sas_dev_attrs
,
8378 .track_queue_depth
= 1,
8381 /* raid transport support for SAS 3.0 HBA devices */
8382 static struct raid_function_template mpt3sas_raid_functions
= {
8383 .cookie
= &mpt3sas_driver_template
,
8384 .is_raid
= scsih_is_raid
,
8385 .get_resync
= scsih_get_resync
,
8386 .get_state
= scsih_get_state
,
8390 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8391 * this device belongs to.
8392 * @pdev: PCI device struct
8394 * return MPI2_VERSION for SAS 2.0 HBA devices,
8395 * MPI25_VERSION for SAS 3.0 HBA devices.
8398 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
8401 switch (pdev
->device
) {
8402 case MPI2_MFGPAGE_DEVID_SSS6200
:
8403 case MPI2_MFGPAGE_DEVID_SAS2004
:
8404 case MPI2_MFGPAGE_DEVID_SAS2008
:
8405 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
8406 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
8407 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
8408 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
8409 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
8410 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
8411 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
8412 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
8413 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
8414 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
8415 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
8416 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
8417 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
8418 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
8419 return MPI2_VERSION
;
8420 case MPI25_MFGPAGE_DEVID_SAS3004
:
8421 case MPI25_MFGPAGE_DEVID_SAS3008
:
8422 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
8423 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
8424 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
8425 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
8426 return MPI25_VERSION
;
8432 * _scsih_probe - attach and add scsi host
8433 * @pdev: PCI device struct
8434 * @id: pci device id
8436 * Returns 0 success, anything else error.
8439 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8441 struct MPT3SAS_ADAPTER
*ioc
;
8442 struct Scsi_Host
*shost
= NULL
;
8444 u16 hba_mpi_version
;
8446 /* Determine in which MPI version class this pci device belongs */
8447 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
8448 if (hba_mpi_version
== 0)
8451 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8452 * for other generation HBA's return with -ENODEV
8454 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
8457 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8458 * for other generation HBA's return with -ENODEV
8460 if ((hbas_to_enumerate
== 2) && (hba_mpi_version
!= MPI25_VERSION
))
8463 switch (hba_mpi_version
) {
8465 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8466 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
8467 sizeof(struct MPT3SAS_ADAPTER
));
8470 ioc
= shost_priv(shost
);
8471 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8472 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8473 ioc
->id
= mpt2_ids
++;
8474 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
8475 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8476 ioc
->is_warpdrive
= 1;
8477 ioc
->hide_ir_msg
= 1;
8479 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8482 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8483 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
8484 sizeof(struct MPT3SAS_ADAPTER
));
8487 ioc
= shost_priv(shost
);
8488 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8489 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8490 ioc
->id
= mpt3_ids
++;
8491 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
8492 if (pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
)
8493 ioc
->msix96_vector
= 1;
8499 INIT_LIST_HEAD(&ioc
->list
);
8500 spin_lock(&gioc_lock
);
8501 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8502 spin_unlock(&gioc_lock
);
8505 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8506 ioc
->tm_cb_idx
= tm_cb_idx
;
8507 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8508 ioc
->base_cb_idx
= base_cb_idx
;
8509 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8510 ioc
->transport_cb_idx
= transport_cb_idx
;
8511 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8512 ioc
->config_cb_idx
= config_cb_idx
;
8513 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8514 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8515 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8516 ioc
->logging_level
= logging_level
;
8517 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8518 /* misc semaphores and spin locks */
8519 mutex_init(&ioc
->reset_in_progress_mutex
);
8520 /* initializing pci_access_mutex lock */
8521 mutex_init(&ioc
->pci_access_mutex
);
8522 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8523 spin_lock_init(&ioc
->scsi_lookup_lock
);
8524 spin_lock_init(&ioc
->sas_device_lock
);
8525 spin_lock_init(&ioc
->sas_node_lock
);
8526 spin_lock_init(&ioc
->fw_event_lock
);
8527 spin_lock_init(&ioc
->raid_device_lock
);
8528 spin_lock_init(&ioc
->diag_trigger_lock
);
8530 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8531 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8532 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8533 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8534 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8535 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8536 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8537 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8538 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8540 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
8542 /* init shost parameters */
8543 shost
->max_cmd_len
= 32;
8544 shost
->max_lun
= max_lun
;
8545 shost
->transportt
= mpt3sas_transport_template
;
8546 shost
->unique_id
= ioc
->id
;
8548 if (max_sectors
!= 0xFFFF) {
8549 if (max_sectors
< 64) {
8550 shost
->max_sectors
= 64;
8551 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8552 "for max_sectors, range is 64 to 32767. Assigning "
8553 "value of 64.\n", ioc
->name
, max_sectors
);
8554 } else if (max_sectors
> 32767) {
8555 shost
->max_sectors
= 32767;
8556 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8557 "for max_sectors, range is 64 to 32767. Assigning "
8558 "default value of 32767.\n", ioc
->name
,
8561 shost
->max_sectors
= max_sectors
& 0xFFFE;
8563 "The max_sectors value is set to %d\n",
8564 ioc
->name
, shost
->max_sectors
);
8568 /* register EEDP capabilities with SCSI layer */
8570 scsi_host_set_prot(shost
, prot_mask
);
8572 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8573 | SHOST_DIF_TYPE2_PROTECTION
8574 | SHOST_DIF_TYPE3_PROTECTION
);
8576 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8579 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8580 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
8581 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8582 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8583 if (!ioc
->firmware_event_thread
) {
8584 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8585 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8587 goto out_thread_fail
;
8590 ioc
->is_driver_loading
= 1;
8591 if ((mpt3sas_base_attach(ioc
))) {
8592 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8593 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8595 goto out_attach_fail
;
8598 if (ioc
->is_warpdrive
) {
8599 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8600 ioc
->hide_drives
= 0;
8601 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8602 ioc
->hide_drives
= 1;
8604 if (mpt3sas_get_num_volumes(ioc
))
8605 ioc
->hide_drives
= 1;
8607 ioc
->hide_drives
= 0;
8610 ioc
->hide_drives
= 0;
8612 rv
= scsi_add_host(shost
, &pdev
->dev
);
8614 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8615 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8616 goto out_add_shost_fail
;
8619 scsi_scan_host(shost
);
8622 mpt3sas_base_detach(ioc
);
8624 destroy_workqueue(ioc
->firmware_event_thread
);
8626 spin_lock(&gioc_lock
);
8627 list_del(&ioc
->list
);
8628 spin_unlock(&gioc_lock
);
8629 scsi_host_put(shost
);
8635 * scsih_suspend - power management suspend main entry point
8636 * @pdev: PCI device struct
8637 * @state: PM state change to (usually PCI_D3)
8639 * Returns 0 success, anything else error.
8642 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8644 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8645 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8646 pci_power_t device_state
;
8648 mpt3sas_base_stop_watchdog(ioc
);
8649 flush_scheduled_work();
8650 scsi_block_requests(shost
);
8651 device_state
= pci_choose_state(pdev
, state
);
8653 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8654 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8656 pci_save_state(pdev
);
8657 mpt3sas_base_free_resources(ioc
);
8658 pci_set_power_state(pdev
, device_state
);
8663 * scsih_resume - power management resume main entry point
8664 * @pdev: PCI device struct
8666 * Returns 0 success, anything else error.
8669 scsih_resume(struct pci_dev
*pdev
)
8671 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8672 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8673 pci_power_t device_state
= pdev
->current_state
;
8677 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8678 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8680 pci_set_power_state(pdev
, PCI_D0
);
8681 pci_enable_wake(pdev
, PCI_D0
, 0);
8682 pci_restore_state(pdev
);
8684 r
= mpt3sas_base_map_resources(ioc
);
8688 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8689 scsi_unblock_requests(shost
);
8690 mpt3sas_base_start_watchdog(ioc
);
8693 #endif /* CONFIG_PM */
8696 * scsih_pci_error_detected - Called when a PCI error is detected.
8697 * @pdev: PCI device struct
8698 * @state: PCI channel state
8700 * Description: Called when a PCI error is detected.
8703 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8706 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8708 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8709 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8711 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
8715 case pci_channel_io_normal
:
8716 return PCI_ERS_RESULT_CAN_RECOVER
;
8717 case pci_channel_io_frozen
:
8718 /* Fatal error, prepare for slot reset */
8719 ioc
->pci_error_recovery
= 1;
8720 scsi_block_requests(ioc
->shost
);
8721 mpt3sas_base_stop_watchdog(ioc
);
8722 mpt3sas_base_free_resources(ioc
);
8723 return PCI_ERS_RESULT_NEED_RESET
;
8724 case pci_channel_io_perm_failure
:
8725 /* Permanent error, prepare for device removal */
8726 ioc
->pci_error_recovery
= 1;
8727 mpt3sas_base_stop_watchdog(ioc
);
8728 _scsih_flush_running_cmds(ioc
);
8729 return PCI_ERS_RESULT_DISCONNECT
;
8731 return PCI_ERS_RESULT_NEED_RESET
;
8735 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8736 * @pdev: PCI device struct
8738 * Description: This routine is called by the pci error recovery
8739 * code after the PCI slot has been reset, just before we
8740 * should resume normal operations.
8743 scsih_pci_slot_reset(struct pci_dev
*pdev
)
8745 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8746 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8749 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
8752 ioc
->pci_error_recovery
= 0;
8754 pci_restore_state(pdev
);
8755 rc
= mpt3sas_base_map_resources(ioc
);
8757 return PCI_ERS_RESULT_DISCONNECT
;
8759 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8762 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
8763 (rc
== 0) ? "success" : "failed");
8766 return PCI_ERS_RESULT_RECOVERED
;
8768 return PCI_ERS_RESULT_DISCONNECT
;
8772 * scsih_pci_resume() - resume normal ops after PCI reset
8773 * @pdev: pointer to PCI device
8775 * Called when the error recovery driver tells us that its
8776 * OK to resume normal operation. Use completion to allow
8777 * halted scsi ops to resume.
8780 scsih_pci_resume(struct pci_dev
*pdev
)
8782 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8783 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8785 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8787 pci_cleanup_aer_uncorrect_error_status(pdev
);
8788 mpt3sas_base_start_watchdog(ioc
);
8789 scsi_unblock_requests(ioc
->shost
);
8793 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8794 * @pdev: pointer to PCI device
8797 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8799 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8800 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8802 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
8805 /* TODO - dump whatever for debugging purposes */
8807 /* Request a slot reset. */
8808 return PCI_ERS_RESULT_NEED_RESET
;
8812 * The pci device ids are defined in mpi/mpi2_cnfg.h.
8814 static const struct pci_device_id mpt3sas_pci_table
[] = {
8815 /* Spitfire ~ 2004 */
8816 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
8817 PCI_ANY_ID
, PCI_ANY_ID
},
8819 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
8820 PCI_ANY_ID
, PCI_ANY_ID
},
8821 /* Liberator ~ 2108 */
8822 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
8823 PCI_ANY_ID
, PCI_ANY_ID
},
8824 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
8825 PCI_ANY_ID
, PCI_ANY_ID
},
8826 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
8827 PCI_ANY_ID
, PCI_ANY_ID
},
8829 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
8830 PCI_ANY_ID
, PCI_ANY_ID
},
8831 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
8832 PCI_ANY_ID
, PCI_ANY_ID
},
8833 /* Thunderbolt ~ 2208 */
8834 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
8835 PCI_ANY_ID
, PCI_ANY_ID
},
8836 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
8837 PCI_ANY_ID
, PCI_ANY_ID
},
8838 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
8839 PCI_ANY_ID
, PCI_ANY_ID
},
8840 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
8841 PCI_ANY_ID
, PCI_ANY_ID
},
8842 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
8843 PCI_ANY_ID
, PCI_ANY_ID
},
8844 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
8845 PCI_ANY_ID
, PCI_ANY_ID
},
8846 /* Mustang ~ 2308 */
8847 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
8848 PCI_ANY_ID
, PCI_ANY_ID
},
8849 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
8850 PCI_ANY_ID
, PCI_ANY_ID
},
8851 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
8852 PCI_ANY_ID
, PCI_ANY_ID
},
8854 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
8855 PCI_ANY_ID
, PCI_ANY_ID
},
8856 /* Fury ~ 3004 and 3008 */
8857 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
8858 PCI_ANY_ID
, PCI_ANY_ID
},
8859 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
8860 PCI_ANY_ID
, PCI_ANY_ID
},
8861 /* Invader ~ 3108 */
8862 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
8863 PCI_ANY_ID
, PCI_ANY_ID
},
8864 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
8865 PCI_ANY_ID
, PCI_ANY_ID
},
8866 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
8867 PCI_ANY_ID
, PCI_ANY_ID
},
8868 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
8869 PCI_ANY_ID
, PCI_ANY_ID
},
8870 {0} /* Terminating entry */
8872 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
8874 static struct pci_error_handlers _mpt3sas_err_handler
= {
8875 .error_detected
= scsih_pci_error_detected
,
8876 .mmio_enabled
= scsih_pci_mmio_enabled
,
8877 .slot_reset
= scsih_pci_slot_reset
,
8878 .resume
= scsih_pci_resume
,
8881 static struct pci_driver mpt3sas_driver
= {
8882 .name
= MPT3SAS_DRIVER_NAME
,
8883 .id_table
= mpt3sas_pci_table
,
8884 .probe
= _scsih_probe
,
8885 .remove
= scsih_remove
,
8886 .shutdown
= scsih_shutdown
,
8887 .err_handler
= &_mpt3sas_err_handler
,
8889 .suspend
= scsih_suspend
,
8890 .resume
= scsih_resume
,
8895 * scsih_init - main entry point for this driver.
8897 * Returns 0 success, anything else error.
8905 mpt3sas_base_initialize_callback_handler();
8907 /* queuecommand callback hander */
8908 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
8910 /* task managment callback handler */
8911 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
8913 /* base internal commands callback handler */
8914 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
8915 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
8916 mpt3sas_port_enable_done
);
8918 /* transport internal commands callback handler */
8919 transport_cb_idx
= mpt3sas_base_register_callback_handler(
8920 mpt3sas_transport_done
);
8922 /* scsih internal commands callback handler */
8923 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
8925 /* configuration page API internal commands callback handler */
8926 config_cb_idx
= mpt3sas_base_register_callback_handler(
8927 mpt3sas_config_done
);
8929 /* ctl module callback handler */
8930 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
8932 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
8933 _scsih_tm_tr_complete
);
8935 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
8936 _scsih_tm_volume_tr_complete
);
8938 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
8939 _scsih_sas_control_complete
);
8945 * scsih_exit - exit point for this driver (when it is a module).
8947 * Returns 0 success, anything else error.
8953 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
8954 mpt3sas_base_release_callback_handler(tm_cb_idx
);
8955 mpt3sas_base_release_callback_handler(base_cb_idx
);
8956 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
8957 mpt3sas_base_release_callback_handler(transport_cb_idx
);
8958 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
8959 mpt3sas_base_release_callback_handler(config_cb_idx
);
8960 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
8962 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
8963 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8964 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8966 /* raid transport support */
8967 if (hbas_to_enumerate
!= 1)
8968 raid_class_release(mpt3sas_raid_template
);
8969 if (hbas_to_enumerate
!= 2)
8970 raid_class_release(mpt2sas_raid_template
);
8971 sas_release_transport(mpt3sas_transport_template
);
8975 * _mpt3sas_init - main entry point for this driver.
8977 * Returns 0 success, anything else error.
8984 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
8985 MPT3SAS_DRIVER_VERSION
);
8987 mpt3sas_transport_template
=
8988 sas_attach_transport(&mpt3sas_transport_functions
);
8989 if (!mpt3sas_transport_template
)
8992 /* No need attach mpt3sas raid functions template
8993 * if hbas_to_enumarate value is one.
8995 if (hbas_to_enumerate
!= 1) {
8996 mpt3sas_raid_template
=
8997 raid_class_attach(&mpt3sas_raid_functions
);
8998 if (!mpt3sas_raid_template
) {
8999 sas_release_transport(mpt3sas_transport_template
);
9004 /* No need to attach mpt2sas raid functions template
9005 * if hbas_to_enumarate value is two
9007 if (hbas_to_enumerate
!= 2) {
9008 mpt2sas_raid_template
=
9009 raid_class_attach(&mpt2sas_raid_functions
);
9010 if (!mpt2sas_raid_template
) {
9011 sas_release_transport(mpt3sas_transport_template
);
9016 error
= scsih_init();
9022 mpt3sas_ctl_init(hbas_to_enumerate
);
9024 error
= pci_register_driver(&mpt3sas_driver
);
9032 * _mpt3sas_exit - exit point for this driver (when it is a module).
9038 pr_info("mpt3sas version %s unloading\n",
9039 MPT3SAS_DRIVER_VERSION
);
9041 pci_unregister_driver(&mpt3sas_driver
);
9043 mpt3sas_ctl_exit(hbas_to_enumerate
);
9048 module_init(_mpt3sas_init
);
9049 module_exit(_mpt3sas_exit
);