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_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3909 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3911 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3913 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3914 ioc
->name
, __func__
);
3917 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3918 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3919 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
3921 if (scmd
->cmd_len
== 32)
3922 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3923 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3924 if (sas_device_priv_data
->sas_target
->flags
&
3925 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3926 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3928 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3929 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3930 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3931 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3932 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3933 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3934 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3935 mpi_request
->SenseBufferLowAddress
=
3936 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
3937 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3938 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3940 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3942 if (mpi_request
->DataLength
) {
3943 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
3944 mpt3sas_base_free_smid(ioc
, smid
);
3948 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3950 raid_device
= sas_target_priv_data
->raid_device
;
3951 if (raid_device
&& raid_device
->direct_io_enabled
)
3952 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
3955 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
3956 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
3957 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
3958 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
3959 mpt3sas_base_put_smid_fast_path(ioc
, smid
, handle
);
3961 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
3962 le16_to_cpu(mpi_request
->DevHandle
));
3964 mpt3sas_base_put_smid_default(ioc
, smid
);
3968 return SCSI_MLQUEUE_HOST_BUSY
;
3972 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3973 * @sense_buffer: sense data returned by target
3974 * @data: normalized skey/asc/ascq
3979 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3981 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3982 /* descriptor format */
3983 data
->skey
= sense_buffer
[1] & 0x0F;
3984 data
->asc
= sense_buffer
[2];
3985 data
->ascq
= sense_buffer
[3];
3988 data
->skey
= sense_buffer
[2] & 0x0F;
3989 data
->asc
= sense_buffer
[12];
3990 data
->ascq
= sense_buffer
[13];
3995 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3996 * @ioc: per adapter object
3997 * @scmd: pointer to scsi command object
3998 * @mpi_reply: reply mf payload returned from firmware
4000 * scsi_status - SCSI Status code returned from target device
4001 * scsi_state - state info associated with SCSI_IO determined by ioc
4002 * ioc_status - ioc supplied status info
4007 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4008 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4012 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4013 MPI2_IOCSTATUS_MASK
;
4014 u8 scsi_state
= mpi_reply
->SCSIState
;
4015 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4016 char *desc_ioc_state
= NULL
;
4017 char *desc_scsi_status
= NULL
;
4018 char *desc_scsi_state
= ioc
->tmp_string
;
4019 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4020 struct _sas_device
*sas_device
= NULL
;
4021 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4022 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4023 char *device_str
= NULL
;
4027 if (ioc
->hide_ir_msg
)
4028 device_str
= "WarpDrive";
4030 device_str
= "volume";
4032 if (log_info
== 0x31170000)
4035 switch (ioc_status
) {
4036 case MPI2_IOCSTATUS_SUCCESS
:
4037 desc_ioc_state
= "success";
4039 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4040 desc_ioc_state
= "invalid function";
4042 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4043 desc_ioc_state
= "scsi recovered error";
4045 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4046 desc_ioc_state
= "scsi invalid dev handle";
4048 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4049 desc_ioc_state
= "scsi device not there";
4051 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4052 desc_ioc_state
= "scsi data overrun";
4054 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4055 desc_ioc_state
= "scsi data underrun";
4057 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4058 desc_ioc_state
= "scsi io data error";
4060 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4061 desc_ioc_state
= "scsi protocol error";
4063 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4064 desc_ioc_state
= "scsi task terminated";
4066 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4067 desc_ioc_state
= "scsi residual mismatch";
4069 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4070 desc_ioc_state
= "scsi task mgmt failed";
4072 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4073 desc_ioc_state
= "scsi ioc terminated";
4075 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4076 desc_ioc_state
= "scsi ext terminated";
4078 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4079 desc_ioc_state
= "eedp guard error";
4081 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4082 desc_ioc_state
= "eedp ref tag error";
4084 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4085 desc_ioc_state
= "eedp app tag error";
4088 desc_ioc_state
= "unknown";
4092 switch (scsi_status
) {
4093 case MPI2_SCSI_STATUS_GOOD
:
4094 desc_scsi_status
= "good";
4096 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4097 desc_scsi_status
= "check condition";
4099 case MPI2_SCSI_STATUS_CONDITION_MET
:
4100 desc_scsi_status
= "condition met";
4102 case MPI2_SCSI_STATUS_BUSY
:
4103 desc_scsi_status
= "busy";
4105 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4106 desc_scsi_status
= "intermediate";
4108 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4109 desc_scsi_status
= "intermediate condmet";
4111 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4112 desc_scsi_status
= "reservation conflict";
4114 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4115 desc_scsi_status
= "command terminated";
4117 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4118 desc_scsi_status
= "task set full";
4120 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4121 desc_scsi_status
= "aca active";
4123 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4124 desc_scsi_status
= "task aborted";
4127 desc_scsi_status
= "unknown";
4131 desc_scsi_state
[0] = '\0';
4133 desc_scsi_state
= " ";
4134 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4135 strcat(desc_scsi_state
, "response info ");
4136 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4137 strcat(desc_scsi_state
, "state terminated ");
4138 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4139 strcat(desc_scsi_state
, "no status ");
4140 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4141 strcat(desc_scsi_state
, "autosense failed ");
4142 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4143 strcat(desc_scsi_state
, "autosense valid ");
4145 scsi_print_command(scmd
);
4147 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4148 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4149 device_str
, (unsigned long long)priv_target
->sas_address
);
4151 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4154 "\tsas_address(0x%016llx), phy(%d)\n",
4155 ioc
->name
, (unsigned long long)
4156 sas_device
->sas_address
, sas_device
->phy
);
4157 if (sas_device
->enclosure_handle
!= 0)
4159 "\tenclosure_logical_id(0x%016llx),"
4160 "slot(%d)\n", ioc
->name
,
4161 (unsigned long long)
4162 sas_device
->enclosure_logical_id
,
4164 if (sas_device
->connector_name
[0])
4166 "\tenclosure level(0x%04x),"
4167 " connector name( %s)\n", ioc
->name
,
4168 sas_device
->enclosure_level
,
4169 sas_device
->connector_name
);
4171 sas_device_put(sas_device
);
4176 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4177 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4178 desc_ioc_state
, ioc_status
, smid
);
4180 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4181 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4182 scsi_get_resid(scmd
));
4184 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4185 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4186 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4188 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4189 ioc
->name
, desc_scsi_status
,
4190 scsi_status
, desc_scsi_state
, scsi_state
);
4192 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4193 struct sense_info data
;
4194 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4196 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4197 ioc
->name
, data
.skey
,
4198 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4201 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4202 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4203 response_bytes
= (u8
*)&response_info
;
4204 _scsih_response_code(ioc
, response_bytes
[0]);
4209 * _scsih_turn_on_pfa_led - illuminate PFA LED
4210 * @ioc: per adapter object
4211 * @handle: device handle
4217 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4219 Mpi2SepReply_t mpi_reply
;
4220 Mpi2SepRequest_t mpi_request
;
4221 struct _sas_device
*sas_device
;
4223 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4227 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4228 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4229 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4230 mpi_request
.SlotStatus
=
4231 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4232 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4233 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4234 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4235 &mpi_request
)) != 0) {
4236 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4237 __FILE__
, __LINE__
, __func__
);
4240 sas_device
->pfa_led_on
= 1;
4242 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4243 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4244 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4245 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4246 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4250 sas_device_put(sas_device
);
4254 * _scsih_turn_off_pfa_led - turn off Fault LED
4255 * @ioc: per adapter object
4256 * @sas_device: sas device whose PFA LED has to turned off
4262 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4263 struct _sas_device
*sas_device
)
4265 Mpi2SepReply_t mpi_reply
;
4266 Mpi2SepRequest_t mpi_request
;
4268 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4269 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4270 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4271 mpi_request
.SlotStatus
= 0;
4272 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4273 mpi_request
.DevHandle
= 0;
4274 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4275 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4276 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4277 &mpi_request
)) != 0) {
4278 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4279 __FILE__
, __LINE__
, __func__
);
4283 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4284 dewtprintk(ioc
, printk(MPT3SAS_FMT
4285 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4286 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4287 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4293 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4294 * @ioc: per adapter object
4295 * @handle: device handle
4296 * Context: interrupt.
4301 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4303 struct fw_event_work
*fw_event
;
4305 fw_event
= alloc_fw_event_work(0);
4308 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4309 fw_event
->device_handle
= handle
;
4310 fw_event
->ioc
= ioc
;
4311 _scsih_fw_event_add(ioc
, fw_event
);
4312 fw_event_work_put(fw_event
);
4316 * _scsih_smart_predicted_fault - process smart errors
4317 * @ioc: per adapter object
4318 * @handle: device handle
4319 * Context: interrupt.
4324 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4326 struct scsi_target
*starget
;
4327 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4328 Mpi2EventNotificationReply_t
*event_reply
;
4329 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4330 struct _sas_device
*sas_device
;
4332 unsigned long flags
;
4334 /* only handle non-raid devices */
4335 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4336 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
4340 starget
= sas_device
->starget
;
4341 sas_target_priv_data
= starget
->hostdata
;
4343 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4344 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
4347 if (sas_device
->enclosure_handle
!= 0)
4348 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4349 "enclosure logical id(0x%016llx), slot(%d)\n",
4350 (unsigned long long)sas_device
->enclosure_logical_id
,
4352 if (sas_device
->connector_name
[0] != '\0')
4353 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4354 "enclosure level(0x%04x), connector name( %s)\n",
4355 sas_device
->enclosure_level
,
4356 sas_device
->connector_name
);
4357 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4359 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4360 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4362 /* insert into event log */
4363 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4364 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4365 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4367 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4368 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4372 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4373 event_reply
->Event
=
4374 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4375 event_reply
->MsgLength
= sz
/4;
4376 event_reply
->EventDataLength
=
4377 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4378 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4379 event_reply
->EventData
;
4380 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4381 event_data
->ASC
= 0x5D;
4382 event_data
->DevHandle
= cpu_to_le16(handle
);
4383 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4384 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4388 sas_device_put(sas_device
);
4392 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4397 * _scsih_io_done - scsi request callback
4398 * @ioc: per adapter object
4399 * @smid: system request message index
4400 * @msix_index: MSIX table index supplied by the OS
4401 * @reply: reply message frame(lower 32bit addr)
4403 * Callback handler when using _scsih_qcmd.
4405 * Return 1 meaning mf should be freed from _base_interrupt
4406 * 0 means the mf is freed from this function.
4409 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4411 Mpi2SCSIIORequest_t
*mpi_request
;
4412 Mpi2SCSIIOReply_t
*mpi_reply
;
4413 struct scsi_cmnd
*scmd
;
4419 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4420 u32 response_code
= 0;
4421 unsigned long flags
;
4423 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4424 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4428 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4430 if (mpi_reply
== NULL
) {
4431 scmd
->result
= DID_OK
<< 16;
4435 sas_device_priv_data
= scmd
->device
->hostdata
;
4436 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4437 sas_device_priv_data
->sas_target
->deleted
) {
4438 scmd
->result
= DID_NO_CONNECT
<< 16;
4441 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4444 * WARPDRIVE: If direct_io is set then it is directIO,
4445 * the failed direct I/O should be redirected to volume
4447 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
4448 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4449 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4450 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4451 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4452 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4453 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
4454 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4455 mpi_request
->DevHandle
=
4456 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4457 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
4458 sas_device_priv_data
->sas_target
->handle
);
4461 /* turning off TLR */
4462 scsi_state
= mpi_reply
->SCSIState
;
4463 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4465 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4466 if (!sas_device_priv_data
->tlr_snoop_check
) {
4467 sas_device_priv_data
->tlr_snoop_check
++;
4468 if (!ioc
->is_warpdrive
&&
4469 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4470 sas_is_tlr_enabled(scmd
->device
) &&
4471 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4472 sas_disable_tlr(scmd
->device
);
4473 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4477 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4478 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4479 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4480 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4483 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4484 scsi_status
= mpi_reply
->SCSIStatus
;
4486 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4487 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4488 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4489 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4490 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4493 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4494 struct sense_info data
;
4495 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4497 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4498 le32_to_cpu(mpi_reply
->SenseCount
));
4499 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4500 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4501 /* failure prediction threshold exceeded */
4502 if (data
.asc
== 0x5D)
4503 _scsih_smart_predicted_fault(ioc
,
4504 le16_to_cpu(mpi_reply
->DevHandle
));
4505 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4507 if (!(ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4508 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4509 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4510 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4511 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4513 switch (ioc_status
) {
4514 case MPI2_IOCSTATUS_BUSY
:
4515 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4516 scmd
->result
= SAM_STAT_BUSY
;
4519 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4520 scmd
->result
= DID_NO_CONNECT
<< 16;
4523 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4524 if (sas_device_priv_data
->block
) {
4525 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4528 if (log_info
== 0x31110630) {
4529 if (scmd
->retries
> 2) {
4530 scmd
->result
= DID_NO_CONNECT
<< 16;
4531 scsi_device_set_state(scmd
->device
,
4534 scmd
->result
= DID_SOFT_ERROR
<< 16;
4535 scmd
->device
->expecting_cc_ua
= 1;
4538 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4539 scmd
->result
= DID_RESET
<< 16;
4542 scmd
->result
= DID_SOFT_ERROR
<< 16;
4544 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4545 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4546 scmd
->result
= DID_RESET
<< 16;
4549 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4550 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4551 scmd
->result
= DID_SOFT_ERROR
<< 16;
4553 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4556 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4557 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4559 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4562 if (xfer_cnt
< scmd
->underflow
) {
4563 if (scsi_status
== SAM_STAT_BUSY
)
4564 scmd
->result
= SAM_STAT_BUSY
;
4566 scmd
->result
= DID_SOFT_ERROR
<< 16;
4567 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4568 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4569 scmd
->result
= DID_SOFT_ERROR
<< 16;
4570 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4571 scmd
->result
= DID_RESET
<< 16;
4572 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4573 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4574 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4575 scmd
->result
= (DRIVER_SENSE
<< 24) |
4576 SAM_STAT_CHECK_CONDITION
;
4577 scmd
->sense_buffer
[0] = 0x70;
4578 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4579 scmd
->sense_buffer
[12] = 0x20;
4580 scmd
->sense_buffer
[13] = 0;
4584 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4585 scsi_set_resid(scmd
, 0);
4586 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4587 case MPI2_IOCSTATUS_SUCCESS
:
4588 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4589 if (response_code
==
4590 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4591 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4592 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4593 scmd
->result
= DID_SOFT_ERROR
<< 16;
4594 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4595 scmd
->result
= DID_RESET
<< 16;
4598 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4599 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4600 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4601 _scsih_eedp_error_handling(scmd
, ioc_status
);
4604 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4605 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4606 case MPI2_IOCSTATUS_INVALID_SGL
:
4607 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4608 case MPI2_IOCSTATUS_INVALID_FIELD
:
4609 case MPI2_IOCSTATUS_INVALID_STATE
:
4610 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4611 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4613 scmd
->result
= DID_SOFT_ERROR
<< 16;
4618 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4619 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4623 scsi_dma_unmap(scmd
);
4625 scmd
->scsi_done(scmd
);
4630 * _scsih_sas_host_refresh - refreshing sas host object contents
4631 * @ioc: per adapter object
4634 * During port enable, fw will send topology events for every device. Its
4635 * possible that the handles may change from the previous setting, so this
4636 * code keeping handles updating if changed.
4641 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4646 Mpi2ConfigReply_t mpi_reply
;
4647 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4648 u16 attached_handle
;
4651 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4652 "updating handles for sas_host(0x%016llx)\n",
4653 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4655 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4656 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4657 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4658 if (!sas_iounit_pg0
) {
4659 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4660 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4664 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4665 sas_iounit_pg0
, sz
)) != 0)
4667 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4668 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4670 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4671 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4673 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4674 PhyData
[0].ControllerDevHandle
);
4675 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4676 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4678 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4679 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4680 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4681 attached_handle
, i
, link_rate
);
4684 kfree(sas_iounit_pg0
);
4688 * _scsih_sas_host_add - create sas host object
4689 * @ioc: per adapter object
4691 * Creating host side data object, stored in ioc->sas_hba
4696 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4699 Mpi2ConfigReply_t mpi_reply
;
4700 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4701 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4702 Mpi2SasPhyPage0_t phy_pg0
;
4703 Mpi2SasDevicePage0_t sas_device_pg0
;
4704 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4707 u8 device_missing_delay
;
4709 mpt3sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4710 if (!ioc
->sas_hba
.num_phys
) {
4711 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4712 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4716 /* sas_iounit page 0 */
4717 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4718 sizeof(Mpi2SasIOUnit0PhyData_t
));
4719 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4720 if (!sas_iounit_pg0
) {
4721 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4722 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4725 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4726 sas_iounit_pg0
, sz
))) {
4727 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4728 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4731 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4732 MPI2_IOCSTATUS_MASK
;
4733 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4734 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4735 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4739 /* sas_iounit page 1 */
4740 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4741 sizeof(Mpi2SasIOUnit1PhyData_t
));
4742 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4743 if (!sas_iounit_pg1
) {
4744 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4745 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4748 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4749 sas_iounit_pg1
, sz
))) {
4750 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4751 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4754 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4755 MPI2_IOCSTATUS_MASK
;
4756 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4757 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4758 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4762 ioc
->io_missing_delay
=
4763 sas_iounit_pg1
->IODeviceMissingDelay
;
4764 device_missing_delay
=
4765 sas_iounit_pg1
->ReportDeviceMissingDelay
;
4766 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4767 ioc
->device_missing_delay
= (device_missing_delay
&
4768 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4770 ioc
->device_missing_delay
= device_missing_delay
&
4771 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4773 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4774 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4775 sizeof(struct _sas_phy
), GFP_KERNEL
);
4776 if (!ioc
->sas_hba
.phy
) {
4777 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4778 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4781 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4782 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4784 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4785 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4788 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4789 MPI2_IOCSTATUS_MASK
;
4790 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4791 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4792 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4797 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4798 PhyData
[0].ControllerDevHandle
);
4799 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4800 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4801 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4802 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4804 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4805 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4806 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4807 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4810 ioc
->sas_hba
.enclosure_handle
=
4811 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4812 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4814 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4815 ioc
->name
, ioc
->sas_hba
.handle
,
4816 (unsigned long long) ioc
->sas_hba
.sas_address
,
4817 ioc
->sas_hba
.num_phys
) ;
4819 if (ioc
->sas_hba
.enclosure_handle
) {
4820 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4821 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4822 ioc
->sas_hba
.enclosure_handle
)))
4823 ioc
->sas_hba
.enclosure_logical_id
=
4824 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4828 kfree(sas_iounit_pg1
);
4829 kfree(sas_iounit_pg0
);
4833 * _scsih_expander_add - creating expander object
4834 * @ioc: per adapter object
4835 * @handle: expander handle
4837 * Creating expander object, stored in ioc->sas_expander_list.
4839 * Return 0 for success, else error.
4842 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4844 struct _sas_node
*sas_expander
;
4845 Mpi2ConfigReply_t mpi_reply
;
4846 Mpi2ExpanderPage0_t expander_pg0
;
4847 Mpi2ExpanderPage1_t expander_pg1
;
4848 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4851 u64 sas_address
, sas_address_parent
= 0;
4853 unsigned long flags
;
4854 struct _sas_port
*mpt3sas_port
= NULL
;
4861 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4864 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4865 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4866 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4867 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4871 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4872 MPI2_IOCSTATUS_MASK
;
4873 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4874 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4875 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4879 /* handle out of order topology events */
4880 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4881 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4883 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4884 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4887 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4888 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4889 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4890 sas_address_parent
);
4891 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4892 if (!sas_expander
) {
4893 rc
= _scsih_expander_add(ioc
, parent_handle
);
4899 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4900 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4901 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4903 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4908 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4910 if (!sas_expander
) {
4911 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4912 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4916 sas_expander
->handle
= handle
;
4917 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4918 sas_expander
->sas_address_parent
= sas_address_parent
;
4919 sas_expander
->sas_address
= sas_address
;
4921 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
4922 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4923 handle
, parent_handle
, (unsigned long long)
4924 sas_expander
->sas_address
, sas_expander
->num_phys
);
4926 if (!sas_expander
->num_phys
)
4928 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4929 sizeof(struct _sas_phy
), GFP_KERNEL
);
4930 if (!sas_expander
->phy
) {
4931 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4932 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4937 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4938 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
4939 sas_address_parent
);
4940 if (!mpt3sas_port
) {
4941 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4942 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4946 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
4948 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4949 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4950 &expander_pg1
, i
, handle
))) {
4951 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4952 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4956 sas_expander
->phy
[i
].handle
= handle
;
4957 sas_expander
->phy
[i
].phy_id
= i
;
4959 if ((mpt3sas_transport_add_expander_phy(ioc
,
4960 &sas_expander
->phy
[i
], expander_pg1
,
4961 sas_expander
->parent_dev
))) {
4962 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4963 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4969 if (sas_expander
->enclosure_handle
) {
4970 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4971 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4972 sas_expander
->enclosure_handle
)))
4973 sas_expander
->enclosure_logical_id
=
4974 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4977 _scsih_expander_node_add(ioc
, sas_expander
);
4983 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4984 sas_address_parent
);
4985 kfree(sas_expander
);
4990 * mpt3sas_expander_remove - removing expander object
4991 * @ioc: per adapter object
4992 * @sas_address: expander sas_address
4997 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
4999 struct _sas_node
*sas_expander
;
5000 unsigned long flags
;
5002 if (ioc
->shost_recovery
)
5005 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5006 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5009 list_del(&sas_expander
->list
);
5010 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5012 _scsih_expander_node_remove(ioc
, sas_expander
);
5016 * _scsih_done - internal SCSI_IO callback handler.
5017 * @ioc: per adapter object
5018 * @smid: system request message index
5019 * @msix_index: MSIX table index supplied by the OS
5020 * @reply: reply message frame(lower 32bit addr)
5022 * Callback handler when sending internal generated SCSI_IO.
5023 * The callback index passed is `ioc->scsih_cb_idx`
5025 * Return 1 meaning mf should be freed from _base_interrupt
5026 * 0 means the mf is freed from this function.
5029 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5031 MPI2DefaultReply_t
*mpi_reply
;
5033 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5034 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5036 if (ioc
->scsih_cmds
.smid
!= smid
)
5038 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5040 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5041 mpi_reply
->MsgLength
*4);
5042 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5044 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5045 complete(&ioc
->scsih_cmds
.done
);
5052 #define MPT3_MAX_LUNS (255)
5056 * _scsih_check_access_status - check access flags
5057 * @ioc: per adapter object
5058 * @sas_address: sas address
5059 * @handle: sas device handle
5060 * @access_flags: errors returned during discovery of the device
5062 * Return 0 for success, else failure
5065 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5066 u16 handle
, u8 access_status
)
5071 switch (access_status
) {
5072 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5073 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5076 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5077 desc
= "sata capability failed";
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5080 desc
= "sata affiliation conflict";
5082 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5083 desc
= "route not addressable";
5085 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5086 desc
= "smp error not addressable";
5088 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5089 desc
= "device blocked";
5091 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5092 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5093 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5094 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5103 desc
= "sata initialization failed";
5114 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5115 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5120 * _scsih_check_device - checking device responsiveness
5121 * @ioc: per adapter object
5122 * @parent_sas_address: sas address of parent expander or sas host
5123 * @handle: attached device handle
5124 * @phy_numberv: phy number
5125 * @link_rate: new link rate
5130 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5131 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5133 Mpi2ConfigReply_t mpi_reply
;
5134 Mpi2SasDevicePage0_t sas_device_pg0
;
5135 struct _sas_device
*sas_device
;
5137 unsigned long flags
;
5139 struct scsi_target
*starget
;
5140 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5144 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5145 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5148 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5149 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5152 /* wide port handling ~ we need only handle device once for the phy that
5153 * is matched in sas device page zero
5155 if (phy_number
!= sas_device_pg0
.PhyNum
)
5158 /* check if this is end device */
5159 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5160 if (!(_scsih_is_end_device(device_info
)))
5163 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5164 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5165 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5171 if (unlikely(sas_device
->handle
!= handle
)) {
5172 starget
= sas_device
->starget
;
5173 sas_target_priv_data
= starget
->hostdata
;
5174 starget_printk(KERN_INFO
, starget
,
5175 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5176 sas_device
->handle
, handle
);
5177 sas_target_priv_data
->handle
= handle
;
5178 sas_device
->handle
= handle
;
5179 if (sas_device_pg0
.Flags
&
5180 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5181 sas_device
->enclosure_level
=
5182 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5183 memcpy(&sas_device
->connector_name
[0],
5184 &sas_device_pg0
.ConnectorName
[0], 4);
5186 sas_device
->enclosure_level
= 0;
5187 sas_device
->connector_name
[0] = '\0';
5191 /* check if device is present */
5192 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5193 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5195 "device is not present handle(0x%04x), flags!!!\n",
5200 /* check if there were any issues with discovery */
5201 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5202 sas_device_pg0
.AccessStatus
))
5205 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5206 _scsih_ublock_io_device(ioc
, sas_address
);
5209 sas_device_put(sas_device
);
5213 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5215 sas_device_put(sas_device
);
5219 * _scsih_add_device - creating sas device object
5220 * @ioc: per adapter object
5221 * @handle: sas device handle
5222 * @phy_num: phy number end device attached to
5223 * @is_pd: is this hidden raid component
5225 * Creating end device object, stored in ioc->sas_device_list.
5227 * Returns 0 for success, non-zero for failure.
5230 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
5233 Mpi2ConfigReply_t mpi_reply
;
5234 Mpi2SasDevicePage0_t sas_device_pg0
;
5235 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5236 struct _sas_device
*sas_device
;
5241 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5242 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5243 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5244 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5248 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5249 MPI2_IOCSTATUS_MASK
;
5250 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5251 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5252 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5256 /* check if this is end device */
5257 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5258 if (!(_scsih_is_end_device(device_info
)))
5260 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5262 /* check if device is present */
5263 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5264 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5265 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5270 /* check if there were any issues with discovery */
5271 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5272 sas_device_pg0
.AccessStatus
))
5275 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
5278 sas_device_put(sas_device
);
5282 sas_device
= kzalloc(sizeof(struct _sas_device
),
5285 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5286 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5290 kref_init(&sas_device
->refcount
);
5291 sas_device
->handle
= handle
;
5292 if (_scsih_get_sas_address(ioc
,
5293 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5294 &sas_device
->sas_address_parent
) != 0)
5295 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5296 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5297 sas_device
->enclosure_handle
=
5298 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5299 if (sas_device
->enclosure_handle
!= 0)
5301 le16_to_cpu(sas_device_pg0
.Slot
);
5302 sas_device
->device_info
= device_info
;
5303 sas_device
->sas_address
= sas_address
;
5304 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5305 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5306 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5308 if (sas_device_pg0
.Flags
& MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5309 sas_device
->enclosure_level
=
5310 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5311 memcpy(&sas_device
->connector_name
[0],
5312 &sas_device_pg0
.ConnectorName
[0], 4);
5314 sas_device
->enclosure_level
= 0;
5315 sas_device
->connector_name
[0] = '\0';
5317 /* get enclosure_logical_id */
5318 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5319 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5320 sas_device
->enclosure_handle
)))
5321 sas_device
->enclosure_logical_id
=
5322 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5324 /* get device name */
5325 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5327 if (ioc
->wait_for_discovery_to_complete
)
5328 _scsih_sas_device_init_add(ioc
, sas_device
);
5330 _scsih_sas_device_add(ioc
, sas_device
);
5332 sas_device_put(sas_device
);
5337 * _scsih_remove_device - removing sas device object
5338 * @ioc: per adapter object
5339 * @sas_device_delete: the sas_device object
5344 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5345 struct _sas_device
*sas_device
)
5347 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5349 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5350 (sas_device
->pfa_led_on
)) {
5351 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5352 sas_device
->pfa_led_on
= 0;
5354 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5355 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5356 ioc
->name
, __func__
,
5357 sas_device
->handle
, (unsigned long long)
5358 sas_device
->sas_address
));
5359 if (sas_device
->enclosure_handle
!= 0)
5360 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5361 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5362 ioc
->name
, __func__
,
5363 (unsigned long long)sas_device
->enclosure_logical_id
,
5365 if (sas_device
->connector_name
[0] != '\0')
5366 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5367 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5368 ioc
->name
, __func__
,
5369 sas_device
->enclosure_level
,
5370 sas_device
->connector_name
));
5372 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5373 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5374 sas_target_priv_data
->deleted
= 1;
5375 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5376 sas_target_priv_data
->handle
=
5377 MPT3SAS_INVALID_DEVICE_HANDLE
;
5380 if (!ioc
->hide_drives
)
5381 mpt3sas_transport_port_remove(ioc
,
5382 sas_device
->sas_address
,
5383 sas_device
->sas_address_parent
);
5386 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5387 ioc
->name
, sas_device
->handle
,
5388 (unsigned long long) sas_device
->sas_address
);
5389 if (sas_device
->enclosure_handle
!= 0)
5391 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5393 (unsigned long long)sas_device
->enclosure_logical_id
,
5395 if (sas_device
->connector_name
[0] != '\0')
5397 "removing enclosure level(0x%04x), connector name( %s)\n",
5398 ioc
->name
, sas_device
->enclosure_level
,
5399 sas_device
->connector_name
);
5401 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5402 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5403 ioc
->name
, __func__
,
5404 sas_device
->handle
, (unsigned long long)
5405 sas_device
->sas_address
));
5406 if (sas_device
->enclosure_handle
!= 0)
5407 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5408 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5409 ioc
->name
, __func__
,
5410 (unsigned long long)sas_device
->enclosure_logical_id
,
5412 if (sas_device
->connector_name
[0] != '\0')
5413 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5414 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5415 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5416 sas_device
->connector_name
));
5420 * _scsih_sas_topology_change_event_debug - debug for topology event
5421 * @ioc: per adapter object
5422 * @event_data: event data payload
5426 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5427 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5433 char *status_str
= NULL
;
5434 u8 link_rate
, prev_link_rate
;
5436 switch (event_data
->ExpStatus
) {
5437 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5440 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5441 status_str
= "remove";
5443 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5445 status_str
= "responding";
5447 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5448 status_str
= "remove delay";
5451 status_str
= "unknown status";
5454 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5455 ioc
->name
, status_str
);
5456 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5457 "start_phy(%02d), count(%d)\n",
5458 le16_to_cpu(event_data
->ExpanderDevHandle
),
5459 le16_to_cpu(event_data
->EnclosureHandle
),
5460 event_data
->StartPhyNum
, event_data
->NumEntries
);
5461 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5462 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5465 phy_number
= event_data
->StartPhyNum
+ i
;
5466 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5467 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5468 switch (reason_code
) {
5469 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5470 status_str
= "target add";
5472 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5473 status_str
= "target remove";
5475 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5476 status_str
= "delay target remove";
5478 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5479 status_str
= "link rate change";
5481 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5482 status_str
= "target responding";
5485 status_str
= "unknown";
5488 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5489 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5490 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5491 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5492 handle
, status_str
, link_rate
, prev_link_rate
);
5498 * _scsih_sas_topology_change_event - handle topology changes
5499 * @ioc: per adapter object
5500 * @fw_event: The fw_event_work object
5505 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5506 struct fw_event_work
*fw_event
)
5509 u16 parent_handle
, handle
;
5511 u8 phy_number
, max_phys
;
5512 struct _sas_node
*sas_expander
;
5514 unsigned long flags
;
5515 u8 link_rate
, prev_link_rate
;
5516 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5517 (Mpi2EventDataSasTopologyChangeList_t
*)
5518 fw_event
->event_data
;
5520 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5521 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5523 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5526 if (!ioc
->sas_hba
.num_phys
)
5527 _scsih_sas_host_add(ioc
);
5529 _scsih_sas_host_refresh(ioc
);
5531 if (fw_event
->ignore
) {
5532 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5533 "ignoring expander event\n", ioc
->name
));
5537 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5539 /* handle expander add */
5540 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5541 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5544 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5545 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5548 sas_address
= sas_expander
->sas_address
;
5549 max_phys
= sas_expander
->num_phys
;
5550 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5551 sas_address
= ioc
->sas_hba
.sas_address
;
5552 max_phys
= ioc
->sas_hba
.num_phys
;
5554 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5557 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5559 /* handle siblings events */
5560 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5561 if (fw_event
->ignore
) {
5562 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5563 "ignoring expander event\n", ioc
->name
));
5566 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5568 phy_number
= event_data
->StartPhyNum
+ i
;
5569 if (phy_number
>= max_phys
)
5571 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5572 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5573 if ((event_data
->PHY
[i
].PhyStatus
&
5574 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5575 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5577 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5580 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5581 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5582 switch (reason_code
) {
5583 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5585 if (ioc
->shost_recovery
)
5588 if (link_rate
== prev_link_rate
)
5591 mpt3sas_transport_update_links(ioc
, sas_address
,
5592 handle
, phy_number
, link_rate
);
5594 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5597 _scsih_check_device(ioc
, sas_address
, handle
,
5598 phy_number
, link_rate
);
5601 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5603 if (ioc
->shost_recovery
)
5606 mpt3sas_transport_update_links(ioc
, sas_address
,
5607 handle
, phy_number
, link_rate
);
5609 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5612 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5614 _scsih_device_remove_by_handle(ioc
, handle
);
5619 /* handle expander removal */
5620 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5622 mpt3sas_expander_remove(ioc
, sas_address
);
5628 * _scsih_sas_device_status_change_event_debug - debug for device event
5629 * @event_data: event data payload
5635 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5636 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5638 char *reason_str
= NULL
;
5640 switch (event_data
->ReasonCode
) {
5641 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5642 reason_str
= "smart data";
5644 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5645 reason_str
= "unsupported device discovered";
5647 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5648 reason_str
= "internal device reset";
5650 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5651 reason_str
= "internal task abort";
5653 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5654 reason_str
= "internal task abort set";
5656 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5657 reason_str
= "internal clear task set";
5659 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5660 reason_str
= "internal query task";
5662 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5663 reason_str
= "sata init failure";
5665 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5666 reason_str
= "internal device reset complete";
5668 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5669 reason_str
= "internal task abort complete";
5671 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5672 reason_str
= "internal async notification";
5674 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5675 reason_str
= "expander reduced functionality";
5677 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5678 reason_str
= "expander reduced functionality complete";
5681 reason_str
= "unknown reason";
5684 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5685 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5686 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5687 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5688 le16_to_cpu(event_data
->TaskTag
));
5689 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5690 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5691 event_data
->ASC
, event_data
->ASCQ
);
5696 * _scsih_sas_device_status_change_event - handle device status change
5697 * @ioc: per adapter object
5698 * @fw_event: The fw_event_work object
5704 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5705 struct fw_event_work
*fw_event
)
5707 struct MPT3SAS_TARGET
*target_priv_data
;
5708 struct _sas_device
*sas_device
;
5710 unsigned long flags
;
5711 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5712 (Mpi2EventDataSasDeviceStatusChange_t
*)
5713 fw_event
->event_data
;
5715 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5716 _scsih_sas_device_status_change_event_debug(ioc
,
5719 /* In MPI Revision K (0xC), the internal device reset complete was
5720 * implemented, so avoid setting tm_busy flag for older firmware.
5722 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5725 if (event_data
->ReasonCode
!=
5726 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5727 event_data
->ReasonCode
!=
5728 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5731 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5732 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5733 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5736 if (!sas_device
|| !sas_device
->starget
)
5739 target_priv_data
= sas_device
->starget
->hostdata
;
5740 if (!target_priv_data
)
5743 if (event_data
->ReasonCode
==
5744 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5745 target_priv_data
->tm_busy
= 1;
5747 target_priv_data
->tm_busy
= 0;
5751 sas_device_put(sas_device
);
5753 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5758 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5760 * @ioc: per adapter object
5761 * @event_data: event data payload
5767 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5768 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5770 char *reason_str
= NULL
;
5772 switch (event_data
->ReasonCode
) {
5773 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5774 reason_str
= "enclosure add";
5776 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5777 reason_str
= "enclosure remove";
5780 reason_str
= "unknown reason";
5784 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
5785 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5786 " number slots(%d)\n", ioc
->name
, reason_str
,
5787 le16_to_cpu(event_data
->EnclosureHandle
),
5788 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5789 le16_to_cpu(event_data
->StartSlot
));
5793 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5794 * @ioc: per adapter object
5795 * @fw_event: The fw_event_work object
5801 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5802 struct fw_event_work
*fw_event
)
5804 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5805 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5806 (Mpi2EventDataSasEnclDevStatusChange_t
*)
5807 fw_event
->event_data
);
5811 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5812 * @ioc: per adapter object
5813 * @fw_event: The fw_event_work object
5819 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
5820 struct fw_event_work
*fw_event
)
5822 struct scsi_cmnd
*scmd
;
5823 struct scsi_device
*sdev
;
5826 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5827 u32 termination_count
;
5829 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5830 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
5831 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5832 fw_event
->event_data
;
5834 unsigned long flags
;
5837 u8 task_abort_retries
;
5839 mutex_lock(&ioc
->tm_cmds
.mutex
);
5841 "%s: enter: phy number(%d), width(%d)\n",
5842 ioc
->name
, __func__
, event_data
->PhyNum
,
5843 event_data
->PortWidth
);
5845 _scsih_block_io_all_device(ioc
);
5847 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5848 mpi_reply
= ioc
->tm_cmds
.reply
;
5849 broadcast_aen_retry
:
5851 /* sanity checks for retrying this loop */
5852 if (max_retries
++ == 5) {
5853 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
5854 ioc
->name
, __func__
));
5856 } else if (max_retries
> 1)
5857 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
5858 ioc
->name
, __func__
, max_retries
- 1));
5860 termination_count
= 0;
5862 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5863 if (ioc
->shost_recovery
)
5865 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5868 sdev
= scmd
->device
;
5869 sas_device_priv_data
= sdev
->hostdata
;
5870 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5872 /* skip hidden raid components */
5873 if (sas_device_priv_data
->sas_target
->flags
&
5874 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5877 if (sas_device_priv_data
->sas_target
->flags
&
5878 MPT_TARGET_FLAGS_VOLUME
)
5881 handle
= sas_device_priv_data
->sas_target
->handle
;
5882 lun
= sas_device_priv_data
->lun
;
5885 if (ioc
->shost_recovery
)
5888 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5889 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5890 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
5893 sdev_printk(KERN_WARNING
, sdev
,
5894 "mpt3sas_scsih_issue_tm: FAILED when sending "
5895 "QUERY_TASK: scmd(%p)\n", scmd
);
5896 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5897 goto broadcast_aen_retry
;
5899 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5900 & MPI2_IOCSTATUS_MASK
;
5901 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5902 sdev_printk(KERN_WARNING
, sdev
,
5903 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5905 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5906 goto broadcast_aen_retry
;
5909 /* see if IO is still owned by IOC and target */
5910 if (mpi_reply
->ResponseCode
==
5911 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5912 mpi_reply
->ResponseCode
==
5913 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5914 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5917 task_abort_retries
= 0;
5919 if (task_abort_retries
++ == 60) {
5920 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5921 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5923 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5924 goto broadcast_aen_retry
;
5927 if (ioc
->shost_recovery
)
5930 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5931 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5934 sdev_printk(KERN_WARNING
, sdev
,
5935 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5936 "scmd(%p)\n", scmd
);
5940 if (task_abort_retries
> 1)
5941 sdev_printk(KERN_WARNING
, sdev
,
5942 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5944 task_abort_retries
- 1, scmd
);
5946 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5947 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5950 if (ioc
->broadcast_aen_pending
) {
5951 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5952 "%s: loop back due to pending AEN\n",
5953 ioc
->name
, __func__
));
5954 ioc
->broadcast_aen_pending
= 0;
5955 goto broadcast_aen_retry
;
5959 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5962 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5963 "%s - exit, query_count = %d termination_count = %d\n",
5964 ioc
->name
, __func__
, query_count
, termination_count
));
5966 ioc
->broadcast_aen_busy
= 0;
5967 if (!ioc
->shost_recovery
)
5968 _scsih_ublock_io_all_device(ioc
);
5969 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5973 * _scsih_sas_discovery_event - handle discovery events
5974 * @ioc: per adapter object
5975 * @fw_event: The fw_event_work object
5981 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
5982 struct fw_event_work
*fw_event
)
5984 Mpi2EventDataSasDiscovery_t
*event_data
=
5985 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
5987 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5988 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
5989 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5991 if (event_data
->DiscoveryStatus
)
5992 pr_info("discovery_status(0x%08x)",
5993 le32_to_cpu(event_data
->DiscoveryStatus
));
5997 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5998 !ioc
->sas_hba
.num_phys
) {
5999 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6000 /* Wait for the reset to complete */
6001 while (ioc
->shost_recovery
)
6004 _scsih_sas_host_add(ioc
);
6009 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6010 * @ioc: per adapter object
6011 * @handle: device handle for physical disk
6012 * @phys_disk_num: physical disk number
6014 * Return 0 for success, else failure.
6017 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
6019 Mpi2RaidActionRequest_t
*mpi_request
;
6020 Mpi2RaidActionReply_t
*mpi_reply
;
6027 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
6030 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6032 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
6033 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
6034 ioc
->name
, __func__
);
6038 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
6040 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6042 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
6043 ioc
->name
, __func__
);
6044 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6049 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
6050 ioc
->scsih_cmds
.smid
= smid
;
6051 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6053 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6054 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
6055 mpi_request
->PhysDiskNum
= phys_disk_num
;
6057 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
6058 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
6059 handle
, phys_disk_num
));
6061 init_completion(&ioc
->scsih_cmds
.done
);
6062 mpt3sas_base_put_smid_default(ioc
, smid
);
6063 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6065 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
6066 pr_err(MPT3SAS_FMT
"%s: timeout\n",
6067 ioc
->name
, __func__
);
6068 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
6074 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
6076 mpi_reply
= ioc
->scsih_cmds
.reply
;
6077 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
6078 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
6079 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
6082 ioc_status
&= MPI2_IOCSTATUS_MASK
;
6083 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6084 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6085 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6086 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
6090 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6091 "IR RAID_ACTION: completed successfully\n",
6096 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6097 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6100 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
6106 * _scsih_reprobe_lun - reprobing lun
6107 * @sdev: scsi device struct
6108 * @no_uld_attach: sdev->no_uld_attach flag setting
6112 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6115 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6116 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6117 sdev
->no_uld_attach
? "hidding" : "exposing");
6118 rc
= scsi_device_reprobe(sdev
);
6122 * _scsih_sas_volume_add - add new volume
6123 * @ioc: per adapter object
6124 * @element: IR config element data
6130 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
6131 Mpi2EventIrConfigElement_t
*element
)
6133 struct _raid_device
*raid_device
;
6134 unsigned long flags
;
6136 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6139 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6142 "failure at %s:%d/%s()!\n", ioc
->name
,
6143 __FILE__
, __LINE__
, __func__
);
6147 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6148 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6149 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6154 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6157 "failure at %s:%d/%s()!\n", ioc
->name
,
6158 __FILE__
, __LINE__
, __func__
);
6162 raid_device
->id
= ioc
->sas_id
++;
6163 raid_device
->channel
= RAID_CHANNEL
;
6164 raid_device
->handle
= handle
;
6165 raid_device
->wwid
= wwid
;
6166 _scsih_raid_device_add(ioc
, raid_device
);
6167 if (!ioc
->wait_for_discovery_to_complete
) {
6168 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6169 raid_device
->id
, 0);
6171 _scsih_raid_device_remove(ioc
, raid_device
);
6173 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6174 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6175 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6180 * _scsih_sas_volume_delete - delete volume
6181 * @ioc: per adapter object
6182 * @handle: volume device handle
6188 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6190 struct _raid_device
*raid_device
;
6191 unsigned long flags
;
6192 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6193 struct scsi_target
*starget
= NULL
;
6195 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6196 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6198 if (raid_device
->starget
) {
6199 starget
= raid_device
->starget
;
6200 sas_target_priv_data
= starget
->hostdata
;
6201 sas_target_priv_data
->deleted
= 1;
6203 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
6204 ioc
->name
, raid_device
->handle
,
6205 (unsigned long long) raid_device
->wwid
);
6206 list_del(&raid_device
->list
);
6209 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6211 scsi_remove_target(&starget
->dev
);
6215 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6216 * @ioc: per adapter object
6217 * @element: IR config element data
6223 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6224 Mpi2EventIrConfigElement_t
*element
)
6226 struct _sas_device
*sas_device
;
6227 struct scsi_target
*starget
= NULL
;
6228 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6229 unsigned long flags
;
6230 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6232 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6233 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6235 sas_device
->volume_handle
= 0;
6236 sas_device
->volume_wwid
= 0;
6237 clear_bit(handle
, ioc
->pd_handles
);
6238 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6239 starget
= sas_device
->starget
;
6240 sas_target_priv_data
= starget
->hostdata
;
6241 sas_target_priv_data
->flags
&=
6242 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6245 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6249 /* exposing raid component */
6251 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6253 sas_device_put(sas_device
);
6257 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6258 * @ioc: per adapter object
6259 * @element: IR config element data
6265 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6266 Mpi2EventIrConfigElement_t
*element
)
6268 struct _sas_device
*sas_device
;
6269 struct scsi_target
*starget
= NULL
;
6270 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6271 unsigned long flags
;
6272 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6273 u16 volume_handle
= 0;
6274 u64 volume_wwid
= 0;
6276 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6278 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6281 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6282 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6284 set_bit(handle
, ioc
->pd_handles
);
6285 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6286 starget
= sas_device
->starget
;
6287 sas_target_priv_data
= starget
->hostdata
;
6288 sas_target_priv_data
->flags
|=
6289 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6290 sas_device
->volume_handle
= volume_handle
;
6291 sas_device
->volume_wwid
= volume_wwid
;
6294 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6298 /* hiding raid component */
6299 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6302 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6304 sas_device_put(sas_device
);
6308 * _scsih_sas_pd_delete - delete pd component
6309 * @ioc: per adapter object
6310 * @element: IR config element data
6316 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6317 Mpi2EventIrConfigElement_t
*element
)
6319 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6321 _scsih_device_remove_by_handle(ioc
, handle
);
6325 * _scsih_sas_pd_add - remove pd component
6326 * @ioc: per adapter object
6327 * @element: IR config element data
6333 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6334 Mpi2EventIrConfigElement_t
*element
)
6336 struct _sas_device
*sas_device
;
6337 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6338 Mpi2ConfigReply_t mpi_reply
;
6339 Mpi2SasDevicePage0_t sas_device_pg0
;
6344 set_bit(handle
, ioc
->pd_handles
);
6346 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6348 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6349 sas_device_put(sas_device
);
6353 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6354 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6355 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6356 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6360 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6361 MPI2_IOCSTATUS_MASK
;
6362 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6363 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6364 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6368 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6369 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6370 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6371 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6373 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6374 _scsih_add_device(ioc
, handle
, 0, 1);
6378 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6379 * @ioc: per adapter object
6380 * @event_data: event data payload
6386 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6387 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6389 Mpi2EventIrConfigElement_t
*element
;
6392 char *reason_str
= NULL
, *element_str
= NULL
;
6394 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6396 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6397 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6398 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6399 "foreign" : "native", event_data
->NumElements
);
6400 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6401 switch (element
->ReasonCode
) {
6402 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6405 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6406 reason_str
= "remove";
6408 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6409 reason_str
= "no change";
6411 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6412 reason_str
= "hide";
6414 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6415 reason_str
= "unhide";
6417 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6418 reason_str
= "volume_created";
6420 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6421 reason_str
= "volume_deleted";
6423 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6424 reason_str
= "pd_created";
6426 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6427 reason_str
= "pd_deleted";
6430 reason_str
= "unknown reason";
6433 element_type
= le16_to_cpu(element
->ElementFlags
) &
6434 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6435 switch (element_type
) {
6436 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6437 element_str
= "volume";
6439 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6440 element_str
= "phys disk";
6442 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6443 element_str
= "hot spare";
6446 element_str
= "unknown element";
6449 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6450 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6451 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6452 le16_to_cpu(element
->PhysDiskDevHandle
),
6453 element
->PhysDiskNum
);
6458 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6459 * @ioc: per adapter object
6460 * @fw_event: The fw_event_work object
6466 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6467 struct fw_event_work
*fw_event
)
6469 Mpi2EventIrConfigElement_t
*element
;
6472 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6473 (Mpi2EventDataIrConfigChangeList_t
*)
6474 fw_event
->event_data
;
6476 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6477 (!ioc
->hide_ir_msg
))
6478 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6480 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6481 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6483 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6484 if (ioc
->shost_recovery
&&
6485 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
6486 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6487 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6488 _scsih_ir_fastpath(ioc
,
6489 le16_to_cpu(element
->PhysDiskDevHandle
),
6490 element
->PhysDiskNum
);
6495 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6497 switch (element
->ReasonCode
) {
6498 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6499 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6500 if (!foreign_config
)
6501 _scsih_sas_volume_add(ioc
, element
);
6503 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6504 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6505 if (!foreign_config
)
6506 _scsih_sas_volume_delete(ioc
,
6507 le16_to_cpu(element
->VolDevHandle
));
6509 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6510 if (!ioc
->is_warpdrive
)
6511 _scsih_sas_pd_hide(ioc
, element
);
6513 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6514 if (!ioc
->is_warpdrive
)
6515 _scsih_sas_pd_expose(ioc
, element
);
6517 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6518 if (!ioc
->is_warpdrive
)
6519 _scsih_sas_pd_add(ioc
, element
);
6521 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6522 if (!ioc
->is_warpdrive
)
6523 _scsih_sas_pd_delete(ioc
, element
);
6530 * _scsih_sas_ir_volume_event - IR volume event
6531 * @ioc: per adapter object
6532 * @fw_event: The fw_event_work object
6538 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6539 struct fw_event_work
*fw_event
)
6542 unsigned long flags
;
6543 struct _raid_device
*raid_device
;
6547 Mpi2EventDataIrVolume_t
*event_data
=
6548 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6550 if (ioc
->shost_recovery
)
6553 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6556 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6557 state
= le32_to_cpu(event_data
->NewValue
);
6558 if (!ioc
->hide_ir_msg
)
6559 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6560 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6561 ioc
->name
, __func__
, handle
,
6562 le32_to_cpu(event_data
->PreviousValue
), state
));
6564 case MPI2_RAID_VOL_STATE_MISSING
:
6565 case MPI2_RAID_VOL_STATE_FAILED
:
6566 _scsih_sas_volume_delete(ioc
, handle
);
6569 case MPI2_RAID_VOL_STATE_ONLINE
:
6570 case MPI2_RAID_VOL_STATE_DEGRADED
:
6571 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6573 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6574 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6575 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6580 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6583 "failure at %s:%d/%s()!\n", ioc
->name
,
6584 __FILE__
, __LINE__
, __func__
);
6588 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6591 "failure at %s:%d/%s()!\n", ioc
->name
,
6592 __FILE__
, __LINE__
, __func__
);
6596 raid_device
->id
= ioc
->sas_id
++;
6597 raid_device
->channel
= RAID_CHANNEL
;
6598 raid_device
->handle
= handle
;
6599 raid_device
->wwid
= wwid
;
6600 _scsih_raid_device_add(ioc
, raid_device
);
6601 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6602 raid_device
->id
, 0);
6604 _scsih_raid_device_remove(ioc
, raid_device
);
6607 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6614 * _scsih_sas_ir_physical_disk_event - PD event
6615 * @ioc: per adapter object
6616 * @fw_event: The fw_event_work object
6622 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6623 struct fw_event_work
*fw_event
)
6625 u16 handle
, parent_handle
;
6627 struct _sas_device
*sas_device
;
6628 Mpi2ConfigReply_t mpi_reply
;
6629 Mpi2SasDevicePage0_t sas_device_pg0
;
6631 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6632 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6635 if (ioc
->shost_recovery
)
6638 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6641 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6642 state
= le32_to_cpu(event_data
->NewValue
);
6644 if (!ioc
->hide_ir_msg
)
6645 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6646 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6647 ioc
->name
, __func__
, handle
,
6648 le32_to_cpu(event_data
->PreviousValue
), state
));
6651 case MPI2_RAID_PD_STATE_ONLINE
:
6652 case MPI2_RAID_PD_STATE_DEGRADED
:
6653 case MPI2_RAID_PD_STATE_REBUILDING
:
6654 case MPI2_RAID_PD_STATE_OPTIMAL
:
6655 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6657 if (!ioc
->is_warpdrive
)
6658 set_bit(handle
, ioc
->pd_handles
);
6660 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6662 sas_device_put(sas_device
);
6666 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6667 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6669 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6670 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6674 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6675 MPI2_IOCSTATUS_MASK
;
6676 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6677 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6678 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6682 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6683 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6684 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6685 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6687 _scsih_add_device(ioc
, handle
, 0, 1);
6691 case MPI2_RAID_PD_STATE_OFFLINE
:
6692 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6693 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6700 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6701 * @ioc: per adapter object
6702 * @event_data: event data payload
6708 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6709 Mpi2EventDataIrOperationStatus_t
*event_data
)
6711 char *reason_str
= NULL
;
6713 switch (event_data
->RAIDOperation
) {
6714 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6715 reason_str
= "resync";
6717 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6718 reason_str
= "online capacity expansion";
6720 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6721 reason_str
= "consistency check";
6723 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6724 reason_str
= "background init";
6726 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6727 reason_str
= "make data consistent";
6734 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6735 "\thandle(0x%04x), percent complete(%d)\n",
6736 ioc
->name
, reason_str
,
6737 le16_to_cpu(event_data
->VolDevHandle
),
6738 event_data
->PercentComplete
);
6742 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6743 * @ioc: per adapter object
6744 * @fw_event: The fw_event_work object
6750 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
6751 struct fw_event_work
*fw_event
)
6753 Mpi2EventDataIrOperationStatus_t
*event_data
=
6754 (Mpi2EventDataIrOperationStatus_t
*)
6755 fw_event
->event_data
;
6756 static struct _raid_device
*raid_device
;
6757 unsigned long flags
;
6760 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6761 (!ioc
->hide_ir_msg
))
6762 _scsih_sas_ir_operation_status_event_debug(ioc
,
6765 /* code added for raid transport support */
6766 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6768 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6769 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6770 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6772 raid_device
->percent_complete
=
6773 event_data
->PercentComplete
;
6774 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6779 * _scsih_prep_device_scan - initialize parameters prior to device scan
6780 * @ioc: per adapter object
6782 * Set the deleted flag prior to device scan. If the device is found during
6783 * the scan, then we clear the deleted flag.
6786 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
6788 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6789 struct scsi_device
*sdev
;
6791 shost_for_each_device(sdev
, ioc
->shost
) {
6792 sas_device_priv_data
= sdev
->hostdata
;
6793 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6794 sas_device_priv_data
->sas_target
->deleted
= 1;
6799 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6800 * @ioc: per adapter object
6801 * @sas_device_pg0: SAS Device page 0
6803 * After host reset, find out whether devices are still responding.
6804 * Used in _scsih_remove_unresponsive_sas_devices.
6809 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
6810 Mpi2SasDevicePage0_t
*sas_device_pg0
)
6812 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
6813 struct scsi_target
*starget
;
6814 struct _sas_device
*sas_device
;
6815 unsigned long flags
;
6817 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6818 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6819 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
6820 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
6821 sas_device
->responding
= 1;
6822 starget
= sas_device
->starget
;
6823 if (starget
&& starget
->hostdata
) {
6824 sas_target_priv_data
= starget
->hostdata
;
6825 sas_target_priv_data
->tm_busy
= 0;
6826 sas_target_priv_data
->deleted
= 0;
6828 sas_target_priv_data
= NULL
;
6830 starget_printk(KERN_INFO
, starget
,
6831 "handle(0x%04x), sas_addr(0x%016llx)\n",
6832 sas_device_pg0
->DevHandle
,
6833 (unsigned long long)
6834 sas_device
->sas_address
);
6836 if (sas_device
->enclosure_handle
!= 0)
6837 starget_printk(KERN_INFO
, starget
,
6838 "enclosure logical id(0x%016llx),"
6840 (unsigned long long)
6841 sas_device
->enclosure_logical_id
,
6844 if (sas_device_pg0
->Flags
&
6845 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6846 sas_device
->enclosure_level
=
6847 le16_to_cpu(sas_device_pg0
->EnclosureLevel
);
6848 memcpy(&sas_device
->connector_name
[0],
6849 &sas_device_pg0
->ConnectorName
[0], 4);
6851 sas_device
->enclosure_level
= 0;
6852 sas_device
->connector_name
[0] = '\0';
6855 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
6857 pr_info("\thandle changed from(0x%04x)!!!\n",
6858 sas_device
->handle
);
6859 sas_device
->handle
= sas_device_pg0
->DevHandle
;
6860 if (sas_target_priv_data
)
6861 sas_target_priv_data
->handle
=
6862 sas_device_pg0
->DevHandle
;
6867 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6871 * _scsih_search_responding_sas_devices -
6872 * @ioc: per adapter object
6874 * After host reset, find out whether devices are still responding.
6880 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
6882 Mpi2SasDevicePage0_t sas_device_pg0
;
6883 Mpi2ConfigReply_t mpi_reply
;
6888 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
6890 if (list_empty(&ioc
->sas_device_list
))
6894 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6895 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6897 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6898 MPI2_IOCSTATUS_MASK
;
6899 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6901 handle
= sas_device_pg0
.DevHandle
=
6902 le16_to_cpu(sas_device_pg0
.DevHandle
);
6903 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6904 if (!(_scsih_is_end_device(device_info
)))
6906 sas_device_pg0
.SASAddress
=
6907 le64_to_cpu(sas_device_pg0
.SASAddress
);
6908 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6909 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
6913 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
6918 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6919 * @ioc: per adapter object
6920 * @wwid: world wide identifier for raid volume
6921 * @handle: device handle
6923 * After host reset, find out whether devices are still responding.
6924 * Used in _scsih_remove_unresponsive_raid_devices.
6929 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6932 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
6933 struct scsi_target
*starget
;
6934 struct _raid_device
*raid_device
;
6935 unsigned long flags
;
6937 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6938 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6939 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6940 starget
= raid_device
->starget
;
6941 if (starget
&& starget
->hostdata
) {
6942 sas_target_priv_data
= starget
->hostdata
;
6943 sas_target_priv_data
->deleted
= 0;
6945 sas_target_priv_data
= NULL
;
6946 raid_device
->responding
= 1;
6947 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6948 starget_printk(KERN_INFO
, raid_device
->starget
,
6949 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6950 (unsigned long long)raid_device
->wwid
);
6953 * WARPDRIVE: The handles of the PDs might have changed
6954 * across the host reset so re-initialize the
6955 * required data for Direct IO
6957 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
6958 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6959 if (raid_device
->handle
== handle
) {
6960 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
6964 pr_info("\thandle changed from(0x%04x)!!!\n",
6965 raid_device
->handle
);
6966 raid_device
->handle
= handle
;
6967 if (sas_target_priv_data
)
6968 sas_target_priv_data
->handle
= handle
;
6969 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6973 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6977 * _scsih_search_responding_raid_devices -
6978 * @ioc: per adapter object
6980 * After host reset, find out whether devices are still responding.
6986 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
6988 Mpi2RaidVolPage1_t volume_pg1
;
6989 Mpi2RaidVolPage0_t volume_pg0
;
6990 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6991 Mpi2ConfigReply_t mpi_reply
;
6996 if (!ioc
->ir_firmware
)
6999 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
7002 if (list_empty(&ioc
->raid_device_list
))
7006 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7007 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7008 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7009 MPI2_IOCSTATUS_MASK
;
7010 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7012 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7014 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7015 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7016 sizeof(Mpi2RaidVolPage0_t
)))
7019 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7020 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7021 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
7022 _scsih_mark_responding_raid_device(ioc
,
7023 le64_to_cpu(volume_pg1
.WWID
), handle
);
7026 /* refresh the pd_handles */
7027 if (!ioc
->is_warpdrive
) {
7028 phys_disk_num
= 0xFF;
7029 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
7030 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7031 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7033 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7034 MPI2_IOCSTATUS_MASK
;
7035 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7037 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7038 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7039 set_bit(handle
, ioc
->pd_handles
);
7043 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
7048 * _scsih_mark_responding_expander - mark a expander as responding
7049 * @ioc: per adapter object
7050 * @sas_address: sas address
7053 * After host reset, find out whether devices are still responding.
7054 * Used in _scsih_remove_unresponsive_expanders.
7059 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
7062 struct _sas_node
*sas_expander
;
7063 unsigned long flags
;
7066 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7067 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
7068 if (sas_expander
->sas_address
!= sas_address
)
7070 sas_expander
->responding
= 1;
7071 if (sas_expander
->handle
== handle
)
7073 pr_info("\texpander(0x%016llx): handle changed" \
7074 " from(0x%04x) to (0x%04x)!!!\n",
7075 (unsigned long long)sas_expander
->sas_address
,
7076 sas_expander
->handle
, handle
);
7077 sas_expander
->handle
= handle
;
7078 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
7079 sas_expander
->phy
[i
].handle
= handle
;
7083 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7087 * _scsih_search_responding_expanders -
7088 * @ioc: per adapter object
7090 * After host reset, find out whether devices are still responding.
7096 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
7098 Mpi2ExpanderPage0_t expander_pg0
;
7099 Mpi2ConfigReply_t mpi_reply
;
7104 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
7106 if (list_empty(&ioc
->sas_expander_list
))
7110 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7111 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7113 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7114 MPI2_IOCSTATUS_MASK
;
7115 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7118 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7119 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7120 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7122 (unsigned long long)sas_address
);
7123 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7127 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
7131 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7132 * @ioc: per adapter object
7137 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7139 struct _sas_device
*sas_device
, *sas_device_next
;
7140 struct _sas_node
*sas_expander
, *sas_expander_next
;
7141 struct _raid_device
*raid_device
, *raid_device_next
;
7142 struct list_head tmp_list
;
7143 unsigned long flags
;
7146 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
7149 /* removing unresponding end devices */
7150 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
7153 * Iterate, pulling off devices marked as non-responding. We become the
7154 * owner for the reference the list had on any object we prune.
7156 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7157 list_for_each_entry_safe(sas_device
, sas_device_next
,
7158 &ioc
->sas_device_list
, list
) {
7159 if (!sas_device
->responding
)
7160 list_move_tail(&sas_device
->list
, &head
);
7162 sas_device
->responding
= 0;
7164 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7167 * Now, uninitialize and remove the unresponding devices we pruned.
7169 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
7170 _scsih_remove_device(ioc
, sas_device
);
7171 list_del_init(&sas_device
->list
);
7172 sas_device_put(sas_device
);
7175 /* removing unresponding volumes */
7176 if (ioc
->ir_firmware
) {
7177 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
7179 list_for_each_entry_safe(raid_device
, raid_device_next
,
7180 &ioc
->raid_device_list
, list
) {
7181 if (!raid_device
->responding
)
7182 _scsih_sas_volume_delete(ioc
,
7183 raid_device
->handle
);
7185 raid_device
->responding
= 0;
7189 /* removing unresponding expanders */
7190 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
7192 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7193 INIT_LIST_HEAD(&tmp_list
);
7194 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7195 &ioc
->sas_expander_list
, list
) {
7196 if (!sas_expander
->responding
)
7197 list_move_tail(&sas_expander
->list
, &tmp_list
);
7199 sas_expander
->responding
= 0;
7201 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7202 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7204 list_del(&sas_expander
->list
);
7205 _scsih_expander_node_remove(ioc
, sas_expander
);
7208 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
7211 /* unblock devices */
7212 _scsih_ublock_io_all_device(ioc
);
7216 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
7217 struct _sas_node
*sas_expander
, u16 handle
)
7219 Mpi2ExpanderPage1_t expander_pg1
;
7220 Mpi2ConfigReply_t mpi_reply
;
7223 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7224 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7225 &expander_pg1
, i
, handle
))) {
7226 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7227 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7231 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7232 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7233 expander_pg1
.NegotiatedLinkRate
>> 4);
7238 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7239 * @ioc: per adapter object
7244 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
7246 Mpi2ExpanderPage0_t expander_pg0
;
7247 Mpi2SasDevicePage0_t sas_device_pg0
;
7248 Mpi2RaidVolPage1_t volume_pg1
;
7249 Mpi2RaidVolPage0_t volume_pg0
;
7250 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7251 Mpi2EventIrConfigElement_t element
;
7252 Mpi2ConfigReply_t mpi_reply
;
7255 u16 handle
, parent_handle
;
7257 struct _sas_device
*sas_device
;
7258 struct _sas_node
*expander_device
;
7259 static struct _raid_device
*raid_device
;
7261 unsigned long flags
;
7263 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7265 _scsih_sas_host_refresh(ioc
);
7267 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7271 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7272 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7273 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7274 MPI2_IOCSTATUS_MASK
;
7275 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7276 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7277 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7278 ioc
->name
, ioc_status
,
7279 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7282 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7283 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7284 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7285 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7286 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7287 if (expander_device
)
7288 _scsih_refresh_expander_links(ioc
, expander_device
,
7291 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7292 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7293 handle
, (unsigned long long)
7294 le64_to_cpu(expander_pg0
.SASAddress
));
7295 _scsih_expander_add(ioc
, handle
);
7296 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7297 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7298 handle
, (unsigned long long)
7299 le64_to_cpu(expander_pg0
.SASAddress
));
7303 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7306 if (!ioc
->ir_firmware
)
7309 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7312 phys_disk_num
= 0xFF;
7313 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7314 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7316 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7317 MPI2_IOCSTATUS_MASK
;
7318 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7319 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7320 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7321 ioc
->name
, ioc_status
,
7322 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7325 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7326 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7327 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7329 sas_device_put(sas_device
);
7332 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7333 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7336 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7337 MPI2_IOCSTATUS_MASK
;
7338 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7339 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7340 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7341 ioc
->name
, ioc_status
,
7342 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7345 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7346 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7348 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7349 " handle (0x%04x), sas_addr(0x%016llx)\n",
7350 ioc
->name
, handle
, (unsigned long long)
7351 le64_to_cpu(sas_device_pg0
.SASAddress
));
7352 mpt3sas_transport_update_links(ioc
, sas_address
,
7353 handle
, sas_device_pg0
.PhyNum
,
7354 MPI2_SAS_NEG_LINK_RATE_1_5
);
7355 set_bit(handle
, ioc
->pd_handles
);
7357 /* This will retry adding the end device.
7358 * _scsih_add_device() will decide on retries and
7359 * return "1" when it should be retried
7361 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7365 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7366 " handle (0x%04x), sas_addr(0x%016llx)\n",
7367 ioc
->name
, handle
, (unsigned long long)
7368 le64_to_cpu(sas_device_pg0
.SASAddress
));
7372 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7375 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7379 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7380 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7381 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7382 MPI2_IOCSTATUS_MASK
;
7383 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7384 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7385 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7386 ioc
->name
, ioc_status
,
7387 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7390 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7391 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7392 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7393 le64_to_cpu(volume_pg1
.WWID
));
7394 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7397 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7398 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7399 sizeof(Mpi2RaidVolPage0_t
)))
7401 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7402 MPI2_IOCSTATUS_MASK
;
7403 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7404 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7405 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7406 ioc
->name
, ioc_status
,
7407 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7410 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7411 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7412 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7413 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7414 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7415 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7417 "\tBEFORE adding volume: handle (0x%04x)\n",
7418 ioc
->name
, volume_pg1
.DevHandle
);
7419 _scsih_sas_volume_add(ioc
, &element
);
7421 "\tAFTER adding volume: handle (0x%04x)\n",
7422 ioc
->name
, volume_pg1
.DevHandle
);
7426 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7431 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7436 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7437 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7439 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7440 MPI2_IOCSTATUS_MASK
;
7441 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7442 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7443 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7444 ioc
->name
, ioc_status
,
7445 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7448 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7449 if (!(_scsih_is_end_device(
7450 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7452 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
7453 le64_to_cpu(sas_device_pg0
.SASAddress
));
7455 sas_device_put(sas_device
);
7458 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7459 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7460 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7461 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7462 handle
, (unsigned long long)
7463 le64_to_cpu(sas_device_pg0
.SASAddress
));
7464 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7465 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7467 /* This will retry adding the end device.
7468 * _scsih_add_device() will decide on retries and
7469 * return "1" when it should be retried
7471 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7475 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7476 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7477 handle
, (unsigned long long)
7478 le64_to_cpu(sas_device_pg0
.SASAddress
));
7481 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7484 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7487 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7488 * @ioc: per adapter object
7489 * @reset_phase: phase
7491 * The handler for doing any required cleanup or initialization.
7493 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7494 * MPT3_IOC_DONE_RESET
7499 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7501 switch (reset_phase
) {
7502 case MPT3_IOC_PRE_RESET
:
7503 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7504 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7506 case MPT3_IOC_AFTER_RESET
:
7507 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7508 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7509 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7510 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7511 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7512 complete(&ioc
->scsih_cmds
.done
);
7514 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7515 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7516 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7517 complete(&ioc
->tm_cmds
.done
);
7520 _scsih_fw_event_cleanup_queue(ioc
);
7521 _scsih_flush_running_cmds(ioc
);
7523 case MPT3_IOC_DONE_RESET
:
7524 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7525 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7526 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7527 !ioc
->sas_hba
.num_phys
)) {
7528 _scsih_prep_device_scan(ioc
);
7529 _scsih_search_responding_sas_devices(ioc
);
7530 _scsih_search_responding_raid_devices(ioc
);
7531 _scsih_search_responding_expanders(ioc
);
7532 _scsih_error_recovery_delete_devices(ioc
);
7539 * _mpt3sas_fw_work - delayed task for processing firmware events
7540 * @ioc: per adapter object
7541 * @fw_event: The fw_event_work object
7547 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7549 _scsih_fw_event_del_from_list(ioc
, fw_event
);
7551 /* the queue is being flushed so ignore this event */
7552 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
7553 fw_event_work_put(fw_event
);
7557 switch (fw_event
->event
) {
7558 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7559 mpt3sas_process_trigger_data(ioc
,
7560 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7561 fw_event
->event_data
);
7563 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7564 while (scsi_host_in_recovery(ioc
->shost
) ||
7565 ioc
->shost_recovery
) {
7567 * If we're unloading, bail. Otherwise, this can become
7570 if (ioc
->remove_host
)
7574 _scsih_remove_unresponding_sas_devices(ioc
);
7575 _scsih_scan_for_devices_after_reset(ioc
);
7577 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7578 ioc
->start_scan
= 0;
7579 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7580 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7582 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7583 "port enable: complete from worker thread\n",
7586 case MPT3SAS_TURN_ON_PFA_LED
:
7587 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7589 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7590 _scsih_sas_topology_change_event(ioc
, fw_event
);
7592 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7593 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7595 case MPI2_EVENT_SAS_DISCOVERY
:
7596 _scsih_sas_discovery_event(ioc
, fw_event
);
7598 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7599 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7601 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7602 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7605 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7606 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7608 case MPI2_EVENT_IR_VOLUME
:
7609 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7611 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7612 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7614 case MPI2_EVENT_IR_OPERATION_STATUS
:
7615 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7619 fw_event_work_put(fw_event
);
7623 * _firmware_event_work
7624 * @ioc: per adapter object
7625 * @work: The fw_event_work object
7628 * wrappers for the work thread handling firmware events
7634 _firmware_event_work(struct work_struct
*work
)
7636 struct fw_event_work
*fw_event
= container_of(work
,
7637 struct fw_event_work
, work
);
7639 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7643 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7644 * @ioc: per adapter object
7645 * @msix_index: MSIX table index supplied by the OS
7646 * @reply: reply message frame(lower 32bit addr)
7647 * Context: interrupt.
7649 * This function merely adds a new work task into ioc->firmware_event_thread.
7650 * The tasks are worked from _firmware_event_work in user context.
7652 * Return 1 meaning mf should be freed from _base_interrupt
7653 * 0 means the mf is freed from this function.
7656 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7659 struct fw_event_work
*fw_event
;
7660 Mpi2EventNotificationReply_t
*mpi_reply
;
7664 /* events turned off due to host reset or driver unloading */
7665 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7668 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7670 if (unlikely(!mpi_reply
)) {
7671 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7672 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7676 event
= le16_to_cpu(mpi_reply
->Event
);
7678 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7679 mpt3sas_trigger_event(ioc
, event
, 0);
7683 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7685 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7686 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7687 mpi_reply
->EventData
;
7689 if (baen_data
->Primitive
!=
7690 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7693 if (ioc
->broadcast_aen_busy
) {
7694 ioc
->broadcast_aen_pending
++;
7697 ioc
->broadcast_aen_busy
= 1;
7701 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7702 _scsih_check_topo_delete_events(ioc
,
7703 (Mpi2EventDataSasTopologyChangeList_t
*)
7704 mpi_reply
->EventData
);
7706 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7707 _scsih_check_ir_config_unhide_events(ioc
,
7708 (Mpi2EventDataIrConfigChangeList_t
*)
7709 mpi_reply
->EventData
);
7711 case MPI2_EVENT_IR_VOLUME
:
7712 _scsih_check_volume_delete_events(ioc
,
7713 (Mpi2EventDataIrVolume_t
*)
7714 mpi_reply
->EventData
);
7716 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7718 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7721 if (!ioc
->is_warpdrive
)
7724 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7725 mpi_reply
->EventData
;
7726 log_code
= (u32
*)log_entry
->LogData
;
7728 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7729 != MPT2_WARPDRIVE_LOGENTRY
)
7732 switch (le32_to_cpu(*log_code
)) {
7733 case MPT2_WARPDRIVE_LC_SSDT
:
7734 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7735 "IO Throttling has occurred in the WarpDrive "
7736 "subsystem. Check WarpDrive documentation for "
7737 "additional details.\n", ioc
->name
);
7739 case MPT2_WARPDRIVE_LC_SSDLW
:
7740 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7741 "Program/Erase Cycles for the WarpDrive subsystem "
7742 "in degraded range. Check WarpDrive documentation "
7743 "for additional details.\n", ioc
->name
);
7745 case MPT2_WARPDRIVE_LC_SSDLF
:
7746 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7747 "There are no Program/Erase Cycles for the "
7748 "WarpDrive subsystem. The storage device will be "
7749 "in read-only mode. Check WarpDrive documentation "
7750 "for additional details.\n", ioc
->name
);
7752 case MPT2_WARPDRIVE_LC_BRMF
:
7753 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7754 "The Backup Rail Monitor has failed on the "
7755 "WarpDrive subsystem. Check WarpDrive "
7756 "documentation for additional details.\n",
7763 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7764 case MPI2_EVENT_IR_OPERATION_STATUS
:
7765 case MPI2_EVENT_SAS_DISCOVERY
:
7766 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7767 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7770 case MPI2_EVENT_TEMP_THRESHOLD
:
7771 _scsih_temp_threshold_events(ioc
,
7772 (Mpi2EventDataTemperature_t
*)
7773 mpi_reply
->EventData
);
7776 default: /* ignore the rest */
7780 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7781 fw_event
= alloc_fw_event_work(sz
);
7783 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7784 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7788 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
7789 fw_event
->ioc
= ioc
;
7790 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7791 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7792 fw_event
->event
= event
;
7793 _scsih_fw_event_add(ioc
, fw_event
);
7794 fw_event_work_put(fw_event
);
7799 * _scsih_expander_node_remove - removing expander device from list.
7800 * @ioc: per adapter object
7801 * @sas_expander: the sas_device object
7802 * Context: Calling function should acquire ioc->sas_node_lock.
7804 * Removing object and freeing associated memory from the
7805 * ioc->sas_expander_list.
7810 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
7811 struct _sas_node
*sas_expander
)
7813 struct _sas_port
*mpt3sas_port
, *next
;
7815 /* remove sibling ports attached to this expander */
7816 list_for_each_entry_safe(mpt3sas_port
, next
,
7817 &sas_expander
->sas_port_list
, port_list
) {
7818 if (ioc
->shost_recovery
)
7820 if (mpt3sas_port
->remote_identify
.device_type
==
7822 mpt3sas_device_remove_by_sas_address(ioc
,
7823 mpt3sas_port
->remote_identify
.sas_address
);
7824 else if (mpt3sas_port
->remote_identify
.device_type
==
7825 SAS_EDGE_EXPANDER_DEVICE
||
7826 mpt3sas_port
->remote_identify
.device_type
==
7827 SAS_FANOUT_EXPANDER_DEVICE
)
7828 mpt3sas_expander_remove(ioc
,
7829 mpt3sas_port
->remote_identify
.sas_address
);
7832 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7833 sas_expander
->sas_address_parent
);
7836 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7838 sas_expander
->handle
, (unsigned long long)
7839 sas_expander
->sas_address
);
7841 kfree(sas_expander
->phy
);
7842 kfree(sas_expander
);
7846 * _scsih_ir_shutdown - IR shutdown notification
7847 * @ioc: per adapter object
7849 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7850 * the host system is shutting down.
7855 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
7857 Mpi2RaidActionRequest_t
*mpi_request
;
7858 Mpi2RaidActionReply_t
*mpi_reply
;
7861 /* is IR firmware build loaded ? */
7862 if (!ioc
->ir_firmware
)
7865 /* are there any volumes ? */
7866 if (list_empty(&ioc
->raid_device_list
))
7869 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7871 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7872 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7873 ioc
->name
, __func__
);
7876 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7878 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7880 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7881 ioc
->name
, __func__
);
7882 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7886 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7887 ioc
->scsih_cmds
.smid
= smid
;
7888 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7890 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7891 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7893 if (!ioc
->hide_ir_msg
)
7894 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
7895 init_completion(&ioc
->scsih_cmds
.done
);
7896 mpt3sas_base_put_smid_default(ioc
, smid
);
7897 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7899 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7900 pr_err(MPT3SAS_FMT
"%s: timeout\n",
7901 ioc
->name
, __func__
);
7905 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7906 mpi_reply
= ioc
->scsih_cmds
.reply
;
7907 if (!ioc
->hide_ir_msg
)
7908 pr_info(MPT3SAS_FMT
"IR shutdown "
7909 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7910 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7911 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7915 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7916 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7920 * scsih_remove - detach and remove add host
7921 * @pdev: PCI device struct
7923 * Routine called when unloading the driver.
7926 void scsih_remove(struct pci_dev
*pdev
)
7928 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7929 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7930 struct _sas_port
*mpt3sas_port
, *next_port
;
7931 struct _raid_device
*raid_device
, *next
;
7932 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7933 struct workqueue_struct
*wq
;
7934 unsigned long flags
;
7936 ioc
->remove_host
= 1;
7937 _scsih_fw_event_cleanup_queue(ioc
);
7939 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7940 wq
= ioc
->firmware_event_thread
;
7941 ioc
->firmware_event_thread
= NULL
;
7942 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7944 destroy_workqueue(wq
);
7946 /* release all the volumes */
7947 _scsih_ir_shutdown(ioc
);
7948 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7950 if (raid_device
->starget
) {
7951 sas_target_priv_data
=
7952 raid_device
->starget
->hostdata
;
7953 sas_target_priv_data
->deleted
= 1;
7954 scsi_remove_target(&raid_device
->starget
->dev
);
7956 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7957 ioc
->name
, raid_device
->handle
,
7958 (unsigned long long) raid_device
->wwid
);
7959 _scsih_raid_device_remove(ioc
, raid_device
);
7962 /* free ports attached to the sas_host */
7963 list_for_each_entry_safe(mpt3sas_port
, next_port
,
7964 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7965 if (mpt3sas_port
->remote_identify
.device_type
==
7967 mpt3sas_device_remove_by_sas_address(ioc
,
7968 mpt3sas_port
->remote_identify
.sas_address
);
7969 else if (mpt3sas_port
->remote_identify
.device_type
==
7970 SAS_EDGE_EXPANDER_DEVICE
||
7971 mpt3sas_port
->remote_identify
.device_type
==
7972 SAS_FANOUT_EXPANDER_DEVICE
)
7973 mpt3sas_expander_remove(ioc
,
7974 mpt3sas_port
->remote_identify
.sas_address
);
7977 /* free phys attached to the sas_host */
7978 if (ioc
->sas_hba
.num_phys
) {
7979 kfree(ioc
->sas_hba
.phy
);
7980 ioc
->sas_hba
.phy
= NULL
;
7981 ioc
->sas_hba
.num_phys
= 0;
7984 sas_remove_host(shost
);
7985 scsi_remove_host(shost
);
7986 mpt3sas_base_detach(ioc
);
7987 spin_lock(&gioc_lock
);
7988 list_del(&ioc
->list
);
7989 spin_unlock(&gioc_lock
);
7990 scsi_host_put(shost
);
7994 * scsih_shutdown - routine call during system shutdown
7995 * @pdev: PCI device struct
8000 scsih_shutdown(struct pci_dev
*pdev
)
8002 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8003 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8004 struct workqueue_struct
*wq
;
8005 unsigned long flags
;
8007 ioc
->remove_host
= 1;
8008 _scsih_fw_event_cleanup_queue(ioc
);
8010 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8011 wq
= ioc
->firmware_event_thread
;
8012 ioc
->firmware_event_thread
= NULL
;
8013 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8015 destroy_workqueue(wq
);
8017 _scsih_ir_shutdown(ioc
);
8018 mpt3sas_base_detach(ioc
);
8023 * _scsih_probe_boot_devices - reports 1st device
8024 * @ioc: per adapter object
8026 * If specified in bios page 2, this routine reports the 1st
8027 * device scsi-ml or sas transport for persistent boot device
8028 * purposes. Please refer to function _scsih_determine_boot_device()
8031 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
8035 struct _sas_device
*sas_device
;
8036 struct _raid_device
*raid_device
;
8038 u64 sas_address_parent
;
8040 unsigned long flags
;
8043 /* no Bios, return immediately */
8044 if (!ioc
->bios_pg3
.BiosVersion
)
8049 if (ioc
->req_boot_device
.device
) {
8050 device
= ioc
->req_boot_device
.device
;
8051 is_raid
= ioc
->req_boot_device
.is_raid
;
8052 } else if (ioc
->req_alt_boot_device
.device
) {
8053 device
= ioc
->req_alt_boot_device
.device
;
8054 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
8055 } else if (ioc
->current_boot_device
.device
) {
8056 device
= ioc
->current_boot_device
.device
;
8057 is_raid
= ioc
->current_boot_device
.is_raid
;
8064 raid_device
= device
;
8065 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8066 raid_device
->id
, 0);
8068 _scsih_raid_device_remove(ioc
, raid_device
);
8070 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8071 sas_device
= device
;
8072 handle
= sas_device
->handle
;
8073 sas_address_parent
= sas_device
->sas_address_parent
;
8074 sas_address
= sas_device
->sas_address
;
8075 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8076 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8078 if (ioc
->hide_drives
)
8080 if (!mpt3sas_transport_port_add(ioc
, handle
,
8081 sas_address_parent
)) {
8082 _scsih_sas_device_remove(ioc
, sas_device
);
8083 } else if (!sas_device
->starget
) {
8084 if (!ioc
->is_driver_loading
) {
8085 mpt3sas_transport_port_remove(ioc
,
8087 sas_address_parent
);
8088 _scsih_sas_device_remove(ioc
, sas_device
);
8095 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8096 * @ioc: per adapter object
8098 * Called during initial loading of the driver.
8101 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
8103 struct _raid_device
*raid_device
, *raid_next
;
8106 list_for_each_entry_safe(raid_device
, raid_next
,
8107 &ioc
->raid_device_list
, list
) {
8108 if (raid_device
->starget
)
8110 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8111 raid_device
->id
, 0);
8113 _scsih_raid_device_remove(ioc
, raid_device
);
8117 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
8119 struct _sas_device
*sas_device
= NULL
;
8120 unsigned long flags
;
8122 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8123 if (!list_empty(&ioc
->sas_device_init_list
)) {
8124 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
8125 struct _sas_device
, list
);
8126 sas_device_get(sas_device
);
8128 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8133 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
8134 struct _sas_device
*sas_device
)
8136 unsigned long flags
;
8138 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8141 * Since we dropped the lock during the call to port_add(), we need to
8142 * be careful here that somebody else didn't move or delete this item
8143 * while we were busy with other things.
8145 * If it was on the list, we need a put() for the reference the list
8146 * had. Either way, we need a get() for the destination list.
8148 if (!list_empty(&sas_device
->list
)) {
8149 list_del_init(&sas_device
->list
);
8150 sas_device_put(sas_device
);
8153 sas_device_get(sas_device
);
8154 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8156 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8160 * _scsih_probe_sas - reporting sas devices to sas transport
8161 * @ioc: per adapter object
8163 * Called during initial loading of the driver.
8166 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
8168 struct _sas_device
*sas_device
;
8170 if (ioc
->hide_drives
)
8173 while ((sas_device
= get_next_sas_device(ioc
))) {
8174 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
8175 sas_device
->sas_address_parent
)) {
8176 _scsih_sas_device_remove(ioc
, sas_device
);
8177 sas_device_put(sas_device
);
8179 } else if (!sas_device
->starget
) {
8181 * When asyn scanning is enabled, its not possible to
8182 * remove devices while scanning is turned on due to an
8183 * oops in scsi_sysfs_add_sdev()->add_device()->
8184 * sysfs_addrm_start()
8186 if (!ioc
->is_driver_loading
) {
8187 mpt3sas_transport_port_remove(ioc
,
8188 sas_device
->sas_address
,
8189 sas_device
->sas_address_parent
);
8190 _scsih_sas_device_remove(ioc
, sas_device
);
8191 sas_device_put(sas_device
);
8195 sas_device_make_active(ioc
, sas_device
);
8196 sas_device_put(sas_device
);
8201 * _scsih_probe_devices - probing for devices
8202 * @ioc: per adapter object
8204 * Called during initial loading of the driver.
8207 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
8209 u16 volume_mapping_flags
;
8211 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8212 return; /* return when IOC doesn't support initiator mode */
8214 _scsih_probe_boot_devices(ioc
);
8216 if (ioc
->ir_firmware
) {
8217 volume_mapping_flags
=
8218 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8219 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8220 if (volume_mapping_flags
==
8221 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8222 _scsih_probe_raid(ioc
);
8223 _scsih_probe_sas(ioc
);
8225 _scsih_probe_sas(ioc
);
8226 _scsih_probe_raid(ioc
);
8229 _scsih_probe_sas(ioc
);
8233 * scsih_scan_start - scsi lld callback for .scan_start
8234 * @shost: SCSI host pointer
8236 * The shost has the ability to discover targets on its own instead
8237 * of scanning the entire bus. In our implemention, we will kick off
8238 * firmware discovery.
8241 scsih_scan_start(struct Scsi_Host
*shost
)
8243 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8245 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8246 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8248 if (disable_discovery
> 0)
8251 ioc
->start_scan
= 1;
8252 rc
= mpt3sas_port_enable(ioc
);
8255 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
8259 * scsih_scan_finished - scsi lld callback for .scan_finished
8260 * @shost: SCSI host pointer
8261 * @time: elapsed time of the scan in jiffies
8263 * This function will be called periodicallyn until it returns 1 with the
8264 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8265 * we wait for firmware discovery to complete, then return 1.
8268 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8270 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8272 if (disable_discovery
> 0) {
8273 ioc
->is_driver_loading
= 0;
8274 ioc
->wait_for_discovery_to_complete
= 0;
8278 if (time
>= (300 * HZ
)) {
8279 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8281 "port enable: FAILED with timeout (timeout=300s)\n",
8283 ioc
->is_driver_loading
= 0;
8287 if (ioc
->start_scan
)
8290 if (ioc
->start_scan_failed
) {
8292 "port enable: FAILED with (ioc_status=0x%08x)\n",
8293 ioc
->name
, ioc
->start_scan_failed
);
8294 ioc
->is_driver_loading
= 0;
8295 ioc
->wait_for_discovery_to_complete
= 0;
8296 ioc
->remove_host
= 1;
8300 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
8301 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8303 if (ioc
->wait_for_discovery_to_complete
) {
8304 ioc
->wait_for_discovery_to_complete
= 0;
8305 _scsih_probe_devices(ioc
);
8307 mpt3sas_base_start_watchdog(ioc
);
8308 ioc
->is_driver_loading
= 0;
8312 /* shost template for SAS 2.0 HBA devices */
8313 static struct scsi_host_template mpt2sas_driver_template
= {
8314 .module
= THIS_MODULE
,
8315 .name
= "Fusion MPT SAS Host",
8316 .proc_name
= MPT2SAS_DRIVER_NAME
,
8317 .queuecommand
= scsih_qcmd
,
8318 .target_alloc
= scsih_target_alloc
,
8319 .slave_alloc
= scsih_slave_alloc
,
8320 .slave_configure
= scsih_slave_configure
,
8321 .target_destroy
= scsih_target_destroy
,
8322 .slave_destroy
= scsih_slave_destroy
,
8323 .scan_finished
= scsih_scan_finished
,
8324 .scan_start
= scsih_scan_start
,
8325 .change_queue_depth
= scsih_change_queue_depth
,
8326 .eh_abort_handler
= scsih_abort
,
8327 .eh_device_reset_handler
= scsih_dev_reset
,
8328 .eh_target_reset_handler
= scsih_target_reset
,
8329 .eh_host_reset_handler
= scsih_host_reset
,
8330 .bios_param
= scsih_bios_param
,
8333 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
8334 .max_sectors
= 32767,
8336 .use_clustering
= ENABLE_CLUSTERING
,
8337 .shost_attrs
= mpt3sas_host_attrs
,
8338 .sdev_attrs
= mpt3sas_dev_attrs
,
8339 .track_queue_depth
= 1,
8342 /* raid transport support for SAS 2.0 HBA devices */
8343 static struct raid_function_template mpt2sas_raid_functions
= {
8344 .cookie
= &mpt2sas_driver_template
,
8345 .is_raid
= scsih_is_raid
,
8346 .get_resync
= scsih_get_resync
,
8347 .get_state
= scsih_get_state
,
8350 /* shost template for SAS 3.0 HBA devices */
8351 static struct scsi_host_template mpt3sas_driver_template
= {
8352 .module
= THIS_MODULE
,
8353 .name
= "Fusion MPT SAS Host",
8354 .proc_name
= MPT3SAS_DRIVER_NAME
,
8355 .queuecommand
= scsih_qcmd
,
8356 .target_alloc
= scsih_target_alloc
,
8357 .slave_alloc
= scsih_slave_alloc
,
8358 .slave_configure
= scsih_slave_configure
,
8359 .target_destroy
= scsih_target_destroy
,
8360 .slave_destroy
= scsih_slave_destroy
,
8361 .scan_finished
= scsih_scan_finished
,
8362 .scan_start
= scsih_scan_start
,
8363 .change_queue_depth
= scsih_change_queue_depth
,
8364 .eh_abort_handler
= scsih_abort
,
8365 .eh_device_reset_handler
= scsih_dev_reset
,
8366 .eh_target_reset_handler
= scsih_target_reset
,
8367 .eh_host_reset_handler
= scsih_host_reset
,
8368 .bios_param
= scsih_bios_param
,
8371 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
8372 .max_sectors
= 32767,
8374 .use_clustering
= ENABLE_CLUSTERING
,
8375 .shost_attrs
= mpt3sas_host_attrs
,
8376 .sdev_attrs
= mpt3sas_dev_attrs
,
8377 .track_queue_depth
= 1,
8380 /* raid transport support for SAS 3.0 HBA devices */
8381 static struct raid_function_template mpt3sas_raid_functions
= {
8382 .cookie
= &mpt3sas_driver_template
,
8383 .is_raid
= scsih_is_raid
,
8384 .get_resync
= scsih_get_resync
,
8385 .get_state
= scsih_get_state
,
8389 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8390 * this device belongs to.
8391 * @pdev: PCI device struct
8393 * return MPI2_VERSION for SAS 2.0 HBA devices,
8394 * MPI25_VERSION for SAS 3.0 HBA devices.
8397 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
8400 switch (pdev
->device
) {
8401 case MPI2_MFGPAGE_DEVID_SSS6200
:
8402 case MPI2_MFGPAGE_DEVID_SAS2004
:
8403 case MPI2_MFGPAGE_DEVID_SAS2008
:
8404 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
8405 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
8406 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
8407 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
8408 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
8409 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
8410 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
8411 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
8412 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
8413 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
8414 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
8415 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
8416 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
8417 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
8418 return MPI2_VERSION
;
8419 case MPI25_MFGPAGE_DEVID_SAS3004
:
8420 case MPI25_MFGPAGE_DEVID_SAS3008
:
8421 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
8422 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
8423 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
8424 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
8425 return MPI25_VERSION
;
8431 * _scsih_probe - attach and add scsi host
8432 * @pdev: PCI device struct
8433 * @id: pci device id
8435 * Returns 0 success, anything else error.
8438 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8440 struct MPT3SAS_ADAPTER
*ioc
;
8441 struct Scsi_Host
*shost
= NULL
;
8443 u16 hba_mpi_version
;
8445 /* Determine in which MPI version class this pci device belongs */
8446 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
8447 if (hba_mpi_version
== 0)
8450 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8451 * for other generation HBA's return with -ENODEV
8453 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
8456 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8457 * for other generation HBA's return with -ENODEV
8459 if ((hbas_to_enumerate
== 2) && (hba_mpi_version
!= MPI25_VERSION
))
8462 switch (hba_mpi_version
) {
8464 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8465 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
8466 sizeof(struct MPT3SAS_ADAPTER
));
8469 ioc
= shost_priv(shost
);
8470 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8471 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8472 ioc
->id
= mpt2_ids
++;
8473 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
8474 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8475 ioc
->is_warpdrive
= 1;
8476 ioc
->hide_ir_msg
= 1;
8478 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8481 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8482 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
8483 sizeof(struct MPT3SAS_ADAPTER
));
8486 ioc
= shost_priv(shost
);
8487 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8488 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8489 ioc
->id
= mpt3_ids
++;
8490 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
8491 if (pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
)
8492 ioc
->msix96_vector
= 1;
8498 INIT_LIST_HEAD(&ioc
->list
);
8499 spin_lock(&gioc_lock
);
8500 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8501 spin_unlock(&gioc_lock
);
8504 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8505 ioc
->tm_cb_idx
= tm_cb_idx
;
8506 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8507 ioc
->base_cb_idx
= base_cb_idx
;
8508 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8509 ioc
->transport_cb_idx
= transport_cb_idx
;
8510 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8511 ioc
->config_cb_idx
= config_cb_idx
;
8512 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8513 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8514 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8515 ioc
->logging_level
= logging_level
;
8516 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8517 /* misc semaphores and spin locks */
8518 mutex_init(&ioc
->reset_in_progress_mutex
);
8519 /* initializing pci_access_mutex lock */
8520 mutex_init(&ioc
->pci_access_mutex
);
8521 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8522 spin_lock_init(&ioc
->scsi_lookup_lock
);
8523 spin_lock_init(&ioc
->sas_device_lock
);
8524 spin_lock_init(&ioc
->sas_node_lock
);
8525 spin_lock_init(&ioc
->fw_event_lock
);
8526 spin_lock_init(&ioc
->raid_device_lock
);
8527 spin_lock_init(&ioc
->diag_trigger_lock
);
8529 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8530 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8531 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8532 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8533 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8534 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8535 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8536 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8537 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8539 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
8541 /* init shost parameters */
8542 shost
->max_cmd_len
= 32;
8543 shost
->max_lun
= max_lun
;
8544 shost
->transportt
= mpt3sas_transport_template
;
8545 shost
->unique_id
= ioc
->id
;
8547 if (max_sectors
!= 0xFFFF) {
8548 if (max_sectors
< 64) {
8549 shost
->max_sectors
= 64;
8550 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8551 "for max_sectors, range is 64 to 32767. Assigning "
8552 "value of 64.\n", ioc
->name
, max_sectors
);
8553 } else if (max_sectors
> 32767) {
8554 shost
->max_sectors
= 32767;
8555 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8556 "for max_sectors, range is 64 to 32767. Assigning "
8557 "default value of 32767.\n", ioc
->name
,
8560 shost
->max_sectors
= max_sectors
& 0xFFFE;
8562 "The max_sectors value is set to %d\n",
8563 ioc
->name
, shost
->max_sectors
);
8567 /* register EEDP capabilities with SCSI layer */
8569 scsi_host_set_prot(shost
, prot_mask
);
8571 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8572 | SHOST_DIF_TYPE2_PROTECTION
8573 | SHOST_DIF_TYPE3_PROTECTION
);
8575 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8578 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8579 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
8580 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8581 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8582 if (!ioc
->firmware_event_thread
) {
8583 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8584 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8586 goto out_thread_fail
;
8589 ioc
->is_driver_loading
= 1;
8590 if ((mpt3sas_base_attach(ioc
))) {
8591 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8592 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8594 goto out_attach_fail
;
8597 if (ioc
->is_warpdrive
) {
8598 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8599 ioc
->hide_drives
= 0;
8600 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8601 ioc
->hide_drives
= 1;
8603 if (mpt3sas_get_num_volumes(ioc
))
8604 ioc
->hide_drives
= 1;
8606 ioc
->hide_drives
= 0;
8609 ioc
->hide_drives
= 0;
8611 rv
= scsi_add_host(shost
, &pdev
->dev
);
8613 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8614 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8615 goto out_add_shost_fail
;
8618 scsi_scan_host(shost
);
8621 mpt3sas_base_detach(ioc
);
8623 destroy_workqueue(ioc
->firmware_event_thread
);
8625 spin_lock(&gioc_lock
);
8626 list_del(&ioc
->list
);
8627 spin_unlock(&gioc_lock
);
8628 scsi_host_put(shost
);
8634 * scsih_suspend - power management suspend main entry point
8635 * @pdev: PCI device struct
8636 * @state: PM state change to (usually PCI_D3)
8638 * Returns 0 success, anything else error.
8641 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8643 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8644 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8645 pci_power_t device_state
;
8647 mpt3sas_base_stop_watchdog(ioc
);
8648 flush_scheduled_work();
8649 scsi_block_requests(shost
);
8650 device_state
= pci_choose_state(pdev
, state
);
8652 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8653 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8655 pci_save_state(pdev
);
8656 mpt3sas_base_free_resources(ioc
);
8657 pci_set_power_state(pdev
, device_state
);
8662 * scsih_resume - power management resume main entry point
8663 * @pdev: PCI device struct
8665 * Returns 0 success, anything else error.
8668 scsih_resume(struct pci_dev
*pdev
)
8670 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8671 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8672 pci_power_t device_state
= pdev
->current_state
;
8676 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8677 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8679 pci_set_power_state(pdev
, PCI_D0
);
8680 pci_enable_wake(pdev
, PCI_D0
, 0);
8681 pci_restore_state(pdev
);
8683 r
= mpt3sas_base_map_resources(ioc
);
8687 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8688 scsi_unblock_requests(shost
);
8689 mpt3sas_base_start_watchdog(ioc
);
8692 #endif /* CONFIG_PM */
8695 * scsih_pci_error_detected - Called when a PCI error is detected.
8696 * @pdev: PCI device struct
8697 * @state: PCI channel state
8699 * Description: Called when a PCI error is detected.
8702 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8705 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8707 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8708 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8710 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
8714 case pci_channel_io_normal
:
8715 return PCI_ERS_RESULT_CAN_RECOVER
;
8716 case pci_channel_io_frozen
:
8717 /* Fatal error, prepare for slot reset */
8718 ioc
->pci_error_recovery
= 1;
8719 scsi_block_requests(ioc
->shost
);
8720 mpt3sas_base_stop_watchdog(ioc
);
8721 mpt3sas_base_free_resources(ioc
);
8722 return PCI_ERS_RESULT_NEED_RESET
;
8723 case pci_channel_io_perm_failure
:
8724 /* Permanent error, prepare for device removal */
8725 ioc
->pci_error_recovery
= 1;
8726 mpt3sas_base_stop_watchdog(ioc
);
8727 _scsih_flush_running_cmds(ioc
);
8728 return PCI_ERS_RESULT_DISCONNECT
;
8730 return PCI_ERS_RESULT_NEED_RESET
;
8734 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8735 * @pdev: PCI device struct
8737 * Description: This routine is called by the pci error recovery
8738 * code after the PCI slot has been reset, just before we
8739 * should resume normal operations.
8742 scsih_pci_slot_reset(struct pci_dev
*pdev
)
8744 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8745 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8748 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
8751 ioc
->pci_error_recovery
= 0;
8753 pci_restore_state(pdev
);
8754 rc
= mpt3sas_base_map_resources(ioc
);
8756 return PCI_ERS_RESULT_DISCONNECT
;
8758 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8761 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
8762 (rc
== 0) ? "success" : "failed");
8765 return PCI_ERS_RESULT_RECOVERED
;
8767 return PCI_ERS_RESULT_DISCONNECT
;
8771 * scsih_pci_resume() - resume normal ops after PCI reset
8772 * @pdev: pointer to PCI device
8774 * Called when the error recovery driver tells us that its
8775 * OK to resume normal operation. Use completion to allow
8776 * halted scsi ops to resume.
8779 scsih_pci_resume(struct pci_dev
*pdev
)
8781 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8782 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8784 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8786 pci_cleanup_aer_uncorrect_error_status(pdev
);
8787 mpt3sas_base_start_watchdog(ioc
);
8788 scsi_unblock_requests(ioc
->shost
);
8792 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8793 * @pdev: pointer to PCI device
8796 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8798 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8799 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8801 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
8804 /* TODO - dump whatever for debugging purposes */
8806 /* Request a slot reset. */
8807 return PCI_ERS_RESULT_NEED_RESET
;
8811 * The pci device ids are defined in mpi/mpi2_cnfg.h.
8813 static const struct pci_device_id mpt3sas_pci_table
[] = {
8814 /* Spitfire ~ 2004 */
8815 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
8816 PCI_ANY_ID
, PCI_ANY_ID
},
8818 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
8819 PCI_ANY_ID
, PCI_ANY_ID
},
8820 /* Liberator ~ 2108 */
8821 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
8822 PCI_ANY_ID
, PCI_ANY_ID
},
8823 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
8824 PCI_ANY_ID
, PCI_ANY_ID
},
8825 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
8826 PCI_ANY_ID
, PCI_ANY_ID
},
8828 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
8829 PCI_ANY_ID
, PCI_ANY_ID
},
8830 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
8831 PCI_ANY_ID
, PCI_ANY_ID
},
8832 /* Thunderbolt ~ 2208 */
8833 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
8834 PCI_ANY_ID
, PCI_ANY_ID
},
8835 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
8836 PCI_ANY_ID
, PCI_ANY_ID
},
8837 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
8838 PCI_ANY_ID
, PCI_ANY_ID
},
8839 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
8840 PCI_ANY_ID
, PCI_ANY_ID
},
8841 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
8842 PCI_ANY_ID
, PCI_ANY_ID
},
8843 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
8844 PCI_ANY_ID
, PCI_ANY_ID
},
8845 /* Mustang ~ 2308 */
8846 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
8847 PCI_ANY_ID
, PCI_ANY_ID
},
8848 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
8849 PCI_ANY_ID
, PCI_ANY_ID
},
8850 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
8851 PCI_ANY_ID
, PCI_ANY_ID
},
8853 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
8854 PCI_ANY_ID
, PCI_ANY_ID
},
8855 /* Fury ~ 3004 and 3008 */
8856 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
8857 PCI_ANY_ID
, PCI_ANY_ID
},
8858 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
8859 PCI_ANY_ID
, PCI_ANY_ID
},
8860 /* Invader ~ 3108 */
8861 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
8862 PCI_ANY_ID
, PCI_ANY_ID
},
8863 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
8864 PCI_ANY_ID
, PCI_ANY_ID
},
8865 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
8866 PCI_ANY_ID
, PCI_ANY_ID
},
8867 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
8868 PCI_ANY_ID
, PCI_ANY_ID
},
8869 {0} /* Terminating entry */
8871 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
8873 static struct pci_error_handlers _mpt3sas_err_handler
= {
8874 .error_detected
= scsih_pci_error_detected
,
8875 .mmio_enabled
= scsih_pci_mmio_enabled
,
8876 .slot_reset
= scsih_pci_slot_reset
,
8877 .resume
= scsih_pci_resume
,
8880 static struct pci_driver mpt3sas_driver
= {
8881 .name
= MPT3SAS_DRIVER_NAME
,
8882 .id_table
= mpt3sas_pci_table
,
8883 .probe
= _scsih_probe
,
8884 .remove
= scsih_remove
,
8885 .shutdown
= scsih_shutdown
,
8886 .err_handler
= &_mpt3sas_err_handler
,
8888 .suspend
= scsih_suspend
,
8889 .resume
= scsih_resume
,
8894 * scsih_init - main entry point for this driver.
8896 * Returns 0 success, anything else error.
8904 mpt3sas_base_initialize_callback_handler();
8906 /* queuecommand callback hander */
8907 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
8909 /* task managment callback handler */
8910 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
8912 /* base internal commands callback handler */
8913 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
8914 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
8915 mpt3sas_port_enable_done
);
8917 /* transport internal commands callback handler */
8918 transport_cb_idx
= mpt3sas_base_register_callback_handler(
8919 mpt3sas_transport_done
);
8921 /* scsih internal commands callback handler */
8922 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
8924 /* configuration page API internal commands callback handler */
8925 config_cb_idx
= mpt3sas_base_register_callback_handler(
8926 mpt3sas_config_done
);
8928 /* ctl module callback handler */
8929 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
8931 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
8932 _scsih_tm_tr_complete
);
8934 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
8935 _scsih_tm_volume_tr_complete
);
8937 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
8938 _scsih_sas_control_complete
);
8944 * scsih_exit - exit point for this driver (when it is a module).
8946 * Returns 0 success, anything else error.
8952 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
8953 mpt3sas_base_release_callback_handler(tm_cb_idx
);
8954 mpt3sas_base_release_callback_handler(base_cb_idx
);
8955 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
8956 mpt3sas_base_release_callback_handler(transport_cb_idx
);
8957 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
8958 mpt3sas_base_release_callback_handler(config_cb_idx
);
8959 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
8961 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
8962 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8963 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8965 /* raid transport support */
8966 if (hbas_to_enumerate
!= 1)
8967 raid_class_release(mpt3sas_raid_template
);
8968 if (hbas_to_enumerate
!= 2)
8969 raid_class_release(mpt2sas_raid_template
);
8970 sas_release_transport(mpt3sas_transport_template
);
8974 * _mpt3sas_init - main entry point for this driver.
8976 * Returns 0 success, anything else error.
8983 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
8984 MPT3SAS_DRIVER_VERSION
);
8986 mpt3sas_transport_template
=
8987 sas_attach_transport(&mpt3sas_transport_functions
);
8988 if (!mpt3sas_transport_template
)
8991 /* No need attach mpt3sas raid functions template
8992 * if hbas_to_enumarate value is one.
8994 if (hbas_to_enumerate
!= 1) {
8995 mpt3sas_raid_template
=
8996 raid_class_attach(&mpt3sas_raid_functions
);
8997 if (!mpt3sas_raid_template
) {
8998 sas_release_transport(mpt3sas_transport_template
);
9003 /* No need to attach mpt2sas raid functions template
9004 * if hbas_to_enumarate value is two
9006 if (hbas_to_enumerate
!= 2) {
9007 mpt2sas_raid_template
=
9008 raid_class_attach(&mpt2sas_raid_functions
);
9009 if (!mpt2sas_raid_template
) {
9010 sas_release_transport(mpt3sas_transport_template
);
9015 error
= scsih_init();
9021 mpt3sas_ctl_init(hbas_to_enumerate
);
9023 error
= pci_register_driver(&mpt3sas_driver
);
9031 * _mpt3sas_exit - exit point for this driver (when it is a module).
9037 pr_info("mpt3sas version %s unloading\n",
9038 MPT3SAS_DRIVER_VERSION
);
9040 pci_unregister_driver(&mpt3sas_driver
);
9042 mpt3sas_ctl_exit(hbas_to_enumerate
);
9047 module_init(_mpt3sas_init
);
9048 module_exit(_mpt3sas_exit
);