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;
1593 switch (ioc
->hba_mpi_version_belonged
) {
1595 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1599 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1605 * scsih_get_state - get raid volume level
1606 * @dev the device struct object
1609 scsih_get_state(struct device
*dev
)
1611 struct scsi_device
*sdev
= to_scsi_device(dev
);
1612 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1613 static struct _raid_device
*raid_device
;
1614 unsigned long flags
;
1615 Mpi2RaidVolPage0_t vol_pg0
;
1616 Mpi2ConfigReply_t mpi_reply
;
1618 enum raid_state state
= RAID_STATE_UNKNOWN
;
1621 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1622 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1625 handle
= raid_device
->handle
;
1626 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1631 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1632 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1633 sizeof(Mpi2RaidVolPage0_t
))) {
1634 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1635 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1639 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1640 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1641 state
= RAID_STATE_RESYNCING
;
1645 switch (vol_pg0
.VolumeState
) {
1646 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1647 case MPI2_RAID_VOL_STATE_ONLINE
:
1648 state
= RAID_STATE_ACTIVE
;
1650 case MPI2_RAID_VOL_STATE_DEGRADED
:
1651 state
= RAID_STATE_DEGRADED
;
1653 case MPI2_RAID_VOL_STATE_FAILED
:
1654 case MPI2_RAID_VOL_STATE_MISSING
:
1655 state
= RAID_STATE_OFFLINE
;
1659 switch (ioc
->hba_mpi_version_belonged
) {
1661 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1665 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1671 * _scsih_set_level - set raid level
1672 * @sdev: scsi device struct
1673 * @volume_type: volume type
1676 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
1677 struct scsi_device
*sdev
, u8 volume_type
)
1679 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1681 switch (volume_type
) {
1682 case MPI2_RAID_VOL_TYPE_RAID0
:
1683 level
= RAID_LEVEL_0
;
1685 case MPI2_RAID_VOL_TYPE_RAID10
:
1686 level
= RAID_LEVEL_10
;
1688 case MPI2_RAID_VOL_TYPE_RAID1E
:
1689 level
= RAID_LEVEL_1E
;
1691 case MPI2_RAID_VOL_TYPE_RAID1
:
1692 level
= RAID_LEVEL_1
;
1696 switch (ioc
->hba_mpi_version_belonged
) {
1698 raid_set_level(mpt2sas_raid_template
,
1699 &sdev
->sdev_gendev
, level
);
1703 raid_set_level(mpt3sas_raid_template
,
1704 &sdev
->sdev_gendev
, level
);
1711 * _scsih_get_volume_capabilities - volume capabilities
1712 * @ioc: per adapter object
1713 * @sas_device: the raid_device object
1715 * Returns 0 for success, else 1
1718 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1719 struct _raid_device
*raid_device
)
1721 Mpi2RaidVolPage0_t
*vol_pg0
;
1722 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1723 Mpi2SasDevicePage0_t sas_device_pg0
;
1724 Mpi2ConfigReply_t mpi_reply
;
1728 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1729 &num_pds
)) || !num_pds
) {
1730 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1731 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1736 raid_device
->num_pds
= num_pds
;
1737 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1738 sizeof(Mpi2RaidVol0PhysDisk_t
));
1739 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1741 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1742 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1747 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1748 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1749 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1750 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1756 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1758 /* figure out what the underlying devices are by
1759 * obtaining the device_info bits for the 1st device
1761 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1762 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1763 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1764 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1765 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1766 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1767 raid_device
->device_info
=
1768 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1777 * _scsih_enable_tlr - setting TLR flags
1778 * @ioc: per adapter object
1779 * @sdev: scsi device struct
1781 * Enabling Transaction Layer Retries for tape devices when
1782 * vpd page 0x90 is present
1786 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1790 if (sdev
->type
!= TYPE_TAPE
)
1793 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1796 sas_enable_tlr(sdev
);
1797 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1798 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1804 * scsih_slave_configure - device configure routine.
1805 * @sdev: scsi device struct
1807 * Returns 0 if ok. Any other return is assumed to be an error and
1808 * the device is ignored.
1811 scsih_slave_configure(struct scsi_device
*sdev
)
1813 struct Scsi_Host
*shost
= sdev
->host
;
1814 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1815 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1816 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1817 struct _sas_device
*sas_device
;
1818 struct _raid_device
*raid_device
;
1819 unsigned long flags
;
1824 u16 handle
, volume_handle
= 0;
1825 u64 volume_wwid
= 0;
1828 sas_device_priv_data
= sdev
->hostdata
;
1829 sas_device_priv_data
->configured_lun
= 1;
1830 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1831 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1832 handle
= sas_target_priv_data
->handle
;
1834 /* raid volume handling */
1835 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1837 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1838 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
1839 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1841 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1842 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1843 __LINE__
, __func__
));
1847 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1848 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1849 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1850 __LINE__
, __func__
));
1855 * WARPDRIVE: Initialize the required data for Direct IO
1857 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
1859 /* RAID Queue Depth Support
1860 * IS volume = underlying qdepth of drive type, either
1861 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1862 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1864 if (raid_device
->device_info
&
1865 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1866 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1869 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1870 if (raid_device
->device_info
&
1871 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1877 switch (raid_device
->volume_type
) {
1878 case MPI2_RAID_VOL_TYPE_RAID0
:
1881 case MPI2_RAID_VOL_TYPE_RAID1E
:
1882 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1883 if (ioc
->manu_pg10
.OEMIdentifier
&&
1884 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1885 MFG10_GF0_R10_DISPLAY
) &&
1886 !(raid_device
->num_pds
% 2))
1891 case MPI2_RAID_VOL_TYPE_RAID1
:
1892 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1895 case MPI2_RAID_VOL_TYPE_RAID10
:
1896 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1899 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1901 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1906 if (!ioc
->hide_ir_msg
)
1907 sdev_printk(KERN_INFO
, sdev
,
1908 "%s: handle(0x%04x), wwid(0x%016llx),"
1909 " pd_count(%d), type(%s)\n",
1910 r_level
, raid_device
->handle
,
1911 (unsigned long long)raid_device
->wwid
,
1912 raid_device
->num_pds
, ds
);
1914 scsih_change_queue_depth(sdev
, qdepth
);
1916 /* raid transport support */
1917 if (!ioc
->is_warpdrive
)
1918 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
1922 /* non-raid handling */
1923 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1924 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1926 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1927 "failure at %s:%d/%s()!\n", ioc
->name
,
1928 __FILE__
, __LINE__
, __func__
));
1931 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1932 volume_handle
, &volume_wwid
)) {
1933 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1934 "failure at %s:%d/%s()!\n", ioc
->name
,
1935 __FILE__
, __LINE__
, __func__
));
1940 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1941 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1942 sas_device_priv_data
->sas_target
->sas_address
);
1944 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1945 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1946 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1951 sas_device
->volume_handle
= volume_handle
;
1952 sas_device
->volume_wwid
= volume_wwid
;
1953 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1954 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1956 if (sas_device
->device_info
&
1957 MPI2_SAS_DEVICE_INFO_SEP
) {
1958 sdev_printk(KERN_WARNING
, sdev
,
1959 "set ignore_delay_remove for handle(0x%04x)\n",
1960 sas_device_priv_data
->sas_target
->handle
);
1961 sas_device_priv_data
->ignore_delay_remove
= 1;
1966 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1967 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1969 else if (sas_device
->device_info
&
1970 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1974 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
1975 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1976 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
1977 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
1978 if (sas_device
->enclosure_handle
!= 0)
1979 sdev_printk(KERN_INFO
, sdev
,
1980 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1981 ds
, (unsigned long long)
1982 sas_device
->enclosure_logical_id
, sas_device
->slot
);
1983 if (sas_device
->connector_name
[0] != '\0')
1984 sdev_printk(KERN_INFO
, sdev
,
1985 "%s: enclosure level(0x%04x), connector name( %s)\n",
1986 ds
, sas_device
->enclosure_level
,
1987 sas_device
->connector_name
);
1989 sas_device_put(sas_device
);
1990 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1993 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
1996 scsih_change_queue_depth(sdev
, qdepth
);
1999 sas_read_port_mode_page(sdev
);
2000 _scsih_enable_tlr(ioc
, sdev
);
2007 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2008 * @sdev: scsi device struct
2009 * @bdev: pointer to block device context
2010 * @capacity: device size (in 512 byte sectors)
2011 * @params: three element array to place output:
2012 * params[0] number of heads (max 255)
2013 * params[1] number of sectors (max 63)
2014 * params[2] number of cylinders
2019 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2020 sector_t capacity
, int params
[])
2030 dummy
= heads
* sectors
;
2031 cylinders
= capacity
;
2032 sector_div(cylinders
, dummy
);
2035 * Handle extended translation size for logical drives
2038 if ((ulong
)capacity
>= 0x200000) {
2041 dummy
= heads
* sectors
;
2042 cylinders
= capacity
;
2043 sector_div(cylinders
, dummy
);
2048 params
[1] = sectors
;
2049 params
[2] = cylinders
;
2055 * _scsih_response_code - translation of device response code
2056 * @ioc: per adapter object
2057 * @response_code: response code returned by the device
2062 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2066 switch (response_code
) {
2067 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2068 desc
= "task management request completed";
2070 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2071 desc
= "invalid frame";
2073 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2074 desc
= "task management request not supported";
2076 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2077 desc
= "task management request failed";
2079 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2080 desc
= "task management request succeeded";
2082 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2083 desc
= "invalid lun";
2086 desc
= "overlapped tag attempted";
2088 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2089 desc
= "task queued, however not sent to target";
2095 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2096 ioc
->name
, response_code
, desc
);
2100 * _scsih_tm_done - tm completion routine
2101 * @ioc: per adapter object
2102 * @smid: system request message index
2103 * @msix_index: MSIX table index supplied by the OS
2104 * @reply: reply message frame(lower 32bit addr)
2107 * The callback handler when using scsih_issue_tm.
2109 * Return 1 meaning mf should be freed from _base_interrupt
2110 * 0 means the mf is freed from this function.
2113 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2115 MPI2DefaultReply_t
*mpi_reply
;
2117 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2119 if (ioc
->tm_cmds
.smid
!= smid
)
2121 mpt3sas_base_flush_reply_queues(ioc
);
2122 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2123 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2125 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2126 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2128 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2129 complete(&ioc
->tm_cmds
.done
);
2134 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2135 * @ioc: per adapter object
2136 * @handle: device handle
2138 * During taskmangement request, we need to freeze the device queue.
2141 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2143 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2144 struct scsi_device
*sdev
;
2147 shost_for_each_device(sdev
, ioc
->shost
) {
2150 sas_device_priv_data
= sdev
->hostdata
;
2151 if (!sas_device_priv_data
)
2153 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2154 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2156 ioc
->ignore_loginfos
= 1;
2162 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2163 * @ioc: per adapter object
2164 * @handle: device handle
2166 * During taskmangement request, we need to freeze the device queue.
2169 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2171 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2172 struct scsi_device
*sdev
;
2175 shost_for_each_device(sdev
, ioc
->shost
) {
2178 sas_device_priv_data
= sdev
->hostdata
;
2179 if (!sas_device_priv_data
)
2181 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2182 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2184 ioc
->ignore_loginfos
= 0;
2190 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2191 * @ioc: per adapter struct
2192 * @device_handle: device handle
2193 * @channel: the channel assigned by the OS
2194 * @id: the id assigned by the OS
2196 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2197 * @smid_task: smid assigned to the task
2198 * @timeout: timeout in seconds
2199 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2202 * A generic API for sending task management requests to firmware.
2204 * The callback index is set inside `ioc->tm_cb_idx`.
2206 * Return SUCCESS or FAILED.
2209 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2210 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2211 enum mutex_type m_type
)
2213 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2214 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2217 unsigned long timeleft
;
2218 struct scsiio_tracker
*scsi_lookup
= NULL
;
2222 if (m_type
== TM_MUTEX_ON
)
2223 mutex_lock(&ioc
->tm_cmds
.mutex
);
2224 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2225 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2226 __func__
, ioc
->name
);
2231 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2232 ioc
->pci_error_recovery
) {
2233 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2234 __func__
, ioc
->name
);
2239 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2240 if (ioc_state
& MPI2_DOORBELL_USED
) {
2241 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2242 "unexpected doorbell active!\n", ioc
->name
));
2243 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2245 rc
= (!rc
) ? SUCCESS
: FAILED
;
2249 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2250 mpt3sas_base_fault_info(ioc
, ioc_state
&
2251 MPI2_DOORBELL_DATA_MASK
);
2252 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2254 rc
= (!rc
) ? SUCCESS
: FAILED
;
2258 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2260 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2261 ioc
->name
, __func__
);
2266 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2267 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2269 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2270 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2271 ioc
->name
, handle
, type
, smid_task
));
2272 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2273 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2274 ioc
->tm_cmds
.smid
= smid
;
2275 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2276 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2277 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2278 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2279 mpi_request
->TaskType
= type
;
2280 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2281 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2282 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2283 init_completion(&ioc
->tm_cmds
.done
);
2284 if ((type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) &&
2285 (scsi_lookup
->msix_io
< ioc
->reply_queue_count
))
2286 msix_task
= scsi_lookup
->msix_io
;
2289 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, msix_task
);
2290 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2291 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2292 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2293 ioc
->name
, __func__
);
2294 _debug_dump_mf(mpi_request
,
2295 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2296 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2297 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2299 rc
= (!rc
) ? SUCCESS
: FAILED
;
2300 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2301 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2306 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2307 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2308 mpi_reply
= ioc
->tm_cmds
.reply
;
2309 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2310 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2311 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2312 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2313 le32_to_cpu(mpi_reply
->TerminationCount
)));
2314 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2315 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2316 if (mpi_reply
->IOCStatus
)
2317 _debug_dump_mf(mpi_request
,
2318 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2323 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2325 if (scsi_lookup
->scmd
== NULL
)
2330 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2331 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2336 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2337 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2338 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2343 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2351 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2352 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2353 if (m_type
== TM_MUTEX_ON
)
2354 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2359 if (m_type
== TM_MUTEX_ON
)
2360 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2365 * _scsih_tm_display_info - displays info about the device
2366 * @ioc: per adapter struct
2367 * @scmd: pointer to scsi command object
2369 * Called by task management callback handlers.
2372 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2374 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2375 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2376 struct _sas_device
*sas_device
= NULL
;
2377 unsigned long flags
;
2378 char *device_str
= NULL
;
2382 if (ioc
->hide_ir_msg
)
2383 device_str
= "WarpDrive";
2385 device_str
= "volume";
2387 scsi_print_command(scmd
);
2388 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2389 starget_printk(KERN_INFO
, starget
,
2390 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2391 device_str
, priv_target
->handle
,
2392 device_str
, (unsigned long long)priv_target
->sas_address
);
2394 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2395 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2397 if (priv_target
->flags
&
2398 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2399 starget_printk(KERN_INFO
, starget
,
2400 "volume handle(0x%04x), "
2401 "volume wwid(0x%016llx)\n",
2402 sas_device
->volume_handle
,
2403 (unsigned long long)sas_device
->volume_wwid
);
2405 starget_printk(KERN_INFO
, starget
,
2406 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2408 (unsigned long long)sas_device
->sas_address
,
2410 if (sas_device
->enclosure_handle
!= 0)
2411 starget_printk(KERN_INFO
, starget
,
2412 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2413 (unsigned long long)
2414 sas_device
->enclosure_logical_id
,
2416 if (sas_device
->connector_name
[0] != '\0')
2417 starget_printk(KERN_INFO
, starget
,
2418 "enclosure level(0x%04x),connector name(%s)\n",
2419 sas_device
->enclosure_level
,
2420 sas_device
->connector_name
);
2422 sas_device_put(sas_device
);
2424 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2429 * scsih_abort - eh threads main abort routine
2430 * @scmd: pointer to scsi command object
2432 * Returns SUCCESS if command aborted else FAILED
2435 scsih_abort(struct scsi_cmnd
*scmd
)
2437 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2438 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2443 sdev_printk(KERN_INFO
, scmd
->device
,
2444 "attempting task abort! scmd(%p)\n", scmd
);
2445 _scsih_tm_display_info(ioc
, scmd
);
2447 sas_device_priv_data
= scmd
->device
->hostdata
;
2448 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2449 sdev_printk(KERN_INFO
, scmd
->device
,
2450 "device been deleted! scmd(%p)\n", scmd
);
2451 scmd
->result
= DID_NO_CONNECT
<< 16;
2452 scmd
->scsi_done(scmd
);
2457 /* search for the command */
2458 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2460 scmd
->result
= DID_RESET
<< 16;
2465 /* for hidden raid components and volumes this is not supported */
2466 if (sas_device_priv_data
->sas_target
->flags
&
2467 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2468 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2469 scmd
->result
= DID_RESET
<< 16;
2474 mpt3sas_halt_firmware(ioc
);
2476 handle
= sas_device_priv_data
->sas_target
->handle
;
2477 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2478 scmd
->device
->id
, scmd
->device
->lun
,
2479 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, TM_MUTEX_ON
);
2482 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2483 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2488 * scsih_dev_reset - eh threads main device reset routine
2489 * @scmd: pointer to scsi command object
2491 * Returns SUCCESS if command aborted else FAILED
2494 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2496 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2497 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2498 struct _sas_device
*sas_device
= NULL
;
2502 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2503 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2505 sdev_printk(KERN_INFO
, scmd
->device
,
2506 "attempting device reset! scmd(%p)\n", scmd
);
2507 _scsih_tm_display_info(ioc
, scmd
);
2509 sas_device_priv_data
= scmd
->device
->hostdata
;
2510 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2511 sdev_printk(KERN_INFO
, scmd
->device
,
2512 "device been deleted! scmd(%p)\n", scmd
);
2513 scmd
->result
= DID_NO_CONNECT
<< 16;
2514 scmd
->scsi_done(scmd
);
2519 /* for hidden raid components obtain the volume_handle */
2521 if (sas_device_priv_data
->sas_target
->flags
&
2522 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2523 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2526 handle
= sas_device
->volume_handle
;
2528 handle
= sas_device_priv_data
->sas_target
->handle
;
2531 scmd
->result
= DID_RESET
<< 16;
2536 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2537 scmd
->device
->id
, scmd
->device
->lun
,
2538 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, TM_MUTEX_ON
);
2541 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2542 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2545 sas_device_put(sas_device
);
2551 * scsih_target_reset - eh threads main target reset routine
2552 * @scmd: pointer to scsi command object
2554 * Returns SUCCESS if command aborted else FAILED
2557 scsih_target_reset(struct scsi_cmnd
*scmd
)
2559 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2560 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2561 struct _sas_device
*sas_device
= NULL
;
2564 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2565 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2567 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2569 _scsih_tm_display_info(ioc
, scmd
);
2571 sas_device_priv_data
= scmd
->device
->hostdata
;
2572 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2573 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2575 scmd
->result
= DID_NO_CONNECT
<< 16;
2576 scmd
->scsi_done(scmd
);
2581 /* for hidden raid components obtain the volume_handle */
2583 if (sas_device_priv_data
->sas_target
->flags
&
2584 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2585 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2588 handle
= sas_device
->volume_handle
;
2590 handle
= sas_device_priv_data
->sas_target
->handle
;
2593 scmd
->result
= DID_RESET
<< 16;
2598 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2599 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2603 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2604 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2607 sas_device_put(sas_device
);
2614 * scsih_host_reset - eh threads main host reset routine
2615 * @scmd: pointer to scsi command object
2617 * Returns SUCCESS if command aborted else FAILED
2620 scsih_host_reset(struct scsi_cmnd
*scmd
)
2622 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2625 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
2627 scsi_print_command(scmd
);
2629 if (ioc
->is_driver_loading
) {
2630 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
2636 retval
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2638 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2640 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2641 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2647 * _scsih_fw_event_add - insert and queue up fw_event
2648 * @ioc: per adapter object
2649 * @fw_event: object describing the event
2650 * Context: This function will acquire ioc->fw_event_lock.
2652 * This adds the firmware event object into link list, then queues it up to
2653 * be processed from user context.
2658 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2660 unsigned long flags
;
2662 if (ioc
->firmware_event_thread
== NULL
)
2665 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2666 fw_event_work_get(fw_event
);
2667 INIT_LIST_HEAD(&fw_event
->list
);
2668 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2669 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2670 fw_event_work_get(fw_event
);
2671 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2672 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2676 * _scsih_fw_event_del_from_list - delete fw_event from the list
2677 * @ioc: per adapter object
2678 * @fw_event: object describing the event
2679 * Context: This function will acquire ioc->fw_event_lock.
2681 * If the fw_event is on the fw_event_list, remove it and do a put.
2686 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2689 unsigned long flags
;
2691 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2692 if (!list_empty(&fw_event
->list
)) {
2693 list_del_init(&fw_event
->list
);
2694 fw_event_work_put(fw_event
);
2696 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2701 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2702 * @ioc: per adapter object
2703 * @event_data: trigger event data
2708 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2709 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2711 struct fw_event_work
*fw_event
;
2714 if (ioc
->is_driver_loading
)
2716 sz
= sizeof(*event_data
);
2717 fw_event
= alloc_fw_event_work(sz
);
2720 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2721 fw_event
->ioc
= ioc
;
2722 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2723 _scsih_fw_event_add(ioc
, fw_event
);
2724 fw_event_work_put(fw_event
);
2728 * _scsih_error_recovery_delete_devices - remove devices not responding
2729 * @ioc: per adapter object
2734 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2736 struct fw_event_work
*fw_event
;
2738 if (ioc
->is_driver_loading
)
2740 fw_event
= alloc_fw_event_work(0);
2743 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2744 fw_event
->ioc
= ioc
;
2745 _scsih_fw_event_add(ioc
, fw_event
);
2746 fw_event_work_put(fw_event
);
2750 * mpt3sas_port_enable_complete - port enable completed (fake event)
2751 * @ioc: per adapter object
2756 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2758 struct fw_event_work
*fw_event
;
2760 fw_event
= alloc_fw_event_work(0);
2763 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2764 fw_event
->ioc
= ioc
;
2765 _scsih_fw_event_add(ioc
, fw_event
);
2766 fw_event_work_put(fw_event
);
2769 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
2771 unsigned long flags
;
2772 struct fw_event_work
*fw_event
= NULL
;
2774 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2775 if (!list_empty(&ioc
->fw_event_list
)) {
2776 fw_event
= list_first_entry(&ioc
->fw_event_list
,
2777 struct fw_event_work
, list
);
2778 list_del_init(&fw_event
->list
);
2780 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2786 * _scsih_fw_event_cleanup_queue - cleanup event queue
2787 * @ioc: per adapter object
2789 * Walk the firmware event queue, either killing timers, or waiting
2790 * for outstanding events to complete
2795 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2797 struct fw_event_work
*fw_event
;
2799 if (list_empty(&ioc
->fw_event_list
) ||
2800 !ioc
->firmware_event_thread
|| in_interrupt())
2803 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
2805 * Wait on the fw_event to complete. If this returns 1, then
2806 * the event was never executed, and we need a put for the
2807 * reference the delayed_work had on the fw_event.
2809 * If it did execute, we wait for it to finish, and the put will
2810 * happen from _firmware_event_work()
2812 if (cancel_delayed_work_sync(&fw_event
->delayed_work
))
2813 fw_event_work_put(fw_event
);
2815 fw_event_work_put(fw_event
);
2820 * _scsih_internal_device_block - block the sdev device
2821 * @sdev: per device object
2822 * @sas_device_priv_data : per device driver private data
2824 * make sure device is blocked without error, if not
2828 _scsih_internal_device_block(struct scsi_device
*sdev
,
2829 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2833 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
2834 sas_device_priv_data
->sas_target
->handle
);
2835 sas_device_priv_data
->block
= 1;
2837 r
= scsi_internal_device_block(sdev
);
2839 sdev_printk(KERN_WARNING
, sdev
,
2840 "device_block failed with return(%d) for handle(0x%04x)\n",
2841 sas_device_priv_data
->sas_target
->handle
, r
);
2845 * _scsih_internal_device_unblock - unblock the sdev device
2846 * @sdev: per device object
2847 * @sas_device_priv_data : per device driver private data
2848 * make sure device is unblocked without error, if not retry
2849 * by blocking and then unblocking
2853 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
2854 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2858 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
2859 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
2860 sas_device_priv_data
->block
= 0;
2861 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2863 /* The device has been set to SDEV_RUNNING by SD layer during
2864 * device addition but the request queue is still stopped by
2865 * our earlier block call. We need to perform a block again
2866 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2868 sdev_printk(KERN_WARNING
, sdev
,
2869 "device_unblock failed with return(%d) for handle(0x%04x) "
2870 "performing a block followed by an unblock\n",
2871 sas_device_priv_data
->sas_target
->handle
, r
);
2872 sas_device_priv_data
->block
= 1;
2873 r
= scsi_internal_device_block(sdev
);
2875 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
2876 "failed with return(%d) for handle(0x%04x)\n",
2877 sas_device_priv_data
->sas_target
->handle
, r
);
2879 sas_device_priv_data
->block
= 0;
2880 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2882 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
2883 " failed with return(%d) for handle(0x%04x)\n",
2884 sas_device_priv_data
->sas_target
->handle
, r
);
2889 * _scsih_ublock_io_all_device - unblock every device
2890 * @ioc: per adapter object
2892 * change the device state from block to running
2895 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2897 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2898 struct scsi_device
*sdev
;
2900 shost_for_each_device(sdev
, ioc
->shost
) {
2901 sas_device_priv_data
= sdev
->hostdata
;
2902 if (!sas_device_priv_data
)
2904 if (!sas_device_priv_data
->block
)
2907 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2908 "device_running, handle(0x%04x)\n",
2909 sas_device_priv_data
->sas_target
->handle
));
2910 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
2916 * _scsih_ublock_io_device - prepare device to be deleted
2917 * @ioc: per adapter object
2918 * @sas_addr: sas address
2920 * unblock then put device in offline state
2923 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2925 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2926 struct scsi_device
*sdev
;
2928 shost_for_each_device(sdev
, ioc
->shost
) {
2929 sas_device_priv_data
= sdev
->hostdata
;
2930 if (!sas_device_priv_data
)
2932 if (sas_device_priv_data
->sas_target
->sas_address
2935 if (sas_device_priv_data
->block
)
2936 _scsih_internal_device_unblock(sdev
,
2937 sas_device_priv_data
);
2942 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2943 * @ioc: per adapter object
2944 * @handle: device handle
2946 * During device pull we need to appropiately set the sdev state.
2949 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2951 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2952 struct scsi_device
*sdev
;
2954 shost_for_each_device(sdev
, ioc
->shost
) {
2955 sas_device_priv_data
= sdev
->hostdata
;
2956 if (!sas_device_priv_data
)
2958 if (sas_device_priv_data
->block
)
2960 if (sas_device_priv_data
->ignore_delay_remove
) {
2961 sdev_printk(KERN_INFO
, sdev
,
2962 "%s skip device_block for SES handle(0x%04x)\n",
2963 __func__
, sas_device_priv_data
->sas_target
->handle
);
2966 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2971 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2972 * @ioc: per adapter object
2973 * @handle: device handle
2975 * During device pull we need to appropiately set the sdev state.
2978 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2980 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2981 struct scsi_device
*sdev
;
2982 struct _sas_device
*sas_device
;
2984 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
2988 shost_for_each_device(sdev
, ioc
->shost
) {
2989 sas_device_priv_data
= sdev
->hostdata
;
2990 if (!sas_device_priv_data
)
2992 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
2994 if (sas_device_priv_data
->block
)
2996 if (sas_device
->pend_sas_rphy_add
)
2998 if (sas_device_priv_data
->ignore_delay_remove
) {
2999 sdev_printk(KERN_INFO
, sdev
,
3000 "%s skip device_block for SES handle(0x%04x)\n",
3001 __func__
, sas_device_priv_data
->sas_target
->handle
);
3004 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3007 sas_device_put(sas_device
);
3011 * _scsih_block_io_to_children_attached_to_ex
3012 * @ioc: per adapter object
3013 * @sas_expander: the sas_device object
3015 * This routine set sdev state to SDEV_BLOCK for all devices
3016 * attached to this expander. This function called when expander is
3020 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3021 struct _sas_node
*sas_expander
)
3023 struct _sas_port
*mpt3sas_port
;
3024 struct _sas_device
*sas_device
;
3025 struct _sas_node
*expander_sibling
;
3026 unsigned long flags
;
3031 list_for_each_entry(mpt3sas_port
,
3032 &sas_expander
->sas_port_list
, port_list
) {
3033 if (mpt3sas_port
->remote_identify
.device_type
==
3035 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3036 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3037 mpt3sas_port
->remote_identify
.sas_address
);
3039 set_bit(sas_device
->handle
,
3040 ioc
->blocking_handles
);
3041 sas_device_put(sas_device
);
3043 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3047 list_for_each_entry(mpt3sas_port
,
3048 &sas_expander
->sas_port_list
, port_list
) {
3050 if (mpt3sas_port
->remote_identify
.device_type
==
3051 SAS_EDGE_EXPANDER_DEVICE
||
3052 mpt3sas_port
->remote_identify
.device_type
==
3053 SAS_FANOUT_EXPANDER_DEVICE
) {
3055 mpt3sas_scsih_expander_find_by_sas_address(
3056 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3057 _scsih_block_io_to_children_attached_to_ex(ioc
,
3064 * _scsih_block_io_to_children_attached_directly
3065 * @ioc: per adapter object
3066 * @event_data: topology change event data
3068 * This routine set sdev state to SDEV_BLOCK for all devices
3069 * direct attached during device pull.
3072 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3073 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3079 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3080 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3083 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3084 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3085 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3086 _scsih_block_io_device(ioc
, handle
);
3091 * _scsih_tm_tr_send - send task management request
3092 * @ioc: per adapter object
3093 * @handle: device handle
3094 * Context: interrupt time.
3096 * This code is to initiate the device removal handshake protocol
3097 * with controller firmware. This function will issue target reset
3098 * using high priority request queue. It will send a sas iounit
3099 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3101 * This is designed to send muliple task management request at the same
3102 * time to the fifo. If the fifo is full, we will append the request,
3103 * and process it in a future completion.
3106 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3108 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3110 struct _sas_device
*sas_device
= NULL
;
3111 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3112 u64 sas_address
= 0;
3113 unsigned long flags
;
3114 struct _tr_list
*delayed_tr
;
3117 if (ioc
->remove_host
) {
3118 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3119 "%s: host has been removed: handle(0x%04x)\n",
3120 __func__
, ioc
->name
, handle
));
3122 } else if (ioc
->pci_error_recovery
) {
3123 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3124 "%s: host in pci error recovery: handle(0x%04x)\n",
3125 __func__
, ioc
->name
,
3129 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3130 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3131 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3132 "%s: host is not operational: handle(0x%04x)\n",
3133 __func__
, ioc
->name
,
3138 /* if PD, then return */
3139 if (test_bit(handle
, ioc
->pd_handles
))
3142 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3143 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3144 if (sas_device
&& sas_device
->starget
&&
3145 sas_device
->starget
->hostdata
) {
3146 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3147 sas_target_priv_data
->deleted
= 1;
3148 sas_address
= sas_device
->sas_address
;
3150 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3152 if (sas_target_priv_data
) {
3153 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3154 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3156 (unsigned long long)sas_address
));
3157 if (sas_device
->enclosure_handle
!= 0)
3158 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3159 "setting delete flag:enclosure logical id(0x%016llx),"
3160 " slot(%d)\n", ioc
->name
, (unsigned long long)
3161 sas_device
->enclosure_logical_id
,
3163 if (sas_device
->connector_name
[0] != '\0')
3164 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3165 "setting delete flag: enclosure level(0x%04x),"
3166 " connector name( %s)\n", ioc
->name
,
3167 sas_device
->enclosure_level
,
3168 sas_device
->connector_name
));
3169 _scsih_ublock_io_device(ioc
, sas_address
);
3170 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3173 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3175 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3178 INIT_LIST_HEAD(&delayed_tr
->list
);
3179 delayed_tr
->handle
= handle
;
3180 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3181 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3182 "DELAYED:tr:handle(0x%04x), (open)\n",
3183 ioc
->name
, handle
));
3187 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3188 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3189 ioc
->name
, handle
, smid
,
3190 ioc
->tm_tr_cb_idx
));
3191 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3192 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3193 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3194 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3195 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3196 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
3197 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3201 sas_device_put(sas_device
);
3205 * _scsih_tm_tr_complete -
3206 * @ioc: per adapter object
3207 * @smid: system request message index
3208 * @msix_index: MSIX table index supplied by the OS
3209 * @reply: reply message frame(lower 32bit addr)
3210 * Context: interrupt time.
3212 * This is the target reset completion routine.
3213 * This code is part of the code to initiate the device removal
3214 * handshake protocol with controller firmware.
3215 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3217 * Return 1 meaning mf should be freed from _base_interrupt
3218 * 0 means the mf is freed from this function.
3221 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3225 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3226 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3227 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3228 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3231 struct _sc_list
*delayed_sc
;
3233 if (ioc
->remove_host
) {
3234 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3235 "%s: host has been removed\n", __func__
, ioc
->name
));
3237 } else if (ioc
->pci_error_recovery
) {
3238 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3239 "%s: host in pci error recovery\n", __func__
,
3243 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3244 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3245 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3246 "%s: host is not operational\n", __func__
, ioc
->name
));
3249 if (unlikely(!mpi_reply
)) {
3250 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3251 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3254 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3255 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3256 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3257 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3258 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3260 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3264 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3265 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3266 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3267 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3268 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3269 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3270 le32_to_cpu(mpi_reply
->TerminationCount
)));
3272 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3273 if (!smid_sas_ctrl
) {
3274 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3276 return _scsih_check_for_pending_tm(ioc
, smid
);
3277 INIT_LIST_HEAD(&delayed_sc
->list
);
3278 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3279 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3280 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3281 "DELAYED:sc:handle(0x%04x), (open)\n",
3282 ioc
->name
, handle
));
3283 return _scsih_check_for_pending_tm(ioc
, smid
);
3286 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3287 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3288 ioc
->name
, handle
, smid_sas_ctrl
,
3289 ioc
->tm_sas_control_cb_idx
));
3290 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3291 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3292 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3293 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3294 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3295 mpt3sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3297 return _scsih_check_for_pending_tm(ioc
, smid
);
3302 * _scsih_sas_control_complete - completion routine
3303 * @ioc: per adapter object
3304 * @smid: system request message index
3305 * @msix_index: MSIX table index supplied by the OS
3306 * @reply: reply message frame(lower 32bit addr)
3307 * Context: interrupt time.
3309 * This is the sas iounit control completion routine.
3310 * This code is part of the code to initiate the device removal
3311 * handshake protocol with controller firmware.
3313 * Return 1 meaning mf should be freed from _base_interrupt
3314 * 0 means the mf is freed from this function.
3317 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3318 u8 msix_index
, u32 reply
)
3320 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3321 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3323 if (likely(mpi_reply
)) {
3324 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3325 "sc_complete:handle(0x%04x), (open) "
3326 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3327 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3328 le16_to_cpu(mpi_reply
->IOCStatus
),
3329 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3331 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3332 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3334 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3338 * _scsih_tm_tr_volume_send - send target reset request for volumes
3339 * @ioc: per adapter object
3340 * @handle: device handle
3341 * Context: interrupt time.
3343 * This is designed to send muliple task management request at the same
3344 * time to the fifo. If the fifo is full, we will append the request,
3345 * and process it in a future completion.
3348 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3350 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3352 struct _tr_list
*delayed_tr
;
3354 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3355 ioc
->pci_error_recovery
) {
3356 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3357 "%s: host reset in progress!\n",
3358 __func__
, ioc
->name
));
3362 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3364 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3367 INIT_LIST_HEAD(&delayed_tr
->list
);
3368 delayed_tr
->handle
= handle
;
3369 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3370 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3371 "DELAYED:tr:handle(0x%04x), (open)\n",
3372 ioc
->name
, handle
));
3376 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3377 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3378 ioc
->name
, handle
, smid
,
3379 ioc
->tm_tr_volume_cb_idx
));
3380 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3381 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3382 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3383 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3384 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3385 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
3389 * _scsih_tm_volume_tr_complete - target reset completion
3390 * @ioc: per adapter object
3391 * @smid: system request message index
3392 * @msix_index: MSIX table index supplied by the OS
3393 * @reply: reply message frame(lower 32bit addr)
3394 * Context: interrupt time.
3396 * Return 1 meaning mf should be freed from _base_interrupt
3397 * 0 means the mf is freed from this function.
3400 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3401 u8 msix_index
, u32 reply
)
3404 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3405 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3406 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3408 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3409 ioc
->pci_error_recovery
) {
3410 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3411 "%s: host reset in progress!\n",
3412 __func__
, ioc
->name
));
3415 if (unlikely(!mpi_reply
)) {
3416 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3417 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3421 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3422 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3423 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3424 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3425 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3427 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3431 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3432 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3433 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3434 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3435 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3436 le32_to_cpu(mpi_reply
->TerminationCount
)));
3438 return _scsih_check_for_pending_tm(ioc
, smid
);
3442 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3443 * @ioc: per adapter object
3444 * @smid: system request message index
3446 * @event_context: used to track events uniquely
3448 * Context - processed in interrupt context.
3451 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
3454 Mpi2EventAckRequest_t
*ack_request
;
3455 int i
= smid
- ioc
->internal_smid
;
3456 unsigned long flags
;
3458 /* Without releasing the smid just update the
3459 * call back index and reuse the same smid for
3460 * processing this delayed request
3462 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3463 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3464 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3466 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3467 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3468 ioc
->name
, le16_to_cpu(event
), smid
,
3470 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3471 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3472 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3473 ack_request
->Event
= event
;
3474 ack_request
->EventContext
= event_context
;
3475 ack_request
->VF_ID
= 0; /* TODO */
3476 ack_request
->VP_ID
= 0;
3477 mpt3sas_base_put_smid_default(ioc
, smid
);
3481 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3482 * sas_io_unit_ctrl messages
3483 * @ioc: per adapter object
3484 * @smid: system request message index
3485 * @handle: device handle
3487 * Context - processed in interrupt context.
3490 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
3491 u16 smid
, u16 handle
)
3493 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3495 int i
= smid
- ioc
->internal_smid
;
3496 unsigned long flags
;
3498 if (ioc
->remove_host
) {
3499 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3500 "%s: host has been removed\n",
3501 __func__
, ioc
->name
));
3503 } else if (ioc
->pci_error_recovery
) {
3504 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3505 "%s: host in pci error recovery\n",
3506 __func__
, ioc
->name
));
3509 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3510 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3511 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3512 "%s: host is not operational\n",
3513 __func__
, ioc
->name
));
3517 /* Without releasing the smid just update the
3518 * call back index and reuse the same smid for
3519 * processing this delayed request
3521 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3522 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
3523 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3525 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3526 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3527 ioc
->name
, le16_to_cpu(handle
), smid
,
3528 ioc
->tm_sas_control_cb_idx
));
3529 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3530 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3531 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3532 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3533 mpi_request
->DevHandle
= handle
;
3534 mpt3sas_base_put_smid_default(ioc
, smid
);
3538 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3539 * @ioc: per adapter object
3540 * @smid: system request message index
3542 * Context: Executed in interrupt context
3544 * This will check delayed internal messages list, and process the
3547 * Return 1 meaning mf should be freed from _base_interrupt
3548 * 0 means the mf is freed from this function.
3551 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3553 struct _sc_list
*delayed_sc
;
3554 struct _event_ack_list
*delayed_event_ack
;
3556 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
3557 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
3558 struct _event_ack_list
, list
);
3559 _scsih_issue_delayed_event_ack(ioc
, smid
,
3560 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
3561 list_del(&delayed_event_ack
->list
);
3562 kfree(delayed_event_ack
);
3566 if (!list_empty(&ioc
->delayed_sc_list
)) {
3567 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
3568 struct _sc_list
, list
);
3569 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
3570 delayed_sc
->handle
);
3571 list_del(&delayed_sc
->list
);
3579 * _scsih_check_for_pending_tm - check for pending task management
3580 * @ioc: per adapter object
3581 * @smid: system request message index
3583 * This will check delayed target reset list, and feed the
3586 * Return 1 meaning mf should be freed from _base_interrupt
3587 * 0 means the mf is freed from this function.
3590 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3592 struct _tr_list
*delayed_tr
;
3594 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3595 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3596 struct _tr_list
, list
);
3597 mpt3sas_base_free_smid(ioc
, smid
);
3598 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3599 list_del(&delayed_tr
->list
);
3604 if (!list_empty(&ioc
->delayed_tr_list
)) {
3605 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3606 struct _tr_list
, list
);
3607 mpt3sas_base_free_smid(ioc
, smid
);
3608 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3609 list_del(&delayed_tr
->list
);
3618 * _scsih_check_topo_delete_events - sanity check on topo events
3619 * @ioc: per adapter object
3620 * @event_data: the event data payload
3622 * This routine added to better handle cable breaker.
3624 * This handles the case where driver receives multiple expander
3625 * add and delete events in a single shot. When there is a delete event
3626 * the routine will void any pending add events waiting in the event queue.
3631 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3632 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3634 struct fw_event_work
*fw_event
;
3635 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3636 u16 expander_handle
;
3637 struct _sas_node
*sas_expander
;
3638 unsigned long flags
;
3642 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3643 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3646 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3647 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3648 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3649 _scsih_tm_tr_send(ioc
, handle
);
3652 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3653 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3654 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3657 if (event_data
->ExpStatus
==
3658 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3659 /* put expander attached devices into blocking state */
3660 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3661 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3663 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3664 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3666 handle
= find_first_bit(ioc
->blocking_handles
,
3667 ioc
->facts
.MaxDevHandle
);
3668 if (handle
< ioc
->facts
.MaxDevHandle
)
3669 _scsih_block_io_device(ioc
, handle
);
3670 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3671 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3672 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3674 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3677 /* mark ignore flag for pending events */
3678 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3679 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3680 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3683 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3684 fw_event
->event_data
;
3685 if (local_event_data
->ExpStatus
==
3686 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3687 local_event_data
->ExpStatus
==
3688 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3689 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3691 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3692 "setting ignoring flag\n", ioc
->name
));
3693 fw_event
->ignore
= 1;
3697 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3701 * _scsih_set_volume_delete_flag - setting volume delete flag
3702 * @ioc: per adapter object
3703 * @handle: device handle
3705 * This returns nothing.
3708 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3710 struct _raid_device
*raid_device
;
3711 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3712 unsigned long flags
;
3714 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3715 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
3716 if (raid_device
&& raid_device
->starget
&&
3717 raid_device
->starget
->hostdata
) {
3718 sas_target_priv_data
=
3719 raid_device
->starget
->hostdata
;
3720 sas_target_priv_data
->deleted
= 1;
3721 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3722 "setting delete flag: handle(0x%04x), "
3723 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3724 (unsigned long long) raid_device
->wwid
));
3726 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3730 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3731 * @handle: input handle
3732 * @a: handle for volume a
3733 * @b: handle for volume b
3735 * IR firmware only supports two raid volumes. The purpose of this
3736 * routine is to set the volume handle in either a or b. When the given
3737 * input handle is non-zero, or when a and b have not been set before.
3740 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3742 if (!handle
|| handle
== *a
|| handle
== *b
)
3751 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3752 * @ioc: per adapter object
3753 * @event_data: the event data payload
3754 * Context: interrupt time.
3756 * This routine will send target reset to volume, followed by target
3757 * resets to the PDs. This is called when a PD has been removed, or
3758 * volume has been deleted or removed. When the target reset is sent
3759 * to volume, the PD target resets need to be queued to start upon
3760 * completion of the volume target reset.
3765 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3766 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3768 Mpi2EventIrConfigElement_t
*element
;
3770 u16 handle
, volume_handle
, a
, b
;
3771 struct _tr_list
*delayed_tr
;
3776 if (ioc
->is_warpdrive
)
3779 /* Volume Resets for Deleted or Removed */
3780 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3781 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3782 if (le32_to_cpu(event_data
->Flags
) &
3783 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3785 if (element
->ReasonCode
==
3786 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3787 element
->ReasonCode
==
3788 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3789 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3790 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3791 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3795 /* Volume Resets for UNHIDE events */
3796 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3797 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3798 if (le32_to_cpu(event_data
->Flags
) &
3799 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3801 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3802 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3803 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3808 _scsih_tm_tr_volume_send(ioc
, a
);
3810 _scsih_tm_tr_volume_send(ioc
, b
);
3812 /* PD target resets */
3813 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3814 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3815 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3817 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3818 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3819 clear_bit(handle
, ioc
->pd_handles
);
3821 _scsih_tm_tr_send(ioc
, handle
);
3822 else if (volume_handle
== a
|| volume_handle
== b
) {
3823 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3824 BUG_ON(!delayed_tr
);
3825 INIT_LIST_HEAD(&delayed_tr
->list
);
3826 delayed_tr
->handle
= handle
;
3827 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3828 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3829 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3832 _scsih_tm_tr_send(ioc
, handle
);
3838 * _scsih_check_volume_delete_events - set delete flag for volumes
3839 * @ioc: per adapter object
3840 * @event_data: the event data payload
3841 * Context: interrupt time.
3843 * This will handle the case when the cable connected to entire volume is
3844 * pulled. We will take care of setting the deleted flag so normal IO will
3850 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3851 Mpi2EventDataIrVolume_t
*event_data
)
3855 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3857 state
= le32_to_cpu(event_data
->NewValue
);
3858 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3859 MPI2_RAID_VOL_STATE_FAILED
)
3860 _scsih_set_volume_delete_flag(ioc
,
3861 le16_to_cpu(event_data
->VolDevHandle
));
3865 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3866 * @ioc: per adapter object
3867 * @event_data: the temp threshold event data
3868 * Context: interrupt time.
3873 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
3874 Mpi2EventDataTemperature_t
*event_data
)
3876 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3877 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
3878 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3879 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3880 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3881 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3882 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3883 event_data
->SensorNum
);
3884 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
3885 ioc
->name
, event_data
->CurrentTemperature
);
3890 * _scsih_flush_running_cmds - completing outstanding commands.
3891 * @ioc: per adapter object
3893 * The flushing out of all pending scmd commands following host reset,
3894 * where all IO is dropped to the floor.
3899 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3901 struct scsi_cmnd
*scmd
;
3905 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3906 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3910 mpt3sas_base_free_smid(ioc
, smid
);
3911 scsi_dma_unmap(scmd
);
3912 if (ioc
->pci_error_recovery
)
3913 scmd
->result
= DID_NO_CONNECT
<< 16;
3915 scmd
->result
= DID_RESET
<< 16;
3916 scmd
->scsi_done(scmd
);
3918 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3923 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3924 * @ioc: per adapter object
3925 * @scmd: pointer to scsi command object
3926 * @mpi_request: pointer to the SCSI_IO reqest message frame
3928 * Supporting protection 1 and 3.
3933 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3934 Mpi2SCSIIORequest_t
*mpi_request
)
3937 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3938 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3939 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3940 (Mpi25SCSIIORequest_t
*)mpi_request
;
3942 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3945 if (prot_op
== SCSI_PROT_READ_STRIP
)
3946 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3947 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3948 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3952 switch (prot_type
) {
3953 case SCSI_PROT_DIF_TYPE1
:
3954 case SCSI_PROT_DIF_TYPE2
:
3957 * enable ref/guard checking
3958 * auto increment ref tag
3960 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3961 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3962 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3963 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3964 cpu_to_be32(scsi_get_lba(scmd
));
3967 case SCSI_PROT_DIF_TYPE3
:
3970 * enable guard checking
3972 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3977 mpi_request_3v
->EEDPBlockSize
=
3978 cpu_to_le16(scmd
->device
->sector_size
);
3979 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3983 * _scsih_eedp_error_handling - return sense code for EEDP errors
3984 * @scmd: pointer to scsi command object
3985 * @ioc_status: ioc status
3990 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3994 switch (ioc_status
) {
3995 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3998 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4001 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4008 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4010 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4011 SAM_STAT_CHECK_CONDITION
;
4017 * scsih_qcmd - main scsi request entry point
4018 * @scmd: pointer to scsi command object
4019 * @done: function pointer to be invoked on completion
4021 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4023 * Returns 0 on success. If there's a failure, return either:
4024 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4025 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4028 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4030 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4031 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4032 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4033 struct _raid_device
*raid_device
;
4034 Mpi2SCSIIORequest_t
*mpi_request
;
4039 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4040 scsi_print_command(scmd
);
4042 sas_device_priv_data
= scmd
->device
->hostdata
;
4043 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4044 scmd
->result
= DID_NO_CONNECT
<< 16;
4045 scmd
->scsi_done(scmd
);
4049 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
4050 scmd
->result
= DID_NO_CONNECT
<< 16;
4051 scmd
->scsi_done(scmd
);
4055 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4057 /* invalid device handle */
4058 handle
= sas_target_priv_data
->handle
;
4059 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4060 scmd
->result
= DID_NO_CONNECT
<< 16;
4061 scmd
->scsi_done(scmd
);
4066 /* host recovery or link resets sent via IOCTLs */
4067 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4068 return SCSI_MLQUEUE_HOST_BUSY
;
4070 /* device has been deleted */
4071 else if (sas_target_priv_data
->deleted
) {
4072 scmd
->result
= DID_NO_CONNECT
<< 16;
4073 scmd
->scsi_done(scmd
);
4075 /* device busy with task managment */
4076 } else if (sas_target_priv_data
->tm_busy
||
4077 sas_device_priv_data
->block
)
4078 return SCSI_MLQUEUE_DEVICE_BUSY
;
4080 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4081 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4082 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4083 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4085 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4088 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4090 /* Make sure Device is not raid volume.
4091 * We do not expose raid functionality to upper layer for warpdrive.
4093 if (!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
)
4094 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4095 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4097 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4099 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4100 ioc
->name
, __func__
);
4103 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4104 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
4105 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4107 if (scmd
->cmd_len
== 32)
4108 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4109 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4110 if (sas_device_priv_data
->sas_target
->flags
&
4111 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4112 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4114 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4115 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4116 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4117 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4118 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4119 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4120 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4121 mpi_request
->SenseBufferLowAddress
=
4122 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4123 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4124 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4126 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4128 if (mpi_request
->DataLength
) {
4129 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
4130 mpt3sas_base_free_smid(ioc
, smid
);
4134 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4136 raid_device
= sas_target_priv_data
->raid_device
;
4137 if (raid_device
&& raid_device
->direct_io_enabled
)
4138 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4141 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4142 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4143 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4144 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4145 mpt3sas_base_put_smid_fast_path(ioc
, smid
, handle
);
4147 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
4148 le16_to_cpu(mpi_request
->DevHandle
));
4150 mpt3sas_base_put_smid_default(ioc
, smid
);
4154 return SCSI_MLQUEUE_HOST_BUSY
;
4158 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4159 * @sense_buffer: sense data returned by target
4160 * @data: normalized skey/asc/ascq
4165 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4167 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4168 /* descriptor format */
4169 data
->skey
= sense_buffer
[1] & 0x0F;
4170 data
->asc
= sense_buffer
[2];
4171 data
->ascq
= sense_buffer
[3];
4174 data
->skey
= sense_buffer
[2] & 0x0F;
4175 data
->asc
= sense_buffer
[12];
4176 data
->ascq
= sense_buffer
[13];
4181 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4182 * @ioc: per adapter object
4183 * @scmd: pointer to scsi command object
4184 * @mpi_reply: reply mf payload returned from firmware
4186 * scsi_status - SCSI Status code returned from target device
4187 * scsi_state - state info associated with SCSI_IO determined by ioc
4188 * ioc_status - ioc supplied status info
4193 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4194 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4198 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4199 MPI2_IOCSTATUS_MASK
;
4200 u8 scsi_state
= mpi_reply
->SCSIState
;
4201 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4202 char *desc_ioc_state
= NULL
;
4203 char *desc_scsi_status
= NULL
;
4204 char *desc_scsi_state
= ioc
->tmp_string
;
4205 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4206 struct _sas_device
*sas_device
= NULL
;
4207 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4208 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4209 char *device_str
= NULL
;
4213 if (ioc
->hide_ir_msg
)
4214 device_str
= "WarpDrive";
4216 device_str
= "volume";
4218 if (log_info
== 0x31170000)
4221 switch (ioc_status
) {
4222 case MPI2_IOCSTATUS_SUCCESS
:
4223 desc_ioc_state
= "success";
4225 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4226 desc_ioc_state
= "invalid function";
4228 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4229 desc_ioc_state
= "scsi recovered error";
4231 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4232 desc_ioc_state
= "scsi invalid dev handle";
4234 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4235 desc_ioc_state
= "scsi device not there";
4237 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4238 desc_ioc_state
= "scsi data overrun";
4240 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4241 desc_ioc_state
= "scsi data underrun";
4243 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4244 desc_ioc_state
= "scsi io data error";
4246 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4247 desc_ioc_state
= "scsi protocol error";
4249 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4250 desc_ioc_state
= "scsi task terminated";
4252 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4253 desc_ioc_state
= "scsi residual mismatch";
4255 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4256 desc_ioc_state
= "scsi task mgmt failed";
4258 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4259 desc_ioc_state
= "scsi ioc terminated";
4261 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4262 desc_ioc_state
= "scsi ext terminated";
4264 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4265 desc_ioc_state
= "eedp guard error";
4267 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4268 desc_ioc_state
= "eedp ref tag error";
4270 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4271 desc_ioc_state
= "eedp app tag error";
4273 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4274 desc_ioc_state
= "insufficient power";
4277 desc_ioc_state
= "unknown";
4281 switch (scsi_status
) {
4282 case MPI2_SCSI_STATUS_GOOD
:
4283 desc_scsi_status
= "good";
4285 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4286 desc_scsi_status
= "check condition";
4288 case MPI2_SCSI_STATUS_CONDITION_MET
:
4289 desc_scsi_status
= "condition met";
4291 case MPI2_SCSI_STATUS_BUSY
:
4292 desc_scsi_status
= "busy";
4294 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4295 desc_scsi_status
= "intermediate";
4297 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4298 desc_scsi_status
= "intermediate condmet";
4300 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4301 desc_scsi_status
= "reservation conflict";
4303 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4304 desc_scsi_status
= "command terminated";
4306 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4307 desc_scsi_status
= "task set full";
4309 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4310 desc_scsi_status
= "aca active";
4312 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4313 desc_scsi_status
= "task aborted";
4316 desc_scsi_status
= "unknown";
4320 desc_scsi_state
[0] = '\0';
4322 desc_scsi_state
= " ";
4323 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4324 strcat(desc_scsi_state
, "response info ");
4325 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4326 strcat(desc_scsi_state
, "state terminated ");
4327 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4328 strcat(desc_scsi_state
, "no status ");
4329 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4330 strcat(desc_scsi_state
, "autosense failed ");
4331 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4332 strcat(desc_scsi_state
, "autosense valid ");
4334 scsi_print_command(scmd
);
4336 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4337 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4338 device_str
, (unsigned long long)priv_target
->sas_address
);
4340 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4343 "\tsas_address(0x%016llx), phy(%d)\n",
4344 ioc
->name
, (unsigned long long)
4345 sas_device
->sas_address
, sas_device
->phy
);
4346 if (sas_device
->enclosure_handle
!= 0)
4348 "\tenclosure_logical_id(0x%016llx),"
4349 "slot(%d)\n", ioc
->name
,
4350 (unsigned long long)
4351 sas_device
->enclosure_logical_id
,
4353 if (sas_device
->connector_name
[0])
4355 "\tenclosure level(0x%04x),"
4356 " connector name( %s)\n", ioc
->name
,
4357 sas_device
->enclosure_level
,
4358 sas_device
->connector_name
);
4360 sas_device_put(sas_device
);
4365 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4366 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4367 desc_ioc_state
, ioc_status
, smid
);
4369 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4370 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4371 scsi_get_resid(scmd
));
4373 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4374 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4375 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4377 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4378 ioc
->name
, desc_scsi_status
,
4379 scsi_status
, desc_scsi_state
, scsi_state
);
4381 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4382 struct sense_info data
;
4383 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4385 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4386 ioc
->name
, data
.skey
,
4387 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4390 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4391 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4392 response_bytes
= (u8
*)&response_info
;
4393 _scsih_response_code(ioc
, response_bytes
[0]);
4398 * _scsih_turn_on_pfa_led - illuminate PFA LED
4399 * @ioc: per adapter object
4400 * @handle: device handle
4406 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4408 Mpi2SepReply_t mpi_reply
;
4409 Mpi2SepRequest_t mpi_request
;
4410 struct _sas_device
*sas_device
;
4412 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4416 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4417 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4418 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4419 mpi_request
.SlotStatus
=
4420 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4421 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4422 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4423 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4424 &mpi_request
)) != 0) {
4425 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4426 __FILE__
, __LINE__
, __func__
);
4429 sas_device
->pfa_led_on
= 1;
4431 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4432 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4433 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4434 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4435 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4439 sas_device_put(sas_device
);
4443 * _scsih_turn_off_pfa_led - turn off Fault LED
4444 * @ioc: per adapter object
4445 * @sas_device: sas device whose PFA LED has to turned off
4451 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4452 struct _sas_device
*sas_device
)
4454 Mpi2SepReply_t mpi_reply
;
4455 Mpi2SepRequest_t mpi_request
;
4457 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4458 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4459 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4460 mpi_request
.SlotStatus
= 0;
4461 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4462 mpi_request
.DevHandle
= 0;
4463 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4464 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4465 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4466 &mpi_request
)) != 0) {
4467 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4468 __FILE__
, __LINE__
, __func__
);
4472 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4473 dewtprintk(ioc
, printk(MPT3SAS_FMT
4474 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4475 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4476 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4482 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4483 * @ioc: per adapter object
4484 * @handle: device handle
4485 * Context: interrupt.
4490 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4492 struct fw_event_work
*fw_event
;
4494 fw_event
= alloc_fw_event_work(0);
4497 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4498 fw_event
->device_handle
= handle
;
4499 fw_event
->ioc
= ioc
;
4500 _scsih_fw_event_add(ioc
, fw_event
);
4501 fw_event_work_put(fw_event
);
4505 * _scsih_smart_predicted_fault - process smart errors
4506 * @ioc: per adapter object
4507 * @handle: device handle
4508 * Context: interrupt.
4513 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4515 struct scsi_target
*starget
;
4516 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4517 Mpi2EventNotificationReply_t
*event_reply
;
4518 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4519 struct _sas_device
*sas_device
;
4521 unsigned long flags
;
4523 /* only handle non-raid devices */
4524 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4525 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
4529 starget
= sas_device
->starget
;
4530 sas_target_priv_data
= starget
->hostdata
;
4532 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4533 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
4536 if (sas_device
->enclosure_handle
!= 0)
4537 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4538 "enclosure logical id(0x%016llx), slot(%d)\n",
4539 (unsigned long long)sas_device
->enclosure_logical_id
,
4541 if (sas_device
->connector_name
[0] != '\0')
4542 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4543 "enclosure level(0x%04x), connector name( %s)\n",
4544 sas_device
->enclosure_level
,
4545 sas_device
->connector_name
);
4546 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4548 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4549 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4551 /* insert into event log */
4552 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4553 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4554 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4556 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4557 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4561 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4562 event_reply
->Event
=
4563 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4564 event_reply
->MsgLength
= sz
/4;
4565 event_reply
->EventDataLength
=
4566 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4567 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4568 event_reply
->EventData
;
4569 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4570 event_data
->ASC
= 0x5D;
4571 event_data
->DevHandle
= cpu_to_le16(handle
);
4572 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4573 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4577 sas_device_put(sas_device
);
4581 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4586 * _scsih_io_done - scsi request callback
4587 * @ioc: per adapter object
4588 * @smid: system request message index
4589 * @msix_index: MSIX table index supplied by the OS
4590 * @reply: reply message frame(lower 32bit addr)
4592 * Callback handler when using _scsih_qcmd.
4594 * Return 1 meaning mf should be freed from _base_interrupt
4595 * 0 means the mf is freed from this function.
4598 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4600 Mpi2SCSIIORequest_t
*mpi_request
;
4601 Mpi2SCSIIOReply_t
*mpi_reply
;
4602 struct scsi_cmnd
*scmd
;
4608 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4609 u32 response_code
= 0;
4610 unsigned long flags
;
4612 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4613 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4617 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4619 if (mpi_reply
== NULL
) {
4620 scmd
->result
= DID_OK
<< 16;
4624 sas_device_priv_data
= scmd
->device
->hostdata
;
4625 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4626 sas_device_priv_data
->sas_target
->deleted
) {
4627 scmd
->result
= DID_NO_CONNECT
<< 16;
4630 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4633 * WARPDRIVE: If direct_io is set then it is directIO,
4634 * the failed direct I/O should be redirected to volume
4636 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
4637 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4638 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4639 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4640 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4641 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4642 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
4643 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4644 mpi_request
->DevHandle
=
4645 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4646 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
4647 sas_device_priv_data
->sas_target
->handle
);
4650 /* turning off TLR */
4651 scsi_state
= mpi_reply
->SCSIState
;
4652 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4654 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4655 if (!sas_device_priv_data
->tlr_snoop_check
) {
4656 sas_device_priv_data
->tlr_snoop_check
++;
4657 if (!ioc
->is_warpdrive
&&
4658 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4659 sas_is_tlr_enabled(scmd
->device
) &&
4660 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4661 sas_disable_tlr(scmd
->device
);
4662 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4666 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4667 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4668 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4669 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4672 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4673 scsi_status
= mpi_reply
->SCSIStatus
;
4675 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4676 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4677 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4678 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4679 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4682 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4683 struct sense_info data
;
4684 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4686 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4687 le32_to_cpu(mpi_reply
->SenseCount
));
4688 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4689 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4690 /* failure prediction threshold exceeded */
4691 if (data
.asc
== 0x5D)
4692 _scsih_smart_predicted_fault(ioc
,
4693 le16_to_cpu(mpi_reply
->DevHandle
));
4694 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4696 if (!(ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4697 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4698 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4699 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4700 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4702 switch (ioc_status
) {
4703 case MPI2_IOCSTATUS_BUSY
:
4704 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4705 scmd
->result
= SAM_STAT_BUSY
;
4708 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4709 scmd
->result
= DID_NO_CONNECT
<< 16;
4712 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4713 if (sas_device_priv_data
->block
) {
4714 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4717 if (log_info
== 0x31110630) {
4718 if (scmd
->retries
> 2) {
4719 scmd
->result
= DID_NO_CONNECT
<< 16;
4720 scsi_device_set_state(scmd
->device
,
4723 scmd
->result
= DID_SOFT_ERROR
<< 16;
4724 scmd
->device
->expecting_cc_ua
= 1;
4727 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4728 scmd
->result
= DID_RESET
<< 16;
4731 scmd
->result
= DID_SOFT_ERROR
<< 16;
4733 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4734 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4735 scmd
->result
= DID_RESET
<< 16;
4738 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4739 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4740 scmd
->result
= DID_SOFT_ERROR
<< 16;
4742 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4745 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4746 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4748 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4751 if (xfer_cnt
< scmd
->underflow
) {
4752 if (scsi_status
== SAM_STAT_BUSY
)
4753 scmd
->result
= SAM_STAT_BUSY
;
4755 scmd
->result
= DID_SOFT_ERROR
<< 16;
4756 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4757 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4758 scmd
->result
= DID_SOFT_ERROR
<< 16;
4759 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4760 scmd
->result
= DID_RESET
<< 16;
4761 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4762 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4763 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4764 scmd
->result
= (DRIVER_SENSE
<< 24) |
4765 SAM_STAT_CHECK_CONDITION
;
4766 scmd
->sense_buffer
[0] = 0x70;
4767 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4768 scmd
->sense_buffer
[12] = 0x20;
4769 scmd
->sense_buffer
[13] = 0;
4773 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4774 scsi_set_resid(scmd
, 0);
4775 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4776 case MPI2_IOCSTATUS_SUCCESS
:
4777 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4778 if (response_code
==
4779 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4780 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4781 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4782 scmd
->result
= DID_SOFT_ERROR
<< 16;
4783 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4784 scmd
->result
= DID_RESET
<< 16;
4787 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4788 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4789 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4790 _scsih_eedp_error_handling(scmd
, ioc_status
);
4793 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4794 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4795 case MPI2_IOCSTATUS_INVALID_SGL
:
4796 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4797 case MPI2_IOCSTATUS_INVALID_FIELD
:
4798 case MPI2_IOCSTATUS_INVALID_STATE
:
4799 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4800 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4801 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4803 scmd
->result
= DID_SOFT_ERROR
<< 16;
4808 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4809 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4813 scsi_dma_unmap(scmd
);
4815 scmd
->scsi_done(scmd
);
4820 * _scsih_sas_host_refresh - refreshing sas host object contents
4821 * @ioc: per adapter object
4824 * During port enable, fw will send topology events for every device. Its
4825 * possible that the handles may change from the previous setting, so this
4826 * code keeping handles updating if changed.
4831 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4836 Mpi2ConfigReply_t mpi_reply
;
4837 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4838 u16 attached_handle
;
4841 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4842 "updating handles for sas_host(0x%016llx)\n",
4843 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4845 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4846 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4847 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4848 if (!sas_iounit_pg0
) {
4849 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4850 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4854 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4855 sas_iounit_pg0
, sz
)) != 0)
4857 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4858 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4860 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4861 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4863 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4864 PhyData
[0].ControllerDevHandle
);
4865 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4866 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4868 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4869 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4870 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4871 attached_handle
, i
, link_rate
);
4874 kfree(sas_iounit_pg0
);
4878 * _scsih_sas_host_add - create sas host object
4879 * @ioc: per adapter object
4881 * Creating host side data object, stored in ioc->sas_hba
4886 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4889 Mpi2ConfigReply_t mpi_reply
;
4890 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4891 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4892 Mpi2SasPhyPage0_t phy_pg0
;
4893 Mpi2SasDevicePage0_t sas_device_pg0
;
4894 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4897 u8 device_missing_delay
;
4899 mpt3sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4900 if (!ioc
->sas_hba
.num_phys
) {
4901 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4902 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4906 /* sas_iounit page 0 */
4907 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4908 sizeof(Mpi2SasIOUnit0PhyData_t
));
4909 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4910 if (!sas_iounit_pg0
) {
4911 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4912 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4915 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4916 sas_iounit_pg0
, sz
))) {
4917 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4918 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4921 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4922 MPI2_IOCSTATUS_MASK
;
4923 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4924 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4925 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4929 /* sas_iounit page 1 */
4930 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4931 sizeof(Mpi2SasIOUnit1PhyData_t
));
4932 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4933 if (!sas_iounit_pg1
) {
4934 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4935 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4938 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4939 sas_iounit_pg1
, sz
))) {
4940 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4941 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4944 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4945 MPI2_IOCSTATUS_MASK
;
4946 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4947 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4948 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4952 ioc
->io_missing_delay
=
4953 sas_iounit_pg1
->IODeviceMissingDelay
;
4954 device_missing_delay
=
4955 sas_iounit_pg1
->ReportDeviceMissingDelay
;
4956 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4957 ioc
->device_missing_delay
= (device_missing_delay
&
4958 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4960 ioc
->device_missing_delay
= device_missing_delay
&
4961 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4963 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4964 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4965 sizeof(struct _sas_phy
), GFP_KERNEL
);
4966 if (!ioc
->sas_hba
.phy
) {
4967 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4968 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4971 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4972 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4974 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4975 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4978 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4979 MPI2_IOCSTATUS_MASK
;
4980 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4981 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4982 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4987 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4988 PhyData
[0].ControllerDevHandle
);
4989 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4990 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4991 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4992 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4994 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4995 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4996 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4997 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5000 ioc
->sas_hba
.enclosure_handle
=
5001 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5002 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5004 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5005 ioc
->name
, ioc
->sas_hba
.handle
,
5006 (unsigned long long) ioc
->sas_hba
.sas_address
,
5007 ioc
->sas_hba
.num_phys
) ;
5009 if (ioc
->sas_hba
.enclosure_handle
) {
5010 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5011 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5012 ioc
->sas_hba
.enclosure_handle
)))
5013 ioc
->sas_hba
.enclosure_logical_id
=
5014 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5018 kfree(sas_iounit_pg1
);
5019 kfree(sas_iounit_pg0
);
5023 * _scsih_expander_add - creating expander object
5024 * @ioc: per adapter object
5025 * @handle: expander handle
5027 * Creating expander object, stored in ioc->sas_expander_list.
5029 * Return 0 for success, else error.
5032 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5034 struct _sas_node
*sas_expander
;
5035 Mpi2ConfigReply_t mpi_reply
;
5036 Mpi2ExpanderPage0_t expander_pg0
;
5037 Mpi2ExpanderPage1_t expander_pg1
;
5038 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5041 u64 sas_address
, sas_address_parent
= 0;
5043 unsigned long flags
;
5044 struct _sas_port
*mpt3sas_port
= NULL
;
5051 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5054 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5055 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5056 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5057 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5061 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5062 MPI2_IOCSTATUS_MASK
;
5063 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5064 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5065 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5069 /* handle out of order topology events */
5070 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5071 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5073 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5074 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5077 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5078 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5079 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5080 sas_address_parent
);
5081 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5082 if (!sas_expander
) {
5083 rc
= _scsih_expander_add(ioc
, parent_handle
);
5089 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5090 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5091 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5093 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5098 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5100 if (!sas_expander
) {
5101 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5102 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5106 sas_expander
->handle
= handle
;
5107 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5108 sas_expander
->sas_address_parent
= sas_address_parent
;
5109 sas_expander
->sas_address
= sas_address
;
5111 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5112 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5113 handle
, parent_handle
, (unsigned long long)
5114 sas_expander
->sas_address
, sas_expander
->num_phys
);
5116 if (!sas_expander
->num_phys
)
5118 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5119 sizeof(struct _sas_phy
), GFP_KERNEL
);
5120 if (!sas_expander
->phy
) {
5121 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5122 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5127 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5128 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5129 sas_address_parent
);
5130 if (!mpt3sas_port
) {
5131 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5132 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5136 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5138 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5139 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5140 &expander_pg1
, i
, handle
))) {
5141 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5142 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5146 sas_expander
->phy
[i
].handle
= handle
;
5147 sas_expander
->phy
[i
].phy_id
= i
;
5149 if ((mpt3sas_transport_add_expander_phy(ioc
,
5150 &sas_expander
->phy
[i
], expander_pg1
,
5151 sas_expander
->parent_dev
))) {
5152 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5153 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5159 if (sas_expander
->enclosure_handle
) {
5160 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5161 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5162 sas_expander
->enclosure_handle
)))
5163 sas_expander
->enclosure_logical_id
=
5164 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5167 _scsih_expander_node_add(ioc
, sas_expander
);
5173 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5174 sas_address_parent
);
5175 kfree(sas_expander
);
5180 * mpt3sas_expander_remove - removing expander object
5181 * @ioc: per adapter object
5182 * @sas_address: expander sas_address
5187 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5189 struct _sas_node
*sas_expander
;
5190 unsigned long flags
;
5192 if (ioc
->shost_recovery
)
5195 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5196 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5199 list_del(&sas_expander
->list
);
5200 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5202 _scsih_expander_node_remove(ioc
, sas_expander
);
5206 * _scsih_done - internal SCSI_IO callback handler.
5207 * @ioc: per adapter object
5208 * @smid: system request message index
5209 * @msix_index: MSIX table index supplied by the OS
5210 * @reply: reply message frame(lower 32bit addr)
5212 * Callback handler when sending internal generated SCSI_IO.
5213 * The callback index passed is `ioc->scsih_cb_idx`
5215 * Return 1 meaning mf should be freed from _base_interrupt
5216 * 0 means the mf is freed from this function.
5219 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5221 MPI2DefaultReply_t
*mpi_reply
;
5223 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5224 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5226 if (ioc
->scsih_cmds
.smid
!= smid
)
5228 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5230 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5231 mpi_reply
->MsgLength
*4);
5232 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5234 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5235 complete(&ioc
->scsih_cmds
.done
);
5242 #define MPT3_MAX_LUNS (255)
5246 * _scsih_check_access_status - check access flags
5247 * @ioc: per adapter object
5248 * @sas_address: sas address
5249 * @handle: sas device handle
5250 * @access_flags: errors returned during discovery of the device
5252 * Return 0 for success, else failure
5255 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5256 u16 handle
, u8 access_status
)
5261 switch (access_status
) {
5262 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5263 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5266 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5267 desc
= "sata capability failed";
5269 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5270 desc
= "sata affiliation conflict";
5272 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5273 desc
= "route not addressable";
5275 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5276 desc
= "smp error not addressable";
5278 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5279 desc
= "device blocked";
5281 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5282 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5283 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5284 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5285 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5286 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5287 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5288 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5289 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5290 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5291 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5292 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5293 desc
= "sata initialization failed";
5304 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5305 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5310 * _scsih_check_device - checking device responsiveness
5311 * @ioc: per adapter object
5312 * @parent_sas_address: sas address of parent expander or sas host
5313 * @handle: attached device handle
5314 * @phy_numberv: phy number
5315 * @link_rate: new link rate
5320 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5321 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5323 Mpi2ConfigReply_t mpi_reply
;
5324 Mpi2SasDevicePage0_t sas_device_pg0
;
5325 struct _sas_device
*sas_device
;
5327 unsigned long flags
;
5329 struct scsi_target
*starget
;
5330 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5334 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5335 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5338 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5339 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5342 /* wide port handling ~ we need only handle device once for the phy that
5343 * is matched in sas device page zero
5345 if (phy_number
!= sas_device_pg0
.PhyNum
)
5348 /* check if this is end device */
5349 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5350 if (!(_scsih_is_end_device(device_info
)))
5353 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5354 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5355 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5361 if (unlikely(sas_device
->handle
!= handle
)) {
5362 starget
= sas_device
->starget
;
5363 sas_target_priv_data
= starget
->hostdata
;
5364 starget_printk(KERN_INFO
, starget
,
5365 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5366 sas_device
->handle
, handle
);
5367 sas_target_priv_data
->handle
= handle
;
5368 sas_device
->handle
= handle
;
5369 if (sas_device_pg0
.Flags
&
5370 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5371 sas_device
->enclosure_level
=
5372 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5373 memcpy(&sas_device
->connector_name
[0],
5374 &sas_device_pg0
.ConnectorName
[0], 4);
5376 sas_device
->enclosure_level
= 0;
5377 sas_device
->connector_name
[0] = '\0';
5381 /* check if device is present */
5382 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5383 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5385 "device is not present handle(0x%04x), flags!!!\n",
5390 /* check if there were any issues with discovery */
5391 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5392 sas_device_pg0
.AccessStatus
))
5395 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5396 _scsih_ublock_io_device(ioc
, sas_address
);
5399 sas_device_put(sas_device
);
5403 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5405 sas_device_put(sas_device
);
5409 * _scsih_add_device - creating sas device object
5410 * @ioc: per adapter object
5411 * @handle: sas device handle
5412 * @phy_num: phy number end device attached to
5413 * @is_pd: is this hidden raid component
5415 * Creating end device object, stored in ioc->sas_device_list.
5417 * Returns 0 for success, non-zero for failure.
5420 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
5423 Mpi2ConfigReply_t mpi_reply
;
5424 Mpi2SasDevicePage0_t sas_device_pg0
;
5425 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5426 struct _sas_device
*sas_device
;
5431 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5432 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5433 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5434 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5438 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5439 MPI2_IOCSTATUS_MASK
;
5440 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5441 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5442 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5446 /* check if this is end device */
5447 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5448 if (!(_scsih_is_end_device(device_info
)))
5450 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5452 /* check if device is present */
5453 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5454 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5455 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5460 /* check if there were any issues with discovery */
5461 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5462 sas_device_pg0
.AccessStatus
))
5465 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
5468 sas_device_put(sas_device
);
5472 sas_device
= kzalloc(sizeof(struct _sas_device
),
5475 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5476 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5480 kref_init(&sas_device
->refcount
);
5481 sas_device
->handle
= handle
;
5482 if (_scsih_get_sas_address(ioc
,
5483 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5484 &sas_device
->sas_address_parent
) != 0)
5485 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5486 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5487 sas_device
->enclosure_handle
=
5488 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5489 if (sas_device
->enclosure_handle
!= 0)
5491 le16_to_cpu(sas_device_pg0
.Slot
);
5492 sas_device
->device_info
= device_info
;
5493 sas_device
->sas_address
= sas_address
;
5494 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5495 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5496 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5498 if (sas_device_pg0
.Flags
& MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5499 sas_device
->enclosure_level
=
5500 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5501 memcpy(&sas_device
->connector_name
[0],
5502 &sas_device_pg0
.ConnectorName
[0], 4);
5504 sas_device
->enclosure_level
= 0;
5505 sas_device
->connector_name
[0] = '\0';
5507 /* get enclosure_logical_id */
5508 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5509 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5510 sas_device
->enclosure_handle
)))
5511 sas_device
->enclosure_logical_id
=
5512 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5514 /* get device name */
5515 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5517 if (ioc
->wait_for_discovery_to_complete
)
5518 _scsih_sas_device_init_add(ioc
, sas_device
);
5520 _scsih_sas_device_add(ioc
, sas_device
);
5522 sas_device_put(sas_device
);
5527 * _scsih_remove_device - removing sas device object
5528 * @ioc: per adapter object
5529 * @sas_device_delete: the sas_device object
5534 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5535 struct _sas_device
*sas_device
)
5537 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5539 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5540 (sas_device
->pfa_led_on
)) {
5541 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5542 sas_device
->pfa_led_on
= 0;
5544 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5545 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5546 ioc
->name
, __func__
,
5547 sas_device
->handle
, (unsigned long long)
5548 sas_device
->sas_address
));
5549 if (sas_device
->enclosure_handle
!= 0)
5550 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5551 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5552 ioc
->name
, __func__
,
5553 (unsigned long long)sas_device
->enclosure_logical_id
,
5555 if (sas_device
->connector_name
[0] != '\0')
5556 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5557 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5558 ioc
->name
, __func__
,
5559 sas_device
->enclosure_level
,
5560 sas_device
->connector_name
));
5562 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5563 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5564 sas_target_priv_data
->deleted
= 1;
5565 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5566 sas_target_priv_data
->handle
=
5567 MPT3SAS_INVALID_DEVICE_HANDLE
;
5570 if (!ioc
->hide_drives
)
5571 mpt3sas_transport_port_remove(ioc
,
5572 sas_device
->sas_address
,
5573 sas_device
->sas_address_parent
);
5576 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5577 ioc
->name
, sas_device
->handle
,
5578 (unsigned long long) sas_device
->sas_address
);
5579 if (sas_device
->enclosure_handle
!= 0)
5581 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5583 (unsigned long long)sas_device
->enclosure_logical_id
,
5585 if (sas_device
->connector_name
[0] != '\0')
5587 "removing enclosure level(0x%04x), connector name( %s)\n",
5588 ioc
->name
, sas_device
->enclosure_level
,
5589 sas_device
->connector_name
);
5591 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5592 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5593 ioc
->name
, __func__
,
5594 sas_device
->handle
, (unsigned long long)
5595 sas_device
->sas_address
));
5596 if (sas_device
->enclosure_handle
!= 0)
5597 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5598 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5599 ioc
->name
, __func__
,
5600 (unsigned long long)sas_device
->enclosure_logical_id
,
5602 if (sas_device
->connector_name
[0] != '\0')
5603 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5604 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5605 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5606 sas_device
->connector_name
));
5610 * _scsih_sas_topology_change_event_debug - debug for topology event
5611 * @ioc: per adapter object
5612 * @event_data: event data payload
5616 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5617 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5623 char *status_str
= NULL
;
5624 u8 link_rate
, prev_link_rate
;
5626 switch (event_data
->ExpStatus
) {
5627 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5630 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5631 status_str
= "remove";
5633 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5635 status_str
= "responding";
5637 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5638 status_str
= "remove delay";
5641 status_str
= "unknown status";
5644 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5645 ioc
->name
, status_str
);
5646 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5647 "start_phy(%02d), count(%d)\n",
5648 le16_to_cpu(event_data
->ExpanderDevHandle
),
5649 le16_to_cpu(event_data
->EnclosureHandle
),
5650 event_data
->StartPhyNum
, event_data
->NumEntries
);
5651 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5652 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5655 phy_number
= event_data
->StartPhyNum
+ i
;
5656 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5657 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5658 switch (reason_code
) {
5659 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5660 status_str
= "target add";
5662 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5663 status_str
= "target remove";
5665 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5666 status_str
= "delay target remove";
5668 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5669 status_str
= "link rate change";
5671 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5672 status_str
= "target responding";
5675 status_str
= "unknown";
5678 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5679 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5680 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5681 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5682 handle
, status_str
, link_rate
, prev_link_rate
);
5688 * _scsih_sas_topology_change_event - handle topology changes
5689 * @ioc: per adapter object
5690 * @fw_event: The fw_event_work object
5695 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5696 struct fw_event_work
*fw_event
)
5699 u16 parent_handle
, handle
;
5701 u8 phy_number
, max_phys
;
5702 struct _sas_node
*sas_expander
;
5704 unsigned long flags
;
5705 u8 link_rate
, prev_link_rate
;
5706 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5707 (Mpi2EventDataSasTopologyChangeList_t
*)
5708 fw_event
->event_data
;
5710 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5711 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5713 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5716 if (!ioc
->sas_hba
.num_phys
)
5717 _scsih_sas_host_add(ioc
);
5719 _scsih_sas_host_refresh(ioc
);
5721 if (fw_event
->ignore
) {
5722 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5723 "ignoring expander event\n", ioc
->name
));
5727 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5729 /* handle expander add */
5730 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5731 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5734 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5735 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5738 sas_address
= sas_expander
->sas_address
;
5739 max_phys
= sas_expander
->num_phys
;
5740 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5741 sas_address
= ioc
->sas_hba
.sas_address
;
5742 max_phys
= ioc
->sas_hba
.num_phys
;
5744 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5747 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5749 /* handle siblings events */
5750 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5751 if (fw_event
->ignore
) {
5752 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5753 "ignoring expander event\n", ioc
->name
));
5756 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5758 phy_number
= event_data
->StartPhyNum
+ i
;
5759 if (phy_number
>= max_phys
)
5761 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5762 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5763 if ((event_data
->PHY
[i
].PhyStatus
&
5764 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5765 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5767 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5770 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5771 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5772 switch (reason_code
) {
5773 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5775 if (ioc
->shost_recovery
)
5778 if (link_rate
== prev_link_rate
)
5781 mpt3sas_transport_update_links(ioc
, sas_address
,
5782 handle
, phy_number
, link_rate
);
5784 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5787 _scsih_check_device(ioc
, sas_address
, handle
,
5788 phy_number
, link_rate
);
5791 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5793 if (ioc
->shost_recovery
)
5796 mpt3sas_transport_update_links(ioc
, sas_address
,
5797 handle
, phy_number
, link_rate
);
5799 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5802 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5804 _scsih_device_remove_by_handle(ioc
, handle
);
5809 /* handle expander removal */
5810 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5812 mpt3sas_expander_remove(ioc
, sas_address
);
5818 * _scsih_sas_device_status_change_event_debug - debug for device event
5819 * @event_data: event data payload
5825 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5826 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5828 char *reason_str
= NULL
;
5830 switch (event_data
->ReasonCode
) {
5831 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5832 reason_str
= "smart data";
5834 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5835 reason_str
= "unsupported device discovered";
5837 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5838 reason_str
= "internal device reset";
5840 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5841 reason_str
= "internal task abort";
5843 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5844 reason_str
= "internal task abort set";
5846 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5847 reason_str
= "internal clear task set";
5849 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5850 reason_str
= "internal query task";
5852 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5853 reason_str
= "sata init failure";
5855 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5856 reason_str
= "internal device reset complete";
5858 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5859 reason_str
= "internal task abort complete";
5861 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5862 reason_str
= "internal async notification";
5864 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5865 reason_str
= "expander reduced functionality";
5867 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5868 reason_str
= "expander reduced functionality complete";
5871 reason_str
= "unknown reason";
5874 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5875 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5876 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5877 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5878 le16_to_cpu(event_data
->TaskTag
));
5879 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5880 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5881 event_data
->ASC
, event_data
->ASCQ
);
5886 * _scsih_sas_device_status_change_event - handle device status change
5887 * @ioc: per adapter object
5888 * @fw_event: The fw_event_work object
5894 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5895 struct fw_event_work
*fw_event
)
5897 struct MPT3SAS_TARGET
*target_priv_data
;
5898 struct _sas_device
*sas_device
;
5900 unsigned long flags
;
5901 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5902 (Mpi2EventDataSasDeviceStatusChange_t
*)
5903 fw_event
->event_data
;
5905 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5906 _scsih_sas_device_status_change_event_debug(ioc
,
5909 /* In MPI Revision K (0xC), the internal device reset complete was
5910 * implemented, so avoid setting tm_busy flag for older firmware.
5912 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5915 if (event_data
->ReasonCode
!=
5916 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5917 event_data
->ReasonCode
!=
5918 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5921 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5922 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5923 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5926 if (!sas_device
|| !sas_device
->starget
)
5929 target_priv_data
= sas_device
->starget
->hostdata
;
5930 if (!target_priv_data
)
5933 if (event_data
->ReasonCode
==
5934 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5935 target_priv_data
->tm_busy
= 1;
5937 target_priv_data
->tm_busy
= 0;
5941 sas_device_put(sas_device
);
5943 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5948 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5950 * @ioc: per adapter object
5951 * @event_data: event data payload
5957 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5958 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5960 char *reason_str
= NULL
;
5962 switch (event_data
->ReasonCode
) {
5963 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5964 reason_str
= "enclosure add";
5966 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5967 reason_str
= "enclosure remove";
5970 reason_str
= "unknown reason";
5974 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
5975 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5976 " number slots(%d)\n", ioc
->name
, reason_str
,
5977 le16_to_cpu(event_data
->EnclosureHandle
),
5978 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5979 le16_to_cpu(event_data
->StartSlot
));
5983 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5984 * @ioc: per adapter object
5985 * @fw_event: The fw_event_work object
5991 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5992 struct fw_event_work
*fw_event
)
5994 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5995 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5996 (Mpi2EventDataSasEnclDevStatusChange_t
*)
5997 fw_event
->event_data
);
6001 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6002 * @ioc: per adapter object
6003 * @fw_event: The fw_event_work object
6009 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
6010 struct fw_event_work
*fw_event
)
6012 struct scsi_cmnd
*scmd
;
6013 struct scsi_device
*sdev
;
6016 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6017 u32 termination_count
;
6019 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
6020 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
6021 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6022 fw_event
->event_data
;
6024 unsigned long flags
;
6027 u8 task_abort_retries
;
6029 mutex_lock(&ioc
->tm_cmds
.mutex
);
6031 "%s: enter: phy number(%d), width(%d)\n",
6032 ioc
->name
, __func__
, event_data
->PhyNum
,
6033 event_data
->PortWidth
);
6035 _scsih_block_io_all_device(ioc
);
6037 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6038 mpi_reply
= ioc
->tm_cmds
.reply
;
6039 broadcast_aen_retry
:
6041 /* sanity checks for retrying this loop */
6042 if (max_retries
++ == 5) {
6043 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
6044 ioc
->name
, __func__
));
6046 } else if (max_retries
> 1)
6047 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
6048 ioc
->name
, __func__
, max_retries
- 1));
6050 termination_count
= 0;
6052 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
6053 if (ioc
->shost_recovery
)
6055 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
6058 sdev
= scmd
->device
;
6059 sas_device_priv_data
= sdev
->hostdata
;
6060 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
6062 /* skip hidden raid components */
6063 if (sas_device_priv_data
->sas_target
->flags
&
6064 MPT_TARGET_FLAGS_RAID_COMPONENT
)
6067 if (sas_device_priv_data
->sas_target
->flags
&
6068 MPT_TARGET_FLAGS_VOLUME
)
6071 handle
= sas_device_priv_data
->sas_target
->handle
;
6072 lun
= sas_device_priv_data
->lun
;
6075 if (ioc
->shost_recovery
)
6078 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6079 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
6080 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
6083 sdev_printk(KERN_WARNING
, sdev
,
6084 "mpt3sas_scsih_issue_tm: FAILED when sending "
6085 "QUERY_TASK: scmd(%p)\n", scmd
);
6086 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6087 goto broadcast_aen_retry
;
6089 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
6090 & MPI2_IOCSTATUS_MASK
;
6091 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6092 sdev_printk(KERN_WARNING
, sdev
,
6093 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6095 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6096 goto broadcast_aen_retry
;
6099 /* see if IO is still owned by IOC and target */
6100 if (mpi_reply
->ResponseCode
==
6101 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
6102 mpi_reply
->ResponseCode
==
6103 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
6104 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6107 task_abort_retries
= 0;
6109 if (task_abort_retries
++ == 60) {
6110 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6111 "%s: ABORT_TASK: giving up\n", ioc
->name
,
6113 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6114 goto broadcast_aen_retry
;
6117 if (ioc
->shost_recovery
)
6120 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
6121 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
6124 sdev_printk(KERN_WARNING
, sdev
,
6125 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6126 "scmd(%p)\n", scmd
);
6130 if (task_abort_retries
> 1)
6131 sdev_printk(KERN_WARNING
, sdev
,
6132 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6134 task_abort_retries
- 1, scmd
);
6136 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
6137 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6140 if (ioc
->broadcast_aen_pending
) {
6141 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6142 "%s: loop back due to pending AEN\n",
6143 ioc
->name
, __func__
));
6144 ioc
->broadcast_aen_pending
= 0;
6145 goto broadcast_aen_retry
;
6149 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6152 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6153 "%s - exit, query_count = %d termination_count = %d\n",
6154 ioc
->name
, __func__
, query_count
, termination_count
));
6156 ioc
->broadcast_aen_busy
= 0;
6157 if (!ioc
->shost_recovery
)
6158 _scsih_ublock_io_all_device(ioc
);
6159 mutex_unlock(&ioc
->tm_cmds
.mutex
);
6163 * _scsih_sas_discovery_event - handle discovery events
6164 * @ioc: per adapter object
6165 * @fw_event: The fw_event_work object
6171 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
6172 struct fw_event_work
*fw_event
)
6174 Mpi2EventDataSasDiscovery_t
*event_data
=
6175 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
6177 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
6178 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
6179 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
6181 if (event_data
->DiscoveryStatus
)
6182 pr_info("discovery_status(0x%08x)",
6183 le32_to_cpu(event_data
->DiscoveryStatus
));
6187 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
6188 !ioc
->sas_hba
.num_phys
) {
6189 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6190 /* Wait for the reset to complete */
6191 while (ioc
->shost_recovery
)
6194 _scsih_sas_host_add(ioc
);
6199 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6200 * @ioc: per adapter object
6201 * @handle: device handle for physical disk
6202 * @phys_disk_num: physical disk number
6204 * Return 0 for success, else failure.
6207 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
6209 Mpi2RaidActionRequest_t
*mpi_request
;
6210 Mpi2RaidActionReply_t
*mpi_reply
;
6217 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
6220 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6222 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
6223 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
6224 ioc
->name
, __func__
);
6228 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
6230 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6232 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
6233 ioc
->name
, __func__
);
6234 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6239 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
6240 ioc
->scsih_cmds
.smid
= smid
;
6241 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6243 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6244 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
6245 mpi_request
->PhysDiskNum
= phys_disk_num
;
6247 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
6248 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
6249 handle
, phys_disk_num
));
6251 init_completion(&ioc
->scsih_cmds
.done
);
6252 mpt3sas_base_put_smid_default(ioc
, smid
);
6253 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6255 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
6256 pr_err(MPT3SAS_FMT
"%s: timeout\n",
6257 ioc
->name
, __func__
);
6258 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
6264 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
6266 mpi_reply
= ioc
->scsih_cmds
.reply
;
6267 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
6268 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
6269 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
6272 ioc_status
&= MPI2_IOCSTATUS_MASK
;
6273 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6274 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6275 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6276 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
6280 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6281 "IR RAID_ACTION: completed successfully\n",
6286 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6287 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6290 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
6296 * _scsih_reprobe_lun - reprobing lun
6297 * @sdev: scsi device struct
6298 * @no_uld_attach: sdev->no_uld_attach flag setting
6302 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6305 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6306 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6307 sdev
->no_uld_attach
? "hidding" : "exposing");
6308 rc
= scsi_device_reprobe(sdev
);
6312 * _scsih_sas_volume_add - add new volume
6313 * @ioc: per adapter object
6314 * @element: IR config element data
6320 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
6321 Mpi2EventIrConfigElement_t
*element
)
6323 struct _raid_device
*raid_device
;
6324 unsigned long flags
;
6326 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6329 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6332 "failure at %s:%d/%s()!\n", ioc
->name
,
6333 __FILE__
, __LINE__
, __func__
);
6337 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6338 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6339 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6344 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6347 "failure at %s:%d/%s()!\n", ioc
->name
,
6348 __FILE__
, __LINE__
, __func__
);
6352 raid_device
->id
= ioc
->sas_id
++;
6353 raid_device
->channel
= RAID_CHANNEL
;
6354 raid_device
->handle
= handle
;
6355 raid_device
->wwid
= wwid
;
6356 _scsih_raid_device_add(ioc
, raid_device
);
6357 if (!ioc
->wait_for_discovery_to_complete
) {
6358 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6359 raid_device
->id
, 0);
6361 _scsih_raid_device_remove(ioc
, raid_device
);
6363 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6364 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6365 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6370 * _scsih_sas_volume_delete - delete volume
6371 * @ioc: per adapter object
6372 * @handle: volume device handle
6378 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6380 struct _raid_device
*raid_device
;
6381 unsigned long flags
;
6382 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6383 struct scsi_target
*starget
= NULL
;
6385 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6386 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6388 if (raid_device
->starget
) {
6389 starget
= raid_device
->starget
;
6390 sas_target_priv_data
= starget
->hostdata
;
6391 sas_target_priv_data
->deleted
= 1;
6393 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
6394 ioc
->name
, raid_device
->handle
,
6395 (unsigned long long) raid_device
->wwid
);
6396 list_del(&raid_device
->list
);
6399 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6401 scsi_remove_target(&starget
->dev
);
6405 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6406 * @ioc: per adapter object
6407 * @element: IR config element data
6413 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6414 Mpi2EventIrConfigElement_t
*element
)
6416 struct _sas_device
*sas_device
;
6417 struct scsi_target
*starget
= NULL
;
6418 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6419 unsigned long flags
;
6420 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6422 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6423 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6425 sas_device
->volume_handle
= 0;
6426 sas_device
->volume_wwid
= 0;
6427 clear_bit(handle
, ioc
->pd_handles
);
6428 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6429 starget
= sas_device
->starget
;
6430 sas_target_priv_data
= starget
->hostdata
;
6431 sas_target_priv_data
->flags
&=
6432 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6435 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6439 /* exposing raid component */
6441 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6443 sas_device_put(sas_device
);
6447 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6448 * @ioc: per adapter object
6449 * @element: IR config element data
6455 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6456 Mpi2EventIrConfigElement_t
*element
)
6458 struct _sas_device
*sas_device
;
6459 struct scsi_target
*starget
= NULL
;
6460 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6461 unsigned long flags
;
6462 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6463 u16 volume_handle
= 0;
6464 u64 volume_wwid
= 0;
6466 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6468 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6471 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6472 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6474 set_bit(handle
, ioc
->pd_handles
);
6475 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6476 starget
= sas_device
->starget
;
6477 sas_target_priv_data
= starget
->hostdata
;
6478 sas_target_priv_data
->flags
|=
6479 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6480 sas_device
->volume_handle
= volume_handle
;
6481 sas_device
->volume_wwid
= volume_wwid
;
6484 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6488 /* hiding raid component */
6489 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6492 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6494 sas_device_put(sas_device
);
6498 * _scsih_sas_pd_delete - delete pd component
6499 * @ioc: per adapter object
6500 * @element: IR config element data
6506 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6507 Mpi2EventIrConfigElement_t
*element
)
6509 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6511 _scsih_device_remove_by_handle(ioc
, handle
);
6515 * _scsih_sas_pd_add - remove pd component
6516 * @ioc: per adapter object
6517 * @element: IR config element data
6523 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6524 Mpi2EventIrConfigElement_t
*element
)
6526 struct _sas_device
*sas_device
;
6527 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6528 Mpi2ConfigReply_t mpi_reply
;
6529 Mpi2SasDevicePage0_t sas_device_pg0
;
6534 set_bit(handle
, ioc
->pd_handles
);
6536 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6538 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6539 sas_device_put(sas_device
);
6543 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6544 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6545 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6546 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6550 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6551 MPI2_IOCSTATUS_MASK
;
6552 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6553 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6554 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6558 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6559 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6560 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6561 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6563 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6564 _scsih_add_device(ioc
, handle
, 0, 1);
6568 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6569 * @ioc: per adapter object
6570 * @event_data: event data payload
6576 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6577 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6579 Mpi2EventIrConfigElement_t
*element
;
6582 char *reason_str
= NULL
, *element_str
= NULL
;
6584 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6586 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6587 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6588 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6589 "foreign" : "native", event_data
->NumElements
);
6590 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6591 switch (element
->ReasonCode
) {
6592 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6595 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6596 reason_str
= "remove";
6598 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6599 reason_str
= "no change";
6601 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6602 reason_str
= "hide";
6604 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6605 reason_str
= "unhide";
6607 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6608 reason_str
= "volume_created";
6610 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6611 reason_str
= "volume_deleted";
6613 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6614 reason_str
= "pd_created";
6616 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6617 reason_str
= "pd_deleted";
6620 reason_str
= "unknown reason";
6623 element_type
= le16_to_cpu(element
->ElementFlags
) &
6624 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6625 switch (element_type
) {
6626 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6627 element_str
= "volume";
6629 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6630 element_str
= "phys disk";
6632 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6633 element_str
= "hot spare";
6636 element_str
= "unknown element";
6639 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6640 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6641 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6642 le16_to_cpu(element
->PhysDiskDevHandle
),
6643 element
->PhysDiskNum
);
6648 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6649 * @ioc: per adapter object
6650 * @fw_event: The fw_event_work object
6656 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6657 struct fw_event_work
*fw_event
)
6659 Mpi2EventIrConfigElement_t
*element
;
6662 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6663 (Mpi2EventDataIrConfigChangeList_t
*)
6664 fw_event
->event_data
;
6666 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6667 (!ioc
->hide_ir_msg
))
6668 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6670 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6671 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6673 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6674 if (ioc
->shost_recovery
&&
6675 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
6676 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6677 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6678 _scsih_ir_fastpath(ioc
,
6679 le16_to_cpu(element
->PhysDiskDevHandle
),
6680 element
->PhysDiskNum
);
6685 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6687 switch (element
->ReasonCode
) {
6688 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6689 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6690 if (!foreign_config
)
6691 _scsih_sas_volume_add(ioc
, element
);
6693 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6694 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6695 if (!foreign_config
)
6696 _scsih_sas_volume_delete(ioc
,
6697 le16_to_cpu(element
->VolDevHandle
));
6699 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6700 if (!ioc
->is_warpdrive
)
6701 _scsih_sas_pd_hide(ioc
, element
);
6703 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6704 if (!ioc
->is_warpdrive
)
6705 _scsih_sas_pd_expose(ioc
, element
);
6707 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6708 if (!ioc
->is_warpdrive
)
6709 _scsih_sas_pd_add(ioc
, element
);
6711 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6712 if (!ioc
->is_warpdrive
)
6713 _scsih_sas_pd_delete(ioc
, element
);
6720 * _scsih_sas_ir_volume_event - IR volume event
6721 * @ioc: per adapter object
6722 * @fw_event: The fw_event_work object
6728 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6729 struct fw_event_work
*fw_event
)
6732 unsigned long flags
;
6733 struct _raid_device
*raid_device
;
6737 Mpi2EventDataIrVolume_t
*event_data
=
6738 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6740 if (ioc
->shost_recovery
)
6743 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6746 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6747 state
= le32_to_cpu(event_data
->NewValue
);
6748 if (!ioc
->hide_ir_msg
)
6749 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6750 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6751 ioc
->name
, __func__
, handle
,
6752 le32_to_cpu(event_data
->PreviousValue
), state
));
6754 case MPI2_RAID_VOL_STATE_MISSING
:
6755 case MPI2_RAID_VOL_STATE_FAILED
:
6756 _scsih_sas_volume_delete(ioc
, handle
);
6759 case MPI2_RAID_VOL_STATE_ONLINE
:
6760 case MPI2_RAID_VOL_STATE_DEGRADED
:
6761 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6763 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6764 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6765 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6770 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6773 "failure at %s:%d/%s()!\n", ioc
->name
,
6774 __FILE__
, __LINE__
, __func__
);
6778 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6781 "failure at %s:%d/%s()!\n", ioc
->name
,
6782 __FILE__
, __LINE__
, __func__
);
6786 raid_device
->id
= ioc
->sas_id
++;
6787 raid_device
->channel
= RAID_CHANNEL
;
6788 raid_device
->handle
= handle
;
6789 raid_device
->wwid
= wwid
;
6790 _scsih_raid_device_add(ioc
, raid_device
);
6791 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6792 raid_device
->id
, 0);
6794 _scsih_raid_device_remove(ioc
, raid_device
);
6797 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6804 * _scsih_sas_ir_physical_disk_event - PD event
6805 * @ioc: per adapter object
6806 * @fw_event: The fw_event_work object
6812 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6813 struct fw_event_work
*fw_event
)
6815 u16 handle
, parent_handle
;
6817 struct _sas_device
*sas_device
;
6818 Mpi2ConfigReply_t mpi_reply
;
6819 Mpi2SasDevicePage0_t sas_device_pg0
;
6821 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6822 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6825 if (ioc
->shost_recovery
)
6828 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6831 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6832 state
= le32_to_cpu(event_data
->NewValue
);
6834 if (!ioc
->hide_ir_msg
)
6835 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6836 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6837 ioc
->name
, __func__
, handle
,
6838 le32_to_cpu(event_data
->PreviousValue
), state
));
6841 case MPI2_RAID_PD_STATE_ONLINE
:
6842 case MPI2_RAID_PD_STATE_DEGRADED
:
6843 case MPI2_RAID_PD_STATE_REBUILDING
:
6844 case MPI2_RAID_PD_STATE_OPTIMAL
:
6845 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6847 if (!ioc
->is_warpdrive
)
6848 set_bit(handle
, ioc
->pd_handles
);
6850 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6852 sas_device_put(sas_device
);
6856 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6857 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6859 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6860 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6864 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6865 MPI2_IOCSTATUS_MASK
;
6866 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6867 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6868 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6872 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6873 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6874 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6875 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6877 _scsih_add_device(ioc
, handle
, 0, 1);
6881 case MPI2_RAID_PD_STATE_OFFLINE
:
6882 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6883 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6890 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6891 * @ioc: per adapter object
6892 * @event_data: event data payload
6898 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6899 Mpi2EventDataIrOperationStatus_t
*event_data
)
6901 char *reason_str
= NULL
;
6903 switch (event_data
->RAIDOperation
) {
6904 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6905 reason_str
= "resync";
6907 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6908 reason_str
= "online capacity expansion";
6910 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6911 reason_str
= "consistency check";
6913 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6914 reason_str
= "background init";
6916 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6917 reason_str
= "make data consistent";
6924 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6925 "\thandle(0x%04x), percent complete(%d)\n",
6926 ioc
->name
, reason_str
,
6927 le16_to_cpu(event_data
->VolDevHandle
),
6928 event_data
->PercentComplete
);
6932 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6933 * @ioc: per adapter object
6934 * @fw_event: The fw_event_work object
6940 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
6941 struct fw_event_work
*fw_event
)
6943 Mpi2EventDataIrOperationStatus_t
*event_data
=
6944 (Mpi2EventDataIrOperationStatus_t
*)
6945 fw_event
->event_data
;
6946 static struct _raid_device
*raid_device
;
6947 unsigned long flags
;
6950 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6951 (!ioc
->hide_ir_msg
))
6952 _scsih_sas_ir_operation_status_event_debug(ioc
,
6955 /* code added for raid transport support */
6956 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6958 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6959 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6960 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6962 raid_device
->percent_complete
=
6963 event_data
->PercentComplete
;
6964 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6969 * _scsih_prep_device_scan - initialize parameters prior to device scan
6970 * @ioc: per adapter object
6972 * Set the deleted flag prior to device scan. If the device is found during
6973 * the scan, then we clear the deleted flag.
6976 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
6978 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6979 struct scsi_device
*sdev
;
6981 shost_for_each_device(sdev
, ioc
->shost
) {
6982 sas_device_priv_data
= sdev
->hostdata
;
6983 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6984 sas_device_priv_data
->sas_target
->deleted
= 1;
6989 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6990 * @ioc: per adapter object
6991 * @sas_device_pg0: SAS Device page 0
6993 * After host reset, find out whether devices are still responding.
6994 * Used in _scsih_remove_unresponsive_sas_devices.
6999 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
7000 Mpi2SasDevicePage0_t
*sas_device_pg0
)
7002 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7003 struct scsi_target
*starget
;
7004 struct _sas_device
*sas_device
;
7005 unsigned long flags
;
7007 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7008 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
7009 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
7010 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
7011 sas_device
->responding
= 1;
7012 starget
= sas_device
->starget
;
7013 if (starget
&& starget
->hostdata
) {
7014 sas_target_priv_data
= starget
->hostdata
;
7015 sas_target_priv_data
->tm_busy
= 0;
7016 sas_target_priv_data
->deleted
= 0;
7018 sas_target_priv_data
= NULL
;
7020 starget_printk(KERN_INFO
, starget
,
7021 "handle(0x%04x), sas_addr(0x%016llx)\n",
7022 sas_device_pg0
->DevHandle
,
7023 (unsigned long long)
7024 sas_device
->sas_address
);
7026 if (sas_device
->enclosure_handle
!= 0)
7027 starget_printk(KERN_INFO
, starget
,
7028 "enclosure logical id(0x%016llx),"
7030 (unsigned long long)
7031 sas_device
->enclosure_logical_id
,
7034 if (sas_device_pg0
->Flags
&
7035 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
7036 sas_device
->enclosure_level
=
7037 le16_to_cpu(sas_device_pg0
->EnclosureLevel
);
7038 memcpy(&sas_device
->connector_name
[0],
7039 &sas_device_pg0
->ConnectorName
[0], 4);
7041 sas_device
->enclosure_level
= 0;
7042 sas_device
->connector_name
[0] = '\0';
7045 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
7047 pr_info("\thandle changed from(0x%04x)!!!\n",
7048 sas_device
->handle
);
7049 sas_device
->handle
= sas_device_pg0
->DevHandle
;
7050 if (sas_target_priv_data
)
7051 sas_target_priv_data
->handle
=
7052 sas_device_pg0
->DevHandle
;
7057 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7061 * _scsih_search_responding_sas_devices -
7062 * @ioc: per adapter object
7064 * After host reset, find out whether devices are still responding.
7070 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7072 Mpi2SasDevicePage0_t sas_device_pg0
;
7073 Mpi2ConfigReply_t mpi_reply
;
7078 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
7080 if (list_empty(&ioc
->sas_device_list
))
7084 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7085 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7087 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7088 MPI2_IOCSTATUS_MASK
;
7089 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7091 handle
= sas_device_pg0
.DevHandle
=
7092 le16_to_cpu(sas_device_pg0
.DevHandle
);
7093 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
7094 if (!(_scsih_is_end_device(device_info
)))
7096 sas_device_pg0
.SASAddress
=
7097 le64_to_cpu(sas_device_pg0
.SASAddress
);
7098 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
7099 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
7103 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
7108 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7109 * @ioc: per adapter object
7110 * @wwid: world wide identifier for raid volume
7111 * @handle: device handle
7113 * After host reset, find out whether devices are still responding.
7114 * Used in _scsih_remove_unresponsive_raid_devices.
7119 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
7122 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7123 struct scsi_target
*starget
;
7124 struct _raid_device
*raid_device
;
7125 unsigned long flags
;
7127 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7128 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
7129 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
7130 starget
= raid_device
->starget
;
7131 if (starget
&& starget
->hostdata
) {
7132 sas_target_priv_data
= starget
->hostdata
;
7133 sas_target_priv_data
->deleted
= 0;
7135 sas_target_priv_data
= NULL
;
7136 raid_device
->responding
= 1;
7137 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7138 starget_printk(KERN_INFO
, raid_device
->starget
,
7139 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
7140 (unsigned long long)raid_device
->wwid
);
7143 * WARPDRIVE: The handles of the PDs might have changed
7144 * across the host reset so re-initialize the
7145 * required data for Direct IO
7147 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
7148 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7149 if (raid_device
->handle
== handle
) {
7150 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
7154 pr_info("\thandle changed from(0x%04x)!!!\n",
7155 raid_device
->handle
);
7156 raid_device
->handle
= handle
;
7157 if (sas_target_priv_data
)
7158 sas_target_priv_data
->handle
= handle
;
7159 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7163 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7167 * _scsih_search_responding_raid_devices -
7168 * @ioc: per adapter object
7170 * After host reset, find out whether devices are still responding.
7176 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
7178 Mpi2RaidVolPage1_t volume_pg1
;
7179 Mpi2RaidVolPage0_t volume_pg0
;
7180 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7181 Mpi2ConfigReply_t mpi_reply
;
7186 if (!ioc
->ir_firmware
)
7189 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
7192 if (list_empty(&ioc
->raid_device_list
))
7196 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7197 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7198 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7199 MPI2_IOCSTATUS_MASK
;
7200 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7202 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7204 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7205 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7206 sizeof(Mpi2RaidVolPage0_t
)))
7209 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7210 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7211 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
7212 _scsih_mark_responding_raid_device(ioc
,
7213 le64_to_cpu(volume_pg1
.WWID
), handle
);
7216 /* refresh the pd_handles */
7217 if (!ioc
->is_warpdrive
) {
7218 phys_disk_num
= 0xFF;
7219 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
7220 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7221 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7223 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7224 MPI2_IOCSTATUS_MASK
;
7225 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7227 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7228 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7229 set_bit(handle
, ioc
->pd_handles
);
7233 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
7238 * _scsih_mark_responding_expander - mark a expander as responding
7239 * @ioc: per adapter object
7240 * @sas_address: sas address
7243 * After host reset, find out whether devices are still responding.
7244 * Used in _scsih_remove_unresponsive_expanders.
7249 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
7252 struct _sas_node
*sas_expander
;
7253 unsigned long flags
;
7256 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7257 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
7258 if (sas_expander
->sas_address
!= sas_address
)
7260 sas_expander
->responding
= 1;
7261 if (sas_expander
->handle
== handle
)
7263 pr_info("\texpander(0x%016llx): handle changed" \
7264 " from(0x%04x) to (0x%04x)!!!\n",
7265 (unsigned long long)sas_expander
->sas_address
,
7266 sas_expander
->handle
, handle
);
7267 sas_expander
->handle
= handle
;
7268 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
7269 sas_expander
->phy
[i
].handle
= handle
;
7273 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7277 * _scsih_search_responding_expanders -
7278 * @ioc: per adapter object
7280 * After host reset, find out whether devices are still responding.
7286 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
7288 Mpi2ExpanderPage0_t expander_pg0
;
7289 Mpi2ConfigReply_t mpi_reply
;
7294 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
7296 if (list_empty(&ioc
->sas_expander_list
))
7300 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7301 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7303 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7304 MPI2_IOCSTATUS_MASK
;
7305 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7308 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7309 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7310 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7312 (unsigned long long)sas_address
);
7313 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7317 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
7321 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7322 * @ioc: per adapter object
7327 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7329 struct _sas_device
*sas_device
, *sas_device_next
;
7330 struct _sas_node
*sas_expander
, *sas_expander_next
;
7331 struct _raid_device
*raid_device
, *raid_device_next
;
7332 struct list_head tmp_list
;
7333 unsigned long flags
;
7336 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
7339 /* removing unresponding end devices */
7340 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
7343 * Iterate, pulling off devices marked as non-responding. We become the
7344 * owner for the reference the list had on any object we prune.
7346 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7347 list_for_each_entry_safe(sas_device
, sas_device_next
,
7348 &ioc
->sas_device_list
, list
) {
7349 if (!sas_device
->responding
)
7350 list_move_tail(&sas_device
->list
, &head
);
7352 sas_device
->responding
= 0;
7354 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7357 * Now, uninitialize and remove the unresponding devices we pruned.
7359 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
7360 _scsih_remove_device(ioc
, sas_device
);
7361 list_del_init(&sas_device
->list
);
7362 sas_device_put(sas_device
);
7365 /* removing unresponding volumes */
7366 if (ioc
->ir_firmware
) {
7367 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
7369 list_for_each_entry_safe(raid_device
, raid_device_next
,
7370 &ioc
->raid_device_list
, list
) {
7371 if (!raid_device
->responding
)
7372 _scsih_sas_volume_delete(ioc
,
7373 raid_device
->handle
);
7375 raid_device
->responding
= 0;
7379 /* removing unresponding expanders */
7380 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
7382 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7383 INIT_LIST_HEAD(&tmp_list
);
7384 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7385 &ioc
->sas_expander_list
, list
) {
7386 if (!sas_expander
->responding
)
7387 list_move_tail(&sas_expander
->list
, &tmp_list
);
7389 sas_expander
->responding
= 0;
7391 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7392 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7394 list_del(&sas_expander
->list
);
7395 _scsih_expander_node_remove(ioc
, sas_expander
);
7398 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
7401 /* unblock devices */
7402 _scsih_ublock_io_all_device(ioc
);
7406 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
7407 struct _sas_node
*sas_expander
, u16 handle
)
7409 Mpi2ExpanderPage1_t expander_pg1
;
7410 Mpi2ConfigReply_t mpi_reply
;
7413 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7414 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7415 &expander_pg1
, i
, handle
))) {
7416 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7417 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7421 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7422 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7423 expander_pg1
.NegotiatedLinkRate
>> 4);
7428 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7429 * @ioc: per adapter object
7434 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
7436 Mpi2ExpanderPage0_t expander_pg0
;
7437 Mpi2SasDevicePage0_t sas_device_pg0
;
7438 Mpi2RaidVolPage1_t volume_pg1
;
7439 Mpi2RaidVolPage0_t volume_pg0
;
7440 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7441 Mpi2EventIrConfigElement_t element
;
7442 Mpi2ConfigReply_t mpi_reply
;
7445 u16 handle
, parent_handle
;
7447 struct _sas_device
*sas_device
;
7448 struct _sas_node
*expander_device
;
7449 static struct _raid_device
*raid_device
;
7451 unsigned long flags
;
7453 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7455 _scsih_sas_host_refresh(ioc
);
7457 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7461 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7462 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7463 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7464 MPI2_IOCSTATUS_MASK
;
7465 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7466 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7467 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7468 ioc
->name
, ioc_status
,
7469 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7472 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7473 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7474 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7475 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7476 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7477 if (expander_device
)
7478 _scsih_refresh_expander_links(ioc
, expander_device
,
7481 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7482 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7483 handle
, (unsigned long long)
7484 le64_to_cpu(expander_pg0
.SASAddress
));
7485 _scsih_expander_add(ioc
, handle
);
7486 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7487 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7488 handle
, (unsigned long long)
7489 le64_to_cpu(expander_pg0
.SASAddress
));
7493 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7496 if (!ioc
->ir_firmware
)
7499 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7502 phys_disk_num
= 0xFF;
7503 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7504 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7506 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7507 MPI2_IOCSTATUS_MASK
;
7508 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7509 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7510 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7511 ioc
->name
, ioc_status
,
7512 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7515 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7516 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7517 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7519 sas_device_put(sas_device
);
7522 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7523 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7526 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7527 MPI2_IOCSTATUS_MASK
;
7528 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7529 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7530 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7531 ioc
->name
, ioc_status
,
7532 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7535 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7536 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7538 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7539 " handle (0x%04x), sas_addr(0x%016llx)\n",
7540 ioc
->name
, handle
, (unsigned long long)
7541 le64_to_cpu(sas_device_pg0
.SASAddress
));
7542 mpt3sas_transport_update_links(ioc
, sas_address
,
7543 handle
, sas_device_pg0
.PhyNum
,
7544 MPI2_SAS_NEG_LINK_RATE_1_5
);
7545 set_bit(handle
, ioc
->pd_handles
);
7547 /* This will retry adding the end device.
7548 * _scsih_add_device() will decide on retries and
7549 * return "1" when it should be retried
7551 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7555 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7556 " handle (0x%04x), sas_addr(0x%016llx)\n",
7557 ioc
->name
, handle
, (unsigned long long)
7558 le64_to_cpu(sas_device_pg0
.SASAddress
));
7562 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7565 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7569 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7570 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7571 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7572 MPI2_IOCSTATUS_MASK
;
7573 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7574 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7575 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7576 ioc
->name
, ioc_status
,
7577 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7580 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7581 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7582 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7583 le64_to_cpu(volume_pg1
.WWID
));
7584 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7587 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7588 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7589 sizeof(Mpi2RaidVolPage0_t
)))
7591 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7592 MPI2_IOCSTATUS_MASK
;
7593 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7594 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7595 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7596 ioc
->name
, ioc_status
,
7597 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7600 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7601 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7602 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7603 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7604 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7605 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7607 "\tBEFORE adding volume: handle (0x%04x)\n",
7608 ioc
->name
, volume_pg1
.DevHandle
);
7609 _scsih_sas_volume_add(ioc
, &element
);
7611 "\tAFTER adding volume: handle (0x%04x)\n",
7612 ioc
->name
, volume_pg1
.DevHandle
);
7616 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7621 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7626 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7627 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7629 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7630 MPI2_IOCSTATUS_MASK
;
7631 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7632 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7633 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7634 ioc
->name
, ioc_status
,
7635 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7638 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7639 if (!(_scsih_is_end_device(
7640 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7642 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
7643 le64_to_cpu(sas_device_pg0
.SASAddress
));
7645 sas_device_put(sas_device
);
7648 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7649 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7650 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7651 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7652 handle
, (unsigned long long)
7653 le64_to_cpu(sas_device_pg0
.SASAddress
));
7654 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7655 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7657 /* This will retry adding the end device.
7658 * _scsih_add_device() will decide on retries and
7659 * return "1" when it should be retried
7661 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7665 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7666 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7667 handle
, (unsigned long long)
7668 le64_to_cpu(sas_device_pg0
.SASAddress
));
7671 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7674 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7677 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7678 * @ioc: per adapter object
7679 * @reset_phase: phase
7681 * The handler for doing any required cleanup or initialization.
7683 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7684 * MPT3_IOC_DONE_RESET
7689 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7691 switch (reset_phase
) {
7692 case MPT3_IOC_PRE_RESET
:
7693 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7694 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7696 case MPT3_IOC_AFTER_RESET
:
7697 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7698 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7699 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7700 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7701 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7702 complete(&ioc
->scsih_cmds
.done
);
7704 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7705 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7706 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7707 complete(&ioc
->tm_cmds
.done
);
7710 _scsih_fw_event_cleanup_queue(ioc
);
7711 _scsih_flush_running_cmds(ioc
);
7713 case MPT3_IOC_DONE_RESET
:
7714 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7715 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7716 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7717 !ioc
->sas_hba
.num_phys
)) {
7718 _scsih_prep_device_scan(ioc
);
7719 _scsih_search_responding_sas_devices(ioc
);
7720 _scsih_search_responding_raid_devices(ioc
);
7721 _scsih_search_responding_expanders(ioc
);
7722 _scsih_error_recovery_delete_devices(ioc
);
7729 * _mpt3sas_fw_work - delayed task for processing firmware events
7730 * @ioc: per adapter object
7731 * @fw_event: The fw_event_work object
7737 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7739 _scsih_fw_event_del_from_list(ioc
, fw_event
);
7741 /* the queue is being flushed so ignore this event */
7742 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
7743 fw_event_work_put(fw_event
);
7747 switch (fw_event
->event
) {
7748 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7749 mpt3sas_process_trigger_data(ioc
,
7750 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7751 fw_event
->event_data
);
7753 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7754 while (scsi_host_in_recovery(ioc
->shost
) ||
7755 ioc
->shost_recovery
) {
7757 * If we're unloading, bail. Otherwise, this can become
7760 if (ioc
->remove_host
)
7764 _scsih_remove_unresponding_sas_devices(ioc
);
7765 _scsih_scan_for_devices_after_reset(ioc
);
7767 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7768 ioc
->start_scan
= 0;
7769 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7770 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7772 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7773 "port enable: complete from worker thread\n",
7776 case MPT3SAS_TURN_ON_PFA_LED
:
7777 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7779 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7780 _scsih_sas_topology_change_event(ioc
, fw_event
);
7782 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7783 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7785 case MPI2_EVENT_SAS_DISCOVERY
:
7786 _scsih_sas_discovery_event(ioc
, fw_event
);
7788 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7789 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7791 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7792 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7795 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7796 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7798 case MPI2_EVENT_IR_VOLUME
:
7799 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7801 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7802 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7804 case MPI2_EVENT_IR_OPERATION_STATUS
:
7805 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7809 fw_event_work_put(fw_event
);
7813 * _firmware_event_work
7814 * @ioc: per adapter object
7815 * @work: The fw_event_work object
7818 * wrappers for the work thread handling firmware events
7824 _firmware_event_work(struct work_struct
*work
)
7826 struct fw_event_work
*fw_event
= container_of(work
,
7827 struct fw_event_work
, work
);
7829 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7833 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7834 * @ioc: per adapter object
7835 * @msix_index: MSIX table index supplied by the OS
7836 * @reply: reply message frame(lower 32bit addr)
7837 * Context: interrupt.
7839 * This function merely adds a new work task into ioc->firmware_event_thread.
7840 * The tasks are worked from _firmware_event_work in user context.
7842 * Return 1 meaning mf should be freed from _base_interrupt
7843 * 0 means the mf is freed from this function.
7846 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7849 struct fw_event_work
*fw_event
;
7850 Mpi2EventNotificationReply_t
*mpi_reply
;
7854 /* events turned off due to host reset or driver unloading */
7855 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7858 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7860 if (unlikely(!mpi_reply
)) {
7861 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7862 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7866 event
= le16_to_cpu(mpi_reply
->Event
);
7868 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7869 mpt3sas_trigger_event(ioc
, event
, 0);
7873 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7875 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7876 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7877 mpi_reply
->EventData
;
7879 if (baen_data
->Primitive
!=
7880 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7883 if (ioc
->broadcast_aen_busy
) {
7884 ioc
->broadcast_aen_pending
++;
7887 ioc
->broadcast_aen_busy
= 1;
7891 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7892 _scsih_check_topo_delete_events(ioc
,
7893 (Mpi2EventDataSasTopologyChangeList_t
*)
7894 mpi_reply
->EventData
);
7896 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7897 _scsih_check_ir_config_unhide_events(ioc
,
7898 (Mpi2EventDataIrConfigChangeList_t
*)
7899 mpi_reply
->EventData
);
7901 case MPI2_EVENT_IR_VOLUME
:
7902 _scsih_check_volume_delete_events(ioc
,
7903 (Mpi2EventDataIrVolume_t
*)
7904 mpi_reply
->EventData
);
7906 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7908 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7911 if (!ioc
->is_warpdrive
)
7914 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7915 mpi_reply
->EventData
;
7916 log_code
= (u32
*)log_entry
->LogData
;
7918 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7919 != MPT2_WARPDRIVE_LOGENTRY
)
7922 switch (le32_to_cpu(*log_code
)) {
7923 case MPT2_WARPDRIVE_LC_SSDT
:
7924 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7925 "IO Throttling has occurred in the WarpDrive "
7926 "subsystem. Check WarpDrive documentation for "
7927 "additional details.\n", ioc
->name
);
7929 case MPT2_WARPDRIVE_LC_SSDLW
:
7930 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7931 "Program/Erase Cycles for the WarpDrive subsystem "
7932 "in degraded range. Check WarpDrive documentation "
7933 "for additional details.\n", ioc
->name
);
7935 case MPT2_WARPDRIVE_LC_SSDLF
:
7936 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7937 "There are no Program/Erase Cycles for the "
7938 "WarpDrive subsystem. The storage device will be "
7939 "in read-only mode. Check WarpDrive documentation "
7940 "for additional details.\n", ioc
->name
);
7942 case MPT2_WARPDRIVE_LC_BRMF
:
7943 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7944 "The Backup Rail Monitor has failed on the "
7945 "WarpDrive subsystem. Check WarpDrive "
7946 "documentation for additional details.\n",
7953 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7954 case MPI2_EVENT_IR_OPERATION_STATUS
:
7955 case MPI2_EVENT_SAS_DISCOVERY
:
7956 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7957 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7960 case MPI2_EVENT_TEMP_THRESHOLD
:
7961 _scsih_temp_threshold_events(ioc
,
7962 (Mpi2EventDataTemperature_t
*)
7963 mpi_reply
->EventData
);
7966 default: /* ignore the rest */
7970 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7971 fw_event
= alloc_fw_event_work(sz
);
7973 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7974 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7978 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
7979 fw_event
->ioc
= ioc
;
7980 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7981 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7982 fw_event
->event
= event
;
7983 _scsih_fw_event_add(ioc
, fw_event
);
7984 fw_event_work_put(fw_event
);
7989 * _scsih_expander_node_remove - removing expander device from list.
7990 * @ioc: per adapter object
7991 * @sas_expander: the sas_device object
7992 * Context: Calling function should acquire ioc->sas_node_lock.
7994 * Removing object and freeing associated memory from the
7995 * ioc->sas_expander_list.
8000 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
8001 struct _sas_node
*sas_expander
)
8003 struct _sas_port
*mpt3sas_port
, *next
;
8005 /* remove sibling ports attached to this expander */
8006 list_for_each_entry_safe(mpt3sas_port
, next
,
8007 &sas_expander
->sas_port_list
, port_list
) {
8008 if (ioc
->shost_recovery
)
8010 if (mpt3sas_port
->remote_identify
.device_type
==
8012 mpt3sas_device_remove_by_sas_address(ioc
,
8013 mpt3sas_port
->remote_identify
.sas_address
);
8014 else if (mpt3sas_port
->remote_identify
.device_type
==
8015 SAS_EDGE_EXPANDER_DEVICE
||
8016 mpt3sas_port
->remote_identify
.device_type
==
8017 SAS_FANOUT_EXPANDER_DEVICE
)
8018 mpt3sas_expander_remove(ioc
,
8019 mpt3sas_port
->remote_identify
.sas_address
);
8022 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
8023 sas_expander
->sas_address_parent
);
8026 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8028 sas_expander
->handle
, (unsigned long long)
8029 sas_expander
->sas_address
);
8031 kfree(sas_expander
->phy
);
8032 kfree(sas_expander
);
8036 * _scsih_ir_shutdown - IR shutdown notification
8037 * @ioc: per adapter object
8039 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8040 * the host system is shutting down.
8045 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
8047 Mpi2RaidActionRequest_t
*mpi_request
;
8048 Mpi2RaidActionReply_t
*mpi_reply
;
8051 /* is IR firmware build loaded ? */
8052 if (!ioc
->ir_firmware
)
8055 /* are there any volumes ? */
8056 if (list_empty(&ioc
->raid_device_list
))
8059 mutex_lock(&ioc
->scsih_cmds
.mutex
);
8061 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
8062 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
8063 ioc
->name
, __func__
);
8066 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
8068 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
8070 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
8071 ioc
->name
, __func__
);
8072 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8076 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
8077 ioc
->scsih_cmds
.smid
= smid
;
8078 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
8080 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
8081 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
8083 if (!ioc
->hide_ir_msg
)
8084 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
8085 init_completion(&ioc
->scsih_cmds
.done
);
8086 mpt3sas_base_put_smid_default(ioc
, smid
);
8087 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
8089 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
8090 pr_err(MPT3SAS_FMT
"%s: timeout\n",
8091 ioc
->name
, __func__
);
8095 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
8096 mpi_reply
= ioc
->scsih_cmds
.reply
;
8097 if (!ioc
->hide_ir_msg
)
8098 pr_info(MPT3SAS_FMT
"IR shutdown "
8099 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8100 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
8101 le32_to_cpu(mpi_reply
->IOCLogInfo
));
8105 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8106 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
8110 * scsih_remove - detach and remove add host
8111 * @pdev: PCI device struct
8113 * Routine called when unloading the driver.
8116 void scsih_remove(struct pci_dev
*pdev
)
8118 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8119 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8120 struct _sas_port
*mpt3sas_port
, *next_port
;
8121 struct _raid_device
*raid_device
, *next
;
8122 struct MPT3SAS_TARGET
*sas_target_priv_data
;
8123 struct workqueue_struct
*wq
;
8124 unsigned long flags
;
8126 ioc
->remove_host
= 1;
8127 _scsih_fw_event_cleanup_queue(ioc
);
8129 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8130 wq
= ioc
->firmware_event_thread
;
8131 ioc
->firmware_event_thread
= NULL
;
8132 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8134 destroy_workqueue(wq
);
8136 /* release all the volumes */
8137 _scsih_ir_shutdown(ioc
);
8138 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
8140 if (raid_device
->starget
) {
8141 sas_target_priv_data
=
8142 raid_device
->starget
->hostdata
;
8143 sas_target_priv_data
->deleted
= 1;
8144 scsi_remove_target(&raid_device
->starget
->dev
);
8146 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
8147 ioc
->name
, raid_device
->handle
,
8148 (unsigned long long) raid_device
->wwid
);
8149 _scsih_raid_device_remove(ioc
, raid_device
);
8152 /* free ports attached to the sas_host */
8153 list_for_each_entry_safe(mpt3sas_port
, next_port
,
8154 &ioc
->sas_hba
.sas_port_list
, port_list
) {
8155 if (mpt3sas_port
->remote_identify
.device_type
==
8157 mpt3sas_device_remove_by_sas_address(ioc
,
8158 mpt3sas_port
->remote_identify
.sas_address
);
8159 else if (mpt3sas_port
->remote_identify
.device_type
==
8160 SAS_EDGE_EXPANDER_DEVICE
||
8161 mpt3sas_port
->remote_identify
.device_type
==
8162 SAS_FANOUT_EXPANDER_DEVICE
)
8163 mpt3sas_expander_remove(ioc
,
8164 mpt3sas_port
->remote_identify
.sas_address
);
8167 /* free phys attached to the sas_host */
8168 if (ioc
->sas_hba
.num_phys
) {
8169 kfree(ioc
->sas_hba
.phy
);
8170 ioc
->sas_hba
.phy
= NULL
;
8171 ioc
->sas_hba
.num_phys
= 0;
8174 sas_remove_host(shost
);
8175 scsi_remove_host(shost
);
8176 mpt3sas_base_detach(ioc
);
8177 spin_lock(&gioc_lock
);
8178 list_del(&ioc
->list
);
8179 spin_unlock(&gioc_lock
);
8180 scsi_host_put(shost
);
8184 * scsih_shutdown - routine call during system shutdown
8185 * @pdev: PCI device struct
8190 scsih_shutdown(struct pci_dev
*pdev
)
8192 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8193 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8194 struct workqueue_struct
*wq
;
8195 unsigned long flags
;
8197 ioc
->remove_host
= 1;
8198 _scsih_fw_event_cleanup_queue(ioc
);
8200 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8201 wq
= ioc
->firmware_event_thread
;
8202 ioc
->firmware_event_thread
= NULL
;
8203 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8205 destroy_workqueue(wq
);
8207 _scsih_ir_shutdown(ioc
);
8208 mpt3sas_base_detach(ioc
);
8213 * _scsih_probe_boot_devices - reports 1st device
8214 * @ioc: per adapter object
8216 * If specified in bios page 2, this routine reports the 1st
8217 * device scsi-ml or sas transport for persistent boot device
8218 * purposes. Please refer to function _scsih_determine_boot_device()
8221 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
8225 struct _sas_device
*sas_device
;
8226 struct _raid_device
*raid_device
;
8228 u64 sas_address_parent
;
8230 unsigned long flags
;
8233 /* no Bios, return immediately */
8234 if (!ioc
->bios_pg3
.BiosVersion
)
8239 if (ioc
->req_boot_device
.device
) {
8240 device
= ioc
->req_boot_device
.device
;
8241 is_raid
= ioc
->req_boot_device
.is_raid
;
8242 } else if (ioc
->req_alt_boot_device
.device
) {
8243 device
= ioc
->req_alt_boot_device
.device
;
8244 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
8245 } else if (ioc
->current_boot_device
.device
) {
8246 device
= ioc
->current_boot_device
.device
;
8247 is_raid
= ioc
->current_boot_device
.is_raid
;
8254 raid_device
= device
;
8255 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8256 raid_device
->id
, 0);
8258 _scsih_raid_device_remove(ioc
, raid_device
);
8260 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8261 sas_device
= device
;
8262 handle
= sas_device
->handle
;
8263 sas_address_parent
= sas_device
->sas_address_parent
;
8264 sas_address
= sas_device
->sas_address
;
8265 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8266 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8268 if (ioc
->hide_drives
)
8270 if (!mpt3sas_transport_port_add(ioc
, handle
,
8271 sas_address_parent
)) {
8272 _scsih_sas_device_remove(ioc
, sas_device
);
8273 } else if (!sas_device
->starget
) {
8274 if (!ioc
->is_driver_loading
) {
8275 mpt3sas_transport_port_remove(ioc
,
8277 sas_address_parent
);
8278 _scsih_sas_device_remove(ioc
, sas_device
);
8285 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8286 * @ioc: per adapter object
8288 * Called during initial loading of the driver.
8291 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
8293 struct _raid_device
*raid_device
, *raid_next
;
8296 list_for_each_entry_safe(raid_device
, raid_next
,
8297 &ioc
->raid_device_list
, list
) {
8298 if (raid_device
->starget
)
8300 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8301 raid_device
->id
, 0);
8303 _scsih_raid_device_remove(ioc
, raid_device
);
8307 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
8309 struct _sas_device
*sas_device
= NULL
;
8310 unsigned long flags
;
8312 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8313 if (!list_empty(&ioc
->sas_device_init_list
)) {
8314 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
8315 struct _sas_device
, list
);
8316 sas_device_get(sas_device
);
8318 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8323 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
8324 struct _sas_device
*sas_device
)
8326 unsigned long flags
;
8328 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8331 * Since we dropped the lock during the call to port_add(), we need to
8332 * be careful here that somebody else didn't move or delete this item
8333 * while we were busy with other things.
8335 * If it was on the list, we need a put() for the reference the list
8336 * had. Either way, we need a get() for the destination list.
8338 if (!list_empty(&sas_device
->list
)) {
8339 list_del_init(&sas_device
->list
);
8340 sas_device_put(sas_device
);
8343 sas_device_get(sas_device
);
8344 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8346 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8350 * _scsih_probe_sas - reporting sas devices to sas transport
8351 * @ioc: per adapter object
8353 * Called during initial loading of the driver.
8356 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
8358 struct _sas_device
*sas_device
;
8360 if (ioc
->hide_drives
)
8363 while ((sas_device
= get_next_sas_device(ioc
))) {
8364 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
8365 sas_device
->sas_address_parent
)) {
8366 _scsih_sas_device_remove(ioc
, sas_device
);
8367 sas_device_put(sas_device
);
8369 } else if (!sas_device
->starget
) {
8371 * When asyn scanning is enabled, its not possible to
8372 * remove devices while scanning is turned on due to an
8373 * oops in scsi_sysfs_add_sdev()->add_device()->
8374 * sysfs_addrm_start()
8376 if (!ioc
->is_driver_loading
) {
8377 mpt3sas_transport_port_remove(ioc
,
8378 sas_device
->sas_address
,
8379 sas_device
->sas_address_parent
);
8380 _scsih_sas_device_remove(ioc
, sas_device
);
8381 sas_device_put(sas_device
);
8385 sas_device_make_active(ioc
, sas_device
);
8386 sas_device_put(sas_device
);
8391 * _scsih_probe_devices - probing for devices
8392 * @ioc: per adapter object
8394 * Called during initial loading of the driver.
8397 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
8399 u16 volume_mapping_flags
;
8401 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8402 return; /* return when IOC doesn't support initiator mode */
8404 _scsih_probe_boot_devices(ioc
);
8406 if (ioc
->ir_firmware
) {
8407 volume_mapping_flags
=
8408 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8409 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8410 if (volume_mapping_flags
==
8411 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8412 _scsih_probe_raid(ioc
);
8413 _scsih_probe_sas(ioc
);
8415 _scsih_probe_sas(ioc
);
8416 _scsih_probe_raid(ioc
);
8419 _scsih_probe_sas(ioc
);
8423 * scsih_scan_start - scsi lld callback for .scan_start
8424 * @shost: SCSI host pointer
8426 * The shost has the ability to discover targets on its own instead
8427 * of scanning the entire bus. In our implemention, we will kick off
8428 * firmware discovery.
8431 scsih_scan_start(struct Scsi_Host
*shost
)
8433 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8435 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8436 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8438 if (disable_discovery
> 0)
8441 ioc
->start_scan
= 1;
8442 rc
= mpt3sas_port_enable(ioc
);
8445 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
8449 * scsih_scan_finished - scsi lld callback for .scan_finished
8450 * @shost: SCSI host pointer
8451 * @time: elapsed time of the scan in jiffies
8453 * This function will be called periodicallyn until it returns 1 with the
8454 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8455 * we wait for firmware discovery to complete, then return 1.
8458 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8460 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8462 if (disable_discovery
> 0) {
8463 ioc
->is_driver_loading
= 0;
8464 ioc
->wait_for_discovery_to_complete
= 0;
8468 if (time
>= (300 * HZ
)) {
8469 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8471 "port enable: FAILED with timeout (timeout=300s)\n",
8473 ioc
->is_driver_loading
= 0;
8477 if (ioc
->start_scan
)
8480 if (ioc
->start_scan_failed
) {
8482 "port enable: FAILED with (ioc_status=0x%08x)\n",
8483 ioc
->name
, ioc
->start_scan_failed
);
8484 ioc
->is_driver_loading
= 0;
8485 ioc
->wait_for_discovery_to_complete
= 0;
8486 ioc
->remove_host
= 1;
8490 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
8491 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8493 if (ioc
->wait_for_discovery_to_complete
) {
8494 ioc
->wait_for_discovery_to_complete
= 0;
8495 _scsih_probe_devices(ioc
);
8497 mpt3sas_base_start_watchdog(ioc
);
8498 ioc
->is_driver_loading
= 0;
8502 /* shost template for SAS 2.0 HBA devices */
8503 static struct scsi_host_template mpt2sas_driver_template
= {
8504 .module
= THIS_MODULE
,
8505 .name
= "Fusion MPT SAS Host",
8506 .proc_name
= MPT2SAS_DRIVER_NAME
,
8507 .queuecommand
= scsih_qcmd
,
8508 .target_alloc
= scsih_target_alloc
,
8509 .slave_alloc
= scsih_slave_alloc
,
8510 .slave_configure
= scsih_slave_configure
,
8511 .target_destroy
= scsih_target_destroy
,
8512 .slave_destroy
= scsih_slave_destroy
,
8513 .scan_finished
= scsih_scan_finished
,
8514 .scan_start
= scsih_scan_start
,
8515 .change_queue_depth
= scsih_change_queue_depth
,
8516 .eh_abort_handler
= scsih_abort
,
8517 .eh_device_reset_handler
= scsih_dev_reset
,
8518 .eh_target_reset_handler
= scsih_target_reset
,
8519 .eh_host_reset_handler
= scsih_host_reset
,
8520 .bios_param
= scsih_bios_param
,
8523 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
8524 .max_sectors
= 32767,
8526 .use_clustering
= ENABLE_CLUSTERING
,
8527 .shost_attrs
= mpt3sas_host_attrs
,
8528 .sdev_attrs
= mpt3sas_dev_attrs
,
8529 .track_queue_depth
= 1,
8532 /* raid transport support for SAS 2.0 HBA devices */
8533 static struct raid_function_template mpt2sas_raid_functions
= {
8534 .cookie
= &mpt2sas_driver_template
,
8535 .is_raid
= scsih_is_raid
,
8536 .get_resync
= scsih_get_resync
,
8537 .get_state
= scsih_get_state
,
8540 /* shost template for SAS 3.0 HBA devices */
8541 static struct scsi_host_template mpt3sas_driver_template
= {
8542 .module
= THIS_MODULE
,
8543 .name
= "Fusion MPT SAS Host",
8544 .proc_name
= MPT3SAS_DRIVER_NAME
,
8545 .queuecommand
= scsih_qcmd
,
8546 .target_alloc
= scsih_target_alloc
,
8547 .slave_alloc
= scsih_slave_alloc
,
8548 .slave_configure
= scsih_slave_configure
,
8549 .target_destroy
= scsih_target_destroy
,
8550 .slave_destroy
= scsih_slave_destroy
,
8551 .scan_finished
= scsih_scan_finished
,
8552 .scan_start
= scsih_scan_start
,
8553 .change_queue_depth
= scsih_change_queue_depth
,
8554 .eh_abort_handler
= scsih_abort
,
8555 .eh_device_reset_handler
= scsih_dev_reset
,
8556 .eh_target_reset_handler
= scsih_target_reset
,
8557 .eh_host_reset_handler
= scsih_host_reset
,
8558 .bios_param
= scsih_bios_param
,
8561 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
8562 .max_sectors
= 32767,
8564 .use_clustering
= ENABLE_CLUSTERING
,
8565 .shost_attrs
= mpt3sas_host_attrs
,
8566 .sdev_attrs
= mpt3sas_dev_attrs
,
8567 .track_queue_depth
= 1,
8570 /* raid transport support for SAS 3.0 HBA devices */
8571 static struct raid_function_template mpt3sas_raid_functions
= {
8572 .cookie
= &mpt3sas_driver_template
,
8573 .is_raid
= scsih_is_raid
,
8574 .get_resync
= scsih_get_resync
,
8575 .get_state
= scsih_get_state
,
8579 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8580 * this device belongs to.
8581 * @pdev: PCI device struct
8583 * return MPI2_VERSION for SAS 2.0 HBA devices,
8584 * MPI25_VERSION for SAS 3.0 HBA devices, and
8585 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8588 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
8591 switch (pdev
->device
) {
8592 case MPI2_MFGPAGE_DEVID_SSS6200
:
8593 case MPI2_MFGPAGE_DEVID_SAS2004
:
8594 case MPI2_MFGPAGE_DEVID_SAS2008
:
8595 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
8596 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
8597 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
8598 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
8599 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
8600 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
8601 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
8602 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
8603 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
8604 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
8605 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
8606 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
8607 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
8608 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
8609 return MPI2_VERSION
;
8610 case MPI25_MFGPAGE_DEVID_SAS3004
:
8611 case MPI25_MFGPAGE_DEVID_SAS3008
:
8612 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
8613 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
8614 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
8615 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
8616 return MPI25_VERSION
;
8617 case MPI26_MFGPAGE_DEVID_SAS3216
:
8618 case MPI26_MFGPAGE_DEVID_SAS3224
:
8619 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
8620 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
8621 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
8622 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
8623 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
8624 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
8625 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
8626 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
8627 return MPI26_VERSION
;
8633 * _scsih_probe - attach and add scsi host
8634 * @pdev: PCI device struct
8635 * @id: pci device id
8637 * Returns 0 success, anything else error.
8640 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8642 struct MPT3SAS_ADAPTER
*ioc
;
8643 struct Scsi_Host
*shost
= NULL
;
8645 u16 hba_mpi_version
;
8647 /* Determine in which MPI version class this pci device belongs */
8648 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
8649 if (hba_mpi_version
== 0)
8652 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8653 * for other generation HBA's return with -ENODEV
8655 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
8658 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8659 * for other generation HBA's return with -ENODEV
8661 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
8662 || hba_mpi_version
== MPI26_VERSION
)))
8665 switch (hba_mpi_version
) {
8667 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8668 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
8669 sizeof(struct MPT3SAS_ADAPTER
));
8672 ioc
= shost_priv(shost
);
8673 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8674 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8675 ioc
->id
= mpt2_ids
++;
8676 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
8677 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8678 ioc
->is_warpdrive
= 1;
8679 ioc
->hide_ir_msg
= 1;
8681 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8685 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8686 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
8687 sizeof(struct MPT3SAS_ADAPTER
));
8690 ioc
= shost_priv(shost
);
8691 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8692 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8693 ioc
->id
= mpt3_ids
++;
8694 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
8695 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
8696 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
8697 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
))
8698 ioc
->msix96_vector
= 1;
8704 INIT_LIST_HEAD(&ioc
->list
);
8705 spin_lock(&gioc_lock
);
8706 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8707 spin_unlock(&gioc_lock
);
8710 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8711 ioc
->tm_cb_idx
= tm_cb_idx
;
8712 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8713 ioc
->base_cb_idx
= base_cb_idx
;
8714 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8715 ioc
->transport_cb_idx
= transport_cb_idx
;
8716 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8717 ioc
->config_cb_idx
= config_cb_idx
;
8718 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8719 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8720 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8721 ioc
->logging_level
= logging_level
;
8722 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8723 /* misc semaphores and spin locks */
8724 mutex_init(&ioc
->reset_in_progress_mutex
);
8725 /* initializing pci_access_mutex lock */
8726 mutex_init(&ioc
->pci_access_mutex
);
8727 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8728 spin_lock_init(&ioc
->scsi_lookup_lock
);
8729 spin_lock_init(&ioc
->sas_device_lock
);
8730 spin_lock_init(&ioc
->sas_node_lock
);
8731 spin_lock_init(&ioc
->fw_event_lock
);
8732 spin_lock_init(&ioc
->raid_device_lock
);
8733 spin_lock_init(&ioc
->diag_trigger_lock
);
8735 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8736 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8737 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8738 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8739 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8740 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8741 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8742 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
8743 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
8744 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8745 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8747 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
8749 /* init shost parameters */
8750 shost
->max_cmd_len
= 32;
8751 shost
->max_lun
= max_lun
;
8752 shost
->transportt
= mpt3sas_transport_template
;
8753 shost
->unique_id
= ioc
->id
;
8755 if (max_sectors
!= 0xFFFF) {
8756 if (max_sectors
< 64) {
8757 shost
->max_sectors
= 64;
8758 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8759 "for max_sectors, range is 64 to 32767. Assigning "
8760 "value of 64.\n", ioc
->name
, max_sectors
);
8761 } else if (max_sectors
> 32767) {
8762 shost
->max_sectors
= 32767;
8763 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8764 "for max_sectors, range is 64 to 32767. Assigning "
8765 "default value of 32767.\n", ioc
->name
,
8768 shost
->max_sectors
= max_sectors
& 0xFFFE;
8770 "The max_sectors value is set to %d\n",
8771 ioc
->name
, shost
->max_sectors
);
8775 /* register EEDP capabilities with SCSI layer */
8777 scsi_host_set_prot(shost
, prot_mask
);
8779 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8780 | SHOST_DIF_TYPE2_PROTECTION
8781 | SHOST_DIF_TYPE3_PROTECTION
);
8783 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8786 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8787 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
8788 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8789 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8790 if (!ioc
->firmware_event_thread
) {
8791 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8792 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8794 goto out_thread_fail
;
8797 ioc
->is_driver_loading
= 1;
8798 if ((mpt3sas_base_attach(ioc
))) {
8799 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8800 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8802 goto out_attach_fail
;
8805 if (ioc
->is_warpdrive
) {
8806 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8807 ioc
->hide_drives
= 0;
8808 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8809 ioc
->hide_drives
= 1;
8811 if (mpt3sas_get_num_volumes(ioc
))
8812 ioc
->hide_drives
= 1;
8814 ioc
->hide_drives
= 0;
8817 ioc
->hide_drives
= 0;
8819 rv
= scsi_add_host(shost
, &pdev
->dev
);
8821 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8822 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8823 goto out_add_shost_fail
;
8826 scsi_scan_host(shost
);
8829 mpt3sas_base_detach(ioc
);
8831 destroy_workqueue(ioc
->firmware_event_thread
);
8833 spin_lock(&gioc_lock
);
8834 list_del(&ioc
->list
);
8835 spin_unlock(&gioc_lock
);
8836 scsi_host_put(shost
);
8842 * scsih_suspend - power management suspend main entry point
8843 * @pdev: PCI device struct
8844 * @state: PM state change to (usually PCI_D3)
8846 * Returns 0 success, anything else error.
8849 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8851 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8852 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8853 pci_power_t device_state
;
8855 mpt3sas_base_stop_watchdog(ioc
);
8856 flush_scheduled_work();
8857 scsi_block_requests(shost
);
8858 device_state
= pci_choose_state(pdev
, state
);
8860 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8861 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8863 pci_save_state(pdev
);
8864 mpt3sas_base_free_resources(ioc
);
8865 pci_set_power_state(pdev
, device_state
);
8870 * scsih_resume - power management resume main entry point
8871 * @pdev: PCI device struct
8873 * Returns 0 success, anything else error.
8876 scsih_resume(struct pci_dev
*pdev
)
8878 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8879 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8880 pci_power_t device_state
= pdev
->current_state
;
8884 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8885 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8887 pci_set_power_state(pdev
, PCI_D0
);
8888 pci_enable_wake(pdev
, PCI_D0
, 0);
8889 pci_restore_state(pdev
);
8891 r
= mpt3sas_base_map_resources(ioc
);
8895 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8896 scsi_unblock_requests(shost
);
8897 mpt3sas_base_start_watchdog(ioc
);
8900 #endif /* CONFIG_PM */
8903 * scsih_pci_error_detected - Called when a PCI error is detected.
8904 * @pdev: PCI device struct
8905 * @state: PCI channel state
8907 * Description: Called when a PCI error is detected.
8910 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8913 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8915 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8916 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8918 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
8922 case pci_channel_io_normal
:
8923 return PCI_ERS_RESULT_CAN_RECOVER
;
8924 case pci_channel_io_frozen
:
8925 /* Fatal error, prepare for slot reset */
8926 ioc
->pci_error_recovery
= 1;
8927 scsi_block_requests(ioc
->shost
);
8928 mpt3sas_base_stop_watchdog(ioc
);
8929 mpt3sas_base_free_resources(ioc
);
8930 return PCI_ERS_RESULT_NEED_RESET
;
8931 case pci_channel_io_perm_failure
:
8932 /* Permanent error, prepare for device removal */
8933 ioc
->pci_error_recovery
= 1;
8934 mpt3sas_base_stop_watchdog(ioc
);
8935 _scsih_flush_running_cmds(ioc
);
8936 return PCI_ERS_RESULT_DISCONNECT
;
8938 return PCI_ERS_RESULT_NEED_RESET
;
8942 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8943 * @pdev: PCI device struct
8945 * Description: This routine is called by the pci error recovery
8946 * code after the PCI slot has been reset, just before we
8947 * should resume normal operations.
8950 scsih_pci_slot_reset(struct pci_dev
*pdev
)
8952 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8953 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8956 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
8959 ioc
->pci_error_recovery
= 0;
8961 pci_restore_state(pdev
);
8962 rc
= mpt3sas_base_map_resources(ioc
);
8964 return PCI_ERS_RESULT_DISCONNECT
;
8966 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8969 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
8970 (rc
== 0) ? "success" : "failed");
8973 return PCI_ERS_RESULT_RECOVERED
;
8975 return PCI_ERS_RESULT_DISCONNECT
;
8979 * scsih_pci_resume() - resume normal ops after PCI reset
8980 * @pdev: pointer to PCI device
8982 * Called when the error recovery driver tells us that its
8983 * OK to resume normal operation. Use completion to allow
8984 * halted scsi ops to resume.
8987 scsih_pci_resume(struct pci_dev
*pdev
)
8989 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8990 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8992 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8994 pci_cleanup_aer_uncorrect_error_status(pdev
);
8995 mpt3sas_base_start_watchdog(ioc
);
8996 scsi_unblock_requests(ioc
->shost
);
9000 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
9001 * @pdev: pointer to PCI device
9004 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
9006 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9007 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9009 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
9012 /* TODO - dump whatever for debugging purposes */
9014 /* Request a slot reset. */
9015 return PCI_ERS_RESULT_NEED_RESET
;
9019 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9021 static const struct pci_device_id mpt3sas_pci_table
[] = {
9022 /* Spitfire ~ 2004 */
9023 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
9024 PCI_ANY_ID
, PCI_ANY_ID
},
9026 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
9027 PCI_ANY_ID
, PCI_ANY_ID
},
9028 /* Liberator ~ 2108 */
9029 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
9030 PCI_ANY_ID
, PCI_ANY_ID
},
9031 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
9032 PCI_ANY_ID
, PCI_ANY_ID
},
9033 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
9034 PCI_ANY_ID
, PCI_ANY_ID
},
9036 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
9037 PCI_ANY_ID
, PCI_ANY_ID
},
9038 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
9039 PCI_ANY_ID
, PCI_ANY_ID
},
9040 /* Thunderbolt ~ 2208 */
9041 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
9042 PCI_ANY_ID
, PCI_ANY_ID
},
9043 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
9044 PCI_ANY_ID
, PCI_ANY_ID
},
9045 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
9046 PCI_ANY_ID
, PCI_ANY_ID
},
9047 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
9048 PCI_ANY_ID
, PCI_ANY_ID
},
9049 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
9050 PCI_ANY_ID
, PCI_ANY_ID
},
9051 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
9052 PCI_ANY_ID
, PCI_ANY_ID
},
9053 /* Mustang ~ 2308 */
9054 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
9055 PCI_ANY_ID
, PCI_ANY_ID
},
9056 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
9057 PCI_ANY_ID
, PCI_ANY_ID
},
9058 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
9059 PCI_ANY_ID
, PCI_ANY_ID
},
9061 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
9062 PCI_ANY_ID
, PCI_ANY_ID
},
9063 /* Fury ~ 3004 and 3008 */
9064 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
9065 PCI_ANY_ID
, PCI_ANY_ID
},
9066 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
9067 PCI_ANY_ID
, PCI_ANY_ID
},
9068 /* Invader ~ 3108 */
9069 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
9070 PCI_ANY_ID
, PCI_ANY_ID
},
9071 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
9072 PCI_ANY_ID
, PCI_ANY_ID
},
9073 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
9074 PCI_ANY_ID
, PCI_ANY_ID
},
9075 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
9076 PCI_ANY_ID
, PCI_ANY_ID
},
9077 /* Cutlass ~ 3216 and 3224 */
9078 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
9079 PCI_ANY_ID
, PCI_ANY_ID
},
9080 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
9081 PCI_ANY_ID
, PCI_ANY_ID
},
9082 /* Intruder ~ 3316 and 3324 */
9083 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
9084 PCI_ANY_ID
, PCI_ANY_ID
},
9085 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
9086 PCI_ANY_ID
, PCI_ANY_ID
},
9087 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
9088 PCI_ANY_ID
, PCI_ANY_ID
},
9089 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
9090 PCI_ANY_ID
, PCI_ANY_ID
},
9091 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
9092 PCI_ANY_ID
, PCI_ANY_ID
},
9093 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
9094 PCI_ANY_ID
, PCI_ANY_ID
},
9095 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
9096 PCI_ANY_ID
, PCI_ANY_ID
},
9097 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
9098 PCI_ANY_ID
, PCI_ANY_ID
},
9099 {0} /* Terminating entry */
9101 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
9103 static struct pci_error_handlers _mpt3sas_err_handler
= {
9104 .error_detected
= scsih_pci_error_detected
,
9105 .mmio_enabled
= scsih_pci_mmio_enabled
,
9106 .slot_reset
= scsih_pci_slot_reset
,
9107 .resume
= scsih_pci_resume
,
9110 static struct pci_driver mpt3sas_driver
= {
9111 .name
= MPT3SAS_DRIVER_NAME
,
9112 .id_table
= mpt3sas_pci_table
,
9113 .probe
= _scsih_probe
,
9114 .remove
= scsih_remove
,
9115 .shutdown
= scsih_shutdown
,
9116 .err_handler
= &_mpt3sas_err_handler
,
9118 .suspend
= scsih_suspend
,
9119 .resume
= scsih_resume
,
9124 * scsih_init - main entry point for this driver.
9126 * Returns 0 success, anything else error.
9134 mpt3sas_base_initialize_callback_handler();
9136 /* queuecommand callback hander */
9137 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
9139 /* task managment callback handler */
9140 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
9142 /* base internal commands callback handler */
9143 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
9144 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
9145 mpt3sas_port_enable_done
);
9147 /* transport internal commands callback handler */
9148 transport_cb_idx
= mpt3sas_base_register_callback_handler(
9149 mpt3sas_transport_done
);
9151 /* scsih internal commands callback handler */
9152 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
9154 /* configuration page API internal commands callback handler */
9155 config_cb_idx
= mpt3sas_base_register_callback_handler(
9156 mpt3sas_config_done
);
9158 /* ctl module callback handler */
9159 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
9161 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
9162 _scsih_tm_tr_complete
);
9164 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
9165 _scsih_tm_volume_tr_complete
);
9167 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
9168 _scsih_sas_control_complete
);
9174 * scsih_exit - exit point for this driver (when it is a module).
9176 * Returns 0 success, anything else error.
9182 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
9183 mpt3sas_base_release_callback_handler(tm_cb_idx
);
9184 mpt3sas_base_release_callback_handler(base_cb_idx
);
9185 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
9186 mpt3sas_base_release_callback_handler(transport_cb_idx
);
9187 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
9188 mpt3sas_base_release_callback_handler(config_cb_idx
);
9189 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
9191 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
9192 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
9193 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
9195 /* raid transport support */
9196 if (hbas_to_enumerate
!= 1)
9197 raid_class_release(mpt3sas_raid_template
);
9198 if (hbas_to_enumerate
!= 2)
9199 raid_class_release(mpt2sas_raid_template
);
9200 sas_release_transport(mpt3sas_transport_template
);
9204 * _mpt3sas_init - main entry point for this driver.
9206 * Returns 0 success, anything else error.
9213 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
9214 MPT3SAS_DRIVER_VERSION
);
9216 mpt3sas_transport_template
=
9217 sas_attach_transport(&mpt3sas_transport_functions
);
9218 if (!mpt3sas_transport_template
)
9221 /* No need attach mpt3sas raid functions template
9222 * if hbas_to_enumarate value is one.
9224 if (hbas_to_enumerate
!= 1) {
9225 mpt3sas_raid_template
=
9226 raid_class_attach(&mpt3sas_raid_functions
);
9227 if (!mpt3sas_raid_template
) {
9228 sas_release_transport(mpt3sas_transport_template
);
9233 /* No need to attach mpt2sas raid functions template
9234 * if hbas_to_enumarate value is two
9236 if (hbas_to_enumerate
!= 2) {
9237 mpt2sas_raid_template
=
9238 raid_class_attach(&mpt2sas_raid_functions
);
9239 if (!mpt2sas_raid_template
) {
9240 sas_release_transport(mpt3sas_transport_template
);
9245 error
= scsih_init();
9251 mpt3sas_ctl_init(hbas_to_enumerate
);
9253 error
= pci_register_driver(&mpt3sas_driver
);
9261 * _mpt3sas_exit - exit point for this driver (when it is a module).
9267 pr_info("mpt3sas version %s unloading\n",
9268 MPT3SAS_DRIVER_VERSION
);
9270 pci_unregister_driver(&mpt3sas_driver
);
9272 mpt3sas_ctl_exit(hbas_to_enumerate
);
9277 module_init(_mpt3sas_init
);
9278 module_exit(_mpt3sas_exit
);