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 * @ioc: per adapter object
178 * @device_handle: device handle
179 * @VF_ID: virtual function id
180 * @VP_ID: virtual port id
181 * @ignore: flag meaning this event has been marked to ignore
182 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
183 * @refcount: kref for this event
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
;
192 struct MPT3SAS_ADAPTER
*ioc
;
198 struct kref refcount
;
199 char event_data
[0] __aligned(4);
202 static void fw_event_work_free(struct kref
*r
)
204 kfree(container_of(r
, struct fw_event_work
, refcount
));
207 static void fw_event_work_get(struct fw_event_work
*fw_work
)
209 kref_get(&fw_work
->refcount
);
212 static void fw_event_work_put(struct fw_event_work
*fw_work
)
214 kref_put(&fw_work
->refcount
, fw_event_work_free
);
217 static struct fw_event_work
*alloc_fw_event_work(int len
)
219 struct fw_event_work
*fw_event
;
221 fw_event
= kzalloc(sizeof(*fw_event
) + len
, GFP_ATOMIC
);
225 kref_init(&fw_event
->refcount
);
230 * struct _scsi_io_transfer - scsi io transfer
231 * @handle: sas device handle (assigned by firmware)
232 * @is_raid: flag set for hidden raid components
233 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
234 * @data_length: data transfer length
235 * @data_dma: dma pointer to data
238 * @cdb_length: cdb length
240 * @timeout: timeout for this command
241 * @VF_ID: virtual function id
242 * @VP_ID: virtual port id
243 * @valid_reply: flag set for reply message
244 * @sense_length: sense length
245 * @ioc_status: ioc status
246 * @scsi_state: scsi state
247 * @scsi_status: scsi staus
248 * @log_info: log information
249 * @transfer_length: data length transfer when there is a reply message
251 * Used for sending internal scsi commands to devices within this module.
252 * Refer to _scsi_send_scsi_io().
254 struct _scsi_io_transfer
{
257 enum dma_data_direction dir
;
260 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
268 /* the following bits are only valid when 'valid_reply = 1' */
278 * _scsih_set_debug_level - global setting of ioc->logging_level.
280 * Note: The logging levels are defined in mpt3sas_debug.h.
283 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
285 int ret
= param_set_int(val
, kp
);
286 struct MPT3SAS_ADAPTER
*ioc
;
291 pr_info("setting logging_level(0x%08x)\n", logging_level
);
292 spin_lock(&gioc_lock
);
293 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
294 ioc
->logging_level
= logging_level
;
295 spin_unlock(&gioc_lock
);
298 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
299 &logging_level
, 0644);
302 * _scsih_srch_boot_sas_address - search based on sas_address
303 * @sas_address: sas address
304 * @boot_device: boot device object from bios page 2
306 * Returns 1 when there's a match, 0 means no match.
309 _scsih_srch_boot_sas_address(u64 sas_address
,
310 Mpi2BootDeviceSasWwid_t
*boot_device
)
312 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
316 * _scsih_srch_boot_device_name - search based on device name
317 * @device_name: device name specified in INDENTIFY fram
318 * @boot_device: boot device object from bios page 2
320 * Returns 1 when there's a match, 0 means no match.
323 _scsih_srch_boot_device_name(u64 device_name
,
324 Mpi2BootDeviceDeviceName_t
*boot_device
)
326 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
330 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
331 * @enclosure_logical_id: enclosure logical id
332 * @slot_number: slot number
333 * @boot_device: boot device object from bios page 2
335 * Returns 1 when there's a match, 0 means no match.
338 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
339 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
341 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
342 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
343 SlotNumber
)) ? 1 : 0;
347 * _scsih_is_boot_device - search for matching boot device.
348 * @sas_address: sas address
349 * @device_name: device name specified in INDENTIFY fram
350 * @enclosure_logical_id: enclosure logical id
351 * @slot_number: slot number
352 * @form: specifies boot device form
353 * @boot_device: boot device object from bios page 2
355 * Returns 1 when there's a match, 0 means no match.
358 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
359 u64 enclosure_logical_id
, u16 slot
, u8 form
,
360 Mpi2BiosPage2BootDevice_t
*boot_device
)
365 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
368 rc
= _scsih_srch_boot_sas_address(
369 sas_address
, &boot_device
->SasWwid
);
371 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
372 if (!enclosure_logical_id
)
374 rc
= _scsih_srch_boot_encl_slot(
375 enclosure_logical_id
,
376 slot
, &boot_device
->EnclosureSlot
);
378 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
381 rc
= _scsih_srch_boot_device_name(
382 device_name
, &boot_device
->DeviceName
);
384 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
392 * _scsih_get_sas_address - set the sas_address for given device handle
393 * @handle: device handle
394 * @sas_address: sas address
396 * Returns 0 success, non-zero when failure
399 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
402 Mpi2SasDevicePage0_t sas_device_pg0
;
403 Mpi2ConfigReply_t mpi_reply
;
408 if (handle
<= ioc
->sas_hba
.num_phys
) {
409 *sas_address
= ioc
->sas_hba
.sas_address
;
413 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
415 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
416 __FILE__
, __LINE__
, __func__
);
420 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
421 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
422 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
426 /* we hit this becuase the given parent handle doesn't exist */
427 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
430 /* else error case */
432 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
433 ioc
->name
, handle
, ioc_status
,
434 __FILE__
, __LINE__
, __func__
);
439 * _scsih_determine_boot_device - determine boot device.
440 * @ioc: per adapter object
441 * @device: either sas_device or raid_device object
442 * @is_raid: [flag] 1 = raid object, 0 = sas object
444 * Determines whether this device should be first reported device to
445 * to scsi-ml or sas transport, this purpose is for persistent boot device.
446 * There are primary, alternate, and current entries in bios page 2. The order
447 * priority is primary, alternate, then current. This routine saves
448 * the corresponding device object and is_raid flag in the ioc object.
449 * The saved data to be used later in _scsih_probe_boot_devices().
452 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
,
453 void *device
, u8 is_raid
)
455 struct _sas_device
*sas_device
;
456 struct _raid_device
*raid_device
;
459 u64 enclosure_logical_id
;
462 /* only process this function when driver loads */
463 if (!ioc
->is_driver_loading
)
466 /* no Bios, return immediately */
467 if (!ioc
->bios_pg3
.BiosVersion
)
472 sas_address
= sas_device
->sas_address
;
473 device_name
= sas_device
->device_name
;
474 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
475 slot
= sas_device
->slot
;
477 raid_device
= device
;
478 sas_address
= raid_device
->wwid
;
480 enclosure_logical_id
= 0;
484 if (!ioc
->req_boot_device
.device
) {
485 if (_scsih_is_boot_device(sas_address
, device_name
,
486 enclosure_logical_id
, slot
,
487 (ioc
->bios_pg2
.ReqBootDeviceForm
&
488 MPI2_BIOSPAGE2_FORM_MASK
),
489 &ioc
->bios_pg2
.RequestedBootDevice
)) {
490 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
491 "%s: req_boot_device(0x%016llx)\n",
493 (unsigned long long)sas_address
));
494 ioc
->req_boot_device
.device
= device
;
495 ioc
->req_boot_device
.is_raid
= is_raid
;
499 if (!ioc
->req_alt_boot_device
.device
) {
500 if (_scsih_is_boot_device(sas_address
, device_name
,
501 enclosure_logical_id
, slot
,
502 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
503 MPI2_BIOSPAGE2_FORM_MASK
),
504 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
505 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
506 "%s: req_alt_boot_device(0x%016llx)\n",
508 (unsigned long long)sas_address
));
509 ioc
->req_alt_boot_device
.device
= device
;
510 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
514 if (!ioc
->current_boot_device
.device
) {
515 if (_scsih_is_boot_device(sas_address
, device_name
,
516 enclosure_logical_id
, slot
,
517 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
518 MPI2_BIOSPAGE2_FORM_MASK
),
519 &ioc
->bios_pg2
.CurrentBootDevice
)) {
520 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
521 "%s: current_boot_device(0x%016llx)\n",
523 (unsigned long long)sas_address
));
524 ioc
->current_boot_device
.device
= device
;
525 ioc
->current_boot_device
.is_raid
= is_raid
;
530 static struct _sas_device
*
531 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
532 struct MPT3SAS_TARGET
*tgt_priv
)
534 struct _sas_device
*ret
;
536 assert_spin_locked(&ioc
->sas_device_lock
);
538 ret
= tgt_priv
->sdev
;
545 static struct _sas_device
*
546 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
547 struct MPT3SAS_TARGET
*tgt_priv
)
549 struct _sas_device
*ret
;
552 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
553 ret
= __mpt3sas_get_sdev_from_target(ioc
, tgt_priv
);
554 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
561 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
564 struct _sas_device
*sas_device
;
566 assert_spin_locked(&ioc
->sas_device_lock
);
568 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
569 if (sas_device
->sas_address
== sas_address
)
572 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
573 if (sas_device
->sas_address
== sas_address
)
579 sas_device_get(sas_device
);
584 * mpt3sas_get_sdev_by_addr - sas device search
585 * @ioc: per adapter object
586 * @sas_address: sas address
587 * Context: Calling function should acquire ioc->sas_device_lock
589 * This searches for sas_device based on sas_address, then return sas_device
593 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
596 struct _sas_device
*sas_device
;
599 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
600 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
602 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
607 static struct _sas_device
*
608 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
610 struct _sas_device
*sas_device
;
612 assert_spin_locked(&ioc
->sas_device_lock
);
614 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
615 if (sas_device
->handle
== handle
)
618 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
619 if (sas_device
->handle
== handle
)
625 sas_device_get(sas_device
);
630 * mpt3sas_get_sdev_by_handle - sas device search
631 * @ioc: per adapter object
632 * @handle: sas device handle (assigned by firmware)
633 * Context: Calling function should acquire ioc->sas_device_lock
635 * This searches for sas_device based on sas_address, then return sas_device
638 static struct _sas_device
*
639 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
641 struct _sas_device
*sas_device
;
644 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
645 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
646 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
652 * _scsih_sas_device_remove - remove sas_device from list.
653 * @ioc: per adapter object
654 * @sas_device: the sas_device object
655 * Context: This function will acquire ioc->sas_device_lock.
657 * If sas_device is on the list, remove it and decrement its reference count.
660 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
661 struct _sas_device
*sas_device
)
668 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
669 ioc
->name
, sas_device
->handle
,
670 (unsigned long long) sas_device
->sas_address
);
672 if (sas_device
->enclosure_handle
!= 0)
674 "removing enclosure logical id(0x%016llx), slot(%d)\n",
675 ioc
->name
, (unsigned long long)
676 sas_device
->enclosure_logical_id
, sas_device
->slot
);
678 if (sas_device
->connector_name
[0] != '\0')
680 "removing enclosure level(0x%04x), connector name( %s)\n",
681 ioc
->name
, sas_device
->enclosure_level
,
682 sas_device
->connector_name
);
685 * The lock serializes access to the list, but we still need to verify
686 * that nobody removed the entry while we were waiting on the lock.
688 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
689 if (!list_empty(&sas_device
->list
)) {
690 list_del_init(&sas_device
->list
);
691 sas_device_put(sas_device
);
693 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
697 * _scsih_device_remove_by_handle - removing device object by handle
698 * @ioc: per adapter object
699 * @handle: device handle
704 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
706 struct _sas_device
*sas_device
;
709 if (ioc
->shost_recovery
)
712 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
713 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
715 list_del_init(&sas_device
->list
);
716 sas_device_put(sas_device
);
718 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
720 _scsih_remove_device(ioc
, sas_device
);
721 sas_device_put(sas_device
);
726 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
727 * @ioc: per adapter object
728 * @sas_address: device sas_address
733 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
736 struct _sas_device
*sas_device
;
739 if (ioc
->shost_recovery
)
742 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
743 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
, sas_address
);
745 list_del_init(&sas_device
->list
);
746 sas_device_put(sas_device
);
748 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
750 _scsih_remove_device(ioc
, sas_device
);
751 sas_device_put(sas_device
);
756 * _scsih_sas_device_add - insert sas_device to the list.
757 * @ioc: per adapter object
758 * @sas_device: the sas_device object
759 * Context: This function will acquire ioc->sas_device_lock.
761 * Adding new object to the ioc->sas_device_list.
764 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
765 struct _sas_device
*sas_device
)
769 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
770 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
771 ioc
->name
, __func__
, sas_device
->handle
,
772 (unsigned long long)sas_device
->sas_address
));
774 if (sas_device
->enclosure_handle
!= 0)
775 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
776 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
777 ioc
->name
, __func__
, (unsigned long long)
778 sas_device
->enclosure_logical_id
, sas_device
->slot
));
780 if (sas_device
->connector_name
[0] != '\0')
781 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
782 "%s: enclosure level(0x%04x), connector name( %s)\n",
784 sas_device
->enclosure_level
, sas_device
->connector_name
));
786 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
787 sas_device_get(sas_device
);
788 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
789 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
791 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
792 sas_device
->sas_address_parent
)) {
793 _scsih_sas_device_remove(ioc
, sas_device
);
794 } else if (!sas_device
->starget
) {
796 * When asyn scanning is enabled, its not possible to remove
797 * devices while scanning is turned on due to an oops in
798 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
800 if (!ioc
->is_driver_loading
) {
801 mpt3sas_transport_port_remove(ioc
,
802 sas_device
->sas_address
,
803 sas_device
->sas_address_parent
);
804 _scsih_sas_device_remove(ioc
, sas_device
);
810 * _scsih_sas_device_init_add - insert sas_device to the list.
811 * @ioc: per adapter object
812 * @sas_device: the sas_device object
813 * Context: This function will acquire ioc->sas_device_lock.
815 * Adding new object at driver load time to the ioc->sas_device_init_list.
818 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
819 struct _sas_device
*sas_device
)
823 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
824 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
825 __func__
, sas_device
->handle
,
826 (unsigned long long)sas_device
->sas_address
));
828 if (sas_device
->enclosure_handle
!= 0)
829 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
830 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
831 ioc
->name
, __func__
, (unsigned long long)
832 sas_device
->enclosure_logical_id
, sas_device
->slot
));
834 if (sas_device
->connector_name
[0] != '\0')
835 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
836 "%s: enclosure level(0x%04x), connector name( %s)\n",
837 ioc
->name
, __func__
, sas_device
->enclosure_level
,
838 sas_device
->connector_name
));
840 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
841 sas_device_get(sas_device
);
842 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
843 _scsih_determine_boot_device(ioc
, sas_device
, 0);
844 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
848 * _scsih_raid_device_find_by_id - raid device search
849 * @ioc: per adapter object
850 * @id: sas device target id
851 * @channel: sas device channel
852 * Context: Calling function should acquire ioc->raid_device_lock
854 * This searches for raid_device based on target id, then return raid_device
857 static struct _raid_device
*
858 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
860 struct _raid_device
*raid_device
, *r
;
863 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
864 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
875 * mpt3sas_raid_device_find_by_handle - raid device search
876 * @ioc: per adapter object
877 * @handle: sas device handle (assigned by firmware)
878 * Context: Calling function should acquire ioc->raid_device_lock
880 * This searches for raid_device based on handle, then return raid_device
883 struct _raid_device
*
884 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
886 struct _raid_device
*raid_device
, *r
;
889 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
890 if (raid_device
->handle
!= handle
)
901 * _scsih_raid_device_find_by_wwid - raid device search
902 * @ioc: per adapter object
903 * @handle: sas device handle (assigned by firmware)
904 * Context: Calling function should acquire ioc->raid_device_lock
906 * This searches for raid_device based on wwid, then return raid_device
909 static struct _raid_device
*
910 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
912 struct _raid_device
*raid_device
, *r
;
915 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
916 if (raid_device
->wwid
!= wwid
)
927 * _scsih_raid_device_add - add raid_device object
928 * @ioc: per adapter object
929 * @raid_device: raid_device object
931 * This is added to the raid_device_list link list.
934 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
935 struct _raid_device
*raid_device
)
939 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
940 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
941 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
943 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
944 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
945 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
949 * _scsih_raid_device_remove - delete raid_device object
950 * @ioc: per adapter object
951 * @raid_device: raid_device object
955 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
956 struct _raid_device
*raid_device
)
960 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
961 list_del(&raid_device
->list
);
963 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
967 * mpt3sas_scsih_expander_find_by_handle - expander device search
968 * @ioc: per adapter object
969 * @handle: expander handle (assigned by firmware)
970 * Context: Calling function should acquire ioc->sas_device_lock
972 * This searches for expander device based on handle, then returns the
976 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
978 struct _sas_node
*sas_expander
, *r
;
981 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
982 if (sas_expander
->handle
!= handle
)
992 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
993 * @ioc: per adapter object
994 * @sas_address: sas address
995 * Context: Calling function should acquire ioc->sas_node_lock.
997 * This searches for expander device based on sas_address, then returns the
1001 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1004 struct _sas_node
*sas_expander
, *r
;
1007 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1008 if (sas_expander
->sas_address
!= sas_address
)
1018 * _scsih_expander_node_add - insert expander device to the list.
1019 * @ioc: per adapter object
1020 * @sas_expander: the sas_device object
1021 * Context: This function will acquire ioc->sas_node_lock.
1023 * Adding new object to the ioc->sas_expander_list.
1028 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1029 struct _sas_node
*sas_expander
)
1031 unsigned long flags
;
1033 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1034 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1035 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1039 * _scsih_is_end_device - determines if device is an end device
1040 * @device_info: bitfield providing information about the device.
1043 * Returns 1 if end device.
1046 _scsih_is_end_device(u32 device_info
)
1048 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1049 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1050 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1051 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1058 * _scsih_scsi_lookup_get - returns scmd entry
1059 * @ioc: per adapter object
1060 * @smid: system request message index
1062 * Returns the smid stored scmd pointer.
1064 static struct scsi_cmnd
*
1065 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1067 return ioc
->scsi_lookup
[smid
- 1].scmd
;
1071 * _scsih_scsi_lookup_get_clear - returns scmd entry
1072 * @ioc: per adapter object
1073 * @smid: system request message index
1075 * Returns the smid stored scmd pointer.
1076 * Then will derefrence the stored scmd pointer.
1078 static inline struct scsi_cmnd
*
1079 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1081 unsigned long flags
;
1082 struct scsi_cmnd
*scmd
;
1084 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1085 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
1086 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
1087 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1093 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1094 * @ioc: per adapter object
1095 * @smid: system request message index
1096 * @scmd: pointer to scsi command object
1097 * Context: This function will acquire ioc->scsi_lookup_lock.
1099 * This will search for a scmd pointer in the scsi_lookup array,
1100 * returning the revelent smid. A returned value of zero means invalid.
1103 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1107 unsigned long flags
;
1110 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1112 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1113 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1114 smid
= ioc
->scsi_lookup
[i
].smid
;
1119 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1124 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1125 * @ioc: per adapter object
1128 * Context: This function will acquire ioc->scsi_lookup_lock.
1130 * This will search for a matching channel:id in the scsi_lookup array,
1131 * returning 1 if found.
1134 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1138 unsigned long flags
;
1141 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1143 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1144 if (ioc
->scsi_lookup
[i
].scmd
&&
1145 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1146 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1152 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1157 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1158 * @ioc: per adapter object
1162 * Context: This function will acquire ioc->scsi_lookup_lock.
1164 * This will search for a matching channel:id:lun in the scsi_lookup array,
1165 * returning 1 if found.
1168 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1169 unsigned int lun
, int channel
)
1172 unsigned long flags
;
1175 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1177 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1178 if (ioc
->scsi_lookup
[i
].scmd
&&
1179 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1180 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1181 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1187 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1192 * scsih_change_queue_depth - setting device queue depth
1193 * @sdev: scsi device struct
1194 * @qdepth: requested queue depth
1196 * Returns queue depth.
1199 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1201 struct Scsi_Host
*shost
= sdev
->host
;
1203 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1204 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1205 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1206 struct _sas_device
*sas_device
;
1207 unsigned long flags
;
1209 max_depth
= shost
->can_queue
;
1211 /* limit max device queue for SATA to 32 */
1212 sas_device_priv_data
= sdev
->hostdata
;
1213 if (!sas_device_priv_data
)
1215 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1216 if (!sas_target_priv_data
)
1218 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1221 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1222 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1224 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1225 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1227 sas_device_put(sas_device
);
1229 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1233 if (!sdev
->tagged_supported
)
1235 if (qdepth
> max_depth
)
1237 return scsi_change_queue_depth(sdev
, qdepth
);
1241 * scsih_target_alloc - target add routine
1242 * @starget: scsi target struct
1244 * Returns 0 if ok. Any other return is assumed to be an error and
1245 * the device is ignored.
1248 scsih_target_alloc(struct scsi_target
*starget
)
1250 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1251 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1252 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1253 struct _sas_device
*sas_device
;
1254 struct _raid_device
*raid_device
;
1255 unsigned long flags
;
1256 struct sas_rphy
*rphy
;
1258 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1260 if (!sas_target_priv_data
)
1263 starget
->hostdata
= sas_target_priv_data
;
1264 sas_target_priv_data
->starget
= starget
;
1265 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1268 if (starget
->channel
== RAID_CHANNEL
) {
1269 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1270 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1273 sas_target_priv_data
->handle
= raid_device
->handle
;
1274 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1275 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1276 if (ioc
->is_warpdrive
)
1277 sas_target_priv_data
->raid_device
= raid_device
;
1278 raid_device
->starget
= starget
;
1280 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1284 /* sas/sata devices */
1285 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1286 rphy
= dev_to_rphy(starget
->dev
.parent
);
1287 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1288 rphy
->identify
.sas_address
);
1291 sas_target_priv_data
->handle
= sas_device
->handle
;
1292 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1293 sas_target_priv_data
->sdev
= sas_device
;
1294 sas_device
->starget
= starget
;
1295 sas_device
->id
= starget
->id
;
1296 sas_device
->channel
= starget
->channel
;
1297 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1298 sas_target_priv_data
->flags
|=
1299 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1300 if (sas_device
->fast_path
)
1301 sas_target_priv_data
->flags
|= MPT_TARGET_FASTPATH_IO
;
1303 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1309 * scsih_target_destroy - target destroy routine
1310 * @starget: scsi target struct
1315 scsih_target_destroy(struct scsi_target
*starget
)
1317 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1318 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1319 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1320 struct _sas_device
*sas_device
;
1321 struct _raid_device
*raid_device
;
1322 unsigned long flags
;
1324 sas_target_priv_data
= starget
->hostdata
;
1325 if (!sas_target_priv_data
)
1328 if (starget
->channel
== RAID_CHANNEL
) {
1329 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1330 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1333 raid_device
->starget
= NULL
;
1334 raid_device
->sdev
= NULL
;
1336 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1340 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1341 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1342 if (sas_device
&& (sas_device
->starget
== starget
) &&
1343 (sas_device
->id
== starget
->id
) &&
1344 (sas_device
->channel
== starget
->channel
))
1345 sas_device
->starget
= NULL
;
1349 * Corresponding get() is in _scsih_target_alloc()
1351 sas_target_priv_data
->sdev
= NULL
;
1352 sas_device_put(sas_device
);
1354 sas_device_put(sas_device
);
1356 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1359 kfree(sas_target_priv_data
);
1360 starget
->hostdata
= NULL
;
1364 * scsih_slave_alloc - device add routine
1365 * @sdev: scsi device struct
1367 * Returns 0 if ok. Any other return is assumed to be an error and
1368 * the device is ignored.
1371 scsih_slave_alloc(struct scsi_device
*sdev
)
1373 struct Scsi_Host
*shost
;
1374 struct MPT3SAS_ADAPTER
*ioc
;
1375 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1376 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1377 struct scsi_target
*starget
;
1378 struct _raid_device
*raid_device
;
1379 struct _sas_device
*sas_device
;
1380 unsigned long flags
;
1382 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1384 if (!sas_device_priv_data
)
1387 sas_device_priv_data
->lun
= sdev
->lun
;
1388 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1390 starget
= scsi_target(sdev
);
1391 sas_target_priv_data
= starget
->hostdata
;
1392 sas_target_priv_data
->num_luns
++;
1393 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1394 sdev
->hostdata
= sas_device_priv_data
;
1395 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1396 sdev
->no_uld_attach
= 1;
1398 shost
= dev_to_shost(&starget
->dev
);
1399 ioc
= shost_priv(shost
);
1400 if (starget
->channel
== RAID_CHANNEL
) {
1401 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1402 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1403 starget
->id
, starget
->channel
);
1405 raid_device
->sdev
= sdev
; /* raid is single lun */
1406 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1409 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1410 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1411 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1412 sas_target_priv_data
->sas_address
);
1413 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1414 sdev_printk(KERN_INFO
, sdev
,
1415 "%s : sas_device->starget set to starget @ %d\n",
1416 __func__
, __LINE__
);
1417 sas_device
->starget
= starget
;
1421 sas_device_put(sas_device
);
1423 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1430 * scsih_slave_destroy - device destroy routine
1431 * @sdev: scsi device struct
1436 scsih_slave_destroy(struct scsi_device
*sdev
)
1438 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1439 struct scsi_target
*starget
;
1440 struct Scsi_Host
*shost
;
1441 struct MPT3SAS_ADAPTER
*ioc
;
1442 struct _sas_device
*sas_device
;
1443 unsigned long flags
;
1445 if (!sdev
->hostdata
)
1448 starget
= scsi_target(sdev
);
1449 sas_target_priv_data
= starget
->hostdata
;
1450 sas_target_priv_data
->num_luns
--;
1452 shost
= dev_to_shost(&starget
->dev
);
1453 ioc
= shost_priv(shost
);
1455 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1456 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1457 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1458 sas_target_priv_data
);
1459 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1460 sas_device
->starget
= NULL
;
1463 sas_device_put(sas_device
);
1464 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1467 kfree(sdev
->hostdata
);
1468 sdev
->hostdata
= NULL
;
1472 * _scsih_display_sata_capabilities - sata capabilities
1473 * @ioc: per adapter object
1474 * @handle: device handle
1475 * @sdev: scsi device struct
1478 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1479 u16 handle
, struct scsi_device
*sdev
)
1481 Mpi2ConfigReply_t mpi_reply
;
1482 Mpi2SasDevicePage0_t sas_device_pg0
;
1487 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1488 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1489 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1490 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1494 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1495 MPI2_IOCSTATUS_MASK
;
1496 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1497 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1498 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1502 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1503 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1505 sdev_printk(KERN_INFO
, sdev
,
1506 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1507 "sw_preserve(%s)\n",
1508 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1509 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1510 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1512 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1513 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1514 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1518 * raid transport support -
1519 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1520 * unloading the driver followed by a load - I beleive that the subroutine
1521 * raid_class_release() is not cleaning up properly.
1525 * scsih_is_raid - return boolean indicating device is raid volume
1526 * @dev the device struct object
1529 scsih_is_raid(struct device
*dev
)
1531 struct scsi_device
*sdev
= to_scsi_device(dev
);
1532 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1534 if (ioc
->is_warpdrive
)
1536 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1540 * scsih_get_resync - get raid volume resync percent complete
1541 * @dev the device struct object
1544 scsih_get_resync(struct device
*dev
)
1546 struct scsi_device
*sdev
= to_scsi_device(dev
);
1547 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1548 static struct _raid_device
*raid_device
;
1549 unsigned long flags
;
1550 Mpi2RaidVolPage0_t vol_pg0
;
1551 Mpi2ConfigReply_t mpi_reply
;
1552 u32 volume_status_flags
;
1553 u8 percent_complete
;
1556 percent_complete
= 0;
1558 if (ioc
->is_warpdrive
)
1561 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1562 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1565 handle
= raid_device
->handle
;
1566 percent_complete
= raid_device
->percent_complete
;
1568 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1573 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1574 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1575 sizeof(Mpi2RaidVolPage0_t
))) {
1576 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1577 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1578 percent_complete
= 0;
1582 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1583 if (!(volume_status_flags
&
1584 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1585 percent_complete
= 0;
1589 switch (ioc
->hba_mpi_version_belonged
) {
1591 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1595 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1601 * scsih_get_state - get raid volume level
1602 * @dev the device struct object
1605 scsih_get_state(struct device
*dev
)
1607 struct scsi_device
*sdev
= to_scsi_device(dev
);
1608 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1609 static struct _raid_device
*raid_device
;
1610 unsigned long flags
;
1611 Mpi2RaidVolPage0_t vol_pg0
;
1612 Mpi2ConfigReply_t mpi_reply
;
1614 enum raid_state state
= RAID_STATE_UNKNOWN
;
1617 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1618 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1621 handle
= raid_device
->handle
;
1622 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1627 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1628 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1629 sizeof(Mpi2RaidVolPage0_t
))) {
1630 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1631 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1635 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1636 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1637 state
= RAID_STATE_RESYNCING
;
1641 switch (vol_pg0
.VolumeState
) {
1642 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1643 case MPI2_RAID_VOL_STATE_ONLINE
:
1644 state
= RAID_STATE_ACTIVE
;
1646 case MPI2_RAID_VOL_STATE_DEGRADED
:
1647 state
= RAID_STATE_DEGRADED
;
1649 case MPI2_RAID_VOL_STATE_FAILED
:
1650 case MPI2_RAID_VOL_STATE_MISSING
:
1651 state
= RAID_STATE_OFFLINE
;
1655 switch (ioc
->hba_mpi_version_belonged
) {
1657 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1661 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1667 * _scsih_set_level - set raid level
1668 * @sdev: scsi device struct
1669 * @volume_type: volume type
1672 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
1673 struct scsi_device
*sdev
, u8 volume_type
)
1675 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1677 switch (volume_type
) {
1678 case MPI2_RAID_VOL_TYPE_RAID0
:
1679 level
= RAID_LEVEL_0
;
1681 case MPI2_RAID_VOL_TYPE_RAID10
:
1682 level
= RAID_LEVEL_10
;
1684 case MPI2_RAID_VOL_TYPE_RAID1E
:
1685 level
= RAID_LEVEL_1E
;
1687 case MPI2_RAID_VOL_TYPE_RAID1
:
1688 level
= RAID_LEVEL_1
;
1692 switch (ioc
->hba_mpi_version_belonged
) {
1694 raid_set_level(mpt2sas_raid_template
,
1695 &sdev
->sdev_gendev
, level
);
1699 raid_set_level(mpt3sas_raid_template
,
1700 &sdev
->sdev_gendev
, level
);
1707 * _scsih_get_volume_capabilities - volume capabilities
1708 * @ioc: per adapter object
1709 * @sas_device: the raid_device object
1711 * Returns 0 for success, else 1
1714 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1715 struct _raid_device
*raid_device
)
1717 Mpi2RaidVolPage0_t
*vol_pg0
;
1718 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1719 Mpi2SasDevicePage0_t sas_device_pg0
;
1720 Mpi2ConfigReply_t mpi_reply
;
1724 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1725 &num_pds
)) || !num_pds
) {
1726 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1727 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1732 raid_device
->num_pds
= num_pds
;
1733 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1734 sizeof(Mpi2RaidVol0PhysDisk_t
));
1735 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1737 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1738 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1743 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1744 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1745 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1746 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1752 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1754 /* figure out what the underlying devices are by
1755 * obtaining the device_info bits for the 1st device
1757 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1758 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1759 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1760 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1761 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1762 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1763 raid_device
->device_info
=
1764 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1773 * _scsih_enable_tlr - setting TLR flags
1774 * @ioc: per adapter object
1775 * @sdev: scsi device struct
1777 * Enabling Transaction Layer Retries for tape devices when
1778 * vpd page 0x90 is present
1782 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1786 if (sdev
->type
!= TYPE_TAPE
)
1789 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1792 sas_enable_tlr(sdev
);
1793 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1794 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1800 * scsih_slave_configure - device configure routine.
1801 * @sdev: scsi device struct
1803 * Returns 0 if ok. Any other return is assumed to be an error and
1804 * the device is ignored.
1807 scsih_slave_configure(struct scsi_device
*sdev
)
1809 struct Scsi_Host
*shost
= sdev
->host
;
1810 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1811 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1812 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1813 struct _sas_device
*sas_device
;
1814 struct _raid_device
*raid_device
;
1815 unsigned long flags
;
1820 u16 handle
, volume_handle
= 0;
1821 u64 volume_wwid
= 0;
1824 sas_device_priv_data
= sdev
->hostdata
;
1825 sas_device_priv_data
->configured_lun
= 1;
1826 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1827 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1828 handle
= sas_target_priv_data
->handle
;
1830 /* raid volume handling */
1831 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1833 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1834 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
1835 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1837 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1838 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1839 __LINE__
, __func__
));
1843 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1844 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1845 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1846 __LINE__
, __func__
));
1851 * WARPDRIVE: Initialize the required data for Direct IO
1853 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
1855 /* RAID Queue Depth Support
1856 * IS volume = underlying qdepth of drive type, either
1857 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1858 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1860 if (raid_device
->device_info
&
1861 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1862 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1865 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1866 if (raid_device
->device_info
&
1867 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1873 switch (raid_device
->volume_type
) {
1874 case MPI2_RAID_VOL_TYPE_RAID0
:
1877 case MPI2_RAID_VOL_TYPE_RAID1E
:
1878 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1879 if (ioc
->manu_pg10
.OEMIdentifier
&&
1880 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1881 MFG10_GF0_R10_DISPLAY
) &&
1882 !(raid_device
->num_pds
% 2))
1887 case MPI2_RAID_VOL_TYPE_RAID1
:
1888 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1891 case MPI2_RAID_VOL_TYPE_RAID10
:
1892 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1895 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1897 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1902 if (!ioc
->hide_ir_msg
)
1903 sdev_printk(KERN_INFO
, sdev
,
1904 "%s: handle(0x%04x), wwid(0x%016llx),"
1905 " pd_count(%d), type(%s)\n",
1906 r_level
, raid_device
->handle
,
1907 (unsigned long long)raid_device
->wwid
,
1908 raid_device
->num_pds
, ds
);
1910 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
1911 blk_queue_max_hw_sectors(sdev
->request_queue
,
1912 MPT3SAS_RAID_MAX_SECTORS
);
1913 sdev_printk(KERN_INFO
, sdev
,
1914 "Set queue's max_sector to: %u\n",
1915 MPT3SAS_RAID_MAX_SECTORS
);
1918 scsih_change_queue_depth(sdev
, qdepth
);
1920 /* raid transport support */
1921 if (!ioc
->is_warpdrive
)
1922 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
1926 /* non-raid handling */
1927 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1928 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1930 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1931 "failure at %s:%d/%s()!\n", ioc
->name
,
1932 __FILE__
, __LINE__
, __func__
));
1935 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1936 volume_handle
, &volume_wwid
)) {
1937 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1938 "failure at %s:%d/%s()!\n", ioc
->name
,
1939 __FILE__
, __LINE__
, __func__
));
1944 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1945 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1946 sas_device_priv_data
->sas_target
->sas_address
);
1948 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1949 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1950 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1955 sas_device
->volume_handle
= volume_handle
;
1956 sas_device
->volume_wwid
= volume_wwid
;
1957 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1958 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1960 if (sas_device
->device_info
&
1961 MPI2_SAS_DEVICE_INFO_SEP
) {
1962 sdev_printk(KERN_WARNING
, sdev
,
1963 "set ignore_delay_remove for handle(0x%04x)\n",
1964 sas_device_priv_data
->sas_target
->handle
);
1965 sas_device_priv_data
->ignore_delay_remove
= 1;
1970 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1971 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1973 else if (sas_device
->device_info
&
1974 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1978 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
1979 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1980 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
1981 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
1982 if (sas_device
->enclosure_handle
!= 0)
1983 sdev_printk(KERN_INFO
, sdev
,
1984 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1985 ds
, (unsigned long long)
1986 sas_device
->enclosure_logical_id
, sas_device
->slot
);
1987 if (sas_device
->connector_name
[0] != '\0')
1988 sdev_printk(KERN_INFO
, sdev
,
1989 "%s: enclosure level(0x%04x), connector name( %s)\n",
1990 ds
, sas_device
->enclosure_level
,
1991 sas_device
->connector_name
);
1993 sas_device_put(sas_device
);
1994 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1997 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2000 scsih_change_queue_depth(sdev
, qdepth
);
2003 sas_read_port_mode_page(sdev
);
2004 _scsih_enable_tlr(ioc
, sdev
);
2011 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2012 * @sdev: scsi device struct
2013 * @bdev: pointer to block device context
2014 * @capacity: device size (in 512 byte sectors)
2015 * @params: three element array to place output:
2016 * params[0] number of heads (max 255)
2017 * params[1] number of sectors (max 63)
2018 * params[2] number of cylinders
2023 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2024 sector_t capacity
, int params
[])
2034 dummy
= heads
* sectors
;
2035 cylinders
= capacity
;
2036 sector_div(cylinders
, dummy
);
2039 * Handle extended translation size for logical drives
2042 if ((ulong
)capacity
>= 0x200000) {
2045 dummy
= heads
* sectors
;
2046 cylinders
= capacity
;
2047 sector_div(cylinders
, dummy
);
2052 params
[1] = sectors
;
2053 params
[2] = cylinders
;
2059 * _scsih_response_code - translation of device response code
2060 * @ioc: per adapter object
2061 * @response_code: response code returned by the device
2066 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2070 switch (response_code
) {
2071 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2072 desc
= "task management request completed";
2074 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2075 desc
= "invalid frame";
2077 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2078 desc
= "task management request not supported";
2080 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2081 desc
= "task management request failed";
2083 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2084 desc
= "task management request succeeded";
2086 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2087 desc
= "invalid lun";
2090 desc
= "overlapped tag attempted";
2092 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2093 desc
= "task queued, however not sent to target";
2099 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2100 ioc
->name
, response_code
, desc
);
2104 * _scsih_tm_done - tm completion routine
2105 * @ioc: per adapter object
2106 * @smid: system request message index
2107 * @msix_index: MSIX table index supplied by the OS
2108 * @reply: reply message frame(lower 32bit addr)
2111 * The callback handler when using scsih_issue_tm.
2113 * Return 1 meaning mf should be freed from _base_interrupt
2114 * 0 means the mf is freed from this function.
2117 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2119 MPI2DefaultReply_t
*mpi_reply
;
2121 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2123 if (ioc
->tm_cmds
.smid
!= smid
)
2125 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2126 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2128 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2129 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2131 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2132 complete(&ioc
->tm_cmds
.done
);
2137 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2138 * @ioc: per adapter object
2139 * @handle: device handle
2141 * During taskmangement request, we need to freeze the device queue.
2144 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2146 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2147 struct scsi_device
*sdev
;
2150 shost_for_each_device(sdev
, ioc
->shost
) {
2153 sas_device_priv_data
= sdev
->hostdata
;
2154 if (!sas_device_priv_data
)
2156 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2157 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2159 ioc
->ignore_loginfos
= 1;
2165 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2166 * @ioc: per adapter object
2167 * @handle: device handle
2169 * During taskmangement request, we need to freeze the device queue.
2172 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2174 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2175 struct scsi_device
*sdev
;
2178 shost_for_each_device(sdev
, ioc
->shost
) {
2181 sas_device_priv_data
= sdev
->hostdata
;
2182 if (!sas_device_priv_data
)
2184 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2185 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2187 ioc
->ignore_loginfos
= 0;
2193 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2194 * @ioc: per adapter struct
2195 * @device_handle: device handle
2196 * @channel: the channel assigned by the OS
2197 * @id: the id assigned by the OS
2199 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2200 * @smid_task: smid assigned to the task
2201 * @timeout: timeout in seconds
2204 * A generic API for sending task management requests to firmware.
2206 * The callback index is set inside `ioc->tm_cb_idx`.
2208 * Return SUCCESS or FAILED.
2211 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2212 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2214 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2215 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2218 struct scsiio_tracker
*scsi_lookup
= NULL
;
2222 lockdep_assert_held(&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
);
2230 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2231 ioc
->pci_error_recovery
) {
2232 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2233 __func__
, ioc
->name
);
2237 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2238 if (ioc_state
& MPI2_DOORBELL_USED
) {
2239 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2240 "unexpected doorbell active!\n", ioc
->name
));
2241 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2242 return (!rc
) ? SUCCESS
: FAILED
;
2245 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2246 mpt3sas_base_fault_info(ioc
, ioc_state
&
2247 MPI2_DOORBELL_DATA_MASK
);
2248 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2249 return (!rc
) ? SUCCESS
: FAILED
;
2252 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2254 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2255 ioc
->name
, __func__
);
2259 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2260 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2262 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2263 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2264 ioc
->name
, handle
, type
, smid_task
));
2265 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2266 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2267 ioc
->tm_cmds
.smid
= smid
;
2268 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2269 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2270 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2271 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2272 mpi_request
->TaskType
= type
;
2273 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2274 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2275 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2276 init_completion(&ioc
->tm_cmds
.done
);
2277 if ((type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) &&
2278 (scsi_lookup
->msix_io
< ioc
->reply_queue_count
))
2279 msix_task
= scsi_lookup
->msix_io
;
2282 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, msix_task
);
2283 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2284 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2285 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2286 ioc
->name
, __func__
);
2287 _debug_dump_mf(mpi_request
,
2288 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2289 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2290 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2292 rc
= (!rc
) ? SUCCESS
: FAILED
;
2297 /* sync IRQs in case those were busy during flush. */
2298 mpt3sas_base_sync_reply_irqs(ioc
);
2300 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2301 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2302 mpi_reply
= ioc
->tm_cmds
.reply
;
2303 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2304 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2305 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2306 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2307 le32_to_cpu(mpi_reply
->TerminationCount
)));
2308 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2309 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2310 if (mpi_reply
->IOCStatus
)
2311 _debug_dump_mf(mpi_request
,
2312 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2317 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2319 if (scsi_lookup
->scmd
== NULL
)
2324 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2325 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2330 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2331 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2332 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2337 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2346 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2347 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2351 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2352 uint channel
, uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2356 mutex_lock(&ioc
->tm_cmds
.mutex
);
2357 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, channel
, id
, lun
, type
,
2358 smid_task
, timeout
);
2359 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_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2478 scmd
->device
->id
, scmd
->device
->lun
,
2479 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
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_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2537 scmd
->device
->id
, scmd
->device
->lun
,
2538 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30);
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_locked_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
, FORCE_BIG_HAMMER
);
2637 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2639 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2640 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2646 * _scsih_fw_event_add - insert and queue up fw_event
2647 * @ioc: per adapter object
2648 * @fw_event: object describing the event
2649 * Context: This function will acquire ioc->fw_event_lock.
2651 * This adds the firmware event object into link list, then queues it up to
2652 * be processed from user context.
2657 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2659 unsigned long flags
;
2661 if (ioc
->firmware_event_thread
== NULL
)
2664 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2665 fw_event_work_get(fw_event
);
2666 INIT_LIST_HEAD(&fw_event
->list
);
2667 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2668 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2669 fw_event_work_get(fw_event
);
2670 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2671 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2675 * _scsih_fw_event_del_from_list - delete fw_event from the list
2676 * @ioc: per adapter object
2677 * @fw_event: object describing the event
2678 * Context: This function will acquire ioc->fw_event_lock.
2680 * If the fw_event is on the fw_event_list, remove it and do a put.
2685 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2688 unsigned long flags
;
2690 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2691 if (!list_empty(&fw_event
->list
)) {
2692 list_del_init(&fw_event
->list
);
2693 fw_event_work_put(fw_event
);
2695 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2700 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2701 * @ioc: per adapter object
2702 * @event_data: trigger event data
2707 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2708 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2710 struct fw_event_work
*fw_event
;
2713 if (ioc
->is_driver_loading
)
2715 sz
= sizeof(*event_data
);
2716 fw_event
= alloc_fw_event_work(sz
);
2719 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2720 fw_event
->ioc
= ioc
;
2721 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2722 _scsih_fw_event_add(ioc
, fw_event
);
2723 fw_event_work_put(fw_event
);
2727 * _scsih_error_recovery_delete_devices - remove devices not responding
2728 * @ioc: per adapter object
2733 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2735 struct fw_event_work
*fw_event
;
2737 if (ioc
->is_driver_loading
)
2739 fw_event
= alloc_fw_event_work(0);
2742 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2743 fw_event
->ioc
= ioc
;
2744 _scsih_fw_event_add(ioc
, fw_event
);
2745 fw_event_work_put(fw_event
);
2749 * mpt3sas_port_enable_complete - port enable completed (fake event)
2750 * @ioc: per adapter object
2755 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2757 struct fw_event_work
*fw_event
;
2759 fw_event
= alloc_fw_event_work(0);
2762 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2763 fw_event
->ioc
= ioc
;
2764 _scsih_fw_event_add(ioc
, fw_event
);
2765 fw_event_work_put(fw_event
);
2768 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
2770 unsigned long flags
;
2771 struct fw_event_work
*fw_event
= NULL
;
2773 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2774 if (!list_empty(&ioc
->fw_event_list
)) {
2775 fw_event
= list_first_entry(&ioc
->fw_event_list
,
2776 struct fw_event_work
, list
);
2777 list_del_init(&fw_event
->list
);
2779 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2785 * _scsih_fw_event_cleanup_queue - cleanup event queue
2786 * @ioc: per adapter object
2788 * Walk the firmware event queue, either killing timers, or waiting
2789 * for outstanding events to complete
2794 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2796 struct fw_event_work
*fw_event
;
2798 if (list_empty(&ioc
->fw_event_list
) ||
2799 !ioc
->firmware_event_thread
|| in_interrupt())
2802 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
2804 * Wait on the fw_event to complete. If this returns 1, then
2805 * the event was never executed, and we need a put for the
2806 * reference the work had on the fw_event.
2808 * If it did execute, we wait for it to finish, and the put will
2809 * happen from _firmware_event_work()
2811 if (cancel_work_sync(&fw_event
->work
))
2812 fw_event_work_put(fw_event
);
2814 fw_event_work_put(fw_event
);
2819 * _scsih_internal_device_block - block the sdev device
2820 * @sdev: per device object
2821 * @sas_device_priv_data : per device driver private data
2823 * make sure device is blocked without error, if not
2827 _scsih_internal_device_block(struct scsi_device
*sdev
,
2828 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2832 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
2833 sas_device_priv_data
->sas_target
->handle
);
2834 sas_device_priv_data
->block
= 1;
2836 r
= scsi_internal_device_block(sdev
);
2838 sdev_printk(KERN_WARNING
, sdev
,
2839 "device_block failed with return(%d) for handle(0x%04x)\n",
2840 sas_device_priv_data
->sas_target
->handle
, r
);
2844 * _scsih_internal_device_unblock - unblock the sdev device
2845 * @sdev: per device object
2846 * @sas_device_priv_data : per device driver private data
2847 * make sure device is unblocked without error, if not retry
2848 * by blocking and then unblocking
2852 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
2853 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2857 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
2858 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
2859 sas_device_priv_data
->block
= 0;
2860 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2862 /* The device has been set to SDEV_RUNNING by SD layer during
2863 * device addition but the request queue is still stopped by
2864 * our earlier block call. We need to perform a block again
2865 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2867 sdev_printk(KERN_WARNING
, sdev
,
2868 "device_unblock failed with return(%d) for handle(0x%04x) "
2869 "performing a block followed by an unblock\n",
2870 sas_device_priv_data
->sas_target
->handle
, r
);
2871 sas_device_priv_data
->block
= 1;
2872 r
= scsi_internal_device_block(sdev
);
2874 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
2875 "failed with return(%d) for handle(0x%04x)\n",
2876 sas_device_priv_data
->sas_target
->handle
, r
);
2878 sas_device_priv_data
->block
= 0;
2879 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2881 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
2882 " failed with return(%d) for handle(0x%04x)\n",
2883 sas_device_priv_data
->sas_target
->handle
, r
);
2888 * _scsih_ublock_io_all_device - unblock every device
2889 * @ioc: per adapter object
2891 * change the device state from block to running
2894 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2896 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2897 struct scsi_device
*sdev
;
2899 shost_for_each_device(sdev
, ioc
->shost
) {
2900 sas_device_priv_data
= sdev
->hostdata
;
2901 if (!sas_device_priv_data
)
2903 if (!sas_device_priv_data
->block
)
2906 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2907 "device_running, handle(0x%04x)\n",
2908 sas_device_priv_data
->sas_target
->handle
));
2909 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
2915 * _scsih_ublock_io_device - prepare device to be deleted
2916 * @ioc: per adapter object
2917 * @sas_addr: sas address
2919 * unblock then put device in offline state
2922 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2924 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2925 struct scsi_device
*sdev
;
2927 shost_for_each_device(sdev
, ioc
->shost
) {
2928 sas_device_priv_data
= sdev
->hostdata
;
2929 if (!sas_device_priv_data
)
2931 if (sas_device_priv_data
->sas_target
->sas_address
2934 if (sas_device_priv_data
->block
)
2935 _scsih_internal_device_unblock(sdev
,
2936 sas_device_priv_data
);
2941 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2942 * @ioc: per adapter object
2943 * @handle: device handle
2945 * During device pull we need to appropiately set the sdev state.
2948 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2950 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2951 struct scsi_device
*sdev
;
2953 shost_for_each_device(sdev
, ioc
->shost
) {
2954 sas_device_priv_data
= sdev
->hostdata
;
2955 if (!sas_device_priv_data
)
2957 if (sas_device_priv_data
->block
)
2959 if (sas_device_priv_data
->ignore_delay_remove
) {
2960 sdev_printk(KERN_INFO
, sdev
,
2961 "%s skip device_block for SES handle(0x%04x)\n",
2962 __func__
, sas_device_priv_data
->sas_target
->handle
);
2965 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2970 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2971 * @ioc: per adapter object
2972 * @handle: device handle
2974 * During device pull we need to appropiately set the sdev state.
2977 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2979 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2980 struct scsi_device
*sdev
;
2981 struct _sas_device
*sas_device
;
2983 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
2987 shost_for_each_device(sdev
, ioc
->shost
) {
2988 sas_device_priv_data
= sdev
->hostdata
;
2989 if (!sas_device_priv_data
)
2991 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
2993 if (sas_device_priv_data
->block
)
2995 if (sas_device
->pend_sas_rphy_add
)
2997 if (sas_device_priv_data
->ignore_delay_remove
) {
2998 sdev_printk(KERN_INFO
, sdev
,
2999 "%s skip device_block for SES handle(0x%04x)\n",
3000 __func__
, sas_device_priv_data
->sas_target
->handle
);
3003 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3006 sas_device_put(sas_device
);
3010 * _scsih_block_io_to_children_attached_to_ex
3011 * @ioc: per adapter object
3012 * @sas_expander: the sas_device object
3014 * This routine set sdev state to SDEV_BLOCK for all devices
3015 * attached to this expander. This function called when expander is
3019 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3020 struct _sas_node
*sas_expander
)
3022 struct _sas_port
*mpt3sas_port
;
3023 struct _sas_device
*sas_device
;
3024 struct _sas_node
*expander_sibling
;
3025 unsigned long flags
;
3030 list_for_each_entry(mpt3sas_port
,
3031 &sas_expander
->sas_port_list
, port_list
) {
3032 if (mpt3sas_port
->remote_identify
.device_type
==
3034 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3035 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3036 mpt3sas_port
->remote_identify
.sas_address
);
3038 set_bit(sas_device
->handle
,
3039 ioc
->blocking_handles
);
3040 sas_device_put(sas_device
);
3042 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3046 list_for_each_entry(mpt3sas_port
,
3047 &sas_expander
->sas_port_list
, port_list
) {
3049 if (mpt3sas_port
->remote_identify
.device_type
==
3050 SAS_EDGE_EXPANDER_DEVICE
||
3051 mpt3sas_port
->remote_identify
.device_type
==
3052 SAS_FANOUT_EXPANDER_DEVICE
) {
3054 mpt3sas_scsih_expander_find_by_sas_address(
3055 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3056 _scsih_block_io_to_children_attached_to_ex(ioc
,
3063 * _scsih_block_io_to_children_attached_directly
3064 * @ioc: per adapter object
3065 * @event_data: topology change event data
3067 * This routine set sdev state to SDEV_BLOCK for all devices
3068 * direct attached during device pull.
3071 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3072 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3078 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3079 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3082 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3083 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3084 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3085 _scsih_block_io_device(ioc
, handle
);
3090 * _scsih_tm_tr_send - send task management request
3091 * @ioc: per adapter object
3092 * @handle: device handle
3093 * Context: interrupt time.
3095 * This code is to initiate the device removal handshake protocol
3096 * with controller firmware. This function will issue target reset
3097 * using high priority request queue. It will send a sas iounit
3098 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3100 * This is designed to send muliple task management request at the same
3101 * time to the fifo. If the fifo is full, we will append the request,
3102 * and process it in a future completion.
3105 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3107 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3109 struct _sas_device
*sas_device
= NULL
;
3110 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3111 u64 sas_address
= 0;
3112 unsigned long flags
;
3113 struct _tr_list
*delayed_tr
;
3116 if (ioc
->remove_host
) {
3117 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3118 "%s: host has been removed: handle(0x%04x)\n",
3119 __func__
, ioc
->name
, handle
));
3121 } else if (ioc
->pci_error_recovery
) {
3122 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3123 "%s: host in pci error recovery: handle(0x%04x)\n",
3124 __func__
, ioc
->name
,
3128 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3129 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3130 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3131 "%s: host is not operational: handle(0x%04x)\n",
3132 __func__
, ioc
->name
,
3137 /* if PD, then return */
3138 if (test_bit(handle
, ioc
->pd_handles
))
3141 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3142 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3143 if (sas_device
&& sas_device
->starget
&&
3144 sas_device
->starget
->hostdata
) {
3145 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3146 sas_target_priv_data
->deleted
= 1;
3147 sas_address
= sas_device
->sas_address
;
3149 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3151 if (sas_target_priv_data
) {
3152 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3153 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3155 (unsigned long long)sas_address
));
3156 if (sas_device
->enclosure_handle
!= 0)
3157 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3158 "setting delete flag:enclosure logical id(0x%016llx),"
3159 " slot(%d)\n", ioc
->name
, (unsigned long long)
3160 sas_device
->enclosure_logical_id
,
3162 if (sas_device
->connector_name
[0] != '\0')
3163 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3164 "setting delete flag: enclosure level(0x%04x),"
3165 " connector name( %s)\n", ioc
->name
,
3166 sas_device
->enclosure_level
,
3167 sas_device
->connector_name
));
3168 _scsih_ublock_io_device(ioc
, sas_address
);
3169 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3172 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3174 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3177 INIT_LIST_HEAD(&delayed_tr
->list
);
3178 delayed_tr
->handle
= handle
;
3179 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3180 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3181 "DELAYED:tr:handle(0x%04x), (open)\n",
3182 ioc
->name
, handle
));
3186 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3187 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3188 ioc
->name
, handle
, smid
,
3189 ioc
->tm_tr_cb_idx
));
3190 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3191 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3192 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3193 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3194 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3195 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
3196 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3200 sas_device_put(sas_device
);
3204 * _scsih_tm_tr_complete -
3205 * @ioc: per adapter object
3206 * @smid: system request message index
3207 * @msix_index: MSIX table index supplied by the OS
3208 * @reply: reply message frame(lower 32bit addr)
3209 * Context: interrupt time.
3211 * This is the target reset completion routine.
3212 * This code is part of the code to initiate the device removal
3213 * handshake protocol with controller firmware.
3214 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3216 * Return 1 meaning mf should be freed from _base_interrupt
3217 * 0 means the mf is freed from this function.
3220 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3224 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3225 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3226 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3227 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3230 struct _sc_list
*delayed_sc
;
3232 if (ioc
->remove_host
) {
3233 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3234 "%s: host has been removed\n", __func__
, ioc
->name
));
3236 } else if (ioc
->pci_error_recovery
) {
3237 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3238 "%s: host in pci error recovery\n", __func__
,
3242 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3243 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3244 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3245 "%s: host is not operational\n", __func__
, ioc
->name
));
3248 if (unlikely(!mpi_reply
)) {
3249 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3250 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3253 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3254 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3255 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3256 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3257 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3259 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3263 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3264 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3265 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3266 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3267 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3268 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3269 le32_to_cpu(mpi_reply
->TerminationCount
)));
3271 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3272 if (!smid_sas_ctrl
) {
3273 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3275 return _scsih_check_for_pending_tm(ioc
, smid
);
3276 INIT_LIST_HEAD(&delayed_sc
->list
);
3277 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3278 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3279 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3280 "DELAYED:sc:handle(0x%04x), (open)\n",
3281 ioc
->name
, handle
));
3282 return _scsih_check_for_pending_tm(ioc
, smid
);
3285 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3286 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3287 ioc
->name
, handle
, smid_sas_ctrl
,
3288 ioc
->tm_sas_control_cb_idx
));
3289 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3290 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3291 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3292 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3293 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3294 mpt3sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3296 return _scsih_check_for_pending_tm(ioc
, smid
);
3301 * _scsih_sas_control_complete - completion routine
3302 * @ioc: per adapter object
3303 * @smid: system request message index
3304 * @msix_index: MSIX table index supplied by the OS
3305 * @reply: reply message frame(lower 32bit addr)
3306 * Context: interrupt time.
3308 * This is the sas iounit control completion routine.
3309 * This code is part of the code to initiate the device removal
3310 * handshake protocol with controller firmware.
3312 * Return 1 meaning mf should be freed from _base_interrupt
3313 * 0 means the mf is freed from this function.
3316 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3317 u8 msix_index
, u32 reply
)
3319 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3320 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3322 if (likely(mpi_reply
)) {
3323 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3324 "sc_complete:handle(0x%04x), (open) "
3325 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3326 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3327 le16_to_cpu(mpi_reply
->IOCStatus
),
3328 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3330 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3331 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3333 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3337 * _scsih_tm_tr_volume_send - send target reset request for volumes
3338 * @ioc: per adapter object
3339 * @handle: device handle
3340 * Context: interrupt time.
3342 * This is designed to send muliple task management request at the same
3343 * time to the fifo. If the fifo is full, we will append the request,
3344 * and process it in a future completion.
3347 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3349 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3351 struct _tr_list
*delayed_tr
;
3353 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3354 ioc
->pci_error_recovery
) {
3355 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3356 "%s: host reset in progress!\n",
3357 __func__
, ioc
->name
));
3361 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3363 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3366 INIT_LIST_HEAD(&delayed_tr
->list
);
3367 delayed_tr
->handle
= handle
;
3368 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3369 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3370 "DELAYED:tr:handle(0x%04x), (open)\n",
3371 ioc
->name
, handle
));
3375 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3376 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3377 ioc
->name
, handle
, smid
,
3378 ioc
->tm_tr_volume_cb_idx
));
3379 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3380 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3381 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3382 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3383 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3384 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
3388 * _scsih_tm_volume_tr_complete - target reset completion
3389 * @ioc: per adapter object
3390 * @smid: system request message index
3391 * @msix_index: MSIX table index supplied by the OS
3392 * @reply: reply message frame(lower 32bit addr)
3393 * Context: interrupt time.
3395 * Return 1 meaning mf should be freed from _base_interrupt
3396 * 0 means the mf is freed from this function.
3399 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3400 u8 msix_index
, u32 reply
)
3403 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3404 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3405 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3407 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3408 ioc
->pci_error_recovery
) {
3409 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3410 "%s: host reset in progress!\n",
3411 __func__
, ioc
->name
));
3414 if (unlikely(!mpi_reply
)) {
3415 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3416 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3420 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3421 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3422 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3423 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3424 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3426 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3430 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3431 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3432 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3433 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3434 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3435 le32_to_cpu(mpi_reply
->TerminationCount
)));
3437 return _scsih_check_for_pending_tm(ioc
, smid
);
3441 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3442 * @ioc: per adapter object
3443 * @smid: system request message index
3445 * @event_context: used to track events uniquely
3447 * Context - processed in interrupt context.
3450 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
3453 Mpi2EventAckRequest_t
*ack_request
;
3454 int i
= smid
- ioc
->internal_smid
;
3455 unsigned long flags
;
3457 /* Without releasing the smid just update the
3458 * call back index and reuse the same smid for
3459 * processing this delayed request
3461 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3462 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3463 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3465 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3466 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3467 ioc
->name
, le16_to_cpu(event
), smid
,
3469 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3470 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3471 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3472 ack_request
->Event
= event
;
3473 ack_request
->EventContext
= event_context
;
3474 ack_request
->VF_ID
= 0; /* TODO */
3475 ack_request
->VP_ID
= 0;
3476 mpt3sas_base_put_smid_default(ioc
, smid
);
3480 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3481 * sas_io_unit_ctrl messages
3482 * @ioc: per adapter object
3483 * @smid: system request message index
3484 * @handle: device handle
3486 * Context - processed in interrupt context.
3489 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
3490 u16 smid
, u16 handle
)
3492 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3494 int i
= smid
- ioc
->internal_smid
;
3495 unsigned long flags
;
3497 if (ioc
->remove_host
) {
3498 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3499 "%s: host has been removed\n",
3500 __func__
, ioc
->name
));
3502 } else if (ioc
->pci_error_recovery
) {
3503 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3504 "%s: host in pci error recovery\n",
3505 __func__
, ioc
->name
));
3508 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3509 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3510 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3511 "%s: host is not operational\n",
3512 __func__
, ioc
->name
));
3516 /* Without releasing the smid just update the
3517 * call back index and reuse the same smid for
3518 * processing this delayed request
3520 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3521 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
3522 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3524 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3525 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3526 ioc
->name
, le16_to_cpu(handle
), smid
,
3527 ioc
->tm_sas_control_cb_idx
));
3528 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3529 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3530 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3531 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3532 mpi_request
->DevHandle
= handle
;
3533 mpt3sas_base_put_smid_default(ioc
, smid
);
3537 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3538 * @ioc: per adapter object
3539 * @smid: system request message index
3541 * Context: Executed in interrupt context
3543 * This will check delayed internal messages list, and process the
3546 * Return 1 meaning mf should be freed from _base_interrupt
3547 * 0 means the mf is freed from this function.
3550 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3552 struct _sc_list
*delayed_sc
;
3553 struct _event_ack_list
*delayed_event_ack
;
3555 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
3556 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
3557 struct _event_ack_list
, list
);
3558 _scsih_issue_delayed_event_ack(ioc
, smid
,
3559 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
3560 list_del(&delayed_event_ack
->list
);
3561 kfree(delayed_event_ack
);
3565 if (!list_empty(&ioc
->delayed_sc_list
)) {
3566 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
3567 struct _sc_list
, list
);
3568 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
3569 delayed_sc
->handle
);
3570 list_del(&delayed_sc
->list
);
3578 * _scsih_check_for_pending_tm - check for pending task management
3579 * @ioc: per adapter object
3580 * @smid: system request message index
3582 * This will check delayed target reset list, and feed the
3585 * Return 1 meaning mf should be freed from _base_interrupt
3586 * 0 means the mf is freed from this function.
3589 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3591 struct _tr_list
*delayed_tr
;
3593 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3594 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3595 struct _tr_list
, list
);
3596 mpt3sas_base_free_smid(ioc
, smid
);
3597 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3598 list_del(&delayed_tr
->list
);
3603 if (!list_empty(&ioc
->delayed_tr_list
)) {
3604 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3605 struct _tr_list
, list
);
3606 mpt3sas_base_free_smid(ioc
, smid
);
3607 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3608 list_del(&delayed_tr
->list
);
3617 * _scsih_check_topo_delete_events - sanity check on topo events
3618 * @ioc: per adapter object
3619 * @event_data: the event data payload
3621 * This routine added to better handle cable breaker.
3623 * This handles the case where driver receives multiple expander
3624 * add and delete events in a single shot. When there is a delete event
3625 * the routine will void any pending add events waiting in the event queue.
3630 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3631 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3633 struct fw_event_work
*fw_event
;
3634 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3635 u16 expander_handle
;
3636 struct _sas_node
*sas_expander
;
3637 unsigned long flags
;
3641 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3642 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3645 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3646 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3647 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3648 _scsih_tm_tr_send(ioc
, handle
);
3651 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3652 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3653 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3656 if (event_data
->ExpStatus
==
3657 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3658 /* put expander attached devices into blocking state */
3659 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3660 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3662 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3663 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3665 handle
= find_first_bit(ioc
->blocking_handles
,
3666 ioc
->facts
.MaxDevHandle
);
3667 if (handle
< ioc
->facts
.MaxDevHandle
)
3668 _scsih_block_io_device(ioc
, handle
);
3669 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3670 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3671 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3673 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3676 /* mark ignore flag for pending events */
3677 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3678 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3679 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3682 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3683 fw_event
->event_data
;
3684 if (local_event_data
->ExpStatus
==
3685 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3686 local_event_data
->ExpStatus
==
3687 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3688 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3690 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3691 "setting ignoring flag\n", ioc
->name
));
3692 fw_event
->ignore
= 1;
3696 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3700 * _scsih_set_volume_delete_flag - setting volume delete flag
3701 * @ioc: per adapter object
3702 * @handle: device handle
3704 * This returns nothing.
3707 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3709 struct _raid_device
*raid_device
;
3710 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3711 unsigned long flags
;
3713 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3714 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
3715 if (raid_device
&& raid_device
->starget
&&
3716 raid_device
->starget
->hostdata
) {
3717 sas_target_priv_data
=
3718 raid_device
->starget
->hostdata
;
3719 sas_target_priv_data
->deleted
= 1;
3720 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3721 "setting delete flag: handle(0x%04x), "
3722 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3723 (unsigned long long) raid_device
->wwid
));
3725 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3729 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3730 * @handle: input handle
3731 * @a: handle for volume a
3732 * @b: handle for volume b
3734 * IR firmware only supports two raid volumes. The purpose of this
3735 * routine is to set the volume handle in either a or b. When the given
3736 * input handle is non-zero, or when a and b have not been set before.
3739 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3741 if (!handle
|| handle
== *a
|| handle
== *b
)
3750 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3751 * @ioc: per adapter object
3752 * @event_data: the event data payload
3753 * Context: interrupt time.
3755 * This routine will send target reset to volume, followed by target
3756 * resets to the PDs. This is called when a PD has been removed, or
3757 * volume has been deleted or removed. When the target reset is sent
3758 * to volume, the PD target resets need to be queued to start upon
3759 * completion of the volume target reset.
3764 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3765 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3767 Mpi2EventIrConfigElement_t
*element
;
3769 u16 handle
, volume_handle
, a
, b
;
3770 struct _tr_list
*delayed_tr
;
3775 if (ioc
->is_warpdrive
)
3778 /* Volume Resets for Deleted or Removed */
3779 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3780 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3781 if (le32_to_cpu(event_data
->Flags
) &
3782 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3784 if (element
->ReasonCode
==
3785 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3786 element
->ReasonCode
==
3787 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3788 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3789 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3790 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3794 /* Volume Resets for UNHIDE events */
3795 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3796 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3797 if (le32_to_cpu(event_data
->Flags
) &
3798 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3800 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3801 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3802 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3807 _scsih_tm_tr_volume_send(ioc
, a
);
3809 _scsih_tm_tr_volume_send(ioc
, b
);
3811 /* PD target resets */
3812 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3813 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3814 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3816 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3817 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3818 clear_bit(handle
, ioc
->pd_handles
);
3820 _scsih_tm_tr_send(ioc
, handle
);
3821 else if (volume_handle
== a
|| volume_handle
== b
) {
3822 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3823 BUG_ON(!delayed_tr
);
3824 INIT_LIST_HEAD(&delayed_tr
->list
);
3825 delayed_tr
->handle
= handle
;
3826 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3827 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3828 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3831 _scsih_tm_tr_send(ioc
, handle
);
3837 * _scsih_check_volume_delete_events - set delete flag for volumes
3838 * @ioc: per adapter object
3839 * @event_data: the event data payload
3840 * Context: interrupt time.
3842 * This will handle the case when the cable connected to entire volume is
3843 * pulled. We will take care of setting the deleted flag so normal IO will
3849 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3850 Mpi2EventDataIrVolume_t
*event_data
)
3854 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3856 state
= le32_to_cpu(event_data
->NewValue
);
3857 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3858 MPI2_RAID_VOL_STATE_FAILED
)
3859 _scsih_set_volume_delete_flag(ioc
,
3860 le16_to_cpu(event_data
->VolDevHandle
));
3864 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3865 * @ioc: per adapter object
3866 * @event_data: the temp threshold event data
3867 * Context: interrupt time.
3872 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
3873 Mpi2EventDataTemperature_t
*event_data
)
3875 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3876 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
3877 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3878 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3879 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3880 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3881 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3882 event_data
->SensorNum
);
3883 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
3884 ioc
->name
, event_data
->CurrentTemperature
);
3889 * _scsih_flush_running_cmds - completing outstanding commands.
3890 * @ioc: per adapter object
3892 * The flushing out of all pending scmd commands following host reset,
3893 * where all IO is dropped to the floor.
3898 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3900 struct scsi_cmnd
*scmd
;
3904 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3905 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3909 mpt3sas_base_free_smid(ioc
, smid
);
3910 scsi_dma_unmap(scmd
);
3911 if (ioc
->pci_error_recovery
)
3912 scmd
->result
= DID_NO_CONNECT
<< 16;
3914 scmd
->result
= DID_RESET
<< 16;
3915 scmd
->scsi_done(scmd
);
3917 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3922 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3923 * @ioc: per adapter object
3924 * @scmd: pointer to scsi command object
3925 * @mpi_request: pointer to the SCSI_IO reqest message frame
3927 * Supporting protection 1 and 3.
3932 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3933 Mpi2SCSIIORequest_t
*mpi_request
)
3936 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3937 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3938 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3939 (Mpi25SCSIIORequest_t
*)mpi_request
;
3941 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3944 if (prot_op
== SCSI_PROT_READ_STRIP
)
3945 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3946 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3947 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3951 switch (prot_type
) {
3952 case SCSI_PROT_DIF_TYPE1
:
3953 case SCSI_PROT_DIF_TYPE2
:
3956 * enable ref/guard checking
3957 * auto increment ref tag
3959 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3960 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3961 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3962 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3963 cpu_to_be32(scsi_prot_ref_tag(scmd
));
3966 case SCSI_PROT_DIF_TYPE3
:
3969 * enable guard checking
3971 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3976 mpi_request_3v
->EEDPBlockSize
=
3977 cpu_to_le16(scmd
->device
->sector_size
);
3978 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3982 * _scsih_eedp_error_handling - return sense code for EEDP errors
3983 * @scmd: pointer to scsi command object
3984 * @ioc_status: ioc status
3989 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3993 switch (ioc_status
) {
3994 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3997 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4000 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4007 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4009 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4010 SAM_STAT_CHECK_CONDITION
;
4013 static inline bool ata_12_16_cmd(struct scsi_cmnd
*scmd
)
4015 return (scmd
->cmnd
[0] == ATA_12
|| scmd
->cmnd
[0] == ATA_16
);
4019 * scsih_qcmd - main scsi request entry point
4020 * @scmd: pointer to scsi command object
4021 * @done: function pointer to be invoked on completion
4023 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4025 * Returns 0 on success. If there's a failure, return either:
4026 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4027 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4030 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4032 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4033 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4034 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4035 struct _raid_device
*raid_device
;
4036 Mpi2SCSIIORequest_t
*mpi_request
;
4041 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4042 scsi_print_command(scmd
);
4045 * Lock the device for any subsequent command until command is
4048 if (ata_12_16_cmd(scmd
))
4049 scsi_internal_device_block(scmd
->device
);
4051 sas_device_priv_data
= scmd
->device
->hostdata
;
4052 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4053 scmd
->result
= DID_NO_CONNECT
<< 16;
4054 scmd
->scsi_done(scmd
);
4058 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
4059 scmd
->result
= DID_NO_CONNECT
<< 16;
4060 scmd
->scsi_done(scmd
);
4064 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4066 /* invalid device handle */
4067 handle
= sas_target_priv_data
->handle
;
4068 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4069 scmd
->result
= DID_NO_CONNECT
<< 16;
4070 scmd
->scsi_done(scmd
);
4075 /* host recovery or link resets sent via IOCTLs */
4076 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4077 return SCSI_MLQUEUE_HOST_BUSY
;
4079 /* device has been deleted */
4080 else if (sas_target_priv_data
->deleted
) {
4081 scmd
->result
= DID_NO_CONNECT
<< 16;
4082 scmd
->scsi_done(scmd
);
4084 /* device busy with task managment */
4085 } else if (sas_target_priv_data
->tm_busy
||
4086 sas_device_priv_data
->block
)
4087 return SCSI_MLQUEUE_DEVICE_BUSY
;
4089 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4090 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4091 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4092 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4094 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4097 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4099 /* Make sure Device is not raid volume.
4100 * We do not expose raid functionality to upper layer for warpdrive.
4102 if (!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
)
4103 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4104 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4106 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4108 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4109 ioc
->name
, __func__
);
4112 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4113 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
4114 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4116 if (scmd
->cmd_len
== 32)
4117 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4118 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4119 if (sas_device_priv_data
->sas_target
->flags
&
4120 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4121 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4123 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4124 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4125 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4126 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4127 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4128 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4129 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4130 mpi_request
->SenseBufferLowAddress
=
4131 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4132 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4133 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4135 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4137 if (mpi_request
->DataLength
) {
4138 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
4139 mpt3sas_base_free_smid(ioc
, smid
);
4143 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4145 raid_device
= sas_target_priv_data
->raid_device
;
4146 if (raid_device
&& raid_device
->direct_io_enabled
)
4147 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4150 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4151 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4152 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4153 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4154 mpt3sas_base_put_smid_fast_path(ioc
, smid
, handle
);
4156 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
4157 le16_to_cpu(mpi_request
->DevHandle
));
4159 mpt3sas_base_put_smid_default(ioc
, smid
);
4163 return SCSI_MLQUEUE_HOST_BUSY
;
4167 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4168 * @sense_buffer: sense data returned by target
4169 * @data: normalized skey/asc/ascq
4174 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4176 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4177 /* descriptor format */
4178 data
->skey
= sense_buffer
[1] & 0x0F;
4179 data
->asc
= sense_buffer
[2];
4180 data
->ascq
= sense_buffer
[3];
4183 data
->skey
= sense_buffer
[2] & 0x0F;
4184 data
->asc
= sense_buffer
[12];
4185 data
->ascq
= sense_buffer
[13];
4190 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4191 * @ioc: per adapter object
4192 * @scmd: pointer to scsi command object
4193 * @mpi_reply: reply mf payload returned from firmware
4195 * scsi_status - SCSI Status code returned from target device
4196 * scsi_state - state info associated with SCSI_IO determined by ioc
4197 * ioc_status - ioc supplied status info
4202 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4203 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4207 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4208 MPI2_IOCSTATUS_MASK
;
4209 u8 scsi_state
= mpi_reply
->SCSIState
;
4210 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4211 char *desc_ioc_state
= NULL
;
4212 char *desc_scsi_status
= NULL
;
4213 char *desc_scsi_state
= ioc
->tmp_string
;
4214 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4215 struct _sas_device
*sas_device
= NULL
;
4216 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4217 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4218 char *device_str
= NULL
;
4222 if (ioc
->hide_ir_msg
)
4223 device_str
= "WarpDrive";
4225 device_str
= "volume";
4227 if (log_info
== 0x31170000)
4230 switch (ioc_status
) {
4231 case MPI2_IOCSTATUS_SUCCESS
:
4232 desc_ioc_state
= "success";
4234 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4235 desc_ioc_state
= "invalid function";
4237 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4238 desc_ioc_state
= "scsi recovered error";
4240 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4241 desc_ioc_state
= "scsi invalid dev handle";
4243 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4244 desc_ioc_state
= "scsi device not there";
4246 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4247 desc_ioc_state
= "scsi data overrun";
4249 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4250 desc_ioc_state
= "scsi data underrun";
4252 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4253 desc_ioc_state
= "scsi io data error";
4255 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4256 desc_ioc_state
= "scsi protocol error";
4258 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4259 desc_ioc_state
= "scsi task terminated";
4261 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4262 desc_ioc_state
= "scsi residual mismatch";
4264 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4265 desc_ioc_state
= "scsi task mgmt failed";
4267 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4268 desc_ioc_state
= "scsi ioc terminated";
4270 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4271 desc_ioc_state
= "scsi ext terminated";
4273 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4274 desc_ioc_state
= "eedp guard error";
4276 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4277 desc_ioc_state
= "eedp ref tag error";
4279 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4280 desc_ioc_state
= "eedp app tag error";
4282 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4283 desc_ioc_state
= "insufficient power";
4286 desc_ioc_state
= "unknown";
4290 switch (scsi_status
) {
4291 case MPI2_SCSI_STATUS_GOOD
:
4292 desc_scsi_status
= "good";
4294 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4295 desc_scsi_status
= "check condition";
4297 case MPI2_SCSI_STATUS_CONDITION_MET
:
4298 desc_scsi_status
= "condition met";
4300 case MPI2_SCSI_STATUS_BUSY
:
4301 desc_scsi_status
= "busy";
4303 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4304 desc_scsi_status
= "intermediate";
4306 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4307 desc_scsi_status
= "intermediate condmet";
4309 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4310 desc_scsi_status
= "reservation conflict";
4312 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4313 desc_scsi_status
= "command terminated";
4315 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4316 desc_scsi_status
= "task set full";
4318 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4319 desc_scsi_status
= "aca active";
4321 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4322 desc_scsi_status
= "task aborted";
4325 desc_scsi_status
= "unknown";
4329 desc_scsi_state
[0] = '\0';
4331 desc_scsi_state
= " ";
4332 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4333 strcat(desc_scsi_state
, "response info ");
4334 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4335 strcat(desc_scsi_state
, "state terminated ");
4336 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4337 strcat(desc_scsi_state
, "no status ");
4338 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4339 strcat(desc_scsi_state
, "autosense failed ");
4340 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4341 strcat(desc_scsi_state
, "autosense valid ");
4343 scsi_print_command(scmd
);
4345 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4346 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4347 device_str
, (unsigned long long)priv_target
->sas_address
);
4349 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4352 "\tsas_address(0x%016llx), phy(%d)\n",
4353 ioc
->name
, (unsigned long long)
4354 sas_device
->sas_address
, sas_device
->phy
);
4355 if (sas_device
->enclosure_handle
!= 0)
4357 "\tenclosure_logical_id(0x%016llx),"
4358 "slot(%d)\n", ioc
->name
,
4359 (unsigned long long)
4360 sas_device
->enclosure_logical_id
,
4362 if (sas_device
->connector_name
[0])
4364 "\tenclosure level(0x%04x),"
4365 " connector name( %s)\n", ioc
->name
,
4366 sas_device
->enclosure_level
,
4367 sas_device
->connector_name
);
4369 sas_device_put(sas_device
);
4374 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4375 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4376 desc_ioc_state
, ioc_status
, smid
);
4378 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4379 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4380 scsi_get_resid(scmd
));
4382 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4383 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4384 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4386 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4387 ioc
->name
, desc_scsi_status
,
4388 scsi_status
, desc_scsi_state
, scsi_state
);
4390 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4391 struct sense_info data
;
4392 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4394 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4395 ioc
->name
, data
.skey
,
4396 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4399 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4400 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4401 response_bytes
= (u8
*)&response_info
;
4402 _scsih_response_code(ioc
, response_bytes
[0]);
4407 * _scsih_turn_on_pfa_led - illuminate PFA LED
4408 * @ioc: per adapter object
4409 * @handle: device handle
4415 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4417 Mpi2SepReply_t mpi_reply
;
4418 Mpi2SepRequest_t mpi_request
;
4419 struct _sas_device
*sas_device
;
4421 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4425 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4426 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4427 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4428 mpi_request
.SlotStatus
=
4429 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4430 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4431 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4432 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4433 &mpi_request
)) != 0) {
4434 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4435 __FILE__
, __LINE__
, __func__
);
4438 sas_device
->pfa_led_on
= 1;
4440 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4441 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4442 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4443 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4444 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4448 sas_device_put(sas_device
);
4452 * _scsih_turn_off_pfa_led - turn off Fault LED
4453 * @ioc: per adapter object
4454 * @sas_device: sas device whose PFA LED has to turned off
4460 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4461 struct _sas_device
*sas_device
)
4463 Mpi2SepReply_t mpi_reply
;
4464 Mpi2SepRequest_t mpi_request
;
4466 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4467 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4468 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4469 mpi_request
.SlotStatus
= 0;
4470 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4471 mpi_request
.DevHandle
= 0;
4472 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4473 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4474 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4475 &mpi_request
)) != 0) {
4476 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4477 __FILE__
, __LINE__
, __func__
);
4481 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4482 dewtprintk(ioc
, printk(MPT3SAS_FMT
4483 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4484 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4485 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4491 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4492 * @ioc: per adapter object
4493 * @handle: device handle
4494 * Context: interrupt.
4499 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4501 struct fw_event_work
*fw_event
;
4503 fw_event
= alloc_fw_event_work(0);
4506 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4507 fw_event
->device_handle
= handle
;
4508 fw_event
->ioc
= ioc
;
4509 _scsih_fw_event_add(ioc
, fw_event
);
4510 fw_event_work_put(fw_event
);
4514 * _scsih_smart_predicted_fault - process smart errors
4515 * @ioc: per adapter object
4516 * @handle: device handle
4517 * Context: interrupt.
4522 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4524 struct scsi_target
*starget
;
4525 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4526 Mpi2EventNotificationReply_t
*event_reply
;
4527 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4528 struct _sas_device
*sas_device
;
4530 unsigned long flags
;
4532 /* only handle non-raid devices */
4533 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4534 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
4538 starget
= sas_device
->starget
;
4539 sas_target_priv_data
= starget
->hostdata
;
4541 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4542 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
4545 if (sas_device
->enclosure_handle
!= 0)
4546 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4547 "enclosure logical id(0x%016llx), slot(%d)\n",
4548 (unsigned long long)sas_device
->enclosure_logical_id
,
4550 if (sas_device
->connector_name
[0] != '\0')
4551 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4552 "enclosure level(0x%04x), connector name( %s)\n",
4553 sas_device
->enclosure_level
,
4554 sas_device
->connector_name
);
4555 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4557 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4558 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4560 /* insert into event log */
4561 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4562 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4563 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4565 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4566 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4570 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4571 event_reply
->Event
=
4572 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4573 event_reply
->MsgLength
= sz
/4;
4574 event_reply
->EventDataLength
=
4575 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4576 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4577 event_reply
->EventData
;
4578 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4579 event_data
->ASC
= 0x5D;
4580 event_data
->DevHandle
= cpu_to_le16(handle
);
4581 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4582 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4586 sas_device_put(sas_device
);
4590 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4595 * _scsih_io_done - scsi request callback
4596 * @ioc: per adapter object
4597 * @smid: system request message index
4598 * @msix_index: MSIX table index supplied by the OS
4599 * @reply: reply message frame(lower 32bit addr)
4601 * Callback handler when using _scsih_qcmd.
4603 * Return 1 meaning mf should be freed from _base_interrupt
4604 * 0 means the mf is freed from this function.
4607 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4609 Mpi2SCSIIORequest_t
*mpi_request
;
4610 Mpi2SCSIIOReply_t
*mpi_reply
;
4611 struct scsi_cmnd
*scmd
;
4617 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4618 u32 response_code
= 0;
4619 unsigned long flags
;
4621 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4622 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4626 if (ata_12_16_cmd(scmd
))
4627 scsi_internal_device_unblock(scmd
->device
, SDEV_RUNNING
);
4629 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4631 if (mpi_reply
== NULL
) {
4632 scmd
->result
= DID_OK
<< 16;
4636 sas_device_priv_data
= scmd
->device
->hostdata
;
4637 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4638 sas_device_priv_data
->sas_target
->deleted
) {
4639 scmd
->result
= DID_NO_CONNECT
<< 16;
4642 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4645 * WARPDRIVE: If direct_io is set then it is directIO,
4646 * the failed direct I/O should be redirected to volume
4648 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
4649 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4650 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4651 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4652 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4653 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4654 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
4655 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4656 mpi_request
->DevHandle
=
4657 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4658 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
4659 sas_device_priv_data
->sas_target
->handle
);
4662 /* turning off TLR */
4663 scsi_state
= mpi_reply
->SCSIState
;
4664 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4666 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4667 if (!sas_device_priv_data
->tlr_snoop_check
) {
4668 sas_device_priv_data
->tlr_snoop_check
++;
4669 if (!ioc
->is_warpdrive
&&
4670 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4671 sas_is_tlr_enabled(scmd
->device
) &&
4672 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4673 sas_disable_tlr(scmd
->device
);
4674 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4678 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4679 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4680 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4681 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4684 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4685 scsi_status
= mpi_reply
->SCSIStatus
;
4687 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4688 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4689 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4690 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4691 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4694 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4695 struct sense_info data
;
4696 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4698 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4699 le32_to_cpu(mpi_reply
->SenseCount
));
4700 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4701 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4702 /* failure prediction threshold exceeded */
4703 if (data
.asc
== 0x5D)
4704 _scsih_smart_predicted_fault(ioc
,
4705 le16_to_cpu(mpi_reply
->DevHandle
));
4706 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4708 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4709 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4710 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4711 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4712 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4714 switch (ioc_status
) {
4715 case MPI2_IOCSTATUS_BUSY
:
4716 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4717 scmd
->result
= SAM_STAT_BUSY
;
4720 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4721 scmd
->result
= DID_NO_CONNECT
<< 16;
4724 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4725 if (sas_device_priv_data
->block
) {
4726 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4729 if (log_info
== 0x31110630) {
4730 if (scmd
->retries
> 2) {
4731 scmd
->result
= DID_NO_CONNECT
<< 16;
4732 scsi_device_set_state(scmd
->device
,
4735 scmd
->result
= DID_SOFT_ERROR
<< 16;
4736 scmd
->device
->expecting_cc_ua
= 1;
4739 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4740 scmd
->result
= DID_RESET
<< 16;
4743 scmd
->result
= DID_SOFT_ERROR
<< 16;
4745 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4746 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4747 scmd
->result
= DID_RESET
<< 16;
4750 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4751 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4752 scmd
->result
= DID_SOFT_ERROR
<< 16;
4754 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4757 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4758 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4760 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4763 if (xfer_cnt
< scmd
->underflow
) {
4764 if (scsi_status
== SAM_STAT_BUSY
)
4765 scmd
->result
= SAM_STAT_BUSY
;
4767 scmd
->result
= DID_SOFT_ERROR
<< 16;
4768 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4769 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4770 scmd
->result
= DID_SOFT_ERROR
<< 16;
4771 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4772 scmd
->result
= DID_RESET
<< 16;
4773 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4774 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4775 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4776 scmd
->result
= (DRIVER_SENSE
<< 24) |
4777 SAM_STAT_CHECK_CONDITION
;
4778 scmd
->sense_buffer
[0] = 0x70;
4779 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4780 scmd
->sense_buffer
[12] = 0x20;
4781 scmd
->sense_buffer
[13] = 0;
4785 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4786 scsi_set_resid(scmd
, 0);
4787 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4788 case MPI2_IOCSTATUS_SUCCESS
:
4789 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4790 if (response_code
==
4791 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4792 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4793 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4794 scmd
->result
= DID_SOFT_ERROR
<< 16;
4795 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4796 scmd
->result
= DID_RESET
<< 16;
4799 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4800 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4801 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4802 _scsih_eedp_error_handling(scmd
, ioc_status
);
4805 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4806 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4807 case MPI2_IOCSTATUS_INVALID_SGL
:
4808 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4809 case MPI2_IOCSTATUS_INVALID_FIELD
:
4810 case MPI2_IOCSTATUS_INVALID_STATE
:
4811 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4812 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4813 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4815 scmd
->result
= DID_SOFT_ERROR
<< 16;
4820 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4821 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4825 scsi_dma_unmap(scmd
);
4827 scmd
->scsi_done(scmd
);
4832 * _scsih_sas_host_refresh - refreshing sas host object contents
4833 * @ioc: per adapter object
4836 * During port enable, fw will send topology events for every device. Its
4837 * possible that the handles may change from the previous setting, so this
4838 * code keeping handles updating if changed.
4843 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4848 Mpi2ConfigReply_t mpi_reply
;
4849 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4850 u16 attached_handle
;
4853 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4854 "updating handles for sas_host(0x%016llx)\n",
4855 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4857 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4858 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4859 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4860 if (!sas_iounit_pg0
) {
4861 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4862 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4866 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4867 sas_iounit_pg0
, sz
)) != 0)
4869 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4870 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4872 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4873 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4875 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4876 PhyData
[0].ControllerDevHandle
);
4877 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4878 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4880 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4881 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4882 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4883 attached_handle
, i
, link_rate
);
4886 kfree(sas_iounit_pg0
);
4890 * _scsih_sas_host_add - create sas host object
4891 * @ioc: per adapter object
4893 * Creating host side data object, stored in ioc->sas_hba
4898 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4901 Mpi2ConfigReply_t mpi_reply
;
4902 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4903 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4904 Mpi2SasPhyPage0_t phy_pg0
;
4905 Mpi2SasDevicePage0_t sas_device_pg0
;
4906 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4909 u8 device_missing_delay
;
4912 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
4914 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4915 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4918 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
4919 sizeof(struct _sas_phy
), GFP_KERNEL
);
4920 if (!ioc
->sas_hba
.phy
) {
4921 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4922 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4925 ioc
->sas_hba
.num_phys
= num_phys
;
4927 /* sas_iounit page 0 */
4928 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4929 sizeof(Mpi2SasIOUnit0PhyData_t
));
4930 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4931 if (!sas_iounit_pg0
) {
4932 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4933 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4936 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4937 sas_iounit_pg0
, sz
))) {
4938 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4939 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4942 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4943 MPI2_IOCSTATUS_MASK
;
4944 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4945 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4946 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4950 /* sas_iounit page 1 */
4951 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4952 sizeof(Mpi2SasIOUnit1PhyData_t
));
4953 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4954 if (!sas_iounit_pg1
) {
4955 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4956 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4959 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4960 sas_iounit_pg1
, sz
))) {
4961 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4962 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4965 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4966 MPI2_IOCSTATUS_MASK
;
4967 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4968 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4969 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4973 ioc
->io_missing_delay
=
4974 sas_iounit_pg1
->IODeviceMissingDelay
;
4975 device_missing_delay
=
4976 sas_iounit_pg1
->ReportDeviceMissingDelay
;
4977 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4978 ioc
->device_missing_delay
= (device_missing_delay
&
4979 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4981 ioc
->device_missing_delay
= device_missing_delay
&
4982 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4984 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4985 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4986 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4988 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4989 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4992 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4993 MPI2_IOCSTATUS_MASK
;
4994 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4995 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4996 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5001 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5002 PhyData
[0].ControllerDevHandle
);
5003 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5004 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5005 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5006 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5008 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5009 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5010 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5011 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5014 ioc
->sas_hba
.enclosure_handle
=
5015 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5016 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5018 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5019 ioc
->name
, ioc
->sas_hba
.handle
,
5020 (unsigned long long) ioc
->sas_hba
.sas_address
,
5021 ioc
->sas_hba
.num_phys
) ;
5023 if (ioc
->sas_hba
.enclosure_handle
) {
5024 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5025 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5026 ioc
->sas_hba
.enclosure_handle
)))
5027 ioc
->sas_hba
.enclosure_logical_id
=
5028 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5032 kfree(sas_iounit_pg1
);
5033 kfree(sas_iounit_pg0
);
5037 * _scsih_expander_add - creating expander object
5038 * @ioc: per adapter object
5039 * @handle: expander handle
5041 * Creating expander object, stored in ioc->sas_expander_list.
5043 * Return 0 for success, else error.
5046 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5048 struct _sas_node
*sas_expander
;
5049 Mpi2ConfigReply_t mpi_reply
;
5050 Mpi2ExpanderPage0_t expander_pg0
;
5051 Mpi2ExpanderPage1_t expander_pg1
;
5052 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5055 u64 sas_address
, sas_address_parent
= 0;
5057 unsigned long flags
;
5058 struct _sas_port
*mpt3sas_port
= NULL
;
5065 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5068 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5069 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5070 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5071 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5075 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5076 MPI2_IOCSTATUS_MASK
;
5077 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5078 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5079 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5083 /* handle out of order topology events */
5084 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5085 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5087 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5088 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5091 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5092 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5093 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5094 sas_address_parent
);
5095 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5096 if (!sas_expander
) {
5097 rc
= _scsih_expander_add(ioc
, parent_handle
);
5103 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5104 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5105 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5107 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5112 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5114 if (!sas_expander
) {
5115 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5116 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5120 sas_expander
->handle
= handle
;
5121 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5122 sas_expander
->sas_address_parent
= sas_address_parent
;
5123 sas_expander
->sas_address
= sas_address
;
5125 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5126 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5127 handle
, parent_handle
, (unsigned long long)
5128 sas_expander
->sas_address
, sas_expander
->num_phys
);
5130 if (!sas_expander
->num_phys
)
5132 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5133 sizeof(struct _sas_phy
), GFP_KERNEL
);
5134 if (!sas_expander
->phy
) {
5135 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5136 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5141 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5142 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5143 sas_address_parent
);
5144 if (!mpt3sas_port
) {
5145 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5146 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5150 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5152 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5153 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5154 &expander_pg1
, i
, handle
))) {
5155 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5156 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5160 sas_expander
->phy
[i
].handle
= handle
;
5161 sas_expander
->phy
[i
].phy_id
= i
;
5163 if ((mpt3sas_transport_add_expander_phy(ioc
,
5164 &sas_expander
->phy
[i
], expander_pg1
,
5165 sas_expander
->parent_dev
))) {
5166 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5167 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5173 if (sas_expander
->enclosure_handle
) {
5174 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5175 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5176 sas_expander
->enclosure_handle
)))
5177 sas_expander
->enclosure_logical_id
=
5178 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5181 _scsih_expander_node_add(ioc
, sas_expander
);
5187 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5188 sas_address_parent
);
5189 kfree(sas_expander
);
5194 * mpt3sas_expander_remove - removing expander object
5195 * @ioc: per adapter object
5196 * @sas_address: expander sas_address
5201 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5203 struct _sas_node
*sas_expander
;
5204 unsigned long flags
;
5206 if (ioc
->shost_recovery
)
5209 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5210 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5213 list_del(&sas_expander
->list
);
5214 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5216 _scsih_expander_node_remove(ioc
, sas_expander
);
5220 * _scsih_done - internal SCSI_IO callback handler.
5221 * @ioc: per adapter object
5222 * @smid: system request message index
5223 * @msix_index: MSIX table index supplied by the OS
5224 * @reply: reply message frame(lower 32bit addr)
5226 * Callback handler when sending internal generated SCSI_IO.
5227 * The callback index passed is `ioc->scsih_cb_idx`
5229 * Return 1 meaning mf should be freed from _base_interrupt
5230 * 0 means the mf is freed from this function.
5233 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5235 MPI2DefaultReply_t
*mpi_reply
;
5237 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5238 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5240 if (ioc
->scsih_cmds
.smid
!= smid
)
5242 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5244 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5245 mpi_reply
->MsgLength
*4);
5246 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5248 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5249 complete(&ioc
->scsih_cmds
.done
);
5256 #define MPT3_MAX_LUNS (255)
5260 * _scsih_check_access_status - check access flags
5261 * @ioc: per adapter object
5262 * @sas_address: sas address
5263 * @handle: sas device handle
5264 * @access_flags: errors returned during discovery of the device
5266 * Return 0 for success, else failure
5269 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5270 u16 handle
, u8 access_status
)
5275 switch (access_status
) {
5276 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5277 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5280 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5281 desc
= "sata capability failed";
5283 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5284 desc
= "sata affiliation conflict";
5286 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5287 desc
= "route not addressable";
5289 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5290 desc
= "smp error not addressable";
5292 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5293 desc
= "device blocked";
5295 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5296 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5297 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5298 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5299 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5300 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5301 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5302 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5303 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5304 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5305 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5306 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5307 desc
= "sata initialization failed";
5318 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5319 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5324 * _scsih_check_device - checking device responsiveness
5325 * @ioc: per adapter object
5326 * @parent_sas_address: sas address of parent expander or sas host
5327 * @handle: attached device handle
5328 * @phy_numberv: phy number
5329 * @link_rate: new link rate
5334 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5335 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5337 Mpi2ConfigReply_t mpi_reply
;
5338 Mpi2SasDevicePage0_t sas_device_pg0
;
5339 struct _sas_device
*sas_device
;
5341 unsigned long flags
;
5343 struct scsi_target
*starget
;
5344 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5348 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5349 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5352 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5353 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5356 /* wide port handling ~ we need only handle device once for the phy that
5357 * is matched in sas device page zero
5359 if (phy_number
!= sas_device_pg0
.PhyNum
)
5362 /* check if this is end device */
5363 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5364 if (!(_scsih_is_end_device(device_info
)))
5367 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5368 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5369 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5375 if (unlikely(sas_device
->handle
!= handle
)) {
5376 starget
= sas_device
->starget
;
5377 sas_target_priv_data
= starget
->hostdata
;
5378 starget_printk(KERN_INFO
, starget
,
5379 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5380 sas_device
->handle
, handle
);
5381 sas_target_priv_data
->handle
= handle
;
5382 sas_device
->handle
= handle
;
5383 if (sas_device_pg0
.Flags
&
5384 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5385 sas_device
->enclosure_level
=
5386 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5387 memcpy(sas_device
->connector_name
,
5388 sas_device_pg0
.ConnectorName
, 4);
5389 sas_device
->connector_name
[4] = '\0';
5391 sas_device
->enclosure_level
= 0;
5392 sas_device
->connector_name
[0] = '\0';
5396 /* check if device is present */
5397 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5398 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5400 "device is not present handle(0x%04x), flags!!!\n",
5405 /* check if there were any issues with discovery */
5406 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5407 sas_device_pg0
.AccessStatus
))
5410 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5411 _scsih_ublock_io_device(ioc
, sas_address
);
5414 sas_device_put(sas_device
);
5418 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5420 sas_device_put(sas_device
);
5424 * _scsih_add_device - creating sas device object
5425 * @ioc: per adapter object
5426 * @handle: sas device handle
5427 * @phy_num: phy number end device attached to
5428 * @is_pd: is this hidden raid component
5430 * Creating end device object, stored in ioc->sas_device_list.
5432 * Returns 0 for success, non-zero for failure.
5435 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
5438 Mpi2ConfigReply_t mpi_reply
;
5439 Mpi2SasDevicePage0_t sas_device_pg0
;
5440 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5441 struct _sas_device
*sas_device
;
5446 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5447 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5448 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5449 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5453 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5454 MPI2_IOCSTATUS_MASK
;
5455 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5456 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5457 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5461 /* check if this is end device */
5462 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5463 if (!(_scsih_is_end_device(device_info
)))
5465 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5467 /* check if device is present */
5468 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5469 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5470 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5475 /* check if there were any issues with discovery */
5476 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5477 sas_device_pg0
.AccessStatus
))
5480 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
5483 sas_device_put(sas_device
);
5487 sas_device
= kzalloc(sizeof(struct _sas_device
),
5490 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5491 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5495 kref_init(&sas_device
->refcount
);
5496 sas_device
->handle
= handle
;
5497 if (_scsih_get_sas_address(ioc
,
5498 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5499 &sas_device
->sas_address_parent
) != 0)
5500 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5501 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5502 sas_device
->enclosure_handle
=
5503 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5504 if (sas_device
->enclosure_handle
!= 0)
5506 le16_to_cpu(sas_device_pg0
.Slot
);
5507 sas_device
->device_info
= device_info
;
5508 sas_device
->sas_address
= sas_address
;
5509 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5510 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5511 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5513 if (sas_device_pg0
.Flags
& MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5514 sas_device
->enclosure_level
=
5515 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5516 memcpy(sas_device
->connector_name
,
5517 sas_device_pg0
.ConnectorName
, 4);
5518 sas_device
->connector_name
[4] = '\0';
5520 sas_device
->enclosure_level
= 0;
5521 sas_device
->connector_name
[0] = '\0';
5523 /* get enclosure_logical_id */
5524 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5525 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5526 sas_device
->enclosure_handle
)))
5527 sas_device
->enclosure_logical_id
=
5528 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5530 /* get device name */
5531 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5533 if (ioc
->wait_for_discovery_to_complete
)
5534 _scsih_sas_device_init_add(ioc
, sas_device
);
5536 _scsih_sas_device_add(ioc
, sas_device
);
5538 sas_device_put(sas_device
);
5543 * _scsih_remove_device - removing sas device object
5544 * @ioc: per adapter object
5545 * @sas_device_delete: the sas_device object
5550 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5551 struct _sas_device
*sas_device
)
5553 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5555 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5556 (sas_device
->pfa_led_on
)) {
5557 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5558 sas_device
->pfa_led_on
= 0;
5560 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5561 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5562 ioc
->name
, __func__
,
5563 sas_device
->handle
, (unsigned long long)
5564 sas_device
->sas_address
));
5565 if (sas_device
->enclosure_handle
!= 0)
5566 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5567 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5568 ioc
->name
, __func__
,
5569 (unsigned long long)sas_device
->enclosure_logical_id
,
5571 if (sas_device
->connector_name
[0] != '\0')
5572 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5573 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5574 ioc
->name
, __func__
,
5575 sas_device
->enclosure_level
,
5576 sas_device
->connector_name
));
5578 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5579 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5580 sas_target_priv_data
->deleted
= 1;
5581 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5582 sas_target_priv_data
->handle
=
5583 MPT3SAS_INVALID_DEVICE_HANDLE
;
5586 if (!ioc
->hide_drives
)
5587 mpt3sas_transport_port_remove(ioc
,
5588 sas_device
->sas_address
,
5589 sas_device
->sas_address_parent
);
5592 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5593 ioc
->name
, sas_device
->handle
,
5594 (unsigned long long) sas_device
->sas_address
);
5595 if (sas_device
->enclosure_handle
!= 0)
5597 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5599 (unsigned long long)sas_device
->enclosure_logical_id
,
5601 if (sas_device
->connector_name
[0] != '\0')
5603 "removing enclosure level(0x%04x), connector name( %s)\n",
5604 ioc
->name
, sas_device
->enclosure_level
,
5605 sas_device
->connector_name
);
5607 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5608 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5609 ioc
->name
, __func__
,
5610 sas_device
->handle
, (unsigned long long)
5611 sas_device
->sas_address
));
5612 if (sas_device
->enclosure_handle
!= 0)
5613 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5614 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5615 ioc
->name
, __func__
,
5616 (unsigned long long)sas_device
->enclosure_logical_id
,
5618 if (sas_device
->connector_name
[0] != '\0')
5619 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5620 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5621 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5622 sas_device
->connector_name
));
5626 * _scsih_sas_topology_change_event_debug - debug for topology event
5627 * @ioc: per adapter object
5628 * @event_data: event data payload
5632 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5633 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5639 char *status_str
= NULL
;
5640 u8 link_rate
, prev_link_rate
;
5642 switch (event_data
->ExpStatus
) {
5643 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5646 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5647 status_str
= "remove";
5649 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5651 status_str
= "responding";
5653 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5654 status_str
= "remove delay";
5657 status_str
= "unknown status";
5660 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5661 ioc
->name
, status_str
);
5662 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5663 "start_phy(%02d), count(%d)\n",
5664 le16_to_cpu(event_data
->ExpanderDevHandle
),
5665 le16_to_cpu(event_data
->EnclosureHandle
),
5666 event_data
->StartPhyNum
, event_data
->NumEntries
);
5667 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5668 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5671 phy_number
= event_data
->StartPhyNum
+ i
;
5672 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5673 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5674 switch (reason_code
) {
5675 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5676 status_str
= "target add";
5678 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5679 status_str
= "target remove";
5681 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5682 status_str
= "delay target remove";
5684 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5685 status_str
= "link rate change";
5687 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5688 status_str
= "target responding";
5691 status_str
= "unknown";
5694 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5695 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5696 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5697 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5698 handle
, status_str
, link_rate
, prev_link_rate
);
5704 * _scsih_sas_topology_change_event - handle topology changes
5705 * @ioc: per adapter object
5706 * @fw_event: The fw_event_work object
5711 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5712 struct fw_event_work
*fw_event
)
5715 u16 parent_handle
, handle
;
5717 u8 phy_number
, max_phys
;
5718 struct _sas_node
*sas_expander
;
5720 unsigned long flags
;
5721 u8 link_rate
, prev_link_rate
;
5722 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5723 (Mpi2EventDataSasTopologyChangeList_t
*)
5724 fw_event
->event_data
;
5726 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5727 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5729 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5732 if (!ioc
->sas_hba
.num_phys
)
5733 _scsih_sas_host_add(ioc
);
5735 _scsih_sas_host_refresh(ioc
);
5737 if (fw_event
->ignore
) {
5738 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5739 "ignoring expander event\n", ioc
->name
));
5743 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5745 /* handle expander add */
5746 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5747 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5750 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5751 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5754 sas_address
= sas_expander
->sas_address
;
5755 max_phys
= sas_expander
->num_phys
;
5756 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5757 sas_address
= ioc
->sas_hba
.sas_address
;
5758 max_phys
= ioc
->sas_hba
.num_phys
;
5760 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5763 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5765 /* handle siblings events */
5766 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5767 if (fw_event
->ignore
) {
5768 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5769 "ignoring expander event\n", ioc
->name
));
5772 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5774 phy_number
= event_data
->StartPhyNum
+ i
;
5775 if (phy_number
>= max_phys
)
5777 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5778 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5779 if ((event_data
->PHY
[i
].PhyStatus
&
5780 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5781 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5783 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5786 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5787 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5788 switch (reason_code
) {
5789 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5791 if (ioc
->shost_recovery
)
5794 if (link_rate
== prev_link_rate
)
5797 mpt3sas_transport_update_links(ioc
, sas_address
,
5798 handle
, phy_number
, link_rate
);
5800 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5803 _scsih_check_device(ioc
, sas_address
, handle
,
5804 phy_number
, link_rate
);
5807 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5809 if (ioc
->shost_recovery
)
5812 mpt3sas_transport_update_links(ioc
, sas_address
,
5813 handle
, phy_number
, link_rate
);
5815 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5818 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5820 _scsih_device_remove_by_handle(ioc
, handle
);
5825 /* handle expander removal */
5826 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5828 mpt3sas_expander_remove(ioc
, sas_address
);
5834 * _scsih_sas_device_status_change_event_debug - debug for device event
5835 * @event_data: event data payload
5841 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5842 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5844 char *reason_str
= NULL
;
5846 switch (event_data
->ReasonCode
) {
5847 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5848 reason_str
= "smart data";
5850 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5851 reason_str
= "unsupported device discovered";
5853 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5854 reason_str
= "internal device reset";
5856 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5857 reason_str
= "internal task abort";
5859 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5860 reason_str
= "internal task abort set";
5862 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5863 reason_str
= "internal clear task set";
5865 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5866 reason_str
= "internal query task";
5868 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5869 reason_str
= "sata init failure";
5871 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5872 reason_str
= "internal device reset complete";
5874 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5875 reason_str
= "internal task abort complete";
5877 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5878 reason_str
= "internal async notification";
5880 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5881 reason_str
= "expander reduced functionality";
5883 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5884 reason_str
= "expander reduced functionality complete";
5887 reason_str
= "unknown reason";
5890 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5891 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5892 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5893 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5894 le16_to_cpu(event_data
->TaskTag
));
5895 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5896 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5897 event_data
->ASC
, event_data
->ASCQ
);
5902 * _scsih_sas_device_status_change_event - handle device status change
5903 * @ioc: per adapter object
5904 * @fw_event: The fw_event_work object
5910 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5911 struct fw_event_work
*fw_event
)
5913 struct MPT3SAS_TARGET
*target_priv_data
;
5914 struct _sas_device
*sas_device
;
5916 unsigned long flags
;
5917 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5918 (Mpi2EventDataSasDeviceStatusChange_t
*)
5919 fw_event
->event_data
;
5921 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5922 _scsih_sas_device_status_change_event_debug(ioc
,
5925 /* In MPI Revision K (0xC), the internal device reset complete was
5926 * implemented, so avoid setting tm_busy flag for older firmware.
5928 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5931 if (event_data
->ReasonCode
!=
5932 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5933 event_data
->ReasonCode
!=
5934 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5937 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5938 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5939 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5942 if (!sas_device
|| !sas_device
->starget
)
5945 target_priv_data
= sas_device
->starget
->hostdata
;
5946 if (!target_priv_data
)
5949 if (event_data
->ReasonCode
==
5950 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5951 target_priv_data
->tm_busy
= 1;
5953 target_priv_data
->tm_busy
= 0;
5957 sas_device_put(sas_device
);
5959 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5964 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5966 * @ioc: per adapter object
5967 * @event_data: event data payload
5973 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5974 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5976 char *reason_str
= NULL
;
5978 switch (event_data
->ReasonCode
) {
5979 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5980 reason_str
= "enclosure add";
5982 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5983 reason_str
= "enclosure remove";
5986 reason_str
= "unknown reason";
5990 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
5991 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5992 " number slots(%d)\n", ioc
->name
, reason_str
,
5993 le16_to_cpu(event_data
->EnclosureHandle
),
5994 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5995 le16_to_cpu(event_data
->StartSlot
));
5999 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
6000 * @ioc: per adapter object
6001 * @fw_event: The fw_event_work object
6007 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6008 struct fw_event_work
*fw_event
)
6010 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6011 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
6012 (Mpi2EventDataSasEnclDevStatusChange_t
*)
6013 fw_event
->event_data
);
6017 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6018 * @ioc: per adapter object
6019 * @fw_event: The fw_event_work object
6025 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
6026 struct fw_event_work
*fw_event
)
6028 struct scsi_cmnd
*scmd
;
6029 struct scsi_device
*sdev
;
6032 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6033 u32 termination_count
;
6035 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
6036 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
6037 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6038 fw_event
->event_data
;
6040 unsigned long flags
;
6043 u8 task_abort_retries
;
6045 mutex_lock(&ioc
->tm_cmds
.mutex
);
6047 "%s: enter: phy number(%d), width(%d)\n",
6048 ioc
->name
, __func__
, event_data
->PhyNum
,
6049 event_data
->PortWidth
);
6051 _scsih_block_io_all_device(ioc
);
6053 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6054 mpi_reply
= ioc
->tm_cmds
.reply
;
6055 broadcast_aen_retry
:
6057 /* sanity checks for retrying this loop */
6058 if (max_retries
++ == 5) {
6059 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
6060 ioc
->name
, __func__
));
6062 } else if (max_retries
> 1)
6063 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
6064 ioc
->name
, __func__
, max_retries
- 1));
6066 termination_count
= 0;
6068 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
6069 if (ioc
->shost_recovery
)
6071 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
6074 sdev
= scmd
->device
;
6075 sas_device_priv_data
= sdev
->hostdata
;
6076 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
6078 /* skip hidden raid components */
6079 if (sas_device_priv_data
->sas_target
->flags
&
6080 MPT_TARGET_FLAGS_RAID_COMPONENT
)
6083 if (sas_device_priv_data
->sas_target
->flags
&
6084 MPT_TARGET_FLAGS_VOLUME
)
6087 handle
= sas_device_priv_data
->sas_target
->handle
;
6088 lun
= sas_device_priv_data
->lun
;
6091 if (ioc
->shost_recovery
)
6094 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6095 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
6096 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
6098 sdev_printk(KERN_WARNING
, sdev
,
6099 "mpt3sas_scsih_issue_tm: FAILED when sending "
6100 "QUERY_TASK: scmd(%p)\n", scmd
);
6101 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6102 goto broadcast_aen_retry
;
6104 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
6105 & MPI2_IOCSTATUS_MASK
;
6106 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6107 sdev_printk(KERN_WARNING
, sdev
,
6108 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6110 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6111 goto broadcast_aen_retry
;
6114 /* see if IO is still owned by IOC and target */
6115 if (mpi_reply
->ResponseCode
==
6116 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
6117 mpi_reply
->ResponseCode
==
6118 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
6119 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6122 task_abort_retries
= 0;
6124 if (task_abort_retries
++ == 60) {
6125 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6126 "%s: ABORT_TASK: giving up\n", ioc
->name
,
6128 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6129 goto broadcast_aen_retry
;
6132 if (ioc
->shost_recovery
)
6135 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
6136 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
,
6139 sdev_printk(KERN_WARNING
, sdev
,
6140 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6141 "scmd(%p)\n", scmd
);
6145 if (task_abort_retries
> 1)
6146 sdev_printk(KERN_WARNING
, sdev
,
6147 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6149 task_abort_retries
- 1, scmd
);
6151 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
6152 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6155 if (ioc
->broadcast_aen_pending
) {
6156 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6157 "%s: loop back due to pending AEN\n",
6158 ioc
->name
, __func__
));
6159 ioc
->broadcast_aen_pending
= 0;
6160 goto broadcast_aen_retry
;
6164 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6167 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6168 "%s - exit, query_count = %d termination_count = %d\n",
6169 ioc
->name
, __func__
, query_count
, termination_count
));
6171 ioc
->broadcast_aen_busy
= 0;
6172 if (!ioc
->shost_recovery
)
6173 _scsih_ublock_io_all_device(ioc
);
6174 mutex_unlock(&ioc
->tm_cmds
.mutex
);
6178 * _scsih_sas_discovery_event - handle discovery events
6179 * @ioc: per adapter object
6180 * @fw_event: The fw_event_work object
6186 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
6187 struct fw_event_work
*fw_event
)
6189 Mpi2EventDataSasDiscovery_t
*event_data
=
6190 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
6192 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
6193 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
6194 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
6196 if (event_data
->DiscoveryStatus
)
6197 pr_info("discovery_status(0x%08x)",
6198 le32_to_cpu(event_data
->DiscoveryStatus
));
6202 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
6203 !ioc
->sas_hba
.num_phys
) {
6204 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6205 /* Wait for the reset to complete */
6206 while (ioc
->shost_recovery
)
6209 _scsih_sas_host_add(ioc
);
6214 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6215 * @ioc: per adapter object
6216 * @handle: device handle for physical disk
6217 * @phys_disk_num: physical disk number
6219 * Return 0 for success, else failure.
6222 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
6224 Mpi2RaidActionRequest_t
*mpi_request
;
6225 Mpi2RaidActionReply_t
*mpi_reply
;
6232 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
6235 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6237 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
6238 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
6239 ioc
->name
, __func__
);
6243 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
6245 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6247 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
6248 ioc
->name
, __func__
);
6249 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6254 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
6255 ioc
->scsih_cmds
.smid
= smid
;
6256 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6258 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6259 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
6260 mpi_request
->PhysDiskNum
= phys_disk_num
;
6262 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
6263 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
6264 handle
, phys_disk_num
));
6266 init_completion(&ioc
->scsih_cmds
.done
);
6267 mpt3sas_base_put_smid_default(ioc
, smid
);
6268 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6270 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
6271 pr_err(MPT3SAS_FMT
"%s: timeout\n",
6272 ioc
->name
, __func__
);
6273 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
6279 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
6281 mpi_reply
= ioc
->scsih_cmds
.reply
;
6282 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
6283 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
6284 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
6287 ioc_status
&= MPI2_IOCSTATUS_MASK
;
6288 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6289 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6290 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6291 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
6295 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6296 "IR RAID_ACTION: completed successfully\n",
6301 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6302 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6305 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
6310 * _scsih_reprobe_lun - reprobing lun
6311 * @sdev: scsi device struct
6312 * @no_uld_attach: sdev->no_uld_attach flag setting
6316 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6318 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6319 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6320 sdev
->no_uld_attach
? "hidding" : "exposing");
6321 WARN_ON(scsi_device_reprobe(sdev
));
6325 * _scsih_sas_volume_add - add new volume
6326 * @ioc: per adapter object
6327 * @element: IR config element data
6333 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
6334 Mpi2EventIrConfigElement_t
*element
)
6336 struct _raid_device
*raid_device
;
6337 unsigned long flags
;
6339 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6342 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6345 "failure at %s:%d/%s()!\n", ioc
->name
,
6346 __FILE__
, __LINE__
, __func__
);
6350 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6351 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6352 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6357 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6360 "failure at %s:%d/%s()!\n", ioc
->name
,
6361 __FILE__
, __LINE__
, __func__
);
6365 raid_device
->id
= ioc
->sas_id
++;
6366 raid_device
->channel
= RAID_CHANNEL
;
6367 raid_device
->handle
= handle
;
6368 raid_device
->wwid
= wwid
;
6369 _scsih_raid_device_add(ioc
, raid_device
);
6370 if (!ioc
->wait_for_discovery_to_complete
) {
6371 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6372 raid_device
->id
, 0);
6374 _scsih_raid_device_remove(ioc
, raid_device
);
6376 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6377 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6378 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6383 * _scsih_sas_volume_delete - delete volume
6384 * @ioc: per adapter object
6385 * @handle: volume device handle
6391 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6393 struct _raid_device
*raid_device
;
6394 unsigned long flags
;
6395 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6396 struct scsi_target
*starget
= NULL
;
6398 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6399 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6401 if (raid_device
->starget
) {
6402 starget
= raid_device
->starget
;
6403 sas_target_priv_data
= starget
->hostdata
;
6404 sas_target_priv_data
->deleted
= 1;
6406 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
6407 ioc
->name
, raid_device
->handle
,
6408 (unsigned long long) raid_device
->wwid
);
6409 list_del(&raid_device
->list
);
6412 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6414 scsi_remove_target(&starget
->dev
);
6418 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6419 * @ioc: per adapter object
6420 * @element: IR config element data
6426 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6427 Mpi2EventIrConfigElement_t
*element
)
6429 struct _sas_device
*sas_device
;
6430 struct scsi_target
*starget
= NULL
;
6431 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6432 unsigned long flags
;
6433 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6435 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6436 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6438 sas_device
->volume_handle
= 0;
6439 sas_device
->volume_wwid
= 0;
6440 clear_bit(handle
, ioc
->pd_handles
);
6441 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6442 starget
= sas_device
->starget
;
6443 sas_target_priv_data
= starget
->hostdata
;
6444 sas_target_priv_data
->flags
&=
6445 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6448 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6452 /* exposing raid component */
6454 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6456 sas_device_put(sas_device
);
6460 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6461 * @ioc: per adapter object
6462 * @element: IR config element data
6468 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6469 Mpi2EventIrConfigElement_t
*element
)
6471 struct _sas_device
*sas_device
;
6472 struct scsi_target
*starget
= NULL
;
6473 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6474 unsigned long flags
;
6475 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6476 u16 volume_handle
= 0;
6477 u64 volume_wwid
= 0;
6479 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6481 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6484 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6485 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6487 set_bit(handle
, ioc
->pd_handles
);
6488 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6489 starget
= sas_device
->starget
;
6490 sas_target_priv_data
= starget
->hostdata
;
6491 sas_target_priv_data
->flags
|=
6492 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6493 sas_device
->volume_handle
= volume_handle
;
6494 sas_device
->volume_wwid
= volume_wwid
;
6497 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6501 /* hiding raid component */
6502 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6505 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6507 sas_device_put(sas_device
);
6511 * _scsih_sas_pd_delete - delete pd component
6512 * @ioc: per adapter object
6513 * @element: IR config element data
6519 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6520 Mpi2EventIrConfigElement_t
*element
)
6522 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6524 _scsih_device_remove_by_handle(ioc
, handle
);
6528 * _scsih_sas_pd_add - remove pd component
6529 * @ioc: per adapter object
6530 * @element: IR config element data
6536 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6537 Mpi2EventIrConfigElement_t
*element
)
6539 struct _sas_device
*sas_device
;
6540 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6541 Mpi2ConfigReply_t mpi_reply
;
6542 Mpi2SasDevicePage0_t sas_device_pg0
;
6547 set_bit(handle
, ioc
->pd_handles
);
6549 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6551 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6552 sas_device_put(sas_device
);
6556 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6557 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6558 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6559 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6563 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6564 MPI2_IOCSTATUS_MASK
;
6565 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6566 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6567 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6571 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6572 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6573 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6574 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6576 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6577 _scsih_add_device(ioc
, handle
, 0, 1);
6581 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6582 * @ioc: per adapter object
6583 * @event_data: event data payload
6589 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6590 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6592 Mpi2EventIrConfigElement_t
*element
;
6595 char *reason_str
= NULL
, *element_str
= NULL
;
6597 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6599 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6600 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6601 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6602 "foreign" : "native", event_data
->NumElements
);
6603 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6604 switch (element
->ReasonCode
) {
6605 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6608 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6609 reason_str
= "remove";
6611 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6612 reason_str
= "no change";
6614 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6615 reason_str
= "hide";
6617 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6618 reason_str
= "unhide";
6620 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6621 reason_str
= "volume_created";
6623 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6624 reason_str
= "volume_deleted";
6626 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6627 reason_str
= "pd_created";
6629 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6630 reason_str
= "pd_deleted";
6633 reason_str
= "unknown reason";
6636 element_type
= le16_to_cpu(element
->ElementFlags
) &
6637 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6638 switch (element_type
) {
6639 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6640 element_str
= "volume";
6642 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6643 element_str
= "phys disk";
6645 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6646 element_str
= "hot spare";
6649 element_str
= "unknown element";
6652 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6653 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6654 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6655 le16_to_cpu(element
->PhysDiskDevHandle
),
6656 element
->PhysDiskNum
);
6661 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6662 * @ioc: per adapter object
6663 * @fw_event: The fw_event_work object
6669 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6670 struct fw_event_work
*fw_event
)
6672 Mpi2EventIrConfigElement_t
*element
;
6675 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6676 (Mpi2EventDataIrConfigChangeList_t
*)
6677 fw_event
->event_data
;
6679 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6680 (!ioc
->hide_ir_msg
))
6681 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6683 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6684 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6686 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6687 if (ioc
->shost_recovery
&&
6688 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
6689 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6690 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6691 _scsih_ir_fastpath(ioc
,
6692 le16_to_cpu(element
->PhysDiskDevHandle
),
6693 element
->PhysDiskNum
);
6698 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6700 switch (element
->ReasonCode
) {
6701 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6702 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6703 if (!foreign_config
)
6704 _scsih_sas_volume_add(ioc
, element
);
6706 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6707 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6708 if (!foreign_config
)
6709 _scsih_sas_volume_delete(ioc
,
6710 le16_to_cpu(element
->VolDevHandle
));
6712 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6713 if (!ioc
->is_warpdrive
)
6714 _scsih_sas_pd_hide(ioc
, element
);
6716 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6717 if (!ioc
->is_warpdrive
)
6718 _scsih_sas_pd_expose(ioc
, element
);
6720 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6721 if (!ioc
->is_warpdrive
)
6722 _scsih_sas_pd_add(ioc
, element
);
6724 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6725 if (!ioc
->is_warpdrive
)
6726 _scsih_sas_pd_delete(ioc
, element
);
6733 * _scsih_sas_ir_volume_event - IR volume event
6734 * @ioc: per adapter object
6735 * @fw_event: The fw_event_work object
6741 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6742 struct fw_event_work
*fw_event
)
6745 unsigned long flags
;
6746 struct _raid_device
*raid_device
;
6750 Mpi2EventDataIrVolume_t
*event_data
=
6751 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6753 if (ioc
->shost_recovery
)
6756 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6759 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6760 state
= le32_to_cpu(event_data
->NewValue
);
6761 if (!ioc
->hide_ir_msg
)
6762 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6763 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6764 ioc
->name
, __func__
, handle
,
6765 le32_to_cpu(event_data
->PreviousValue
), state
));
6767 case MPI2_RAID_VOL_STATE_MISSING
:
6768 case MPI2_RAID_VOL_STATE_FAILED
:
6769 _scsih_sas_volume_delete(ioc
, handle
);
6772 case MPI2_RAID_VOL_STATE_ONLINE
:
6773 case MPI2_RAID_VOL_STATE_DEGRADED
:
6774 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6776 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6777 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6778 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6783 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6786 "failure at %s:%d/%s()!\n", ioc
->name
,
6787 __FILE__
, __LINE__
, __func__
);
6791 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6794 "failure at %s:%d/%s()!\n", ioc
->name
,
6795 __FILE__
, __LINE__
, __func__
);
6799 raid_device
->id
= ioc
->sas_id
++;
6800 raid_device
->channel
= RAID_CHANNEL
;
6801 raid_device
->handle
= handle
;
6802 raid_device
->wwid
= wwid
;
6803 _scsih_raid_device_add(ioc
, raid_device
);
6804 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6805 raid_device
->id
, 0);
6807 _scsih_raid_device_remove(ioc
, raid_device
);
6810 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6817 * _scsih_sas_ir_physical_disk_event - PD event
6818 * @ioc: per adapter object
6819 * @fw_event: The fw_event_work object
6825 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6826 struct fw_event_work
*fw_event
)
6828 u16 handle
, parent_handle
;
6830 struct _sas_device
*sas_device
;
6831 Mpi2ConfigReply_t mpi_reply
;
6832 Mpi2SasDevicePage0_t sas_device_pg0
;
6834 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6835 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6838 if (ioc
->shost_recovery
)
6841 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6844 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6845 state
= le32_to_cpu(event_data
->NewValue
);
6847 if (!ioc
->hide_ir_msg
)
6848 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6849 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6850 ioc
->name
, __func__
, handle
,
6851 le32_to_cpu(event_data
->PreviousValue
), state
));
6854 case MPI2_RAID_PD_STATE_ONLINE
:
6855 case MPI2_RAID_PD_STATE_DEGRADED
:
6856 case MPI2_RAID_PD_STATE_REBUILDING
:
6857 case MPI2_RAID_PD_STATE_OPTIMAL
:
6858 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6860 if (!ioc
->is_warpdrive
)
6861 set_bit(handle
, ioc
->pd_handles
);
6863 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6865 sas_device_put(sas_device
);
6869 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6870 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6872 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6873 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6877 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6878 MPI2_IOCSTATUS_MASK
;
6879 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6880 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6881 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6885 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6886 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6887 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6888 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6890 _scsih_add_device(ioc
, handle
, 0, 1);
6894 case MPI2_RAID_PD_STATE_OFFLINE
:
6895 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6896 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6903 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6904 * @ioc: per adapter object
6905 * @event_data: event data payload
6911 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6912 Mpi2EventDataIrOperationStatus_t
*event_data
)
6914 char *reason_str
= NULL
;
6916 switch (event_data
->RAIDOperation
) {
6917 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6918 reason_str
= "resync";
6920 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6921 reason_str
= "online capacity expansion";
6923 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6924 reason_str
= "consistency check";
6926 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6927 reason_str
= "background init";
6929 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6930 reason_str
= "make data consistent";
6937 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6938 "\thandle(0x%04x), percent complete(%d)\n",
6939 ioc
->name
, reason_str
,
6940 le16_to_cpu(event_data
->VolDevHandle
),
6941 event_data
->PercentComplete
);
6945 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6946 * @ioc: per adapter object
6947 * @fw_event: The fw_event_work object
6953 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
6954 struct fw_event_work
*fw_event
)
6956 Mpi2EventDataIrOperationStatus_t
*event_data
=
6957 (Mpi2EventDataIrOperationStatus_t
*)
6958 fw_event
->event_data
;
6959 static struct _raid_device
*raid_device
;
6960 unsigned long flags
;
6963 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6964 (!ioc
->hide_ir_msg
))
6965 _scsih_sas_ir_operation_status_event_debug(ioc
,
6968 /* code added for raid transport support */
6969 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6971 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6972 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6973 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6975 raid_device
->percent_complete
=
6976 event_data
->PercentComplete
;
6977 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6982 * _scsih_prep_device_scan - initialize parameters prior to device scan
6983 * @ioc: per adapter object
6985 * Set the deleted flag prior to device scan. If the device is found during
6986 * the scan, then we clear the deleted flag.
6989 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
6991 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6992 struct scsi_device
*sdev
;
6994 shost_for_each_device(sdev
, ioc
->shost
) {
6995 sas_device_priv_data
= sdev
->hostdata
;
6996 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6997 sas_device_priv_data
->sas_target
->deleted
= 1;
7002 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
7003 * @ioc: per adapter object
7004 * @sas_device_pg0: SAS Device page 0
7006 * After host reset, find out whether devices are still responding.
7007 * Used in _scsih_remove_unresponsive_sas_devices.
7012 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
7013 Mpi2SasDevicePage0_t
*sas_device_pg0
)
7015 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7016 struct scsi_target
*starget
;
7017 struct _sas_device
*sas_device
;
7018 unsigned long flags
;
7020 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7021 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
7022 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
7023 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
7024 sas_device
->responding
= 1;
7025 starget
= sas_device
->starget
;
7026 if (starget
&& starget
->hostdata
) {
7027 sas_target_priv_data
= starget
->hostdata
;
7028 sas_target_priv_data
->tm_busy
= 0;
7029 sas_target_priv_data
->deleted
= 0;
7031 sas_target_priv_data
= NULL
;
7033 starget_printk(KERN_INFO
, starget
,
7034 "handle(0x%04x), sas_addr(0x%016llx)\n",
7035 sas_device_pg0
->DevHandle
,
7036 (unsigned long long)
7037 sas_device
->sas_address
);
7039 if (sas_device
->enclosure_handle
!= 0)
7040 starget_printk(KERN_INFO
, starget
,
7041 "enclosure logical id(0x%016llx),"
7043 (unsigned long long)
7044 sas_device
->enclosure_logical_id
,
7047 if (sas_device_pg0
->Flags
&
7048 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
7049 sas_device
->enclosure_level
=
7050 le16_to_cpu(sas_device_pg0
->EnclosureLevel
);
7051 memcpy(&sas_device
->connector_name
[0],
7052 &sas_device_pg0
->ConnectorName
[0], 4);
7054 sas_device
->enclosure_level
= 0;
7055 sas_device
->connector_name
[0] = '\0';
7058 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
7060 pr_info("\thandle changed from(0x%04x)!!!\n",
7061 sas_device
->handle
);
7062 sas_device
->handle
= sas_device_pg0
->DevHandle
;
7063 if (sas_target_priv_data
)
7064 sas_target_priv_data
->handle
=
7065 sas_device_pg0
->DevHandle
;
7070 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7074 * _scsih_search_responding_sas_devices -
7075 * @ioc: per adapter object
7077 * After host reset, find out whether devices are still responding.
7083 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7085 Mpi2SasDevicePage0_t sas_device_pg0
;
7086 Mpi2ConfigReply_t mpi_reply
;
7091 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
7093 if (list_empty(&ioc
->sas_device_list
))
7097 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7098 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7100 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7101 MPI2_IOCSTATUS_MASK
;
7102 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7104 handle
= sas_device_pg0
.DevHandle
=
7105 le16_to_cpu(sas_device_pg0
.DevHandle
);
7106 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
7107 if (!(_scsih_is_end_device(device_info
)))
7109 sas_device_pg0
.SASAddress
=
7110 le64_to_cpu(sas_device_pg0
.SASAddress
);
7111 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
7112 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
7116 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
7121 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7122 * @ioc: per adapter object
7123 * @wwid: world wide identifier for raid volume
7124 * @handle: device handle
7126 * After host reset, find out whether devices are still responding.
7127 * Used in _scsih_remove_unresponsive_raid_devices.
7132 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
7135 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7136 struct scsi_target
*starget
;
7137 struct _raid_device
*raid_device
;
7138 unsigned long flags
;
7140 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7141 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
7142 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
7143 starget
= raid_device
->starget
;
7144 if (starget
&& starget
->hostdata
) {
7145 sas_target_priv_data
= starget
->hostdata
;
7146 sas_target_priv_data
->deleted
= 0;
7148 sas_target_priv_data
= NULL
;
7149 raid_device
->responding
= 1;
7150 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7151 starget_printk(KERN_INFO
, raid_device
->starget
,
7152 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
7153 (unsigned long long)raid_device
->wwid
);
7156 * WARPDRIVE: The handles of the PDs might have changed
7157 * across the host reset so re-initialize the
7158 * required data for Direct IO
7160 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
7161 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7162 if (raid_device
->handle
== handle
) {
7163 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
7167 pr_info("\thandle changed from(0x%04x)!!!\n",
7168 raid_device
->handle
);
7169 raid_device
->handle
= handle
;
7170 if (sas_target_priv_data
)
7171 sas_target_priv_data
->handle
= handle
;
7172 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7176 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7180 * _scsih_search_responding_raid_devices -
7181 * @ioc: per adapter object
7183 * After host reset, find out whether devices are still responding.
7189 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
7191 Mpi2RaidVolPage1_t volume_pg1
;
7192 Mpi2RaidVolPage0_t volume_pg0
;
7193 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7194 Mpi2ConfigReply_t mpi_reply
;
7199 if (!ioc
->ir_firmware
)
7202 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
7205 if (list_empty(&ioc
->raid_device_list
))
7209 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7210 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7211 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7212 MPI2_IOCSTATUS_MASK
;
7213 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7215 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7217 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7218 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7219 sizeof(Mpi2RaidVolPage0_t
)))
7222 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7223 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7224 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
7225 _scsih_mark_responding_raid_device(ioc
,
7226 le64_to_cpu(volume_pg1
.WWID
), handle
);
7229 /* refresh the pd_handles */
7230 if (!ioc
->is_warpdrive
) {
7231 phys_disk_num
= 0xFF;
7232 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
7233 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7234 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7236 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7237 MPI2_IOCSTATUS_MASK
;
7238 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7240 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7241 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7242 set_bit(handle
, ioc
->pd_handles
);
7246 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
7251 * _scsih_mark_responding_expander - mark a expander as responding
7252 * @ioc: per adapter object
7253 * @sas_address: sas address
7256 * After host reset, find out whether devices are still responding.
7257 * Used in _scsih_remove_unresponsive_expanders.
7262 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
7265 struct _sas_node
*sas_expander
;
7266 unsigned long flags
;
7269 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7270 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
7271 if (sas_expander
->sas_address
!= sas_address
)
7273 sas_expander
->responding
= 1;
7274 if (sas_expander
->handle
== handle
)
7276 pr_info("\texpander(0x%016llx): handle changed" \
7277 " from(0x%04x) to (0x%04x)!!!\n",
7278 (unsigned long long)sas_expander
->sas_address
,
7279 sas_expander
->handle
, handle
);
7280 sas_expander
->handle
= handle
;
7281 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
7282 sas_expander
->phy
[i
].handle
= handle
;
7286 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7290 * _scsih_search_responding_expanders -
7291 * @ioc: per adapter object
7293 * After host reset, find out whether devices are still responding.
7299 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
7301 Mpi2ExpanderPage0_t expander_pg0
;
7302 Mpi2ConfigReply_t mpi_reply
;
7307 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
7309 if (list_empty(&ioc
->sas_expander_list
))
7313 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7314 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7316 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7317 MPI2_IOCSTATUS_MASK
;
7318 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7321 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7322 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7323 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7325 (unsigned long long)sas_address
);
7326 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7330 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
7334 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7335 * @ioc: per adapter object
7340 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7342 struct _sas_device
*sas_device
, *sas_device_next
;
7343 struct _sas_node
*sas_expander
, *sas_expander_next
;
7344 struct _raid_device
*raid_device
, *raid_device_next
;
7345 struct list_head tmp_list
;
7346 unsigned long flags
;
7349 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
7352 /* removing unresponding end devices */
7353 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
7356 * Iterate, pulling off devices marked as non-responding. We become the
7357 * owner for the reference the list had on any object we prune.
7359 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7360 list_for_each_entry_safe(sas_device
, sas_device_next
,
7361 &ioc
->sas_device_list
, list
) {
7362 if (!sas_device
->responding
)
7363 list_move_tail(&sas_device
->list
, &head
);
7365 sas_device
->responding
= 0;
7367 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7370 * Now, uninitialize and remove the unresponding devices we pruned.
7372 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
7373 _scsih_remove_device(ioc
, sas_device
);
7374 list_del_init(&sas_device
->list
);
7375 sas_device_put(sas_device
);
7378 /* removing unresponding volumes */
7379 if (ioc
->ir_firmware
) {
7380 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
7382 list_for_each_entry_safe(raid_device
, raid_device_next
,
7383 &ioc
->raid_device_list
, list
) {
7384 if (!raid_device
->responding
)
7385 _scsih_sas_volume_delete(ioc
,
7386 raid_device
->handle
);
7388 raid_device
->responding
= 0;
7392 /* removing unresponding expanders */
7393 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
7395 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7396 INIT_LIST_HEAD(&tmp_list
);
7397 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7398 &ioc
->sas_expander_list
, list
) {
7399 if (!sas_expander
->responding
)
7400 list_move_tail(&sas_expander
->list
, &tmp_list
);
7402 sas_expander
->responding
= 0;
7404 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7405 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7407 list_del(&sas_expander
->list
);
7408 _scsih_expander_node_remove(ioc
, sas_expander
);
7411 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
7414 /* unblock devices */
7415 _scsih_ublock_io_all_device(ioc
);
7419 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
7420 struct _sas_node
*sas_expander
, u16 handle
)
7422 Mpi2ExpanderPage1_t expander_pg1
;
7423 Mpi2ConfigReply_t mpi_reply
;
7426 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7427 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7428 &expander_pg1
, i
, handle
))) {
7429 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7430 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7434 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7435 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7436 expander_pg1
.NegotiatedLinkRate
>> 4);
7441 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7442 * @ioc: per adapter object
7447 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
7449 Mpi2ExpanderPage0_t expander_pg0
;
7450 Mpi2SasDevicePage0_t sas_device_pg0
;
7451 Mpi2RaidVolPage1_t volume_pg1
;
7452 Mpi2RaidVolPage0_t volume_pg0
;
7453 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7454 Mpi2EventIrConfigElement_t element
;
7455 Mpi2ConfigReply_t mpi_reply
;
7458 u16 handle
, parent_handle
;
7460 struct _sas_device
*sas_device
;
7461 struct _sas_node
*expander_device
;
7462 static struct _raid_device
*raid_device
;
7464 unsigned long flags
;
7466 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7468 _scsih_sas_host_refresh(ioc
);
7470 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7474 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7475 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7476 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7477 MPI2_IOCSTATUS_MASK
;
7478 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7479 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7480 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7481 ioc
->name
, ioc_status
,
7482 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7485 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7486 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7487 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7488 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7489 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7490 if (expander_device
)
7491 _scsih_refresh_expander_links(ioc
, expander_device
,
7494 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7495 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7496 handle
, (unsigned long long)
7497 le64_to_cpu(expander_pg0
.SASAddress
));
7498 _scsih_expander_add(ioc
, handle
);
7499 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7500 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7501 handle
, (unsigned long long)
7502 le64_to_cpu(expander_pg0
.SASAddress
));
7506 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7509 if (!ioc
->ir_firmware
)
7512 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7515 phys_disk_num
= 0xFF;
7516 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7517 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7519 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7520 MPI2_IOCSTATUS_MASK
;
7521 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7522 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7523 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7524 ioc
->name
, ioc_status
,
7525 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7528 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7529 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7530 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7532 sas_device_put(sas_device
);
7535 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7536 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7539 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7540 MPI2_IOCSTATUS_MASK
;
7541 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7542 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7543 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7544 ioc
->name
, ioc_status
,
7545 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7548 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7549 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7551 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7552 " handle (0x%04x), sas_addr(0x%016llx)\n",
7553 ioc
->name
, handle
, (unsigned long long)
7554 le64_to_cpu(sas_device_pg0
.SASAddress
));
7555 mpt3sas_transport_update_links(ioc
, sas_address
,
7556 handle
, sas_device_pg0
.PhyNum
,
7557 MPI2_SAS_NEG_LINK_RATE_1_5
);
7558 set_bit(handle
, ioc
->pd_handles
);
7560 /* This will retry adding the end device.
7561 * _scsih_add_device() will decide on retries and
7562 * return "1" when it should be retried
7564 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7568 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7569 " handle (0x%04x), sas_addr(0x%016llx)\n",
7570 ioc
->name
, handle
, (unsigned long long)
7571 le64_to_cpu(sas_device_pg0
.SASAddress
));
7575 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7578 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7582 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7583 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7584 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7585 MPI2_IOCSTATUS_MASK
;
7586 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7587 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7588 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7589 ioc
->name
, ioc_status
,
7590 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7593 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7594 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7595 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7596 le64_to_cpu(volume_pg1
.WWID
));
7597 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7600 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7601 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7602 sizeof(Mpi2RaidVolPage0_t
)))
7604 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7605 MPI2_IOCSTATUS_MASK
;
7606 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7607 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7608 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7609 ioc
->name
, ioc_status
,
7610 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7613 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7614 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7615 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7616 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7617 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7618 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7620 "\tBEFORE adding volume: handle (0x%04x)\n",
7621 ioc
->name
, volume_pg1
.DevHandle
);
7622 _scsih_sas_volume_add(ioc
, &element
);
7624 "\tAFTER adding volume: handle (0x%04x)\n",
7625 ioc
->name
, volume_pg1
.DevHandle
);
7629 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7634 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7639 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7640 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7642 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7643 MPI2_IOCSTATUS_MASK
;
7644 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7645 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7646 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7647 ioc
->name
, ioc_status
,
7648 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7651 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7652 if (!(_scsih_is_end_device(
7653 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7655 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
7656 le64_to_cpu(sas_device_pg0
.SASAddress
));
7658 sas_device_put(sas_device
);
7661 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7662 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7663 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7664 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7665 handle
, (unsigned long long)
7666 le64_to_cpu(sas_device_pg0
.SASAddress
));
7667 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7668 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7670 /* This will retry adding the end device.
7671 * _scsih_add_device() will decide on retries and
7672 * return "1" when it should be retried
7674 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7678 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7679 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7680 handle
, (unsigned long long)
7681 le64_to_cpu(sas_device_pg0
.SASAddress
));
7684 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7687 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7690 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7691 * @ioc: per adapter object
7692 * @reset_phase: phase
7694 * The handler for doing any required cleanup or initialization.
7696 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7697 * MPT3_IOC_DONE_RESET
7702 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7704 switch (reset_phase
) {
7705 case MPT3_IOC_PRE_RESET
:
7706 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7707 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7709 case MPT3_IOC_AFTER_RESET
:
7710 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7711 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7712 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7713 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7714 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7715 complete(&ioc
->scsih_cmds
.done
);
7717 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7718 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7719 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7720 complete(&ioc
->tm_cmds
.done
);
7723 _scsih_fw_event_cleanup_queue(ioc
);
7724 _scsih_flush_running_cmds(ioc
);
7726 case MPT3_IOC_DONE_RESET
:
7727 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7728 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7729 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7730 !ioc
->sas_hba
.num_phys
)) {
7731 _scsih_prep_device_scan(ioc
);
7732 _scsih_search_responding_sas_devices(ioc
);
7733 _scsih_search_responding_raid_devices(ioc
);
7734 _scsih_search_responding_expanders(ioc
);
7735 _scsih_error_recovery_delete_devices(ioc
);
7742 * _mpt3sas_fw_work - delayed task for processing firmware events
7743 * @ioc: per adapter object
7744 * @fw_event: The fw_event_work object
7750 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7752 _scsih_fw_event_del_from_list(ioc
, fw_event
);
7754 /* the queue is being flushed so ignore this event */
7755 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
7756 fw_event_work_put(fw_event
);
7760 switch (fw_event
->event
) {
7761 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7762 mpt3sas_process_trigger_data(ioc
,
7763 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7764 fw_event
->event_data
);
7766 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7767 while (scsi_host_in_recovery(ioc
->shost
) ||
7768 ioc
->shost_recovery
) {
7770 * If we're unloading, bail. Otherwise, this can become
7773 if (ioc
->remove_host
)
7777 _scsih_remove_unresponding_sas_devices(ioc
);
7778 _scsih_scan_for_devices_after_reset(ioc
);
7780 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7781 ioc
->start_scan
= 0;
7782 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7783 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7785 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7786 "port enable: complete from worker thread\n",
7789 case MPT3SAS_TURN_ON_PFA_LED
:
7790 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7792 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7793 _scsih_sas_topology_change_event(ioc
, fw_event
);
7795 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7796 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7798 case MPI2_EVENT_SAS_DISCOVERY
:
7799 _scsih_sas_discovery_event(ioc
, fw_event
);
7801 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7802 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7804 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7805 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7808 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7809 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7811 case MPI2_EVENT_IR_VOLUME
:
7812 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7814 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7815 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7817 case MPI2_EVENT_IR_OPERATION_STATUS
:
7818 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7822 fw_event_work_put(fw_event
);
7826 * _firmware_event_work
7827 * @ioc: per adapter object
7828 * @work: The fw_event_work object
7831 * wrappers for the work thread handling firmware events
7837 _firmware_event_work(struct work_struct
*work
)
7839 struct fw_event_work
*fw_event
= container_of(work
,
7840 struct fw_event_work
, work
);
7842 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7846 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7847 * @ioc: per adapter object
7848 * @msix_index: MSIX table index supplied by the OS
7849 * @reply: reply message frame(lower 32bit addr)
7850 * Context: interrupt.
7852 * This function merely adds a new work task into ioc->firmware_event_thread.
7853 * The tasks are worked from _firmware_event_work in user context.
7855 * Return 1 meaning mf should be freed from _base_interrupt
7856 * 0 means the mf is freed from this function.
7859 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7862 struct fw_event_work
*fw_event
;
7863 Mpi2EventNotificationReply_t
*mpi_reply
;
7866 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
7868 /* events turned off due to host reset or driver unloading */
7869 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7872 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7874 if (unlikely(!mpi_reply
)) {
7875 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7876 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7880 event
= le16_to_cpu(mpi_reply
->Event
);
7882 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7883 mpt3sas_trigger_event(ioc
, event
, 0);
7887 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7889 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7890 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7891 mpi_reply
->EventData
;
7893 if (baen_data
->Primitive
!=
7894 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7897 if (ioc
->broadcast_aen_busy
) {
7898 ioc
->broadcast_aen_pending
++;
7901 ioc
->broadcast_aen_busy
= 1;
7905 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7906 _scsih_check_topo_delete_events(ioc
,
7907 (Mpi2EventDataSasTopologyChangeList_t
*)
7908 mpi_reply
->EventData
);
7910 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7911 _scsih_check_ir_config_unhide_events(ioc
,
7912 (Mpi2EventDataIrConfigChangeList_t
*)
7913 mpi_reply
->EventData
);
7915 case MPI2_EVENT_IR_VOLUME
:
7916 _scsih_check_volume_delete_events(ioc
,
7917 (Mpi2EventDataIrVolume_t
*)
7918 mpi_reply
->EventData
);
7920 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7922 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7925 if (!ioc
->is_warpdrive
)
7928 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7929 mpi_reply
->EventData
;
7930 log_code
= (u32
*)log_entry
->LogData
;
7932 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7933 != MPT2_WARPDRIVE_LOGENTRY
)
7936 switch (le32_to_cpu(*log_code
)) {
7937 case MPT2_WARPDRIVE_LC_SSDT
:
7938 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7939 "IO Throttling has occurred in the WarpDrive "
7940 "subsystem. Check WarpDrive documentation for "
7941 "additional details.\n", ioc
->name
);
7943 case MPT2_WARPDRIVE_LC_SSDLW
:
7944 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
7945 "Program/Erase Cycles for the WarpDrive subsystem "
7946 "in degraded range. Check WarpDrive documentation "
7947 "for additional details.\n", ioc
->name
);
7949 case MPT2_WARPDRIVE_LC_SSDLF
:
7950 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7951 "There are no Program/Erase Cycles for the "
7952 "WarpDrive subsystem. The storage device will be "
7953 "in read-only mode. Check WarpDrive documentation "
7954 "for additional details.\n", ioc
->name
);
7956 case MPT2_WARPDRIVE_LC_BRMF
:
7957 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
7958 "The Backup Rail Monitor has failed on the "
7959 "WarpDrive subsystem. Check WarpDrive "
7960 "documentation for additional details.\n",
7967 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7968 case MPI2_EVENT_IR_OPERATION_STATUS
:
7969 case MPI2_EVENT_SAS_DISCOVERY
:
7970 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7971 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7974 case MPI2_EVENT_TEMP_THRESHOLD
:
7975 _scsih_temp_threshold_events(ioc
,
7976 (Mpi2EventDataTemperature_t
*)
7977 mpi_reply
->EventData
);
7979 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
7980 ActiveCableEventData
=
7981 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
7982 if (ActiveCableEventData
->ReasonCode
==
7983 MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
) {
7984 pr_info(MPT3SAS_FMT
"Currently an active cable with ReceptacleID %d",
7985 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
7986 pr_info("cannot be powered and devices connected to this active cable");
7987 pr_info("will not be seen. This active cable");
7988 pr_info("requires %d mW of power",
7989 ActiveCableEventData
->ActiveCablePowerRequirement
);
7993 default: /* ignore the rest */
7997 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7998 fw_event
= alloc_fw_event_work(sz
);
8000 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8001 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8005 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
8006 fw_event
->ioc
= ioc
;
8007 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
8008 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
8009 fw_event
->event
= event
;
8010 _scsih_fw_event_add(ioc
, fw_event
);
8011 fw_event_work_put(fw_event
);
8016 * _scsih_expander_node_remove - removing expander device from list.
8017 * @ioc: per adapter object
8018 * @sas_expander: the sas_device object
8019 * Context: Calling function should acquire ioc->sas_node_lock.
8021 * Removing object and freeing associated memory from the
8022 * ioc->sas_expander_list.
8027 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
8028 struct _sas_node
*sas_expander
)
8030 struct _sas_port
*mpt3sas_port
, *next
;
8032 /* remove sibling ports attached to this expander */
8033 list_for_each_entry_safe(mpt3sas_port
, next
,
8034 &sas_expander
->sas_port_list
, port_list
) {
8035 if (ioc
->shost_recovery
)
8037 if (mpt3sas_port
->remote_identify
.device_type
==
8039 mpt3sas_device_remove_by_sas_address(ioc
,
8040 mpt3sas_port
->remote_identify
.sas_address
);
8041 else if (mpt3sas_port
->remote_identify
.device_type
==
8042 SAS_EDGE_EXPANDER_DEVICE
||
8043 mpt3sas_port
->remote_identify
.device_type
==
8044 SAS_FANOUT_EXPANDER_DEVICE
)
8045 mpt3sas_expander_remove(ioc
,
8046 mpt3sas_port
->remote_identify
.sas_address
);
8049 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
8050 sas_expander
->sas_address_parent
);
8053 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8055 sas_expander
->handle
, (unsigned long long)
8056 sas_expander
->sas_address
);
8058 kfree(sas_expander
->phy
);
8059 kfree(sas_expander
);
8063 * _scsih_ir_shutdown - IR shutdown notification
8064 * @ioc: per adapter object
8066 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8067 * the host system is shutting down.
8072 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
8074 Mpi2RaidActionRequest_t
*mpi_request
;
8075 Mpi2RaidActionReply_t
*mpi_reply
;
8078 /* is IR firmware build loaded ? */
8079 if (!ioc
->ir_firmware
)
8082 /* are there any volumes ? */
8083 if (list_empty(&ioc
->raid_device_list
))
8086 mutex_lock(&ioc
->scsih_cmds
.mutex
);
8088 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
8089 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
8090 ioc
->name
, __func__
);
8093 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
8095 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
8097 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
8098 ioc
->name
, __func__
);
8099 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8103 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
8104 ioc
->scsih_cmds
.smid
= smid
;
8105 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
8107 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
8108 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
8110 if (!ioc
->hide_ir_msg
)
8111 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
8112 init_completion(&ioc
->scsih_cmds
.done
);
8113 mpt3sas_base_put_smid_default(ioc
, smid
);
8114 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
8116 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
8117 pr_err(MPT3SAS_FMT
"%s: timeout\n",
8118 ioc
->name
, __func__
);
8122 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
8123 mpi_reply
= ioc
->scsih_cmds
.reply
;
8124 if (!ioc
->hide_ir_msg
)
8125 pr_info(MPT3SAS_FMT
"IR shutdown "
8126 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8127 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
8128 le32_to_cpu(mpi_reply
->IOCLogInfo
));
8132 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8133 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
8137 * scsih_remove - detach and remove add host
8138 * @pdev: PCI device struct
8140 * Routine called when unloading the driver.
8143 static void scsih_remove(struct pci_dev
*pdev
)
8145 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8146 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8147 struct _sas_port
*mpt3sas_port
, *next_port
;
8148 struct _raid_device
*raid_device
, *next
;
8149 struct MPT3SAS_TARGET
*sas_target_priv_data
;
8150 struct workqueue_struct
*wq
;
8151 unsigned long flags
;
8153 ioc
->remove_host
= 1;
8154 _scsih_fw_event_cleanup_queue(ioc
);
8156 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8157 wq
= ioc
->firmware_event_thread
;
8158 ioc
->firmware_event_thread
= NULL
;
8159 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8161 destroy_workqueue(wq
);
8163 /* release all the volumes */
8164 _scsih_ir_shutdown(ioc
);
8165 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
8167 if (raid_device
->starget
) {
8168 sas_target_priv_data
=
8169 raid_device
->starget
->hostdata
;
8170 sas_target_priv_data
->deleted
= 1;
8171 scsi_remove_target(&raid_device
->starget
->dev
);
8173 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
8174 ioc
->name
, raid_device
->handle
,
8175 (unsigned long long) raid_device
->wwid
);
8176 _scsih_raid_device_remove(ioc
, raid_device
);
8179 /* free ports attached to the sas_host */
8180 list_for_each_entry_safe(mpt3sas_port
, next_port
,
8181 &ioc
->sas_hba
.sas_port_list
, port_list
) {
8182 if (mpt3sas_port
->remote_identify
.device_type
==
8184 mpt3sas_device_remove_by_sas_address(ioc
,
8185 mpt3sas_port
->remote_identify
.sas_address
);
8186 else if (mpt3sas_port
->remote_identify
.device_type
==
8187 SAS_EDGE_EXPANDER_DEVICE
||
8188 mpt3sas_port
->remote_identify
.device_type
==
8189 SAS_FANOUT_EXPANDER_DEVICE
)
8190 mpt3sas_expander_remove(ioc
,
8191 mpt3sas_port
->remote_identify
.sas_address
);
8194 /* free phys attached to the sas_host */
8195 if (ioc
->sas_hba
.num_phys
) {
8196 kfree(ioc
->sas_hba
.phy
);
8197 ioc
->sas_hba
.phy
= NULL
;
8198 ioc
->sas_hba
.num_phys
= 0;
8201 sas_remove_host(shost
);
8202 scsi_remove_host(shost
);
8203 mpt3sas_base_detach(ioc
);
8204 spin_lock(&gioc_lock
);
8205 list_del(&ioc
->list
);
8206 spin_unlock(&gioc_lock
);
8207 scsi_host_put(shost
);
8211 * scsih_shutdown - routine call during system shutdown
8212 * @pdev: PCI device struct
8217 scsih_shutdown(struct pci_dev
*pdev
)
8219 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8220 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8221 struct workqueue_struct
*wq
;
8222 unsigned long flags
;
8224 ioc
->remove_host
= 1;
8225 _scsih_fw_event_cleanup_queue(ioc
);
8227 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8228 wq
= ioc
->firmware_event_thread
;
8229 ioc
->firmware_event_thread
= NULL
;
8230 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8232 destroy_workqueue(wq
);
8234 _scsih_ir_shutdown(ioc
);
8235 mpt3sas_base_detach(ioc
);
8240 * _scsih_probe_boot_devices - reports 1st device
8241 * @ioc: per adapter object
8243 * If specified in bios page 2, this routine reports the 1st
8244 * device scsi-ml or sas transport for persistent boot device
8245 * purposes. Please refer to function _scsih_determine_boot_device()
8248 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
8252 struct _sas_device
*sas_device
;
8253 struct _raid_device
*raid_device
;
8255 u64 sas_address_parent
;
8257 unsigned long flags
;
8260 /* no Bios, return immediately */
8261 if (!ioc
->bios_pg3
.BiosVersion
)
8266 if (ioc
->req_boot_device
.device
) {
8267 device
= ioc
->req_boot_device
.device
;
8268 is_raid
= ioc
->req_boot_device
.is_raid
;
8269 } else if (ioc
->req_alt_boot_device
.device
) {
8270 device
= ioc
->req_alt_boot_device
.device
;
8271 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
8272 } else if (ioc
->current_boot_device
.device
) {
8273 device
= ioc
->current_boot_device
.device
;
8274 is_raid
= ioc
->current_boot_device
.is_raid
;
8281 raid_device
= device
;
8282 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8283 raid_device
->id
, 0);
8285 _scsih_raid_device_remove(ioc
, raid_device
);
8287 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8288 sas_device
= device
;
8289 handle
= sas_device
->handle
;
8290 sas_address_parent
= sas_device
->sas_address_parent
;
8291 sas_address
= sas_device
->sas_address
;
8292 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8293 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8295 if (ioc
->hide_drives
)
8297 if (!mpt3sas_transport_port_add(ioc
, handle
,
8298 sas_address_parent
)) {
8299 _scsih_sas_device_remove(ioc
, sas_device
);
8300 } else if (!sas_device
->starget
) {
8301 if (!ioc
->is_driver_loading
) {
8302 mpt3sas_transport_port_remove(ioc
,
8304 sas_address_parent
);
8305 _scsih_sas_device_remove(ioc
, sas_device
);
8312 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8313 * @ioc: per adapter object
8315 * Called during initial loading of the driver.
8318 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
8320 struct _raid_device
*raid_device
, *raid_next
;
8323 list_for_each_entry_safe(raid_device
, raid_next
,
8324 &ioc
->raid_device_list
, list
) {
8325 if (raid_device
->starget
)
8327 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8328 raid_device
->id
, 0);
8330 _scsih_raid_device_remove(ioc
, raid_device
);
8334 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
8336 struct _sas_device
*sas_device
= NULL
;
8337 unsigned long flags
;
8339 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8340 if (!list_empty(&ioc
->sas_device_init_list
)) {
8341 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
8342 struct _sas_device
, list
);
8343 sas_device_get(sas_device
);
8345 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8350 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
8351 struct _sas_device
*sas_device
)
8353 unsigned long flags
;
8355 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8358 * Since we dropped the lock during the call to port_add(), we need to
8359 * be careful here that somebody else didn't move or delete this item
8360 * while we were busy with other things.
8362 * If it was on the list, we need a put() for the reference the list
8363 * had. Either way, we need a get() for the destination list.
8365 if (!list_empty(&sas_device
->list
)) {
8366 list_del_init(&sas_device
->list
);
8367 sas_device_put(sas_device
);
8370 sas_device_get(sas_device
);
8371 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8373 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8377 * _scsih_probe_sas - reporting sas devices to sas transport
8378 * @ioc: per adapter object
8380 * Called during initial loading of the driver.
8383 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
8385 struct _sas_device
*sas_device
;
8387 if (ioc
->hide_drives
)
8390 while ((sas_device
= get_next_sas_device(ioc
))) {
8391 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
8392 sas_device
->sas_address_parent
)) {
8393 _scsih_sas_device_remove(ioc
, sas_device
);
8394 sas_device_put(sas_device
);
8396 } else if (!sas_device
->starget
) {
8398 * When asyn scanning is enabled, its not possible to
8399 * remove devices while scanning is turned on due to an
8400 * oops in scsi_sysfs_add_sdev()->add_device()->
8401 * sysfs_addrm_start()
8403 if (!ioc
->is_driver_loading
) {
8404 mpt3sas_transport_port_remove(ioc
,
8405 sas_device
->sas_address
,
8406 sas_device
->sas_address_parent
);
8407 _scsih_sas_device_remove(ioc
, sas_device
);
8408 sas_device_put(sas_device
);
8412 sas_device_make_active(ioc
, sas_device
);
8413 sas_device_put(sas_device
);
8418 * _scsih_probe_devices - probing for devices
8419 * @ioc: per adapter object
8421 * Called during initial loading of the driver.
8424 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
8426 u16 volume_mapping_flags
;
8428 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8429 return; /* return when IOC doesn't support initiator mode */
8431 _scsih_probe_boot_devices(ioc
);
8433 if (ioc
->ir_firmware
) {
8434 volume_mapping_flags
=
8435 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8436 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8437 if (volume_mapping_flags
==
8438 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8439 _scsih_probe_raid(ioc
);
8440 _scsih_probe_sas(ioc
);
8442 _scsih_probe_sas(ioc
);
8443 _scsih_probe_raid(ioc
);
8446 _scsih_probe_sas(ioc
);
8450 * scsih_scan_start - scsi lld callback for .scan_start
8451 * @shost: SCSI host pointer
8453 * The shost has the ability to discover targets on its own instead
8454 * of scanning the entire bus. In our implemention, we will kick off
8455 * firmware discovery.
8458 scsih_scan_start(struct Scsi_Host
*shost
)
8460 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8462 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8463 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8465 if (disable_discovery
> 0)
8468 ioc
->start_scan
= 1;
8469 rc
= mpt3sas_port_enable(ioc
);
8472 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
8476 * scsih_scan_finished - scsi lld callback for .scan_finished
8477 * @shost: SCSI host pointer
8478 * @time: elapsed time of the scan in jiffies
8480 * This function will be called periodicallyn until it returns 1 with the
8481 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8482 * we wait for firmware discovery to complete, then return 1.
8485 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8487 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8489 if (disable_discovery
> 0) {
8490 ioc
->is_driver_loading
= 0;
8491 ioc
->wait_for_discovery_to_complete
= 0;
8495 if (time
>= (300 * HZ
)) {
8496 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8498 "port enable: FAILED with timeout (timeout=300s)\n",
8500 ioc
->is_driver_loading
= 0;
8504 if (ioc
->start_scan
)
8507 if (ioc
->start_scan_failed
) {
8509 "port enable: FAILED with (ioc_status=0x%08x)\n",
8510 ioc
->name
, ioc
->start_scan_failed
);
8511 ioc
->is_driver_loading
= 0;
8512 ioc
->wait_for_discovery_to_complete
= 0;
8513 ioc
->remove_host
= 1;
8517 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
8518 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8520 if (ioc
->wait_for_discovery_to_complete
) {
8521 ioc
->wait_for_discovery_to_complete
= 0;
8522 _scsih_probe_devices(ioc
);
8524 mpt3sas_base_start_watchdog(ioc
);
8525 ioc
->is_driver_loading
= 0;
8529 /* shost template for SAS 2.0 HBA devices */
8530 static struct scsi_host_template mpt2sas_driver_template
= {
8531 .module
= THIS_MODULE
,
8532 .name
= "Fusion MPT SAS Host",
8533 .proc_name
= MPT2SAS_DRIVER_NAME
,
8534 .queuecommand
= scsih_qcmd
,
8535 .target_alloc
= scsih_target_alloc
,
8536 .slave_alloc
= scsih_slave_alloc
,
8537 .slave_configure
= scsih_slave_configure
,
8538 .target_destroy
= scsih_target_destroy
,
8539 .slave_destroy
= scsih_slave_destroy
,
8540 .scan_finished
= scsih_scan_finished
,
8541 .scan_start
= scsih_scan_start
,
8542 .change_queue_depth
= scsih_change_queue_depth
,
8543 .eh_abort_handler
= scsih_abort
,
8544 .eh_device_reset_handler
= scsih_dev_reset
,
8545 .eh_target_reset_handler
= scsih_target_reset
,
8546 .eh_host_reset_handler
= scsih_host_reset
,
8547 .bios_param
= scsih_bios_param
,
8550 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
8551 .max_sectors
= 32767,
8553 .use_clustering
= ENABLE_CLUSTERING
,
8554 .shost_attrs
= mpt3sas_host_attrs
,
8555 .sdev_attrs
= mpt3sas_dev_attrs
,
8556 .track_queue_depth
= 1,
8559 /* raid transport support for SAS 2.0 HBA devices */
8560 static struct raid_function_template mpt2sas_raid_functions
= {
8561 .cookie
= &mpt2sas_driver_template
,
8562 .is_raid
= scsih_is_raid
,
8563 .get_resync
= scsih_get_resync
,
8564 .get_state
= scsih_get_state
,
8567 /* shost template for SAS 3.0 HBA devices */
8568 static struct scsi_host_template mpt3sas_driver_template
= {
8569 .module
= THIS_MODULE
,
8570 .name
= "Fusion MPT SAS Host",
8571 .proc_name
= MPT3SAS_DRIVER_NAME
,
8572 .queuecommand
= scsih_qcmd
,
8573 .target_alloc
= scsih_target_alloc
,
8574 .slave_alloc
= scsih_slave_alloc
,
8575 .slave_configure
= scsih_slave_configure
,
8576 .target_destroy
= scsih_target_destroy
,
8577 .slave_destroy
= scsih_slave_destroy
,
8578 .scan_finished
= scsih_scan_finished
,
8579 .scan_start
= scsih_scan_start
,
8580 .change_queue_depth
= scsih_change_queue_depth
,
8581 .eh_abort_handler
= scsih_abort
,
8582 .eh_device_reset_handler
= scsih_dev_reset
,
8583 .eh_target_reset_handler
= scsih_target_reset
,
8584 .eh_host_reset_handler
= scsih_host_reset
,
8585 .bios_param
= scsih_bios_param
,
8588 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
8589 .max_sectors
= 32767,
8591 .use_clustering
= ENABLE_CLUSTERING
,
8592 .shost_attrs
= mpt3sas_host_attrs
,
8593 .sdev_attrs
= mpt3sas_dev_attrs
,
8594 .track_queue_depth
= 1,
8597 /* raid transport support for SAS 3.0 HBA devices */
8598 static struct raid_function_template mpt3sas_raid_functions
= {
8599 .cookie
= &mpt3sas_driver_template
,
8600 .is_raid
= scsih_is_raid
,
8601 .get_resync
= scsih_get_resync
,
8602 .get_state
= scsih_get_state
,
8606 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8607 * this device belongs to.
8608 * @pdev: PCI device struct
8610 * return MPI2_VERSION for SAS 2.0 HBA devices,
8611 * MPI25_VERSION for SAS 3.0 HBA devices, and
8612 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8615 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
8618 switch (pdev
->device
) {
8619 case MPI2_MFGPAGE_DEVID_SSS6200
:
8620 case MPI2_MFGPAGE_DEVID_SAS2004
:
8621 case MPI2_MFGPAGE_DEVID_SAS2008
:
8622 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
8623 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
8624 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
8625 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
8626 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
8627 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
8628 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
8629 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
8630 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
8631 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
8632 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
8633 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
8634 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
8635 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
8636 return MPI2_VERSION
;
8637 case MPI25_MFGPAGE_DEVID_SAS3004
:
8638 case MPI25_MFGPAGE_DEVID_SAS3008
:
8639 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
8640 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
8641 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
8642 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
8643 return MPI25_VERSION
;
8644 case MPI26_MFGPAGE_DEVID_SAS3216
:
8645 case MPI26_MFGPAGE_DEVID_SAS3224
:
8646 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
8647 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
8648 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
8649 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
8650 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
8651 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
8652 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
8653 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
8654 return MPI26_VERSION
;
8660 * _scsih_probe - attach and add scsi host
8661 * @pdev: PCI device struct
8662 * @id: pci device id
8664 * Returns 0 success, anything else error.
8667 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8669 struct MPT3SAS_ADAPTER
*ioc
;
8670 struct Scsi_Host
*shost
= NULL
;
8672 u16 hba_mpi_version
;
8674 /* Determine in which MPI version class this pci device belongs */
8675 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
8676 if (hba_mpi_version
== 0)
8679 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8680 * for other generation HBA's return with -ENODEV
8682 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
8685 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8686 * for other generation HBA's return with -ENODEV
8688 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
8689 || hba_mpi_version
== MPI26_VERSION
)))
8692 switch (hba_mpi_version
) {
8694 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8695 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
8696 sizeof(struct MPT3SAS_ADAPTER
));
8699 ioc
= shost_priv(shost
);
8700 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8701 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8702 ioc
->id
= mpt2_ids
++;
8703 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
8704 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8705 ioc
->is_warpdrive
= 1;
8706 ioc
->hide_ir_msg
= 1;
8708 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8712 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8713 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
8714 sizeof(struct MPT3SAS_ADAPTER
));
8717 ioc
= shost_priv(shost
);
8718 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8719 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8720 ioc
->id
= mpt3_ids
++;
8721 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
8722 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
8723 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
8724 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
))
8725 ioc
->msix96_vector
= 1;
8731 INIT_LIST_HEAD(&ioc
->list
);
8732 spin_lock(&gioc_lock
);
8733 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8734 spin_unlock(&gioc_lock
);
8737 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8738 ioc
->tm_cb_idx
= tm_cb_idx
;
8739 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8740 ioc
->base_cb_idx
= base_cb_idx
;
8741 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8742 ioc
->transport_cb_idx
= transport_cb_idx
;
8743 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8744 ioc
->config_cb_idx
= config_cb_idx
;
8745 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8746 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8747 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8748 ioc
->logging_level
= logging_level
;
8749 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8750 /* misc semaphores and spin locks */
8751 mutex_init(&ioc
->reset_in_progress_mutex
);
8752 /* initializing pci_access_mutex lock */
8753 mutex_init(&ioc
->pci_access_mutex
);
8754 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8755 spin_lock_init(&ioc
->scsi_lookup_lock
);
8756 spin_lock_init(&ioc
->sas_device_lock
);
8757 spin_lock_init(&ioc
->sas_node_lock
);
8758 spin_lock_init(&ioc
->fw_event_lock
);
8759 spin_lock_init(&ioc
->raid_device_lock
);
8760 spin_lock_init(&ioc
->diag_trigger_lock
);
8762 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8763 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8764 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8765 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8766 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8767 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8768 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8769 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
8770 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
8771 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8772 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8774 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
8776 /* init shost parameters */
8777 shost
->max_cmd_len
= 32;
8778 shost
->max_lun
= max_lun
;
8779 shost
->transportt
= mpt3sas_transport_template
;
8780 shost
->unique_id
= ioc
->id
;
8782 if (max_sectors
!= 0xFFFF) {
8783 if (max_sectors
< 64) {
8784 shost
->max_sectors
= 64;
8785 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8786 "for max_sectors, range is 64 to 32767. Assigning "
8787 "value of 64.\n", ioc
->name
, max_sectors
);
8788 } else if (max_sectors
> 32767) {
8789 shost
->max_sectors
= 32767;
8790 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8791 "for max_sectors, range is 64 to 32767. Assigning "
8792 "default value of 32767.\n", ioc
->name
,
8795 shost
->max_sectors
= max_sectors
& 0xFFFE;
8797 "The max_sectors value is set to %d\n",
8798 ioc
->name
, shost
->max_sectors
);
8802 /* register EEDP capabilities with SCSI layer */
8804 scsi_host_set_prot(shost
, prot_mask
);
8806 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8807 | SHOST_DIF_TYPE2_PROTECTION
8808 | SHOST_DIF_TYPE3_PROTECTION
);
8810 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8813 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8814 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
8815 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8816 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8817 if (!ioc
->firmware_event_thread
) {
8818 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8819 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8821 goto out_thread_fail
;
8824 ioc
->is_driver_loading
= 1;
8825 if ((mpt3sas_base_attach(ioc
))) {
8826 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8827 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8829 goto out_attach_fail
;
8832 if (ioc
->is_warpdrive
) {
8833 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8834 ioc
->hide_drives
= 0;
8835 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8836 ioc
->hide_drives
= 1;
8838 if (mpt3sas_get_num_volumes(ioc
))
8839 ioc
->hide_drives
= 1;
8841 ioc
->hide_drives
= 0;
8844 ioc
->hide_drives
= 0;
8846 rv
= scsi_add_host(shost
, &pdev
->dev
);
8848 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8849 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8850 goto out_add_shost_fail
;
8853 scsi_scan_host(shost
);
8856 mpt3sas_base_detach(ioc
);
8858 destroy_workqueue(ioc
->firmware_event_thread
);
8860 spin_lock(&gioc_lock
);
8861 list_del(&ioc
->list
);
8862 spin_unlock(&gioc_lock
);
8863 scsi_host_put(shost
);
8869 * scsih_suspend - power management suspend main entry point
8870 * @pdev: PCI device struct
8871 * @state: PM state change to (usually PCI_D3)
8873 * Returns 0 success, anything else error.
8876 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8878 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8879 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8880 pci_power_t device_state
;
8882 mpt3sas_base_stop_watchdog(ioc
);
8883 flush_scheduled_work();
8884 scsi_block_requests(shost
);
8885 device_state
= pci_choose_state(pdev
, state
);
8887 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8888 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8890 pci_save_state(pdev
);
8891 mpt3sas_base_free_resources(ioc
);
8892 pci_set_power_state(pdev
, device_state
);
8897 * scsih_resume - power management resume main entry point
8898 * @pdev: PCI device struct
8900 * Returns 0 success, anything else error.
8903 scsih_resume(struct pci_dev
*pdev
)
8905 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8906 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8907 pci_power_t device_state
= pdev
->current_state
;
8911 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8912 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8914 pci_set_power_state(pdev
, PCI_D0
);
8915 pci_enable_wake(pdev
, PCI_D0
, 0);
8916 pci_restore_state(pdev
);
8918 r
= mpt3sas_base_map_resources(ioc
);
8922 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
8923 scsi_unblock_requests(shost
);
8924 mpt3sas_base_start_watchdog(ioc
);
8927 #endif /* CONFIG_PM */
8930 * scsih_pci_error_detected - Called when a PCI error is detected.
8931 * @pdev: PCI device struct
8932 * @state: PCI channel state
8934 * Description: Called when a PCI error is detected.
8937 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8939 static pci_ers_result_t
8940 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8942 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8943 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8945 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
8949 case pci_channel_io_normal
:
8950 return PCI_ERS_RESULT_CAN_RECOVER
;
8951 case pci_channel_io_frozen
:
8952 /* Fatal error, prepare for slot reset */
8953 ioc
->pci_error_recovery
= 1;
8954 scsi_block_requests(ioc
->shost
);
8955 mpt3sas_base_stop_watchdog(ioc
);
8956 mpt3sas_base_free_resources(ioc
);
8957 return PCI_ERS_RESULT_NEED_RESET
;
8958 case pci_channel_io_perm_failure
:
8959 /* Permanent error, prepare for device removal */
8960 ioc
->pci_error_recovery
= 1;
8961 mpt3sas_base_stop_watchdog(ioc
);
8962 _scsih_flush_running_cmds(ioc
);
8963 return PCI_ERS_RESULT_DISCONNECT
;
8965 return PCI_ERS_RESULT_NEED_RESET
;
8969 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8970 * @pdev: PCI device struct
8972 * Description: This routine is called by the pci error recovery
8973 * code after the PCI slot has been reset, just before we
8974 * should resume normal operations.
8976 static pci_ers_result_t
8977 scsih_pci_slot_reset(struct pci_dev
*pdev
)
8979 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8980 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8983 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
8986 ioc
->pci_error_recovery
= 0;
8988 pci_restore_state(pdev
);
8989 rc
= mpt3sas_base_map_resources(ioc
);
8991 return PCI_ERS_RESULT_DISCONNECT
;
8993 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
8995 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
8996 (rc
== 0) ? "success" : "failed");
8999 return PCI_ERS_RESULT_RECOVERED
;
9001 return PCI_ERS_RESULT_DISCONNECT
;
9005 * scsih_pci_resume() - resume normal ops after PCI reset
9006 * @pdev: pointer to PCI device
9008 * Called when the error recovery driver tells us that its
9009 * OK to resume normal operation. Use completion to allow
9010 * halted scsi ops to resume.
9013 scsih_pci_resume(struct pci_dev
*pdev
)
9015 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9016 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9018 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
9020 pci_cleanup_aer_uncorrect_error_status(pdev
);
9021 mpt3sas_base_start_watchdog(ioc
);
9022 scsi_unblock_requests(ioc
->shost
);
9026 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
9027 * @pdev: pointer to PCI device
9029 static pci_ers_result_t
9030 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
9032 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9033 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9035 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
9038 /* TODO - dump whatever for debugging purposes */
9040 /* This called only if scsih_pci_error_detected returns
9041 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
9042 * works, no need to reset slot.
9044 return PCI_ERS_RESULT_RECOVERED
;
9048 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9050 static const struct pci_device_id mpt3sas_pci_table
[] = {
9051 /* Spitfire ~ 2004 */
9052 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
9053 PCI_ANY_ID
, PCI_ANY_ID
},
9055 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
9056 PCI_ANY_ID
, PCI_ANY_ID
},
9057 /* Liberator ~ 2108 */
9058 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
9059 PCI_ANY_ID
, PCI_ANY_ID
},
9060 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
9061 PCI_ANY_ID
, PCI_ANY_ID
},
9062 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
9063 PCI_ANY_ID
, PCI_ANY_ID
},
9065 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
9066 PCI_ANY_ID
, PCI_ANY_ID
},
9067 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
9068 PCI_ANY_ID
, PCI_ANY_ID
},
9069 /* Thunderbolt ~ 2208 */
9070 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
9071 PCI_ANY_ID
, PCI_ANY_ID
},
9072 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
9073 PCI_ANY_ID
, PCI_ANY_ID
},
9074 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
9075 PCI_ANY_ID
, PCI_ANY_ID
},
9076 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
9077 PCI_ANY_ID
, PCI_ANY_ID
},
9078 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
9079 PCI_ANY_ID
, PCI_ANY_ID
},
9080 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
9081 PCI_ANY_ID
, PCI_ANY_ID
},
9082 /* Mustang ~ 2308 */
9083 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
9084 PCI_ANY_ID
, PCI_ANY_ID
},
9085 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
9086 PCI_ANY_ID
, PCI_ANY_ID
},
9087 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
9088 PCI_ANY_ID
, PCI_ANY_ID
},
9090 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
9091 PCI_ANY_ID
, PCI_ANY_ID
},
9092 /* Fury ~ 3004 and 3008 */
9093 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
9094 PCI_ANY_ID
, PCI_ANY_ID
},
9095 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
9096 PCI_ANY_ID
, PCI_ANY_ID
},
9097 /* Invader ~ 3108 */
9098 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
9099 PCI_ANY_ID
, PCI_ANY_ID
},
9100 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
9101 PCI_ANY_ID
, PCI_ANY_ID
},
9102 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
9103 PCI_ANY_ID
, PCI_ANY_ID
},
9104 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
9105 PCI_ANY_ID
, PCI_ANY_ID
},
9106 /* Cutlass ~ 3216 and 3224 */
9107 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
9108 PCI_ANY_ID
, PCI_ANY_ID
},
9109 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
9110 PCI_ANY_ID
, PCI_ANY_ID
},
9111 /* Intruder ~ 3316 and 3324 */
9112 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
9113 PCI_ANY_ID
, PCI_ANY_ID
},
9114 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
9115 PCI_ANY_ID
, PCI_ANY_ID
},
9116 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
9117 PCI_ANY_ID
, PCI_ANY_ID
},
9118 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
9119 PCI_ANY_ID
, PCI_ANY_ID
},
9120 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
9121 PCI_ANY_ID
, PCI_ANY_ID
},
9122 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
9123 PCI_ANY_ID
, PCI_ANY_ID
},
9124 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
9125 PCI_ANY_ID
, PCI_ANY_ID
},
9126 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
9127 PCI_ANY_ID
, PCI_ANY_ID
},
9128 {0} /* Terminating entry */
9130 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
9132 static struct pci_error_handlers _mpt3sas_err_handler
= {
9133 .error_detected
= scsih_pci_error_detected
,
9134 .mmio_enabled
= scsih_pci_mmio_enabled
,
9135 .slot_reset
= scsih_pci_slot_reset
,
9136 .resume
= scsih_pci_resume
,
9139 static struct pci_driver mpt3sas_driver
= {
9140 .name
= MPT3SAS_DRIVER_NAME
,
9141 .id_table
= mpt3sas_pci_table
,
9142 .probe
= _scsih_probe
,
9143 .remove
= scsih_remove
,
9144 .shutdown
= scsih_shutdown
,
9145 .err_handler
= &_mpt3sas_err_handler
,
9147 .suspend
= scsih_suspend
,
9148 .resume
= scsih_resume
,
9153 * scsih_init - main entry point for this driver.
9155 * Returns 0 success, anything else error.
9163 mpt3sas_base_initialize_callback_handler();
9165 /* queuecommand callback hander */
9166 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
9168 /* task managment callback handler */
9169 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
9171 /* base internal commands callback handler */
9172 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
9173 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
9174 mpt3sas_port_enable_done
);
9176 /* transport internal commands callback handler */
9177 transport_cb_idx
= mpt3sas_base_register_callback_handler(
9178 mpt3sas_transport_done
);
9180 /* scsih internal commands callback handler */
9181 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
9183 /* configuration page API internal commands callback handler */
9184 config_cb_idx
= mpt3sas_base_register_callback_handler(
9185 mpt3sas_config_done
);
9187 /* ctl module callback handler */
9188 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
9190 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
9191 _scsih_tm_tr_complete
);
9193 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
9194 _scsih_tm_volume_tr_complete
);
9196 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
9197 _scsih_sas_control_complete
);
9203 * scsih_exit - exit point for this driver (when it is a module).
9205 * Returns 0 success, anything else error.
9211 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
9212 mpt3sas_base_release_callback_handler(tm_cb_idx
);
9213 mpt3sas_base_release_callback_handler(base_cb_idx
);
9214 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
9215 mpt3sas_base_release_callback_handler(transport_cb_idx
);
9216 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
9217 mpt3sas_base_release_callback_handler(config_cb_idx
);
9218 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
9220 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
9221 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
9222 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
9224 /* raid transport support */
9225 if (hbas_to_enumerate
!= 1)
9226 raid_class_release(mpt3sas_raid_template
);
9227 if (hbas_to_enumerate
!= 2)
9228 raid_class_release(mpt2sas_raid_template
);
9229 sas_release_transport(mpt3sas_transport_template
);
9233 * _mpt3sas_init - main entry point for this driver.
9235 * Returns 0 success, anything else error.
9242 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
9243 MPT3SAS_DRIVER_VERSION
);
9245 mpt3sas_transport_template
=
9246 sas_attach_transport(&mpt3sas_transport_functions
);
9247 if (!mpt3sas_transport_template
)
9250 /* No need attach mpt3sas raid functions template
9251 * if hbas_to_enumarate value is one.
9253 if (hbas_to_enumerate
!= 1) {
9254 mpt3sas_raid_template
=
9255 raid_class_attach(&mpt3sas_raid_functions
);
9256 if (!mpt3sas_raid_template
) {
9257 sas_release_transport(mpt3sas_transport_template
);
9262 /* No need to attach mpt2sas raid functions template
9263 * if hbas_to_enumarate value is two
9265 if (hbas_to_enumerate
!= 2) {
9266 mpt2sas_raid_template
=
9267 raid_class_attach(&mpt2sas_raid_functions
);
9268 if (!mpt2sas_raid_template
) {
9269 sas_release_transport(mpt3sas_transport_template
);
9274 error
= scsih_init();
9280 mpt3sas_ctl_init(hbas_to_enumerate
);
9282 error
= pci_register_driver(&mpt3sas_driver
);
9290 * _mpt3sas_exit - exit point for this driver (when it is a module).
9296 pr_info("mpt3sas version %s unloading\n",
9297 MPT3SAS_DRIVER_VERSION
);
9299 pci_unregister_driver(&mpt3sas_driver
);
9301 mpt3sas_ctl_exit(hbas_to_enumerate
);
9306 module_init(_mpt3sas_init
);
9307 module_exit(_mpt3sas_exit
);