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 because 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 (ioc
->hide_drives
) {
792 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
796 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
797 sas_device
->sas_address_parent
)) {
798 _scsih_sas_device_remove(ioc
, sas_device
);
799 } else if (!sas_device
->starget
) {
801 * When asyn scanning is enabled, its not possible to remove
802 * devices while scanning is turned on due to an oops in
803 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
805 if (!ioc
->is_driver_loading
) {
806 mpt3sas_transport_port_remove(ioc
,
807 sas_device
->sas_address
,
808 sas_device
->sas_address_parent
);
809 _scsih_sas_device_remove(ioc
, sas_device
);
812 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
816 * _scsih_sas_device_init_add - insert sas_device to the list.
817 * @ioc: per adapter object
818 * @sas_device: the sas_device object
819 * Context: This function will acquire ioc->sas_device_lock.
821 * Adding new object at driver load time to the ioc->sas_device_init_list.
824 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
825 struct _sas_device
*sas_device
)
829 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
830 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
831 __func__
, sas_device
->handle
,
832 (unsigned long long)sas_device
->sas_address
));
834 if (sas_device
->enclosure_handle
!= 0)
835 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
836 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
837 ioc
->name
, __func__
, (unsigned long long)
838 sas_device
->enclosure_logical_id
, sas_device
->slot
));
840 if (sas_device
->connector_name
[0] != '\0')
841 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
842 "%s: enclosure level(0x%04x), connector name( %s)\n",
843 ioc
->name
, __func__
, sas_device
->enclosure_level
,
844 sas_device
->connector_name
));
846 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
847 sas_device_get(sas_device
);
848 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
849 _scsih_determine_boot_device(ioc
, sas_device
, 0);
850 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
854 * _scsih_raid_device_find_by_id - raid device search
855 * @ioc: per adapter object
856 * @id: sas device target id
857 * @channel: sas device channel
858 * Context: Calling function should acquire ioc->raid_device_lock
860 * This searches for raid_device based on target id, then return raid_device
863 static struct _raid_device
*
864 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
866 struct _raid_device
*raid_device
, *r
;
869 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
870 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
881 * mpt3sas_raid_device_find_by_handle - raid device search
882 * @ioc: per adapter object
883 * @handle: sas device handle (assigned by firmware)
884 * Context: Calling function should acquire ioc->raid_device_lock
886 * This searches for raid_device based on handle, then return raid_device
889 struct _raid_device
*
890 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
892 struct _raid_device
*raid_device
, *r
;
895 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
896 if (raid_device
->handle
!= handle
)
907 * _scsih_raid_device_find_by_wwid - raid device search
908 * @ioc: per adapter object
909 * @handle: sas device handle (assigned by firmware)
910 * Context: Calling function should acquire ioc->raid_device_lock
912 * This searches for raid_device based on wwid, then return raid_device
915 static struct _raid_device
*
916 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
918 struct _raid_device
*raid_device
, *r
;
921 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
922 if (raid_device
->wwid
!= wwid
)
933 * _scsih_raid_device_add - add raid_device object
934 * @ioc: per adapter object
935 * @raid_device: raid_device object
937 * This is added to the raid_device_list link list.
940 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
941 struct _raid_device
*raid_device
)
945 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
946 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
947 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
949 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
950 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
951 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
955 * _scsih_raid_device_remove - delete raid_device object
956 * @ioc: per adapter object
957 * @raid_device: raid_device object
961 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
962 struct _raid_device
*raid_device
)
966 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
967 list_del(&raid_device
->list
);
969 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
973 * mpt3sas_scsih_expander_find_by_handle - expander device search
974 * @ioc: per adapter object
975 * @handle: expander handle (assigned by firmware)
976 * Context: Calling function should acquire ioc->sas_device_lock
978 * This searches for expander device based on handle, then returns the
982 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
984 struct _sas_node
*sas_expander
, *r
;
987 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
988 if (sas_expander
->handle
!= handle
)
998 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
999 * @ioc: per adapter object
1000 * @sas_address: sas address
1001 * Context: Calling function should acquire ioc->sas_node_lock.
1003 * This searches for expander device based on sas_address, then returns the
1007 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1010 struct _sas_node
*sas_expander
, *r
;
1013 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1014 if (sas_expander
->sas_address
!= sas_address
)
1024 * _scsih_expander_node_add - insert expander device to the list.
1025 * @ioc: per adapter object
1026 * @sas_expander: the sas_device object
1027 * Context: This function will acquire ioc->sas_node_lock.
1029 * Adding new object to the ioc->sas_expander_list.
1034 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1035 struct _sas_node
*sas_expander
)
1037 unsigned long flags
;
1039 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1040 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1041 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1045 * _scsih_is_end_device - determines if device is an end device
1046 * @device_info: bitfield providing information about the device.
1049 * Returns 1 if end device.
1052 _scsih_is_end_device(u32 device_info
)
1054 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1055 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1056 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1057 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1064 * _scsih_scsi_lookup_get - returns scmd entry
1065 * @ioc: per adapter object
1066 * @smid: system request message index
1068 * Returns the smid stored scmd pointer.
1070 static struct scsi_cmnd
*
1071 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1073 return ioc
->scsi_lookup
[smid
- 1].scmd
;
1077 * __scsih_scsi_lookup_get_clear - returns scmd entry without
1079 * @ioc: per adapter object
1080 * @smid: system request message index
1082 * Returns the smid stored scmd pointer.
1083 * Then will dereference the stored scmd pointer.
1085 static inline struct scsi_cmnd
*
1086 __scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
,
1089 struct scsi_cmnd
*scmd
= NULL
;
1091 swap(scmd
, ioc
->scsi_lookup
[smid
- 1].scmd
);
1097 * _scsih_scsi_lookup_get_clear - returns scmd entry
1098 * @ioc: per adapter object
1099 * @smid: system request message index
1101 * Returns the smid stored scmd pointer.
1102 * Then will derefrence the stored scmd pointer.
1104 static inline struct scsi_cmnd
*
1105 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1107 unsigned long flags
;
1108 struct scsi_cmnd
*scmd
;
1110 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1111 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
1112 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1118 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1119 * @ioc: per adapter object
1120 * @smid: system request message index
1121 * @scmd: pointer to scsi command object
1122 * Context: This function will acquire ioc->scsi_lookup_lock.
1124 * This will search for a scmd pointer in the scsi_lookup array,
1125 * returning the revelent smid. A returned value of zero means invalid.
1128 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1132 unsigned long flags
;
1135 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1137 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1138 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1139 smid
= ioc
->scsi_lookup
[i
].smid
;
1144 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1149 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1150 * @ioc: per adapter object
1153 * Context: This function will acquire ioc->scsi_lookup_lock.
1155 * This will search for a matching channel:id in the scsi_lookup array,
1156 * returning 1 if found.
1159 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1163 unsigned long flags
;
1166 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1168 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1169 if (ioc
->scsi_lookup
[i
].scmd
&&
1170 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1171 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1177 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1182 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1183 * @ioc: per adapter object
1187 * Context: This function will acquire ioc->scsi_lookup_lock.
1189 * This will search for a matching channel:id:lun in the scsi_lookup array,
1190 * returning 1 if found.
1193 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1194 unsigned int lun
, int channel
)
1197 unsigned long flags
;
1200 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1202 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1203 if (ioc
->scsi_lookup
[i
].scmd
&&
1204 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1205 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1206 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1212 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1217 * scsih_change_queue_depth - setting device queue depth
1218 * @sdev: scsi device struct
1219 * @qdepth: requested queue depth
1221 * Returns queue depth.
1224 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1226 struct Scsi_Host
*shost
= sdev
->host
;
1228 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1229 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1230 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1231 struct _sas_device
*sas_device
;
1232 unsigned long flags
;
1234 max_depth
= shost
->can_queue
;
1236 /* limit max device queue for SATA to 32 */
1237 sas_device_priv_data
= sdev
->hostdata
;
1238 if (!sas_device_priv_data
)
1240 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1241 if (!sas_target_priv_data
)
1243 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1246 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1247 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1249 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1250 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1252 sas_device_put(sas_device
);
1254 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1258 if (!sdev
->tagged_supported
)
1260 if (qdepth
> max_depth
)
1262 return scsi_change_queue_depth(sdev
, qdepth
);
1266 * scsih_target_alloc - target add routine
1267 * @starget: scsi target struct
1269 * Returns 0 if ok. Any other return is assumed to be an error and
1270 * the device is ignored.
1273 scsih_target_alloc(struct scsi_target
*starget
)
1275 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1276 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1277 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1278 struct _sas_device
*sas_device
;
1279 struct _raid_device
*raid_device
;
1280 unsigned long flags
;
1281 struct sas_rphy
*rphy
;
1283 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1285 if (!sas_target_priv_data
)
1288 starget
->hostdata
= sas_target_priv_data
;
1289 sas_target_priv_data
->starget
= starget
;
1290 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1293 if (starget
->channel
== RAID_CHANNEL
) {
1294 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1295 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1298 sas_target_priv_data
->handle
= raid_device
->handle
;
1299 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1300 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1301 if (ioc
->is_warpdrive
)
1302 sas_target_priv_data
->raid_device
= raid_device
;
1303 raid_device
->starget
= starget
;
1305 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1309 /* sas/sata devices */
1310 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1311 rphy
= dev_to_rphy(starget
->dev
.parent
);
1312 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1313 rphy
->identify
.sas_address
);
1316 sas_target_priv_data
->handle
= sas_device
->handle
;
1317 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1318 sas_target_priv_data
->sdev
= sas_device
;
1319 sas_device
->starget
= starget
;
1320 sas_device
->id
= starget
->id
;
1321 sas_device
->channel
= starget
->channel
;
1322 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1323 sas_target_priv_data
->flags
|=
1324 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1325 if (sas_device
->fast_path
)
1326 sas_target_priv_data
->flags
|= MPT_TARGET_FASTPATH_IO
;
1328 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1334 * scsih_target_destroy - target destroy routine
1335 * @starget: scsi target struct
1340 scsih_target_destroy(struct scsi_target
*starget
)
1342 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1343 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1344 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1345 struct _sas_device
*sas_device
;
1346 struct _raid_device
*raid_device
;
1347 unsigned long flags
;
1349 sas_target_priv_data
= starget
->hostdata
;
1350 if (!sas_target_priv_data
)
1353 if (starget
->channel
== RAID_CHANNEL
) {
1354 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1355 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1358 raid_device
->starget
= NULL
;
1359 raid_device
->sdev
= NULL
;
1361 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1365 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1366 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1367 if (sas_device
&& (sas_device
->starget
== starget
) &&
1368 (sas_device
->id
== starget
->id
) &&
1369 (sas_device
->channel
== starget
->channel
))
1370 sas_device
->starget
= NULL
;
1374 * Corresponding get() is in _scsih_target_alloc()
1376 sas_target_priv_data
->sdev
= NULL
;
1377 sas_device_put(sas_device
);
1379 sas_device_put(sas_device
);
1381 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1384 kfree(sas_target_priv_data
);
1385 starget
->hostdata
= NULL
;
1389 * scsih_slave_alloc - device add routine
1390 * @sdev: scsi device struct
1392 * Returns 0 if ok. Any other return is assumed to be an error and
1393 * the device is ignored.
1396 scsih_slave_alloc(struct scsi_device
*sdev
)
1398 struct Scsi_Host
*shost
;
1399 struct MPT3SAS_ADAPTER
*ioc
;
1400 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1401 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1402 struct scsi_target
*starget
;
1403 struct _raid_device
*raid_device
;
1404 struct _sas_device
*sas_device
;
1405 unsigned long flags
;
1407 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1409 if (!sas_device_priv_data
)
1412 sas_device_priv_data
->lun
= sdev
->lun
;
1413 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1415 starget
= scsi_target(sdev
);
1416 sas_target_priv_data
= starget
->hostdata
;
1417 sas_target_priv_data
->num_luns
++;
1418 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1419 sdev
->hostdata
= sas_device_priv_data
;
1420 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1421 sdev
->no_uld_attach
= 1;
1423 shost
= dev_to_shost(&starget
->dev
);
1424 ioc
= shost_priv(shost
);
1425 if (starget
->channel
== RAID_CHANNEL
) {
1426 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1427 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1428 starget
->id
, starget
->channel
);
1430 raid_device
->sdev
= sdev
; /* raid is single lun */
1431 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1434 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1435 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1436 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1437 sas_target_priv_data
->sas_address
);
1438 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1439 sdev_printk(KERN_INFO
, sdev
,
1440 "%s : sas_device->starget set to starget @ %d\n",
1441 __func__
, __LINE__
);
1442 sas_device
->starget
= starget
;
1446 sas_device_put(sas_device
);
1448 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1455 * scsih_slave_destroy - device destroy routine
1456 * @sdev: scsi device struct
1461 scsih_slave_destroy(struct scsi_device
*sdev
)
1463 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1464 struct scsi_target
*starget
;
1465 struct Scsi_Host
*shost
;
1466 struct MPT3SAS_ADAPTER
*ioc
;
1467 struct _sas_device
*sas_device
;
1468 unsigned long flags
;
1470 if (!sdev
->hostdata
)
1473 starget
= scsi_target(sdev
);
1474 sas_target_priv_data
= starget
->hostdata
;
1475 sas_target_priv_data
->num_luns
--;
1477 shost
= dev_to_shost(&starget
->dev
);
1478 ioc
= shost_priv(shost
);
1480 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1481 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1482 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1483 sas_target_priv_data
);
1484 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1485 sas_device
->starget
= NULL
;
1488 sas_device_put(sas_device
);
1489 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1492 kfree(sdev
->hostdata
);
1493 sdev
->hostdata
= NULL
;
1497 * _scsih_display_sata_capabilities - sata capabilities
1498 * @ioc: per adapter object
1499 * @handle: device handle
1500 * @sdev: scsi device struct
1503 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1504 u16 handle
, struct scsi_device
*sdev
)
1506 Mpi2ConfigReply_t mpi_reply
;
1507 Mpi2SasDevicePage0_t sas_device_pg0
;
1512 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1513 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1514 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1515 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1519 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1520 MPI2_IOCSTATUS_MASK
;
1521 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1522 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1523 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1527 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1528 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1530 sdev_printk(KERN_INFO
, sdev
,
1531 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1532 "sw_preserve(%s)\n",
1533 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1534 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1535 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1537 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1538 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1539 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1543 * raid transport support -
1544 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1545 * unloading the driver followed by a load - I believe that the subroutine
1546 * raid_class_release() is not cleaning up properly.
1550 * scsih_is_raid - return boolean indicating device is raid volume
1551 * @dev the device struct object
1554 scsih_is_raid(struct device
*dev
)
1556 struct scsi_device
*sdev
= to_scsi_device(dev
);
1557 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1559 if (ioc
->is_warpdrive
)
1561 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1565 * scsih_get_resync - get raid volume resync percent complete
1566 * @dev the device struct object
1569 scsih_get_resync(struct device
*dev
)
1571 struct scsi_device
*sdev
= to_scsi_device(dev
);
1572 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1573 static struct _raid_device
*raid_device
;
1574 unsigned long flags
;
1575 Mpi2RaidVolPage0_t vol_pg0
;
1576 Mpi2ConfigReply_t mpi_reply
;
1577 u32 volume_status_flags
;
1578 u8 percent_complete
;
1581 percent_complete
= 0;
1583 if (ioc
->is_warpdrive
)
1586 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1587 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1590 handle
= raid_device
->handle
;
1591 percent_complete
= raid_device
->percent_complete
;
1593 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1598 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1599 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1600 sizeof(Mpi2RaidVolPage0_t
))) {
1601 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1602 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1603 percent_complete
= 0;
1607 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1608 if (!(volume_status_flags
&
1609 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1610 percent_complete
= 0;
1614 switch (ioc
->hba_mpi_version_belonged
) {
1616 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1620 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1626 * scsih_get_state - get raid volume level
1627 * @dev the device struct object
1630 scsih_get_state(struct device
*dev
)
1632 struct scsi_device
*sdev
= to_scsi_device(dev
);
1633 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1634 static struct _raid_device
*raid_device
;
1635 unsigned long flags
;
1636 Mpi2RaidVolPage0_t vol_pg0
;
1637 Mpi2ConfigReply_t mpi_reply
;
1639 enum raid_state state
= RAID_STATE_UNKNOWN
;
1642 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1643 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1646 handle
= raid_device
->handle
;
1647 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1652 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1653 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1654 sizeof(Mpi2RaidVolPage0_t
))) {
1655 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1656 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1660 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1661 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1662 state
= RAID_STATE_RESYNCING
;
1666 switch (vol_pg0
.VolumeState
) {
1667 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1668 case MPI2_RAID_VOL_STATE_ONLINE
:
1669 state
= RAID_STATE_ACTIVE
;
1671 case MPI2_RAID_VOL_STATE_DEGRADED
:
1672 state
= RAID_STATE_DEGRADED
;
1674 case MPI2_RAID_VOL_STATE_FAILED
:
1675 case MPI2_RAID_VOL_STATE_MISSING
:
1676 state
= RAID_STATE_OFFLINE
;
1680 switch (ioc
->hba_mpi_version_belonged
) {
1682 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1686 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1692 * _scsih_set_level - set raid level
1693 * @sdev: scsi device struct
1694 * @volume_type: volume type
1697 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
1698 struct scsi_device
*sdev
, u8 volume_type
)
1700 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1702 switch (volume_type
) {
1703 case MPI2_RAID_VOL_TYPE_RAID0
:
1704 level
= RAID_LEVEL_0
;
1706 case MPI2_RAID_VOL_TYPE_RAID10
:
1707 level
= RAID_LEVEL_10
;
1709 case MPI2_RAID_VOL_TYPE_RAID1E
:
1710 level
= RAID_LEVEL_1E
;
1712 case MPI2_RAID_VOL_TYPE_RAID1
:
1713 level
= RAID_LEVEL_1
;
1717 switch (ioc
->hba_mpi_version_belonged
) {
1719 raid_set_level(mpt2sas_raid_template
,
1720 &sdev
->sdev_gendev
, level
);
1724 raid_set_level(mpt3sas_raid_template
,
1725 &sdev
->sdev_gendev
, level
);
1732 * _scsih_get_volume_capabilities - volume capabilities
1733 * @ioc: per adapter object
1734 * @sas_device: the raid_device object
1736 * Returns 0 for success, else 1
1739 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1740 struct _raid_device
*raid_device
)
1742 Mpi2RaidVolPage0_t
*vol_pg0
;
1743 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1744 Mpi2SasDevicePage0_t sas_device_pg0
;
1745 Mpi2ConfigReply_t mpi_reply
;
1749 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1750 &num_pds
)) || !num_pds
) {
1751 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1752 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1757 raid_device
->num_pds
= num_pds
;
1758 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1759 sizeof(Mpi2RaidVol0PhysDisk_t
));
1760 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1762 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1763 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1768 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1769 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1770 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1771 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1777 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1779 /* figure out what the underlying devices are by
1780 * obtaining the device_info bits for the 1st device
1782 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1783 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1784 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1785 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1786 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1787 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1788 raid_device
->device_info
=
1789 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1798 * _scsih_enable_tlr - setting TLR flags
1799 * @ioc: per adapter object
1800 * @sdev: scsi device struct
1802 * Enabling Transaction Layer Retries for tape devices when
1803 * vpd page 0x90 is present
1807 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1811 if (sdev
->type
!= TYPE_TAPE
)
1814 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1817 sas_enable_tlr(sdev
);
1818 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1819 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1825 * scsih_slave_configure - device configure routine.
1826 * @sdev: scsi device struct
1828 * Returns 0 if ok. Any other return is assumed to be an error and
1829 * the device is ignored.
1832 scsih_slave_configure(struct scsi_device
*sdev
)
1834 struct Scsi_Host
*shost
= sdev
->host
;
1835 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1836 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1837 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1838 struct _sas_device
*sas_device
;
1839 struct _raid_device
*raid_device
;
1840 unsigned long flags
;
1845 u16 handle
, volume_handle
= 0;
1846 u64 volume_wwid
= 0;
1849 sas_device_priv_data
= sdev
->hostdata
;
1850 sas_device_priv_data
->configured_lun
= 1;
1851 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1852 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1853 handle
= sas_target_priv_data
->handle
;
1855 /* raid volume handling */
1856 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1858 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1859 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
1860 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1862 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1863 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1864 __LINE__
, __func__
));
1868 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1869 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1870 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1871 __LINE__
, __func__
));
1876 * WARPDRIVE: Initialize the required data for Direct IO
1878 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
1880 /* RAID Queue Depth Support
1881 * IS volume = underlying qdepth of drive type, either
1882 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1883 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1885 if (raid_device
->device_info
&
1886 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1887 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1890 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1891 if (raid_device
->device_info
&
1892 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1898 switch (raid_device
->volume_type
) {
1899 case MPI2_RAID_VOL_TYPE_RAID0
:
1902 case MPI2_RAID_VOL_TYPE_RAID1E
:
1903 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1904 if (ioc
->manu_pg10
.OEMIdentifier
&&
1905 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1906 MFG10_GF0_R10_DISPLAY
) &&
1907 !(raid_device
->num_pds
% 2))
1912 case MPI2_RAID_VOL_TYPE_RAID1
:
1913 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1916 case MPI2_RAID_VOL_TYPE_RAID10
:
1917 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1920 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1922 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1927 if (!ioc
->hide_ir_msg
)
1928 sdev_printk(KERN_INFO
, sdev
,
1929 "%s: handle(0x%04x), wwid(0x%016llx),"
1930 " pd_count(%d), type(%s)\n",
1931 r_level
, raid_device
->handle
,
1932 (unsigned long long)raid_device
->wwid
,
1933 raid_device
->num_pds
, ds
);
1935 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
1936 blk_queue_max_hw_sectors(sdev
->request_queue
,
1937 MPT3SAS_RAID_MAX_SECTORS
);
1938 sdev_printk(KERN_INFO
, sdev
,
1939 "Set queue's max_sector to: %u\n",
1940 MPT3SAS_RAID_MAX_SECTORS
);
1943 scsih_change_queue_depth(sdev
, qdepth
);
1945 /* raid transport support */
1946 if (!ioc
->is_warpdrive
)
1947 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
1951 /* non-raid handling */
1952 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1953 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1955 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1956 "failure at %s:%d/%s()!\n", ioc
->name
,
1957 __FILE__
, __LINE__
, __func__
));
1960 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1961 volume_handle
, &volume_wwid
)) {
1962 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1963 "failure at %s:%d/%s()!\n", ioc
->name
,
1964 __FILE__
, __LINE__
, __func__
));
1969 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1970 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1971 sas_device_priv_data
->sas_target
->sas_address
);
1973 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1974 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1975 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1980 sas_device
->volume_handle
= volume_handle
;
1981 sas_device
->volume_wwid
= volume_wwid
;
1982 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1983 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1985 if (sas_device
->device_info
&
1986 MPI2_SAS_DEVICE_INFO_SEP
) {
1987 sdev_printk(KERN_WARNING
, sdev
,
1988 "set ignore_delay_remove for handle(0x%04x)\n",
1989 sas_device_priv_data
->sas_target
->handle
);
1990 sas_device_priv_data
->ignore_delay_remove
= 1;
1995 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1996 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1998 else if (sas_device
->device_info
&
1999 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2003 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2004 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2005 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2006 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2007 if (sas_device
->enclosure_handle
!= 0)
2008 sdev_printk(KERN_INFO
, sdev
,
2009 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
2010 ds
, (unsigned long long)
2011 sas_device
->enclosure_logical_id
, sas_device
->slot
);
2012 if (sas_device
->connector_name
[0] != '\0')
2013 sdev_printk(KERN_INFO
, sdev
,
2014 "%s: enclosure level(0x%04x), connector name( %s)\n",
2015 ds
, sas_device
->enclosure_level
,
2016 sas_device
->connector_name
);
2018 sas_device_put(sas_device
);
2019 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2022 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2025 scsih_change_queue_depth(sdev
, qdepth
);
2028 sas_read_port_mode_page(sdev
);
2029 _scsih_enable_tlr(ioc
, sdev
);
2036 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2037 * @sdev: scsi device struct
2038 * @bdev: pointer to block device context
2039 * @capacity: device size (in 512 byte sectors)
2040 * @params: three element array to place output:
2041 * params[0] number of heads (max 255)
2042 * params[1] number of sectors (max 63)
2043 * params[2] number of cylinders
2048 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2049 sector_t capacity
, int params
[])
2059 dummy
= heads
* sectors
;
2060 cylinders
= capacity
;
2061 sector_div(cylinders
, dummy
);
2064 * Handle extended translation size for logical drives
2067 if ((ulong
)capacity
>= 0x200000) {
2070 dummy
= heads
* sectors
;
2071 cylinders
= capacity
;
2072 sector_div(cylinders
, dummy
);
2077 params
[1] = sectors
;
2078 params
[2] = cylinders
;
2084 * _scsih_response_code - translation of device response code
2085 * @ioc: per adapter object
2086 * @response_code: response code returned by the device
2091 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2095 switch (response_code
) {
2096 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2097 desc
= "task management request completed";
2099 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2100 desc
= "invalid frame";
2102 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2103 desc
= "task management request not supported";
2105 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2106 desc
= "task management request failed";
2108 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2109 desc
= "task management request succeeded";
2111 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2112 desc
= "invalid lun";
2115 desc
= "overlapped tag attempted";
2117 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2118 desc
= "task queued, however not sent to target";
2124 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
2125 ioc
->name
, response_code
, desc
);
2129 * _scsih_tm_done - tm completion routine
2130 * @ioc: per adapter object
2131 * @smid: system request message index
2132 * @msix_index: MSIX table index supplied by the OS
2133 * @reply: reply message frame(lower 32bit addr)
2136 * The callback handler when using scsih_issue_tm.
2138 * Return 1 meaning mf should be freed from _base_interrupt
2139 * 0 means the mf is freed from this function.
2142 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2144 MPI2DefaultReply_t
*mpi_reply
;
2146 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2148 if (ioc
->tm_cmds
.smid
!= smid
)
2150 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2151 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2153 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2154 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2156 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2157 complete(&ioc
->tm_cmds
.done
);
2162 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2163 * @ioc: per adapter object
2164 * @handle: device handle
2166 * During taskmangement request, we need to freeze the device queue.
2169 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2171 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2172 struct scsi_device
*sdev
;
2175 shost_for_each_device(sdev
, ioc
->shost
) {
2178 sas_device_priv_data
= sdev
->hostdata
;
2179 if (!sas_device_priv_data
)
2181 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2182 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2184 ioc
->ignore_loginfos
= 1;
2190 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2191 * @ioc: per adapter object
2192 * @handle: device handle
2194 * During taskmangement request, we need to freeze the device queue.
2197 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2199 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2200 struct scsi_device
*sdev
;
2203 shost_for_each_device(sdev
, ioc
->shost
) {
2206 sas_device_priv_data
= sdev
->hostdata
;
2207 if (!sas_device_priv_data
)
2209 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2210 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2212 ioc
->ignore_loginfos
= 0;
2218 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2219 * @ioc: per adapter struct
2220 * @device_handle: device handle
2221 * @channel: the channel assigned by the OS
2222 * @id: the id assigned by the OS
2224 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2225 * @smid_task: smid assigned to the task
2226 * @timeout: timeout in seconds
2229 * A generic API for sending task management requests to firmware.
2231 * The callback index is set inside `ioc->tm_cb_idx`.
2233 * Return SUCCESS or FAILED.
2236 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2237 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2239 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2240 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2243 struct scsiio_tracker
*scsi_lookup
= NULL
;
2247 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2249 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2250 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2251 __func__
, ioc
->name
);
2255 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2256 ioc
->pci_error_recovery
) {
2257 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2258 __func__
, ioc
->name
);
2262 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2263 if (ioc_state
& MPI2_DOORBELL_USED
) {
2264 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2265 "unexpected doorbell active!\n", ioc
->name
));
2266 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2267 return (!rc
) ? SUCCESS
: FAILED
;
2270 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2271 mpt3sas_base_fault_info(ioc
, ioc_state
&
2272 MPI2_DOORBELL_DATA_MASK
);
2273 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2274 return (!rc
) ? SUCCESS
: FAILED
;
2277 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2279 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2280 ioc
->name
, __func__
);
2284 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2285 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2287 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2288 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2289 ioc
->name
, handle
, type
, smid_task
));
2290 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2291 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2292 ioc
->tm_cmds
.smid
= smid
;
2293 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2294 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2295 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2296 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2297 mpi_request
->TaskType
= type
;
2298 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2299 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2300 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2301 init_completion(&ioc
->tm_cmds
.done
);
2302 if ((type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) &&
2303 (scsi_lookup
->msix_io
< ioc
->reply_queue_count
))
2304 msix_task
= scsi_lookup
->msix_io
;
2307 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2308 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2309 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2310 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2311 ioc
->name
, __func__
);
2312 _debug_dump_mf(mpi_request
,
2313 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2314 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2315 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2317 rc
= (!rc
) ? SUCCESS
: FAILED
;
2322 /* sync IRQs in case those were busy during flush. */
2323 mpt3sas_base_sync_reply_irqs(ioc
);
2325 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2326 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2327 mpi_reply
= ioc
->tm_cmds
.reply
;
2328 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2329 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2330 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2331 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2332 le32_to_cpu(mpi_reply
->TerminationCount
)));
2333 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2334 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2335 if (mpi_reply
->IOCStatus
)
2336 _debug_dump_mf(mpi_request
,
2337 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2342 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2344 if (scsi_lookup
->scmd
== NULL
)
2349 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2350 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2355 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2356 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2357 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2362 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2371 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2372 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2376 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2377 uint channel
, uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
)
2381 mutex_lock(&ioc
->tm_cmds
.mutex
);
2382 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, channel
, id
, lun
, type
,
2383 smid_task
, timeout
);
2384 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2390 * _scsih_tm_display_info - displays info about the device
2391 * @ioc: per adapter struct
2392 * @scmd: pointer to scsi command object
2394 * Called by task management callback handlers.
2397 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2399 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2400 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2401 struct _sas_device
*sas_device
= NULL
;
2402 unsigned long flags
;
2403 char *device_str
= NULL
;
2407 if (ioc
->hide_ir_msg
)
2408 device_str
= "WarpDrive";
2410 device_str
= "volume";
2412 scsi_print_command(scmd
);
2413 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2414 starget_printk(KERN_INFO
, starget
,
2415 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2416 device_str
, priv_target
->handle
,
2417 device_str
, (unsigned long long)priv_target
->sas_address
);
2419 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2420 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2422 if (priv_target
->flags
&
2423 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2424 starget_printk(KERN_INFO
, starget
,
2425 "volume handle(0x%04x), "
2426 "volume wwid(0x%016llx)\n",
2427 sas_device
->volume_handle
,
2428 (unsigned long long)sas_device
->volume_wwid
);
2430 starget_printk(KERN_INFO
, starget
,
2431 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2433 (unsigned long long)sas_device
->sas_address
,
2435 if (sas_device
->enclosure_handle
!= 0)
2436 starget_printk(KERN_INFO
, starget
,
2437 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2438 (unsigned long long)
2439 sas_device
->enclosure_logical_id
,
2441 if (sas_device
->connector_name
[0] != '\0')
2442 starget_printk(KERN_INFO
, starget
,
2443 "enclosure level(0x%04x),connector name(%s)\n",
2444 sas_device
->enclosure_level
,
2445 sas_device
->connector_name
);
2447 sas_device_put(sas_device
);
2449 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2454 * scsih_abort - eh threads main abort routine
2455 * @scmd: pointer to scsi command object
2457 * Returns SUCCESS if command aborted else FAILED
2460 scsih_abort(struct scsi_cmnd
*scmd
)
2462 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2463 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2468 sdev_printk(KERN_INFO
, scmd
->device
,
2469 "attempting task abort! scmd(%p)\n", scmd
);
2470 _scsih_tm_display_info(ioc
, scmd
);
2472 sas_device_priv_data
= scmd
->device
->hostdata
;
2473 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2474 sdev_printk(KERN_INFO
, scmd
->device
,
2475 "device been deleted! scmd(%p)\n", scmd
);
2476 scmd
->result
= DID_NO_CONNECT
<< 16;
2477 scmd
->scsi_done(scmd
);
2482 /* search for the command */
2483 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2485 scmd
->result
= DID_RESET
<< 16;
2490 /* for hidden raid components and volumes this is not supported */
2491 if (sas_device_priv_data
->sas_target
->flags
&
2492 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2493 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2494 scmd
->result
= DID_RESET
<< 16;
2499 mpt3sas_halt_firmware(ioc
);
2501 handle
= sas_device_priv_data
->sas_target
->handle
;
2502 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2503 scmd
->device
->id
, scmd
->device
->lun
,
2504 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30);
2507 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2508 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2513 * scsih_dev_reset - eh threads main device reset routine
2514 * @scmd: pointer to scsi command object
2516 * Returns SUCCESS if command aborted else FAILED
2519 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2521 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2522 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2523 struct _sas_device
*sas_device
= NULL
;
2527 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2528 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2530 sdev_printk(KERN_INFO
, scmd
->device
,
2531 "attempting device reset! scmd(%p)\n", scmd
);
2532 _scsih_tm_display_info(ioc
, scmd
);
2534 sas_device_priv_data
= scmd
->device
->hostdata
;
2535 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2536 sdev_printk(KERN_INFO
, scmd
->device
,
2537 "device been deleted! scmd(%p)\n", scmd
);
2538 scmd
->result
= DID_NO_CONNECT
<< 16;
2539 scmd
->scsi_done(scmd
);
2544 /* for hidden raid components obtain the volume_handle */
2546 if (sas_device_priv_data
->sas_target
->flags
&
2547 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2548 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2551 handle
= sas_device
->volume_handle
;
2553 handle
= sas_device_priv_data
->sas_target
->handle
;
2556 scmd
->result
= DID_RESET
<< 16;
2561 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2562 scmd
->device
->id
, scmd
->device
->lun
,
2563 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30);
2566 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2567 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2570 sas_device_put(sas_device
);
2576 * scsih_target_reset - eh threads main target reset routine
2577 * @scmd: pointer to scsi command object
2579 * Returns SUCCESS if command aborted else FAILED
2582 scsih_target_reset(struct scsi_cmnd
*scmd
)
2584 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2585 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2586 struct _sas_device
*sas_device
= NULL
;
2589 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2590 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2592 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2594 _scsih_tm_display_info(ioc
, scmd
);
2596 sas_device_priv_data
= scmd
->device
->hostdata
;
2597 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2598 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2600 scmd
->result
= DID_NO_CONNECT
<< 16;
2601 scmd
->scsi_done(scmd
);
2606 /* for hidden raid components obtain the volume_handle */
2608 if (sas_device_priv_data
->sas_target
->flags
&
2609 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2610 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2613 handle
= sas_device
->volume_handle
;
2615 handle
= sas_device_priv_data
->sas_target
->handle
;
2618 scmd
->result
= DID_RESET
<< 16;
2623 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->channel
,
2624 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2628 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2629 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2632 sas_device_put(sas_device
);
2639 * scsih_host_reset - eh threads main host reset routine
2640 * @scmd: pointer to scsi command object
2642 * Returns SUCCESS if command aborted else FAILED
2645 scsih_host_reset(struct scsi_cmnd
*scmd
)
2647 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2650 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
2652 scsi_print_command(scmd
);
2654 if (ioc
->is_driver_loading
) {
2655 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
2661 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2662 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2664 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2665 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2671 * _scsih_fw_event_add - insert and queue up fw_event
2672 * @ioc: per adapter object
2673 * @fw_event: object describing the event
2674 * Context: This function will acquire ioc->fw_event_lock.
2676 * This adds the firmware event object into link list, then queues it up to
2677 * be processed from user context.
2682 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2684 unsigned long flags
;
2686 if (ioc
->firmware_event_thread
== NULL
)
2689 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2690 fw_event_work_get(fw_event
);
2691 INIT_LIST_HEAD(&fw_event
->list
);
2692 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2693 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2694 fw_event_work_get(fw_event
);
2695 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2696 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2700 * _scsih_fw_event_del_from_list - delete fw_event from the list
2701 * @ioc: per adapter object
2702 * @fw_event: object describing the event
2703 * Context: This function will acquire ioc->fw_event_lock.
2705 * If the fw_event is on the fw_event_list, remove it and do a put.
2710 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2713 unsigned long flags
;
2715 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2716 if (!list_empty(&fw_event
->list
)) {
2717 list_del_init(&fw_event
->list
);
2718 fw_event_work_put(fw_event
);
2720 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2725 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2726 * @ioc: per adapter object
2727 * @event_data: trigger event data
2732 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2733 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2735 struct fw_event_work
*fw_event
;
2738 if (ioc
->is_driver_loading
)
2740 sz
= sizeof(*event_data
);
2741 fw_event
= alloc_fw_event_work(sz
);
2744 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2745 fw_event
->ioc
= ioc
;
2746 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2747 _scsih_fw_event_add(ioc
, fw_event
);
2748 fw_event_work_put(fw_event
);
2752 * _scsih_error_recovery_delete_devices - remove devices not responding
2753 * @ioc: per adapter object
2758 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2760 struct fw_event_work
*fw_event
;
2762 if (ioc
->is_driver_loading
)
2764 fw_event
= alloc_fw_event_work(0);
2767 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2768 fw_event
->ioc
= ioc
;
2769 _scsih_fw_event_add(ioc
, fw_event
);
2770 fw_event_work_put(fw_event
);
2774 * mpt3sas_port_enable_complete - port enable completed (fake event)
2775 * @ioc: per adapter object
2780 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2782 struct fw_event_work
*fw_event
;
2784 fw_event
= alloc_fw_event_work(0);
2787 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2788 fw_event
->ioc
= ioc
;
2789 _scsih_fw_event_add(ioc
, fw_event
);
2790 fw_event_work_put(fw_event
);
2793 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
2795 unsigned long flags
;
2796 struct fw_event_work
*fw_event
= NULL
;
2798 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2799 if (!list_empty(&ioc
->fw_event_list
)) {
2800 fw_event
= list_first_entry(&ioc
->fw_event_list
,
2801 struct fw_event_work
, list
);
2802 list_del_init(&fw_event
->list
);
2804 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2810 * _scsih_fw_event_cleanup_queue - cleanup event queue
2811 * @ioc: per adapter object
2813 * Walk the firmware event queue, either killing timers, or waiting
2814 * for outstanding events to complete
2819 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2821 struct fw_event_work
*fw_event
;
2823 if (list_empty(&ioc
->fw_event_list
) ||
2824 !ioc
->firmware_event_thread
|| in_interrupt())
2827 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
2829 * Wait on the fw_event to complete. If this returns 1, then
2830 * the event was never executed, and we need a put for the
2831 * reference the work had on the fw_event.
2833 * If it did execute, we wait for it to finish, and the put will
2834 * happen from _firmware_event_work()
2836 if (cancel_work_sync(&fw_event
->work
))
2837 fw_event_work_put(fw_event
);
2839 fw_event_work_put(fw_event
);
2844 * _scsih_internal_device_block - block the sdev device
2845 * @sdev: per device object
2846 * @sas_device_priv_data : per device driver private data
2848 * make sure device is blocked without error, if not
2852 _scsih_internal_device_block(struct scsi_device
*sdev
,
2853 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2857 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
2858 sas_device_priv_data
->sas_target
->handle
);
2859 sas_device_priv_data
->block
= 1;
2861 r
= scsi_internal_device_block(sdev
);
2863 sdev_printk(KERN_WARNING
, sdev
,
2864 "device_block failed with return(%d) for handle(0x%04x)\n",
2865 r
, sas_device_priv_data
->sas_target
->handle
);
2869 * _scsih_internal_device_unblock - unblock the sdev device
2870 * @sdev: per device object
2871 * @sas_device_priv_data : per device driver private data
2872 * make sure device is unblocked without error, if not retry
2873 * by blocking and then unblocking
2877 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
2878 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2882 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
2883 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
2884 sas_device_priv_data
->block
= 0;
2885 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2887 /* The device has been set to SDEV_RUNNING by SD layer during
2888 * device addition but the request queue is still stopped by
2889 * our earlier block call. We need to perform a block again
2890 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2892 sdev_printk(KERN_WARNING
, sdev
,
2893 "device_unblock failed with return(%d) for handle(0x%04x) "
2894 "performing a block followed by an unblock\n",
2895 r
, sas_device_priv_data
->sas_target
->handle
);
2896 sas_device_priv_data
->block
= 1;
2897 r
= scsi_internal_device_block(sdev
);
2899 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
2900 "failed with return(%d) for handle(0x%04x)\n",
2901 r
, sas_device_priv_data
->sas_target
->handle
);
2903 sas_device_priv_data
->block
= 0;
2904 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2906 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
2907 " failed with return(%d) for handle(0x%04x)\n",
2908 r
, sas_device_priv_data
->sas_target
->handle
);
2913 * _scsih_ublock_io_all_device - unblock every device
2914 * @ioc: per adapter object
2916 * change the device state from block to running
2919 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2921 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2922 struct scsi_device
*sdev
;
2924 shost_for_each_device(sdev
, ioc
->shost
) {
2925 sas_device_priv_data
= sdev
->hostdata
;
2926 if (!sas_device_priv_data
)
2928 if (!sas_device_priv_data
->block
)
2931 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2932 "device_running, handle(0x%04x)\n",
2933 sas_device_priv_data
->sas_target
->handle
));
2934 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
2940 * _scsih_ublock_io_device - prepare device to be deleted
2941 * @ioc: per adapter object
2942 * @sas_addr: sas address
2944 * unblock then put device in offline state
2947 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2949 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2950 struct scsi_device
*sdev
;
2952 shost_for_each_device(sdev
, ioc
->shost
) {
2953 sas_device_priv_data
= sdev
->hostdata
;
2954 if (!sas_device_priv_data
)
2956 if (sas_device_priv_data
->sas_target
->sas_address
2959 if (sas_device_priv_data
->block
)
2960 _scsih_internal_device_unblock(sdev
,
2961 sas_device_priv_data
);
2966 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2967 * @ioc: per adapter object
2968 * @handle: device handle
2970 * During device pull we need to appropriately set the sdev state.
2973 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2975 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2976 struct scsi_device
*sdev
;
2978 shost_for_each_device(sdev
, ioc
->shost
) {
2979 sas_device_priv_data
= sdev
->hostdata
;
2980 if (!sas_device_priv_data
)
2982 if (sas_device_priv_data
->block
)
2984 if (sas_device_priv_data
->ignore_delay_remove
) {
2985 sdev_printk(KERN_INFO
, sdev
,
2986 "%s skip device_block for SES handle(0x%04x)\n",
2987 __func__
, sas_device_priv_data
->sas_target
->handle
);
2990 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2995 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2996 * @ioc: per adapter object
2997 * @handle: device handle
2999 * During device pull we need to appropriately set the sdev state.
3002 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3004 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3005 struct scsi_device
*sdev
;
3006 struct _sas_device
*sas_device
;
3008 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3012 shost_for_each_device(sdev
, ioc
->shost
) {
3013 sas_device_priv_data
= sdev
->hostdata
;
3014 if (!sas_device_priv_data
)
3016 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3018 if (sas_device_priv_data
->block
)
3020 if (sas_device
->pend_sas_rphy_add
)
3022 if (sas_device_priv_data
->ignore_delay_remove
) {
3023 sdev_printk(KERN_INFO
, sdev
,
3024 "%s skip device_block for SES handle(0x%04x)\n",
3025 __func__
, sas_device_priv_data
->sas_target
->handle
);
3028 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3031 sas_device_put(sas_device
);
3035 * _scsih_block_io_to_children_attached_to_ex
3036 * @ioc: per adapter object
3037 * @sas_expander: the sas_device object
3039 * This routine set sdev state to SDEV_BLOCK for all devices
3040 * attached to this expander. This function called when expander is
3044 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3045 struct _sas_node
*sas_expander
)
3047 struct _sas_port
*mpt3sas_port
;
3048 struct _sas_device
*sas_device
;
3049 struct _sas_node
*expander_sibling
;
3050 unsigned long flags
;
3055 list_for_each_entry(mpt3sas_port
,
3056 &sas_expander
->sas_port_list
, port_list
) {
3057 if (mpt3sas_port
->remote_identify
.device_type
==
3059 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3060 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3061 mpt3sas_port
->remote_identify
.sas_address
);
3063 set_bit(sas_device
->handle
,
3064 ioc
->blocking_handles
);
3065 sas_device_put(sas_device
);
3067 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3071 list_for_each_entry(mpt3sas_port
,
3072 &sas_expander
->sas_port_list
, port_list
) {
3074 if (mpt3sas_port
->remote_identify
.device_type
==
3075 SAS_EDGE_EXPANDER_DEVICE
||
3076 mpt3sas_port
->remote_identify
.device_type
==
3077 SAS_FANOUT_EXPANDER_DEVICE
) {
3079 mpt3sas_scsih_expander_find_by_sas_address(
3080 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3081 _scsih_block_io_to_children_attached_to_ex(ioc
,
3088 * _scsih_block_io_to_children_attached_directly
3089 * @ioc: per adapter object
3090 * @event_data: topology change event data
3092 * This routine set sdev state to SDEV_BLOCK for all devices
3093 * direct attached during device pull.
3096 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3097 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3103 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3104 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3107 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3108 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3109 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3110 _scsih_block_io_device(ioc
, handle
);
3115 * _scsih_tm_tr_send - send task management request
3116 * @ioc: per adapter object
3117 * @handle: device handle
3118 * Context: interrupt time.
3120 * This code is to initiate the device removal handshake protocol
3121 * with controller firmware. This function will issue target reset
3122 * using high priority request queue. It will send a sas iounit
3123 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3125 * This is designed to send muliple task management request at the same
3126 * time to the fifo. If the fifo is full, we will append the request,
3127 * and process it in a future completion.
3130 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3132 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3134 struct _sas_device
*sas_device
= NULL
;
3135 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3136 u64 sas_address
= 0;
3137 unsigned long flags
;
3138 struct _tr_list
*delayed_tr
;
3141 if (ioc
->remove_host
) {
3142 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3143 "%s: host has been removed: handle(0x%04x)\n",
3144 __func__
, ioc
->name
, handle
));
3146 } else if (ioc
->pci_error_recovery
) {
3147 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3148 "%s: host in pci error recovery: handle(0x%04x)\n",
3149 __func__
, ioc
->name
,
3153 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3154 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3155 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3156 "%s: host is not operational: handle(0x%04x)\n",
3157 __func__
, ioc
->name
,
3162 /* if PD, then return */
3163 if (test_bit(handle
, ioc
->pd_handles
))
3166 clear_bit(handle
, ioc
->pend_os_device_add
);
3168 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3169 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3170 if (sas_device
&& sas_device
->starget
&&
3171 sas_device
->starget
->hostdata
) {
3172 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3173 sas_target_priv_data
->deleted
= 1;
3174 sas_address
= sas_device
->sas_address
;
3176 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3178 if (sas_target_priv_data
) {
3179 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3180 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3182 (unsigned long long)sas_address
));
3183 if (sas_device
->enclosure_handle
!= 0)
3184 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3185 "setting delete flag:enclosure logical id(0x%016llx),"
3186 " slot(%d)\n", ioc
->name
, (unsigned long long)
3187 sas_device
->enclosure_logical_id
,
3189 if (sas_device
->connector_name
[0] != '\0')
3190 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3191 "setting delete flag: enclosure level(0x%04x),"
3192 " connector name( %s)\n", ioc
->name
,
3193 sas_device
->enclosure_level
,
3194 sas_device
->connector_name
));
3195 _scsih_ublock_io_device(ioc
, sas_address
);
3196 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3199 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3201 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3204 INIT_LIST_HEAD(&delayed_tr
->list
);
3205 delayed_tr
->handle
= handle
;
3206 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3207 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3208 "DELAYED:tr:handle(0x%04x), (open)\n",
3209 ioc
->name
, handle
));
3213 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3214 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3215 ioc
->name
, handle
, smid
,
3216 ioc
->tm_tr_cb_idx
));
3217 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3218 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3219 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3220 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3221 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3222 set_bit(handle
, ioc
->device_remove_in_progress
);
3223 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3224 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3228 sas_device_put(sas_device
);
3232 * _scsih_tm_tr_complete -
3233 * @ioc: per adapter object
3234 * @smid: system request message index
3235 * @msix_index: MSIX table index supplied by the OS
3236 * @reply: reply message frame(lower 32bit addr)
3237 * Context: interrupt time.
3239 * This is the target reset completion routine.
3240 * This code is part of the code to initiate the device removal
3241 * handshake protocol with controller firmware.
3242 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3244 * Return 1 meaning mf should be freed from _base_interrupt
3245 * 0 means the mf is freed from this function.
3248 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3252 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3253 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3254 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3255 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3258 struct _sc_list
*delayed_sc
;
3260 if (ioc
->remove_host
) {
3261 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3262 "%s: host has been removed\n", __func__
, ioc
->name
));
3264 } else if (ioc
->pci_error_recovery
) {
3265 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3266 "%s: host in pci error recovery\n", __func__
,
3270 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3271 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3272 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3273 "%s: host is not operational\n", __func__
, ioc
->name
));
3276 if (unlikely(!mpi_reply
)) {
3277 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3278 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3281 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3282 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3283 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3284 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3285 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3287 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3291 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3292 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3293 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3294 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3295 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3296 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3297 le32_to_cpu(mpi_reply
->TerminationCount
)));
3299 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3300 if (!smid_sas_ctrl
) {
3301 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3303 return _scsih_check_for_pending_tm(ioc
, smid
);
3304 INIT_LIST_HEAD(&delayed_sc
->list
);
3305 delayed_sc
->handle
= mpi_request_tm
->DevHandle
;
3306 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3307 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3308 "DELAYED:sc:handle(0x%04x), (open)\n",
3309 ioc
->name
, handle
));
3310 return _scsih_check_for_pending_tm(ioc
, smid
);
3313 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3314 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3315 ioc
->name
, handle
, smid_sas_ctrl
,
3316 ioc
->tm_sas_control_cb_idx
));
3317 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3318 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3319 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3320 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3321 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3322 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3324 return _scsih_check_for_pending_tm(ioc
, smid
);
3329 * _scsih_sas_control_complete - completion routine
3330 * @ioc: per adapter object
3331 * @smid: system request message index
3332 * @msix_index: MSIX table index supplied by the OS
3333 * @reply: reply message frame(lower 32bit addr)
3334 * Context: interrupt time.
3336 * This is the sas iounit control completion routine.
3337 * This code is part of the code to initiate the device removal
3338 * handshake protocol with controller firmware.
3340 * Return 1 meaning mf should be freed from _base_interrupt
3341 * 0 means the mf is freed from this function.
3344 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3345 u8 msix_index
, u32 reply
)
3347 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3348 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3350 if (likely(mpi_reply
)) {
3351 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3352 "sc_complete:handle(0x%04x), (open) "
3353 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3354 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3355 le16_to_cpu(mpi_reply
->IOCStatus
),
3356 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3357 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3358 MPI2_IOCSTATUS_SUCCESS
) {
3359 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3360 ioc
->device_remove_in_progress
);
3363 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3364 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3366 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3370 * _scsih_tm_tr_volume_send - send target reset request for volumes
3371 * @ioc: per adapter object
3372 * @handle: device handle
3373 * Context: interrupt time.
3375 * This is designed to send muliple task management request at the same
3376 * time to the fifo. If the fifo is full, we will append the request,
3377 * and process it in a future completion.
3380 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3382 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3384 struct _tr_list
*delayed_tr
;
3386 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3387 ioc
->pci_error_recovery
) {
3388 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3389 "%s: host reset in progress!\n",
3390 __func__
, ioc
->name
));
3394 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3396 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3399 INIT_LIST_HEAD(&delayed_tr
->list
);
3400 delayed_tr
->handle
= handle
;
3401 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3402 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3403 "DELAYED:tr:handle(0x%04x), (open)\n",
3404 ioc
->name
, handle
));
3408 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3409 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3410 ioc
->name
, handle
, smid
,
3411 ioc
->tm_tr_volume_cb_idx
));
3412 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3413 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3414 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3415 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3416 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3417 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3421 * _scsih_tm_volume_tr_complete - target reset completion
3422 * @ioc: per adapter object
3423 * @smid: system request message index
3424 * @msix_index: MSIX table index supplied by the OS
3425 * @reply: reply message frame(lower 32bit addr)
3426 * Context: interrupt time.
3428 * Return 1 meaning mf should be freed from _base_interrupt
3429 * 0 means the mf is freed from this function.
3432 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3433 u8 msix_index
, u32 reply
)
3436 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3437 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3438 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3440 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3441 ioc
->pci_error_recovery
) {
3442 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3443 "%s: host reset in progress!\n",
3444 __func__
, ioc
->name
));
3447 if (unlikely(!mpi_reply
)) {
3448 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3449 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3453 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3454 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3455 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3456 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3457 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3459 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3463 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3464 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3465 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3466 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3467 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3468 le32_to_cpu(mpi_reply
->TerminationCount
)));
3470 return _scsih_check_for_pending_tm(ioc
, smid
);
3474 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3475 * @ioc: per adapter object
3476 * @smid: system request message index
3478 * @event_context: used to track events uniquely
3480 * Context - processed in interrupt context.
3483 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 event
,
3486 Mpi2EventAckRequest_t
*ack_request
;
3487 int i
= smid
- ioc
->internal_smid
;
3488 unsigned long flags
;
3490 /* Without releasing the smid just update the
3491 * call back index and reuse the same smid for
3492 * processing this delayed request
3494 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3495 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
3496 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3498 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3499 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3500 ioc
->name
, le16_to_cpu(event
), smid
,
3502 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3503 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
3504 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
3505 ack_request
->Event
= event
;
3506 ack_request
->EventContext
= event_context
;
3507 ack_request
->VF_ID
= 0; /* TODO */
3508 ack_request
->VP_ID
= 0;
3509 ioc
->put_smid_default(ioc
, smid
);
3513 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3514 * sas_io_unit_ctrl messages
3515 * @ioc: per adapter object
3516 * @smid: system request message index
3517 * @handle: device handle
3519 * Context - processed in interrupt context.
3522 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
3523 u16 smid
, u16 handle
)
3525 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3527 int i
= smid
- ioc
->internal_smid
;
3528 unsigned long flags
;
3530 if (ioc
->remove_host
) {
3531 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3532 "%s: host has been removed\n",
3533 __func__
, ioc
->name
));
3535 } else if (ioc
->pci_error_recovery
) {
3536 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3537 "%s: host in pci error recovery\n",
3538 __func__
, ioc
->name
));
3541 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3542 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3543 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3544 "%s: host is not operational\n",
3545 __func__
, ioc
->name
));
3549 /* Without releasing the smid just update the
3550 * call back index and reuse the same smid for
3551 * processing this delayed request
3553 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3554 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
3555 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3557 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3558 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3559 ioc
->name
, le16_to_cpu(handle
), smid
,
3560 ioc
->tm_sas_control_cb_idx
));
3561 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3562 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3563 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3564 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3565 mpi_request
->DevHandle
= handle
;
3566 ioc
->put_smid_default(ioc
, smid
);
3570 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3571 * @ioc: per adapter object
3572 * @smid: system request message index
3574 * Context: Executed in interrupt context
3576 * This will check delayed internal messages list, and process the
3579 * Return 1 meaning mf should be freed from _base_interrupt
3580 * 0 means the mf is freed from this function.
3583 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3585 struct _sc_list
*delayed_sc
;
3586 struct _event_ack_list
*delayed_event_ack
;
3588 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
3589 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
3590 struct _event_ack_list
, list
);
3591 _scsih_issue_delayed_event_ack(ioc
, smid
,
3592 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
3593 list_del(&delayed_event_ack
->list
);
3594 kfree(delayed_event_ack
);
3598 if (!list_empty(&ioc
->delayed_sc_list
)) {
3599 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
3600 struct _sc_list
, list
);
3601 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
3602 delayed_sc
->handle
);
3603 list_del(&delayed_sc
->list
);
3611 * _scsih_check_for_pending_tm - check for pending task management
3612 * @ioc: per adapter object
3613 * @smid: system request message index
3615 * This will check delayed target reset list, and feed the
3618 * Return 1 meaning mf should be freed from _base_interrupt
3619 * 0 means the mf is freed from this function.
3622 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3624 struct _tr_list
*delayed_tr
;
3626 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3627 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3628 struct _tr_list
, list
);
3629 mpt3sas_base_free_smid(ioc
, smid
);
3630 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3631 list_del(&delayed_tr
->list
);
3636 if (!list_empty(&ioc
->delayed_tr_list
)) {
3637 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3638 struct _tr_list
, list
);
3639 mpt3sas_base_free_smid(ioc
, smid
);
3640 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3641 list_del(&delayed_tr
->list
);
3650 * _scsih_check_topo_delete_events - sanity check on topo events
3651 * @ioc: per adapter object
3652 * @event_data: the event data payload
3654 * This routine added to better handle cable breaker.
3656 * This handles the case where driver receives multiple expander
3657 * add and delete events in a single shot. When there is a delete event
3658 * the routine will void any pending add events waiting in the event queue.
3663 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3664 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3666 struct fw_event_work
*fw_event
;
3667 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3668 u16 expander_handle
;
3669 struct _sas_node
*sas_expander
;
3670 unsigned long flags
;
3674 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3675 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3678 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3679 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3680 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3681 _scsih_tm_tr_send(ioc
, handle
);
3684 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3685 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3686 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3689 if (event_data
->ExpStatus
==
3690 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3691 /* put expander attached devices into blocking state */
3692 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3693 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3695 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3696 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3698 handle
= find_first_bit(ioc
->blocking_handles
,
3699 ioc
->facts
.MaxDevHandle
);
3700 if (handle
< ioc
->facts
.MaxDevHandle
)
3701 _scsih_block_io_device(ioc
, handle
);
3702 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3703 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3704 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3706 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3709 /* mark ignore flag for pending events */
3710 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3711 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3712 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3715 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3716 fw_event
->event_data
;
3717 if (local_event_data
->ExpStatus
==
3718 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3719 local_event_data
->ExpStatus
==
3720 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3721 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3723 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3724 "setting ignoring flag\n", ioc
->name
));
3725 fw_event
->ignore
= 1;
3729 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3733 * _scsih_set_volume_delete_flag - setting volume delete flag
3734 * @ioc: per adapter object
3735 * @handle: device handle
3737 * This returns nothing.
3740 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3742 struct _raid_device
*raid_device
;
3743 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3744 unsigned long flags
;
3746 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3747 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
3748 if (raid_device
&& raid_device
->starget
&&
3749 raid_device
->starget
->hostdata
) {
3750 sas_target_priv_data
=
3751 raid_device
->starget
->hostdata
;
3752 sas_target_priv_data
->deleted
= 1;
3753 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3754 "setting delete flag: handle(0x%04x), "
3755 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3756 (unsigned long long) raid_device
->wwid
));
3758 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3762 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3763 * @handle: input handle
3764 * @a: handle for volume a
3765 * @b: handle for volume b
3767 * IR firmware only supports two raid volumes. The purpose of this
3768 * routine is to set the volume handle in either a or b. When the given
3769 * input handle is non-zero, or when a and b have not been set before.
3772 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3774 if (!handle
|| handle
== *a
|| handle
== *b
)
3783 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3784 * @ioc: per adapter object
3785 * @event_data: the event data payload
3786 * Context: interrupt time.
3788 * This routine will send target reset to volume, followed by target
3789 * resets to the PDs. This is called when a PD has been removed, or
3790 * volume has been deleted or removed. When the target reset is sent
3791 * to volume, the PD target resets need to be queued to start upon
3792 * completion of the volume target reset.
3797 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3798 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3800 Mpi2EventIrConfigElement_t
*element
;
3802 u16 handle
, volume_handle
, a
, b
;
3803 struct _tr_list
*delayed_tr
;
3808 if (ioc
->is_warpdrive
)
3811 /* Volume Resets for Deleted or Removed */
3812 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3813 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3814 if (le32_to_cpu(event_data
->Flags
) &
3815 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3817 if (element
->ReasonCode
==
3818 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3819 element
->ReasonCode
==
3820 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3821 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3822 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3823 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3827 /* Volume Resets for UNHIDE events */
3828 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3829 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3830 if (le32_to_cpu(event_data
->Flags
) &
3831 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3833 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3834 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3835 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3840 _scsih_tm_tr_volume_send(ioc
, a
);
3842 _scsih_tm_tr_volume_send(ioc
, b
);
3844 /* PD target resets */
3845 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3846 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3847 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3849 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3850 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3851 clear_bit(handle
, ioc
->pd_handles
);
3853 _scsih_tm_tr_send(ioc
, handle
);
3854 else if (volume_handle
== a
|| volume_handle
== b
) {
3855 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3856 BUG_ON(!delayed_tr
);
3857 INIT_LIST_HEAD(&delayed_tr
->list
);
3858 delayed_tr
->handle
= handle
;
3859 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3860 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3861 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3864 _scsih_tm_tr_send(ioc
, handle
);
3870 * _scsih_check_volume_delete_events - set delete flag for volumes
3871 * @ioc: per adapter object
3872 * @event_data: the event data payload
3873 * Context: interrupt time.
3875 * This will handle the case when the cable connected to entire volume is
3876 * pulled. We will take care of setting the deleted flag so normal IO will
3882 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3883 Mpi2EventDataIrVolume_t
*event_data
)
3887 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3889 state
= le32_to_cpu(event_data
->NewValue
);
3890 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3891 MPI2_RAID_VOL_STATE_FAILED
)
3892 _scsih_set_volume_delete_flag(ioc
,
3893 le16_to_cpu(event_data
->VolDevHandle
));
3897 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3898 * @ioc: per adapter object
3899 * @event_data: the temp threshold event data
3900 * Context: interrupt time.
3905 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
3906 Mpi2EventDataTemperature_t
*event_data
)
3908 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3909 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
3910 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3911 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3912 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3913 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3914 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3915 event_data
->SensorNum
);
3916 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
3917 ioc
->name
, event_data
->CurrentTemperature
);
3921 static inline bool ata_12_16_cmd(struct scsi_cmnd
*scmd
)
3923 return (scmd
->cmnd
[0] == ATA_12
|| scmd
->cmnd
[0] == ATA_16
);
3927 * _scsih_flush_running_cmds - completing outstanding commands.
3928 * @ioc: per adapter object
3930 * The flushing out of all pending scmd commands following host reset,
3931 * where all IO is dropped to the floor.
3936 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3938 struct scsi_cmnd
*scmd
;
3942 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3943 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3947 if (ata_12_16_cmd(scmd
))
3948 scsi_internal_device_unblock(scmd
->device
,
3950 mpt3sas_base_free_smid(ioc
, smid
);
3951 scsi_dma_unmap(scmd
);
3952 if (ioc
->pci_error_recovery
)
3953 scmd
->result
= DID_NO_CONNECT
<< 16;
3955 scmd
->result
= DID_RESET
<< 16;
3956 scmd
->scsi_done(scmd
);
3958 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3963 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3964 * @ioc: per adapter object
3965 * @scmd: pointer to scsi command object
3966 * @mpi_request: pointer to the SCSI_IO request message frame
3968 * Supporting protection 1 and 3.
3973 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3974 Mpi2SCSIIORequest_t
*mpi_request
)
3977 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3978 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3979 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3980 (Mpi25SCSIIORequest_t
*)mpi_request
;
3982 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3985 if (prot_op
== SCSI_PROT_READ_STRIP
)
3986 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3987 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3988 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3992 switch (prot_type
) {
3993 case SCSI_PROT_DIF_TYPE1
:
3994 case SCSI_PROT_DIF_TYPE2
:
3997 * enable ref/guard checking
3998 * auto increment ref tag
4000 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4001 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4002 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4003 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4004 cpu_to_be32(scsi_prot_ref_tag(scmd
));
4007 case SCSI_PROT_DIF_TYPE3
:
4010 * enable guard checking
4012 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4017 mpi_request_3v
->EEDPBlockSize
=
4018 cpu_to_le16(scmd
->device
->sector_size
);
4020 if (ioc
->is_gen35_ioc
)
4021 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4022 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4026 * _scsih_eedp_error_handling - return sense code for EEDP errors
4027 * @scmd: pointer to scsi command object
4028 * @ioc_status: ioc status
4033 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4037 switch (ioc_status
) {
4038 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4041 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4044 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4051 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4053 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4054 SAM_STAT_CHECK_CONDITION
;
4058 * scsih_qcmd - main scsi request entry point
4059 * @scmd: pointer to scsi command object
4060 * @done: function pointer to be invoked on completion
4062 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4064 * Returns 0 on success. If there's a failure, return either:
4065 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4066 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4069 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4071 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4072 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4073 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4074 struct _raid_device
*raid_device
;
4075 struct request
*rq
= scmd
->request
;
4077 Mpi2SCSIIORequest_t
*mpi_request
;
4082 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4083 scsi_print_command(scmd
);
4086 * Lock the device for any subsequent command until command is
4089 if (ata_12_16_cmd(scmd
))
4090 scsi_internal_device_block(scmd
->device
);
4092 sas_device_priv_data
= scmd
->device
->hostdata
;
4093 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4094 scmd
->result
= DID_NO_CONNECT
<< 16;
4095 scmd
->scsi_done(scmd
);
4099 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
4100 scmd
->result
= DID_NO_CONNECT
<< 16;
4101 scmd
->scsi_done(scmd
);
4105 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4107 /* invalid device handle */
4108 handle
= sas_target_priv_data
->handle
;
4109 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4110 scmd
->result
= DID_NO_CONNECT
<< 16;
4111 scmd
->scsi_done(scmd
);
4116 /* host recovery or link resets sent via IOCTLs */
4117 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
4118 return SCSI_MLQUEUE_HOST_BUSY
;
4120 /* device has been deleted */
4121 else if (sas_target_priv_data
->deleted
) {
4122 scmd
->result
= DID_NO_CONNECT
<< 16;
4123 scmd
->scsi_done(scmd
);
4125 /* device busy with task management */
4126 } else if (sas_target_priv_data
->tm_busy
||
4127 sas_device_priv_data
->block
)
4128 return SCSI_MLQUEUE_DEVICE_BUSY
;
4130 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4131 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4132 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4133 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4135 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4138 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4139 /* NCQ Prio supported, make sure control indicated high priority */
4140 if (sas_device_priv_data
->ncq_prio_enable
) {
4141 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4142 if (class == IOPRIO_CLASS_RT
)
4143 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4145 /* Make sure Device is not raid volume.
4146 * We do not expose raid functionality to upper layer for warpdrive.
4148 if (!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
)
4149 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4150 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4152 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4154 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4155 ioc
->name
, __func__
);
4158 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4159 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
4160 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4162 if (scmd
->cmd_len
== 32)
4163 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4164 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4165 if (sas_device_priv_data
->sas_target
->flags
&
4166 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4167 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4169 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4170 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4171 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4172 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4173 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4174 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4175 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4176 mpi_request
->SenseBufferLowAddress
=
4177 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4178 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4179 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4181 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4183 if (mpi_request
->DataLength
) {
4184 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
4185 mpt3sas_base_free_smid(ioc
, smid
);
4189 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4191 raid_device
= sas_target_priv_data
->raid_device
;
4192 if (raid_device
&& raid_device
->direct_io_enabled
)
4193 mpt3sas_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4196 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4197 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4198 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4199 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4200 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4202 ioc
->put_smid_scsi_io(ioc
, smid
,
4203 le16_to_cpu(mpi_request
->DevHandle
));
4205 ioc
->put_smid_default(ioc
, smid
);
4209 return SCSI_MLQUEUE_HOST_BUSY
;
4213 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4214 * @sense_buffer: sense data returned by target
4215 * @data: normalized skey/asc/ascq
4220 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4222 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4223 /* descriptor format */
4224 data
->skey
= sense_buffer
[1] & 0x0F;
4225 data
->asc
= sense_buffer
[2];
4226 data
->ascq
= sense_buffer
[3];
4229 data
->skey
= sense_buffer
[2] & 0x0F;
4230 data
->asc
= sense_buffer
[12];
4231 data
->ascq
= sense_buffer
[13];
4236 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4237 * @ioc: per adapter object
4238 * @scmd: pointer to scsi command object
4239 * @mpi_reply: reply mf payload returned from firmware
4241 * scsi_status - SCSI Status code returned from target device
4242 * scsi_state - state info associated with SCSI_IO determined by ioc
4243 * ioc_status - ioc supplied status info
4248 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4249 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4253 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4254 MPI2_IOCSTATUS_MASK
;
4255 u8 scsi_state
= mpi_reply
->SCSIState
;
4256 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4257 char *desc_ioc_state
= NULL
;
4258 char *desc_scsi_status
= NULL
;
4259 char *desc_scsi_state
= ioc
->tmp_string
;
4260 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4261 struct _sas_device
*sas_device
= NULL
;
4262 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4263 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4264 char *device_str
= NULL
;
4268 if (ioc
->hide_ir_msg
)
4269 device_str
= "WarpDrive";
4271 device_str
= "volume";
4273 if (log_info
== 0x31170000)
4276 switch (ioc_status
) {
4277 case MPI2_IOCSTATUS_SUCCESS
:
4278 desc_ioc_state
= "success";
4280 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4281 desc_ioc_state
= "invalid function";
4283 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4284 desc_ioc_state
= "scsi recovered error";
4286 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4287 desc_ioc_state
= "scsi invalid dev handle";
4289 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4290 desc_ioc_state
= "scsi device not there";
4292 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4293 desc_ioc_state
= "scsi data overrun";
4295 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4296 desc_ioc_state
= "scsi data underrun";
4298 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4299 desc_ioc_state
= "scsi io data error";
4301 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4302 desc_ioc_state
= "scsi protocol error";
4304 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4305 desc_ioc_state
= "scsi task terminated";
4307 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4308 desc_ioc_state
= "scsi residual mismatch";
4310 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4311 desc_ioc_state
= "scsi task mgmt failed";
4313 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4314 desc_ioc_state
= "scsi ioc terminated";
4316 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4317 desc_ioc_state
= "scsi ext terminated";
4319 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4320 desc_ioc_state
= "eedp guard error";
4322 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4323 desc_ioc_state
= "eedp ref tag error";
4325 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4326 desc_ioc_state
= "eedp app tag error";
4328 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4329 desc_ioc_state
= "insufficient power";
4332 desc_ioc_state
= "unknown";
4336 switch (scsi_status
) {
4337 case MPI2_SCSI_STATUS_GOOD
:
4338 desc_scsi_status
= "good";
4340 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4341 desc_scsi_status
= "check condition";
4343 case MPI2_SCSI_STATUS_CONDITION_MET
:
4344 desc_scsi_status
= "condition met";
4346 case MPI2_SCSI_STATUS_BUSY
:
4347 desc_scsi_status
= "busy";
4349 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4350 desc_scsi_status
= "intermediate";
4352 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4353 desc_scsi_status
= "intermediate condmet";
4355 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4356 desc_scsi_status
= "reservation conflict";
4358 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4359 desc_scsi_status
= "command terminated";
4361 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4362 desc_scsi_status
= "task set full";
4364 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4365 desc_scsi_status
= "aca active";
4367 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4368 desc_scsi_status
= "task aborted";
4371 desc_scsi_status
= "unknown";
4375 desc_scsi_state
[0] = '\0';
4377 desc_scsi_state
= " ";
4378 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4379 strcat(desc_scsi_state
, "response info ");
4380 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4381 strcat(desc_scsi_state
, "state terminated ");
4382 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4383 strcat(desc_scsi_state
, "no status ");
4384 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4385 strcat(desc_scsi_state
, "autosense failed ");
4386 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4387 strcat(desc_scsi_state
, "autosense valid ");
4389 scsi_print_command(scmd
);
4391 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4392 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4393 device_str
, (unsigned long long)priv_target
->sas_address
);
4395 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4398 "\tsas_address(0x%016llx), phy(%d)\n",
4399 ioc
->name
, (unsigned long long)
4400 sas_device
->sas_address
, sas_device
->phy
);
4401 if (sas_device
->enclosure_handle
!= 0)
4403 "\tenclosure_logical_id(0x%016llx),"
4404 "slot(%d)\n", ioc
->name
,
4405 (unsigned long long)
4406 sas_device
->enclosure_logical_id
,
4408 if (sas_device
->connector_name
[0])
4410 "\tenclosure level(0x%04x),"
4411 " connector name( %s)\n", ioc
->name
,
4412 sas_device
->enclosure_level
,
4413 sas_device
->connector_name
);
4415 sas_device_put(sas_device
);
4420 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4421 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4422 desc_ioc_state
, ioc_status
, smid
);
4424 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4425 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4426 scsi_get_resid(scmd
));
4428 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4429 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4430 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4432 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4433 ioc
->name
, desc_scsi_status
,
4434 scsi_status
, desc_scsi_state
, scsi_state
);
4436 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4437 struct sense_info data
;
4438 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4440 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4441 ioc
->name
, data
.skey
,
4442 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4445 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4446 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4447 response_bytes
= (u8
*)&response_info
;
4448 _scsih_response_code(ioc
, response_bytes
[0]);
4453 * _scsih_turn_on_pfa_led - illuminate PFA LED
4454 * @ioc: per adapter object
4455 * @handle: device handle
4461 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4463 Mpi2SepReply_t mpi_reply
;
4464 Mpi2SepRequest_t mpi_request
;
4465 struct _sas_device
*sas_device
;
4467 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
4471 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4472 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4473 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4474 mpi_request
.SlotStatus
=
4475 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4476 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4477 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4478 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4479 &mpi_request
)) != 0) {
4480 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4481 __FILE__
, __LINE__
, __func__
);
4484 sas_device
->pfa_led_on
= 1;
4486 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4487 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4488 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4489 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4490 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4494 sas_device_put(sas_device
);
4498 * _scsih_turn_off_pfa_led - turn off Fault LED
4499 * @ioc: per adapter object
4500 * @sas_device: sas device whose PFA LED has to turned off
4506 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4507 struct _sas_device
*sas_device
)
4509 Mpi2SepReply_t mpi_reply
;
4510 Mpi2SepRequest_t mpi_request
;
4512 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4513 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4514 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4515 mpi_request
.SlotStatus
= 0;
4516 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4517 mpi_request
.DevHandle
= 0;
4518 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4519 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4520 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4521 &mpi_request
)) != 0) {
4522 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4523 __FILE__
, __LINE__
, __func__
);
4527 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4528 dewtprintk(ioc
, printk(MPT3SAS_FMT
4529 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4530 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4531 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4537 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4538 * @ioc: per adapter object
4539 * @handle: device handle
4540 * Context: interrupt.
4545 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4547 struct fw_event_work
*fw_event
;
4549 fw_event
= alloc_fw_event_work(0);
4552 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4553 fw_event
->device_handle
= handle
;
4554 fw_event
->ioc
= ioc
;
4555 _scsih_fw_event_add(ioc
, fw_event
);
4556 fw_event_work_put(fw_event
);
4560 * _scsih_smart_predicted_fault - process smart errors
4561 * @ioc: per adapter object
4562 * @handle: device handle
4563 * Context: interrupt.
4568 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4570 struct scsi_target
*starget
;
4571 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4572 Mpi2EventNotificationReply_t
*event_reply
;
4573 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4574 struct _sas_device
*sas_device
;
4576 unsigned long flags
;
4578 /* only handle non-raid devices */
4579 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4580 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
4584 starget
= sas_device
->starget
;
4585 sas_target_priv_data
= starget
->hostdata
;
4587 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4588 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
4591 if (sas_device
->enclosure_handle
!= 0)
4592 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4593 "enclosure logical id(0x%016llx), slot(%d)\n",
4594 (unsigned long long)sas_device
->enclosure_logical_id
,
4596 if (sas_device
->connector_name
[0] != '\0')
4597 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4598 "enclosure level(0x%04x), connector name( %s)\n",
4599 sas_device
->enclosure_level
,
4600 sas_device
->connector_name
);
4601 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4603 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4604 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4606 /* insert into event log */
4607 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4608 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4609 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4611 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4612 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4616 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4617 event_reply
->Event
=
4618 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4619 event_reply
->MsgLength
= sz
/4;
4620 event_reply
->EventDataLength
=
4621 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4622 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4623 event_reply
->EventData
;
4624 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4625 event_data
->ASC
= 0x5D;
4626 event_data
->DevHandle
= cpu_to_le16(handle
);
4627 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4628 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4632 sas_device_put(sas_device
);
4636 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4641 * _scsih_io_done - scsi request callback
4642 * @ioc: per adapter object
4643 * @smid: system request message index
4644 * @msix_index: MSIX table index supplied by the OS
4645 * @reply: reply message frame(lower 32bit addr)
4647 * Callback handler when using _scsih_qcmd.
4649 * Return 1 meaning mf should be freed from _base_interrupt
4650 * 0 means the mf is freed from this function.
4653 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4655 Mpi2SCSIIORequest_t
*mpi_request
;
4656 Mpi2SCSIIOReply_t
*mpi_reply
;
4657 struct scsi_cmnd
*scmd
;
4663 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4664 u32 response_code
= 0;
4665 unsigned long flags
;
4667 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4669 if (ioc
->broadcast_aen_busy
|| ioc
->pci_error_recovery
||
4670 ioc
->got_task_abort_from_ioctl
)
4671 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4673 scmd
= __scsih_scsi_lookup_get_clear(ioc
, smid
);
4678 if (ata_12_16_cmd(scmd
))
4679 scsi_internal_device_unblock(scmd
->device
, SDEV_RUNNING
);
4681 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4683 if (mpi_reply
== NULL
) {
4684 scmd
->result
= DID_OK
<< 16;
4688 sas_device_priv_data
= scmd
->device
->hostdata
;
4689 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4690 sas_device_priv_data
->sas_target
->deleted
) {
4691 scmd
->result
= DID_NO_CONNECT
<< 16;
4694 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4697 * WARPDRIVE: If direct_io is set then it is directIO,
4698 * the failed direct I/O should be redirected to volume
4700 if (mpt3sas_scsi_direct_io_get(ioc
, smid
) &&
4701 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4702 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4703 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4704 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4705 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4706 mpt3sas_scsi_direct_io_set(ioc
, smid
, 0);
4707 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4708 mpi_request
->DevHandle
=
4709 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4710 ioc
->put_smid_scsi_io(ioc
, smid
,
4711 sas_device_priv_data
->sas_target
->handle
);
4714 /* turning off TLR */
4715 scsi_state
= mpi_reply
->SCSIState
;
4716 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4718 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4719 if (!sas_device_priv_data
->tlr_snoop_check
) {
4720 sas_device_priv_data
->tlr_snoop_check
++;
4721 if (!ioc
->is_warpdrive
&&
4722 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4723 sas_is_tlr_enabled(scmd
->device
) &&
4724 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4725 sas_disable_tlr(scmd
->device
);
4726 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4730 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4731 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4732 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4733 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4736 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4737 scsi_status
= mpi_reply
->SCSIStatus
;
4739 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4740 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4741 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4742 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4743 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4746 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4747 struct sense_info data
;
4748 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4750 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4751 le32_to_cpu(mpi_reply
->SenseCount
));
4752 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4753 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4754 /* failure prediction threshold exceeded */
4755 if (data
.asc
== 0x5D)
4756 _scsih_smart_predicted_fault(ioc
,
4757 le16_to_cpu(mpi_reply
->DevHandle
));
4758 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4760 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4761 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4762 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4763 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4764 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4766 switch (ioc_status
) {
4767 case MPI2_IOCSTATUS_BUSY
:
4768 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4769 scmd
->result
= SAM_STAT_BUSY
;
4772 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4773 scmd
->result
= DID_NO_CONNECT
<< 16;
4776 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4777 if (sas_device_priv_data
->block
) {
4778 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4781 if (log_info
== 0x31110630) {
4782 if (scmd
->retries
> 2) {
4783 scmd
->result
= DID_NO_CONNECT
<< 16;
4784 scsi_device_set_state(scmd
->device
,
4787 scmd
->result
= DID_SOFT_ERROR
<< 16;
4788 scmd
->device
->expecting_cc_ua
= 1;
4791 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4792 scmd
->result
= DID_RESET
<< 16;
4795 scmd
->result
= DID_SOFT_ERROR
<< 16;
4797 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4798 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4799 scmd
->result
= DID_RESET
<< 16;
4802 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4803 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4804 scmd
->result
= DID_SOFT_ERROR
<< 16;
4806 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4809 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4810 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4812 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4815 if (xfer_cnt
< scmd
->underflow
) {
4816 if (scsi_status
== SAM_STAT_BUSY
)
4817 scmd
->result
= SAM_STAT_BUSY
;
4819 scmd
->result
= DID_SOFT_ERROR
<< 16;
4820 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4821 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4822 scmd
->result
= DID_SOFT_ERROR
<< 16;
4823 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4824 scmd
->result
= DID_RESET
<< 16;
4825 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4826 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4827 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4828 scmd
->result
= (DRIVER_SENSE
<< 24) |
4829 SAM_STAT_CHECK_CONDITION
;
4830 scmd
->sense_buffer
[0] = 0x70;
4831 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4832 scmd
->sense_buffer
[12] = 0x20;
4833 scmd
->sense_buffer
[13] = 0;
4837 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4838 scsi_set_resid(scmd
, 0);
4839 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4840 case MPI2_IOCSTATUS_SUCCESS
:
4841 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4842 if (response_code
==
4843 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4844 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4845 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4846 scmd
->result
= DID_SOFT_ERROR
<< 16;
4847 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4848 scmd
->result
= DID_RESET
<< 16;
4851 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4852 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4853 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4854 _scsih_eedp_error_handling(scmd
, ioc_status
);
4857 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4858 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4859 case MPI2_IOCSTATUS_INVALID_SGL
:
4860 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4861 case MPI2_IOCSTATUS_INVALID_FIELD
:
4862 case MPI2_IOCSTATUS_INVALID_STATE
:
4863 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4864 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4865 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4867 scmd
->result
= DID_SOFT_ERROR
<< 16;
4872 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4873 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4877 scsi_dma_unmap(scmd
);
4879 scmd
->scsi_done(scmd
);
4884 * _scsih_sas_host_refresh - refreshing sas host object contents
4885 * @ioc: per adapter object
4888 * During port enable, fw will send topology events for every device. Its
4889 * possible that the handles may change from the previous setting, so this
4890 * code keeping handles updating if changed.
4895 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4900 Mpi2ConfigReply_t mpi_reply
;
4901 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4902 u16 attached_handle
;
4905 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4906 "updating handles for sas_host(0x%016llx)\n",
4907 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4909 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4910 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4911 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4912 if (!sas_iounit_pg0
) {
4913 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4914 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4918 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4919 sas_iounit_pg0
, sz
)) != 0)
4921 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4922 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4924 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4925 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4927 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4928 PhyData
[0].ControllerDevHandle
);
4929 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4930 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4932 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4933 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4934 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4935 attached_handle
, i
, link_rate
);
4938 kfree(sas_iounit_pg0
);
4942 * _scsih_sas_host_add - create sas host object
4943 * @ioc: per adapter object
4945 * Creating host side data object, stored in ioc->sas_hba
4950 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4953 Mpi2ConfigReply_t mpi_reply
;
4954 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4955 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4956 Mpi2SasPhyPage0_t phy_pg0
;
4957 Mpi2SasDevicePage0_t sas_device_pg0
;
4958 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4961 u8 device_missing_delay
;
4964 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
4966 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4967 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4970 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
4971 sizeof(struct _sas_phy
), GFP_KERNEL
);
4972 if (!ioc
->sas_hba
.phy
) {
4973 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4974 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4977 ioc
->sas_hba
.num_phys
= num_phys
;
4979 /* sas_iounit page 0 */
4980 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4981 sizeof(Mpi2SasIOUnit0PhyData_t
));
4982 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4983 if (!sas_iounit_pg0
) {
4984 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4985 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4988 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4989 sas_iounit_pg0
, sz
))) {
4990 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4991 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4994 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4995 MPI2_IOCSTATUS_MASK
;
4996 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4997 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4998 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5002 /* sas_iounit page 1 */
5003 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5004 sizeof(Mpi2SasIOUnit1PhyData_t
));
5005 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5006 if (!sas_iounit_pg1
) {
5007 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5008 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5011 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5012 sas_iounit_pg1
, sz
))) {
5013 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5014 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5017 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5018 MPI2_IOCSTATUS_MASK
;
5019 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5020 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5021 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5025 ioc
->io_missing_delay
=
5026 sas_iounit_pg1
->IODeviceMissingDelay
;
5027 device_missing_delay
=
5028 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5029 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5030 ioc
->device_missing_delay
= (device_missing_delay
&
5031 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5033 ioc
->device_missing_delay
= device_missing_delay
&
5034 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5036 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5037 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5038 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5040 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5041 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5044 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5045 MPI2_IOCSTATUS_MASK
;
5046 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5047 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5048 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5053 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5054 PhyData
[0].ControllerDevHandle
);
5055 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5056 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5057 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5058 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5060 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5061 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5062 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5063 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5066 ioc
->sas_hba
.enclosure_handle
=
5067 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5068 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5070 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5071 ioc
->name
, ioc
->sas_hba
.handle
,
5072 (unsigned long long) ioc
->sas_hba
.sas_address
,
5073 ioc
->sas_hba
.num_phys
) ;
5075 if (ioc
->sas_hba
.enclosure_handle
) {
5076 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5077 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5078 ioc
->sas_hba
.enclosure_handle
)))
5079 ioc
->sas_hba
.enclosure_logical_id
=
5080 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5084 kfree(sas_iounit_pg1
);
5085 kfree(sas_iounit_pg0
);
5089 * _scsih_expander_add - creating expander object
5090 * @ioc: per adapter object
5091 * @handle: expander handle
5093 * Creating expander object, stored in ioc->sas_expander_list.
5095 * Return 0 for success, else error.
5098 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5100 struct _sas_node
*sas_expander
;
5101 Mpi2ConfigReply_t mpi_reply
;
5102 Mpi2ExpanderPage0_t expander_pg0
;
5103 Mpi2ExpanderPage1_t expander_pg1
;
5104 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5107 u64 sas_address
, sas_address_parent
= 0;
5109 unsigned long flags
;
5110 struct _sas_port
*mpt3sas_port
= NULL
;
5117 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5120 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5121 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5122 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5123 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5127 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5128 MPI2_IOCSTATUS_MASK
;
5129 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5130 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5131 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5135 /* handle out of order topology events */
5136 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5137 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5139 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5140 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5143 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5144 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5145 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5146 sas_address_parent
);
5147 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5148 if (!sas_expander
) {
5149 rc
= _scsih_expander_add(ioc
, parent_handle
);
5155 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5156 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5157 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5159 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5164 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5166 if (!sas_expander
) {
5167 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5168 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5172 sas_expander
->handle
= handle
;
5173 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5174 sas_expander
->sas_address_parent
= sas_address_parent
;
5175 sas_expander
->sas_address
= sas_address
;
5177 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
5178 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
5179 handle
, parent_handle
, (unsigned long long)
5180 sas_expander
->sas_address
, sas_expander
->num_phys
);
5182 if (!sas_expander
->num_phys
)
5184 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5185 sizeof(struct _sas_phy
), GFP_KERNEL
);
5186 if (!sas_expander
->phy
) {
5187 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5188 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5193 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5194 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5195 sas_address_parent
);
5196 if (!mpt3sas_port
) {
5197 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5198 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5202 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5204 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5205 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5206 &expander_pg1
, i
, handle
))) {
5207 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5208 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5212 sas_expander
->phy
[i
].handle
= handle
;
5213 sas_expander
->phy
[i
].phy_id
= i
;
5215 if ((mpt3sas_transport_add_expander_phy(ioc
,
5216 &sas_expander
->phy
[i
], expander_pg1
,
5217 sas_expander
->parent_dev
))) {
5218 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5219 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5225 if (sas_expander
->enclosure_handle
) {
5226 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5227 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5228 sas_expander
->enclosure_handle
)))
5229 sas_expander
->enclosure_logical_id
=
5230 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5233 _scsih_expander_node_add(ioc
, sas_expander
);
5239 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5240 sas_address_parent
);
5241 kfree(sas_expander
);
5246 * mpt3sas_expander_remove - removing expander object
5247 * @ioc: per adapter object
5248 * @sas_address: expander sas_address
5253 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5255 struct _sas_node
*sas_expander
;
5256 unsigned long flags
;
5258 if (ioc
->shost_recovery
)
5261 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5262 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5265 list_del(&sas_expander
->list
);
5266 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5268 _scsih_expander_node_remove(ioc
, sas_expander
);
5272 * _scsih_done - internal SCSI_IO callback handler.
5273 * @ioc: per adapter object
5274 * @smid: system request message index
5275 * @msix_index: MSIX table index supplied by the OS
5276 * @reply: reply message frame(lower 32bit addr)
5278 * Callback handler when sending internal generated SCSI_IO.
5279 * The callback index passed is `ioc->scsih_cb_idx`
5281 * Return 1 meaning mf should be freed from _base_interrupt
5282 * 0 means the mf is freed from this function.
5285 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5287 MPI2DefaultReply_t
*mpi_reply
;
5289 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5290 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5292 if (ioc
->scsih_cmds
.smid
!= smid
)
5294 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5296 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5297 mpi_reply
->MsgLength
*4);
5298 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5300 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5301 complete(&ioc
->scsih_cmds
.done
);
5308 #define MPT3_MAX_LUNS (255)
5312 * _scsih_check_access_status - check access flags
5313 * @ioc: per adapter object
5314 * @sas_address: sas address
5315 * @handle: sas device handle
5316 * @access_flags: errors returned during discovery of the device
5318 * Return 0 for success, else failure
5321 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5322 u16 handle
, u8 access_status
)
5327 switch (access_status
) {
5328 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5329 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5332 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5333 desc
= "sata capability failed";
5335 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5336 desc
= "sata affiliation conflict";
5338 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5339 desc
= "route not addressable";
5341 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5342 desc
= "smp error not addressable";
5344 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5345 desc
= "device blocked";
5347 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5348 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5349 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5350 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5351 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5352 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5353 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5354 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5355 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5356 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5357 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5358 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5359 desc
= "sata initialization failed";
5370 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5371 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
5376 * _scsih_check_device - checking device responsiveness
5377 * @ioc: per adapter object
5378 * @parent_sas_address: sas address of parent expander or sas host
5379 * @handle: attached device handle
5380 * @phy_numberv: phy number
5381 * @link_rate: new link rate
5386 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5387 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5389 Mpi2ConfigReply_t mpi_reply
;
5390 Mpi2SasDevicePage0_t sas_device_pg0
;
5391 struct _sas_device
*sas_device
;
5393 unsigned long flags
;
5395 struct scsi_target
*starget
;
5396 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5400 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5401 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5404 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5405 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5408 /* wide port handling ~ we need only handle device once for the phy that
5409 * is matched in sas device page zero
5411 if (phy_number
!= sas_device_pg0
.PhyNum
)
5414 /* check if this is end device */
5415 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5416 if (!(_scsih_is_end_device(device_info
)))
5419 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5420 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5421 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5427 if (unlikely(sas_device
->handle
!= handle
)) {
5428 starget
= sas_device
->starget
;
5429 sas_target_priv_data
= starget
->hostdata
;
5430 starget_printk(KERN_INFO
, starget
,
5431 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5432 sas_device
->handle
, handle
);
5433 sas_target_priv_data
->handle
= handle
;
5434 sas_device
->handle
= handle
;
5435 if (le16_to_cpu(sas_device_pg0
.Flags
) &
5436 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5437 sas_device
->enclosure_level
=
5438 sas_device_pg0
.EnclosureLevel
;
5439 memcpy(sas_device
->connector_name
,
5440 sas_device_pg0
.ConnectorName
, 4);
5441 sas_device
->connector_name
[4] = '\0';
5443 sas_device
->enclosure_level
= 0;
5444 sas_device
->connector_name
[0] = '\0';
5448 /* check if device is present */
5449 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5450 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5452 "device is not present handle(0x%04x), flags!!!\n",
5457 /* check if there were any issues with discovery */
5458 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5459 sas_device_pg0
.AccessStatus
))
5462 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5463 _scsih_ublock_io_device(ioc
, sas_address
);
5466 sas_device_put(sas_device
);
5470 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5472 sas_device_put(sas_device
);
5476 * _scsih_add_device - creating sas device object
5477 * @ioc: per adapter object
5478 * @handle: sas device handle
5479 * @phy_num: phy number end device attached to
5480 * @is_pd: is this hidden raid component
5482 * Creating end device object, stored in ioc->sas_device_list.
5484 * Returns 0 for success, non-zero for failure.
5487 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
5490 Mpi2ConfigReply_t mpi_reply
;
5491 Mpi2SasDevicePage0_t sas_device_pg0
;
5492 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5493 struct _sas_device
*sas_device
;
5498 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5499 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5500 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5501 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5505 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5506 MPI2_IOCSTATUS_MASK
;
5507 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5508 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5509 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5513 /* check if this is end device */
5514 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5515 if (!(_scsih_is_end_device(device_info
)))
5517 set_bit(handle
, ioc
->pend_os_device_add
);
5518 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5520 /* check if device is present */
5521 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5522 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5523 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5528 /* check if there were any issues with discovery */
5529 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5530 sas_device_pg0
.AccessStatus
))
5533 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
5536 clear_bit(handle
, ioc
->pend_os_device_add
);
5537 sas_device_put(sas_device
);
5541 sas_device
= kzalloc(sizeof(struct _sas_device
),
5544 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5545 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5549 kref_init(&sas_device
->refcount
);
5550 sas_device
->handle
= handle
;
5551 if (_scsih_get_sas_address(ioc
,
5552 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5553 &sas_device
->sas_address_parent
) != 0)
5554 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5555 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5556 sas_device
->enclosure_handle
=
5557 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5558 if (sas_device
->enclosure_handle
!= 0)
5560 le16_to_cpu(sas_device_pg0
.Slot
);
5561 sas_device
->device_info
= device_info
;
5562 sas_device
->sas_address
= sas_address
;
5563 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5564 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5565 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5567 if (le16_to_cpu(sas_device_pg0
.Flags
)
5568 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5569 sas_device
->enclosure_level
=
5570 sas_device_pg0
.EnclosureLevel
;
5571 memcpy(sas_device
->connector_name
,
5572 sas_device_pg0
.ConnectorName
, 4);
5573 sas_device
->connector_name
[4] = '\0';
5575 sas_device
->enclosure_level
= 0;
5576 sas_device
->connector_name
[0] = '\0';
5578 /* get enclosure_logical_id */
5579 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5580 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5581 sas_device
->enclosure_handle
)))
5582 sas_device
->enclosure_logical_id
=
5583 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5585 /* get device name */
5586 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5588 if (ioc
->wait_for_discovery_to_complete
)
5589 _scsih_sas_device_init_add(ioc
, sas_device
);
5591 _scsih_sas_device_add(ioc
, sas_device
);
5593 sas_device_put(sas_device
);
5598 * _scsih_remove_device - removing sas device object
5599 * @ioc: per adapter object
5600 * @sas_device_delete: the sas_device object
5605 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5606 struct _sas_device
*sas_device
)
5608 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5610 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5611 (sas_device
->pfa_led_on
)) {
5612 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5613 sas_device
->pfa_led_on
= 0;
5615 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5616 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5617 ioc
->name
, __func__
,
5618 sas_device
->handle
, (unsigned long long)
5619 sas_device
->sas_address
));
5620 if (sas_device
->enclosure_handle
!= 0)
5621 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5622 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5623 ioc
->name
, __func__
,
5624 (unsigned long long)sas_device
->enclosure_logical_id
,
5626 if (sas_device
->connector_name
[0] != '\0')
5627 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5628 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5629 ioc
->name
, __func__
,
5630 sas_device
->enclosure_level
,
5631 sas_device
->connector_name
));
5633 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5634 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5635 sas_target_priv_data
->deleted
= 1;
5636 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5637 sas_target_priv_data
->handle
=
5638 MPT3SAS_INVALID_DEVICE_HANDLE
;
5641 if (!ioc
->hide_drives
)
5642 mpt3sas_transport_port_remove(ioc
,
5643 sas_device
->sas_address
,
5644 sas_device
->sas_address_parent
);
5647 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5648 ioc
->name
, sas_device
->handle
,
5649 (unsigned long long) sas_device
->sas_address
);
5650 if (sas_device
->enclosure_handle
!= 0)
5652 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5654 (unsigned long long)sas_device
->enclosure_logical_id
,
5656 if (sas_device
->connector_name
[0] != '\0')
5658 "removing enclosure level(0x%04x), connector name( %s)\n",
5659 ioc
->name
, sas_device
->enclosure_level
,
5660 sas_device
->connector_name
);
5662 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5663 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5664 ioc
->name
, __func__
,
5665 sas_device
->handle
, (unsigned long long)
5666 sas_device
->sas_address
));
5667 if (sas_device
->enclosure_handle
!= 0)
5668 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5669 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5670 ioc
->name
, __func__
,
5671 (unsigned long long)sas_device
->enclosure_logical_id
,
5673 if (sas_device
->connector_name
[0] != '\0')
5674 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5675 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5676 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5677 sas_device
->connector_name
));
5681 * _scsih_sas_topology_change_event_debug - debug for topology event
5682 * @ioc: per adapter object
5683 * @event_data: event data payload
5687 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5688 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5694 char *status_str
= NULL
;
5695 u8 link_rate
, prev_link_rate
;
5697 switch (event_data
->ExpStatus
) {
5698 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5701 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5702 status_str
= "remove";
5704 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5706 status_str
= "responding";
5708 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5709 status_str
= "remove delay";
5712 status_str
= "unknown status";
5715 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5716 ioc
->name
, status_str
);
5717 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5718 "start_phy(%02d), count(%d)\n",
5719 le16_to_cpu(event_data
->ExpanderDevHandle
),
5720 le16_to_cpu(event_data
->EnclosureHandle
),
5721 event_data
->StartPhyNum
, event_data
->NumEntries
);
5722 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5723 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5726 phy_number
= event_data
->StartPhyNum
+ i
;
5727 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5728 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5729 switch (reason_code
) {
5730 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5731 status_str
= "target add";
5733 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5734 status_str
= "target remove";
5736 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5737 status_str
= "delay target remove";
5739 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5740 status_str
= "link rate change";
5742 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5743 status_str
= "target responding";
5746 status_str
= "unknown";
5749 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5750 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5751 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5752 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5753 handle
, status_str
, link_rate
, prev_link_rate
);
5759 * _scsih_sas_topology_change_event - handle topology changes
5760 * @ioc: per adapter object
5761 * @fw_event: The fw_event_work object
5766 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5767 struct fw_event_work
*fw_event
)
5770 u16 parent_handle
, handle
;
5772 u8 phy_number
, max_phys
;
5773 struct _sas_node
*sas_expander
;
5775 unsigned long flags
;
5776 u8 link_rate
, prev_link_rate
;
5777 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5778 (Mpi2EventDataSasTopologyChangeList_t
*)
5779 fw_event
->event_data
;
5781 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5782 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5784 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5787 if (!ioc
->sas_hba
.num_phys
)
5788 _scsih_sas_host_add(ioc
);
5790 _scsih_sas_host_refresh(ioc
);
5792 if (fw_event
->ignore
) {
5793 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5794 "ignoring expander event\n", ioc
->name
));
5798 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5800 /* handle expander add */
5801 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5802 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5805 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5806 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5809 sas_address
= sas_expander
->sas_address
;
5810 max_phys
= sas_expander
->num_phys
;
5811 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5812 sas_address
= ioc
->sas_hba
.sas_address
;
5813 max_phys
= ioc
->sas_hba
.num_phys
;
5815 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5818 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5820 /* handle siblings events */
5821 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5822 if (fw_event
->ignore
) {
5823 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5824 "ignoring expander event\n", ioc
->name
));
5827 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5829 phy_number
= event_data
->StartPhyNum
+ i
;
5830 if (phy_number
>= max_phys
)
5832 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5833 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5834 if ((event_data
->PHY
[i
].PhyStatus
&
5835 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5836 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5838 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5841 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5842 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5843 switch (reason_code
) {
5844 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5846 if (ioc
->shost_recovery
)
5849 if (link_rate
== prev_link_rate
)
5852 mpt3sas_transport_update_links(ioc
, sas_address
,
5853 handle
, phy_number
, link_rate
);
5855 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5858 _scsih_check_device(ioc
, sas_address
, handle
,
5859 phy_number
, link_rate
);
5861 if (!test_bit(handle
, ioc
->pend_os_device_add
))
5865 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5867 if (ioc
->shost_recovery
)
5870 mpt3sas_transport_update_links(ioc
, sas_address
,
5871 handle
, phy_number
, link_rate
);
5873 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5876 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5878 _scsih_device_remove_by_handle(ioc
, handle
);
5883 /* handle expander removal */
5884 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5886 mpt3sas_expander_remove(ioc
, sas_address
);
5892 * _scsih_sas_device_status_change_event_debug - debug for device event
5893 * @event_data: event data payload
5899 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5900 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5902 char *reason_str
= NULL
;
5904 switch (event_data
->ReasonCode
) {
5905 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5906 reason_str
= "smart data";
5908 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5909 reason_str
= "unsupported device discovered";
5911 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5912 reason_str
= "internal device reset";
5914 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5915 reason_str
= "internal task abort";
5917 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5918 reason_str
= "internal task abort set";
5920 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5921 reason_str
= "internal clear task set";
5923 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5924 reason_str
= "internal query task";
5926 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5927 reason_str
= "sata init failure";
5929 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5930 reason_str
= "internal device reset complete";
5932 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5933 reason_str
= "internal task abort complete";
5935 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5936 reason_str
= "internal async notification";
5938 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5939 reason_str
= "expander reduced functionality";
5941 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5942 reason_str
= "expander reduced functionality complete";
5945 reason_str
= "unknown reason";
5948 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5949 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5950 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5951 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5952 le16_to_cpu(event_data
->TaskTag
));
5953 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5954 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5955 event_data
->ASC
, event_data
->ASCQ
);
5960 * _scsih_sas_device_status_change_event - handle device status change
5961 * @ioc: per adapter object
5962 * @fw_event: The fw_event_work object
5968 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5969 struct fw_event_work
*fw_event
)
5971 struct MPT3SAS_TARGET
*target_priv_data
;
5972 struct _sas_device
*sas_device
;
5974 unsigned long flags
;
5975 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5976 (Mpi2EventDataSasDeviceStatusChange_t
*)
5977 fw_event
->event_data
;
5979 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5980 _scsih_sas_device_status_change_event_debug(ioc
,
5983 /* In MPI Revision K (0xC), the internal device reset complete was
5984 * implemented, so avoid setting tm_busy flag for older firmware.
5986 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5989 if (event_data
->ReasonCode
!=
5990 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5991 event_data
->ReasonCode
!=
5992 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5995 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5996 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5997 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6000 if (!sas_device
|| !sas_device
->starget
)
6003 target_priv_data
= sas_device
->starget
->hostdata
;
6004 if (!target_priv_data
)
6007 if (event_data
->ReasonCode
==
6008 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6009 target_priv_data
->tm_busy
= 1;
6011 target_priv_data
->tm_busy
= 0;
6015 sas_device_put(sas_device
);
6017 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6022 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
6024 * @ioc: per adapter object
6025 * @event_data: event data payload
6031 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6032 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
6034 char *reason_str
= NULL
;
6036 switch (event_data
->ReasonCode
) {
6037 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
6038 reason_str
= "enclosure add";
6040 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
6041 reason_str
= "enclosure remove";
6044 reason_str
= "unknown reason";
6048 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
6049 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
6050 " number slots(%d)\n", ioc
->name
, reason_str
,
6051 le16_to_cpu(event_data
->EnclosureHandle
),
6052 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
6053 le16_to_cpu(event_data
->StartSlot
));
6057 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
6058 * @ioc: per adapter object
6059 * @fw_event: The fw_event_work object
6065 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6066 struct fw_event_work
*fw_event
)
6068 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6069 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
6070 (Mpi2EventDataSasEnclDevStatusChange_t
*)
6071 fw_event
->event_data
);
6075 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6076 * @ioc: per adapter object
6077 * @fw_event: The fw_event_work object
6083 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
6084 struct fw_event_work
*fw_event
)
6086 struct scsi_cmnd
*scmd
;
6087 struct scsi_device
*sdev
;
6090 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6091 u32 termination_count
;
6093 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
6094 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
6095 (Mpi2EventDataSasBroadcastPrimitive_t
*)
6096 fw_event
->event_data
;
6098 unsigned long flags
;
6101 u8 task_abort_retries
;
6103 mutex_lock(&ioc
->tm_cmds
.mutex
);
6105 "%s: enter: phy number(%d), width(%d)\n",
6106 ioc
->name
, __func__
, event_data
->PhyNum
,
6107 event_data
->PortWidth
);
6109 _scsih_block_io_all_device(ioc
);
6111 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6112 mpi_reply
= ioc
->tm_cmds
.reply
;
6113 broadcast_aen_retry
:
6115 /* sanity checks for retrying this loop */
6116 if (max_retries
++ == 5) {
6117 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
6118 ioc
->name
, __func__
));
6120 } else if (max_retries
> 1)
6121 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
6122 ioc
->name
, __func__
, max_retries
- 1));
6124 termination_count
= 0;
6126 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
6127 if (ioc
->shost_recovery
)
6129 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
6132 sdev
= scmd
->device
;
6133 sas_device_priv_data
= sdev
->hostdata
;
6134 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
6136 /* skip hidden raid components */
6137 if (sas_device_priv_data
->sas_target
->flags
&
6138 MPT_TARGET_FLAGS_RAID_COMPONENT
)
6141 if (sas_device_priv_data
->sas_target
->flags
&
6142 MPT_TARGET_FLAGS_VOLUME
)
6145 handle
= sas_device_priv_data
->sas_target
->handle
;
6146 lun
= sas_device_priv_data
->lun
;
6149 if (ioc
->shost_recovery
)
6152 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6153 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
6154 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30);
6156 sdev_printk(KERN_WARNING
, sdev
,
6157 "mpt3sas_scsih_issue_tm: FAILED when sending "
6158 "QUERY_TASK: scmd(%p)\n", scmd
);
6159 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6160 goto broadcast_aen_retry
;
6162 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
6163 & MPI2_IOCSTATUS_MASK
;
6164 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6165 sdev_printk(KERN_WARNING
, sdev
,
6166 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6168 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6169 goto broadcast_aen_retry
;
6172 /* see if IO is still owned by IOC and target */
6173 if (mpi_reply
->ResponseCode
==
6174 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
6175 mpi_reply
->ResponseCode
==
6176 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
6177 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6180 task_abort_retries
= 0;
6182 if (task_abort_retries
++ == 60) {
6183 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6184 "%s: ABORT_TASK: giving up\n", ioc
->name
,
6186 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6187 goto broadcast_aen_retry
;
6190 if (ioc
->shost_recovery
)
6193 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
6194 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
,
6197 sdev_printk(KERN_WARNING
, sdev
,
6198 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6199 "scmd(%p)\n", scmd
);
6203 if (task_abort_retries
> 1)
6204 sdev_printk(KERN_WARNING
, sdev
,
6205 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6207 task_abort_retries
- 1, scmd
);
6209 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
6210 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6213 if (ioc
->broadcast_aen_pending
) {
6214 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6215 "%s: loop back due to pending AEN\n",
6216 ioc
->name
, __func__
));
6217 ioc
->broadcast_aen_pending
= 0;
6218 goto broadcast_aen_retry
;
6222 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6225 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6226 "%s - exit, query_count = %d termination_count = %d\n",
6227 ioc
->name
, __func__
, query_count
, termination_count
));
6229 ioc
->broadcast_aen_busy
= 0;
6230 if (!ioc
->shost_recovery
)
6231 _scsih_ublock_io_all_device(ioc
);
6232 mutex_unlock(&ioc
->tm_cmds
.mutex
);
6236 * _scsih_sas_discovery_event - handle discovery events
6237 * @ioc: per adapter object
6238 * @fw_event: The fw_event_work object
6244 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
6245 struct fw_event_work
*fw_event
)
6247 Mpi2EventDataSasDiscovery_t
*event_data
=
6248 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
6250 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
6251 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
6252 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
6254 if (event_data
->DiscoveryStatus
)
6255 pr_info("discovery_status(0x%08x)",
6256 le32_to_cpu(event_data
->DiscoveryStatus
));
6260 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
6261 !ioc
->sas_hba
.num_phys
) {
6262 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6263 /* Wait for the reset to complete */
6264 while (ioc
->shost_recovery
)
6267 _scsih_sas_host_add(ioc
);
6272 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6273 * @ioc: per adapter object
6274 * @handle: device handle for physical disk
6275 * @phys_disk_num: physical disk number
6277 * Return 0 for success, else failure.
6280 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
6282 Mpi2RaidActionRequest_t
*mpi_request
;
6283 Mpi2RaidActionReply_t
*mpi_reply
;
6290 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
6293 mutex_lock(&ioc
->scsih_cmds
.mutex
);
6295 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
6296 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
6297 ioc
->name
, __func__
);
6301 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
6303 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
6305 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
6306 ioc
->name
, __func__
);
6307 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6312 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
6313 ioc
->scsih_cmds
.smid
= smid
;
6314 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
6316 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
6317 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
6318 mpi_request
->PhysDiskNum
= phys_disk_num
;
6320 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
6321 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
6322 handle
, phys_disk_num
));
6324 init_completion(&ioc
->scsih_cmds
.done
);
6325 ioc
->put_smid_default(ioc
, smid
);
6326 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
6328 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
6329 pr_err(MPT3SAS_FMT
"%s: timeout\n",
6330 ioc
->name
, __func__
);
6331 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
6337 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
6339 mpi_reply
= ioc
->scsih_cmds
.reply
;
6340 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
6341 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
6342 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
6345 ioc_status
&= MPI2_IOCSTATUS_MASK
;
6346 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6347 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6348 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6349 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
6353 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6354 "IR RAID_ACTION: completed successfully\n",
6359 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6360 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
6363 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
6368 * _scsih_reprobe_lun - reprobing lun
6369 * @sdev: scsi device struct
6370 * @no_uld_attach: sdev->no_uld_attach flag setting
6374 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6376 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6377 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6378 sdev
->no_uld_attach
? "hiding" : "exposing");
6379 WARN_ON(scsi_device_reprobe(sdev
));
6383 * _scsih_sas_volume_add - add new volume
6384 * @ioc: per adapter object
6385 * @element: IR config element data
6391 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
6392 Mpi2EventIrConfigElement_t
*element
)
6394 struct _raid_device
*raid_device
;
6395 unsigned long flags
;
6397 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6400 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6403 "failure at %s:%d/%s()!\n", ioc
->name
,
6404 __FILE__
, __LINE__
, __func__
);
6408 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6409 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6410 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6415 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6418 "failure at %s:%d/%s()!\n", ioc
->name
,
6419 __FILE__
, __LINE__
, __func__
);
6423 raid_device
->id
= ioc
->sas_id
++;
6424 raid_device
->channel
= RAID_CHANNEL
;
6425 raid_device
->handle
= handle
;
6426 raid_device
->wwid
= wwid
;
6427 _scsih_raid_device_add(ioc
, raid_device
);
6428 if (!ioc
->wait_for_discovery_to_complete
) {
6429 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6430 raid_device
->id
, 0);
6432 _scsih_raid_device_remove(ioc
, raid_device
);
6434 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6435 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6436 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6441 * _scsih_sas_volume_delete - delete volume
6442 * @ioc: per adapter object
6443 * @handle: volume device handle
6449 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6451 struct _raid_device
*raid_device
;
6452 unsigned long flags
;
6453 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6454 struct scsi_target
*starget
= NULL
;
6456 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6457 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6459 if (raid_device
->starget
) {
6460 starget
= raid_device
->starget
;
6461 sas_target_priv_data
= starget
->hostdata
;
6462 sas_target_priv_data
->deleted
= 1;
6464 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
6465 ioc
->name
, raid_device
->handle
,
6466 (unsigned long long) raid_device
->wwid
);
6467 list_del(&raid_device
->list
);
6470 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6472 scsi_remove_target(&starget
->dev
);
6476 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6477 * @ioc: per adapter object
6478 * @element: IR config element data
6484 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6485 Mpi2EventIrConfigElement_t
*element
)
6487 struct _sas_device
*sas_device
;
6488 struct scsi_target
*starget
= NULL
;
6489 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6490 unsigned long flags
;
6491 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6493 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6494 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6496 sas_device
->volume_handle
= 0;
6497 sas_device
->volume_wwid
= 0;
6498 clear_bit(handle
, ioc
->pd_handles
);
6499 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6500 starget
= sas_device
->starget
;
6501 sas_target_priv_data
= starget
->hostdata
;
6502 sas_target_priv_data
->flags
&=
6503 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6506 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6510 /* exposing raid component */
6512 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6514 sas_device_put(sas_device
);
6518 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6519 * @ioc: per adapter object
6520 * @element: IR config element data
6526 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6527 Mpi2EventIrConfigElement_t
*element
)
6529 struct _sas_device
*sas_device
;
6530 struct scsi_target
*starget
= NULL
;
6531 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6532 unsigned long flags
;
6533 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6534 u16 volume_handle
= 0;
6535 u64 volume_wwid
= 0;
6537 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6539 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6542 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6543 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
6545 set_bit(handle
, ioc
->pd_handles
);
6546 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6547 starget
= sas_device
->starget
;
6548 sas_target_priv_data
= starget
->hostdata
;
6549 sas_target_priv_data
->flags
|=
6550 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6551 sas_device
->volume_handle
= volume_handle
;
6552 sas_device
->volume_wwid
= volume_wwid
;
6555 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6559 /* hiding raid component */
6560 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6563 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6565 sas_device_put(sas_device
);
6569 * _scsih_sas_pd_delete - delete pd component
6570 * @ioc: per adapter object
6571 * @element: IR config element data
6577 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6578 Mpi2EventIrConfigElement_t
*element
)
6580 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6582 _scsih_device_remove_by_handle(ioc
, handle
);
6586 * _scsih_sas_pd_add - remove pd component
6587 * @ioc: per adapter object
6588 * @element: IR config element data
6594 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6595 Mpi2EventIrConfigElement_t
*element
)
6597 struct _sas_device
*sas_device
;
6598 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6599 Mpi2ConfigReply_t mpi_reply
;
6600 Mpi2SasDevicePage0_t sas_device_pg0
;
6605 set_bit(handle
, ioc
->pd_handles
);
6607 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6609 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6610 sas_device_put(sas_device
);
6614 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6615 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6616 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6617 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6621 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6622 MPI2_IOCSTATUS_MASK
;
6623 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6624 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6625 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6629 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6630 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6631 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6632 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6634 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6635 _scsih_add_device(ioc
, handle
, 0, 1);
6639 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6640 * @ioc: per adapter object
6641 * @event_data: event data payload
6647 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6648 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6650 Mpi2EventIrConfigElement_t
*element
;
6653 char *reason_str
= NULL
, *element_str
= NULL
;
6655 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6657 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6658 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6659 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6660 "foreign" : "native", event_data
->NumElements
);
6661 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6662 switch (element
->ReasonCode
) {
6663 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6666 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6667 reason_str
= "remove";
6669 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6670 reason_str
= "no change";
6672 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6673 reason_str
= "hide";
6675 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6676 reason_str
= "unhide";
6678 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6679 reason_str
= "volume_created";
6681 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6682 reason_str
= "volume_deleted";
6684 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6685 reason_str
= "pd_created";
6687 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6688 reason_str
= "pd_deleted";
6691 reason_str
= "unknown reason";
6694 element_type
= le16_to_cpu(element
->ElementFlags
) &
6695 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6696 switch (element_type
) {
6697 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6698 element_str
= "volume";
6700 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6701 element_str
= "phys disk";
6703 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6704 element_str
= "hot spare";
6707 element_str
= "unknown element";
6710 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6711 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6712 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6713 le16_to_cpu(element
->PhysDiskDevHandle
),
6714 element
->PhysDiskNum
);
6719 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6720 * @ioc: per adapter object
6721 * @fw_event: The fw_event_work object
6727 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6728 struct fw_event_work
*fw_event
)
6730 Mpi2EventIrConfigElement_t
*element
;
6733 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6734 (Mpi2EventDataIrConfigChangeList_t
*)
6735 fw_event
->event_data
;
6737 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
6738 (!ioc
->hide_ir_msg
))
6739 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6741 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6742 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6744 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6745 if (ioc
->shost_recovery
&&
6746 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
6747 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6748 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6749 _scsih_ir_fastpath(ioc
,
6750 le16_to_cpu(element
->PhysDiskDevHandle
),
6751 element
->PhysDiskNum
);
6756 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6758 switch (element
->ReasonCode
) {
6759 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6760 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6761 if (!foreign_config
)
6762 _scsih_sas_volume_add(ioc
, element
);
6764 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6765 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6766 if (!foreign_config
)
6767 _scsih_sas_volume_delete(ioc
,
6768 le16_to_cpu(element
->VolDevHandle
));
6770 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6771 if (!ioc
->is_warpdrive
)
6772 _scsih_sas_pd_hide(ioc
, element
);
6774 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6775 if (!ioc
->is_warpdrive
)
6776 _scsih_sas_pd_expose(ioc
, element
);
6778 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6779 if (!ioc
->is_warpdrive
)
6780 _scsih_sas_pd_add(ioc
, element
);
6782 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6783 if (!ioc
->is_warpdrive
)
6784 _scsih_sas_pd_delete(ioc
, element
);
6791 * _scsih_sas_ir_volume_event - IR volume event
6792 * @ioc: per adapter object
6793 * @fw_event: The fw_event_work object
6799 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6800 struct fw_event_work
*fw_event
)
6803 unsigned long flags
;
6804 struct _raid_device
*raid_device
;
6808 Mpi2EventDataIrVolume_t
*event_data
=
6809 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6811 if (ioc
->shost_recovery
)
6814 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6817 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6818 state
= le32_to_cpu(event_data
->NewValue
);
6819 if (!ioc
->hide_ir_msg
)
6820 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6821 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6822 ioc
->name
, __func__
, handle
,
6823 le32_to_cpu(event_data
->PreviousValue
), state
));
6825 case MPI2_RAID_VOL_STATE_MISSING
:
6826 case MPI2_RAID_VOL_STATE_FAILED
:
6827 _scsih_sas_volume_delete(ioc
, handle
);
6830 case MPI2_RAID_VOL_STATE_ONLINE
:
6831 case MPI2_RAID_VOL_STATE_DEGRADED
:
6832 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6834 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6835 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
6836 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6841 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6844 "failure at %s:%d/%s()!\n", ioc
->name
,
6845 __FILE__
, __LINE__
, __func__
);
6849 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6852 "failure at %s:%d/%s()!\n", ioc
->name
,
6853 __FILE__
, __LINE__
, __func__
);
6857 raid_device
->id
= ioc
->sas_id
++;
6858 raid_device
->channel
= RAID_CHANNEL
;
6859 raid_device
->handle
= handle
;
6860 raid_device
->wwid
= wwid
;
6861 _scsih_raid_device_add(ioc
, raid_device
);
6862 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6863 raid_device
->id
, 0);
6865 _scsih_raid_device_remove(ioc
, raid_device
);
6868 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6875 * _scsih_sas_ir_physical_disk_event - PD event
6876 * @ioc: per adapter object
6877 * @fw_event: The fw_event_work object
6883 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6884 struct fw_event_work
*fw_event
)
6886 u16 handle
, parent_handle
;
6888 struct _sas_device
*sas_device
;
6889 Mpi2ConfigReply_t mpi_reply
;
6890 Mpi2SasDevicePage0_t sas_device_pg0
;
6892 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6893 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6896 if (ioc
->shost_recovery
)
6899 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6902 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6903 state
= le32_to_cpu(event_data
->NewValue
);
6905 if (!ioc
->hide_ir_msg
)
6906 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6907 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6908 ioc
->name
, __func__
, handle
,
6909 le32_to_cpu(event_data
->PreviousValue
), state
));
6912 case MPI2_RAID_PD_STATE_ONLINE
:
6913 case MPI2_RAID_PD_STATE_DEGRADED
:
6914 case MPI2_RAID_PD_STATE_REBUILDING
:
6915 case MPI2_RAID_PD_STATE_OPTIMAL
:
6916 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6918 if (!ioc
->is_warpdrive
)
6919 set_bit(handle
, ioc
->pd_handles
);
6921 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
6923 sas_device_put(sas_device
);
6927 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6928 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6930 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6931 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6935 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6936 MPI2_IOCSTATUS_MASK
;
6937 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6938 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6939 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6943 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6944 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6945 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6946 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6948 _scsih_add_device(ioc
, handle
, 0, 1);
6952 case MPI2_RAID_PD_STATE_OFFLINE
:
6953 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6954 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6961 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6962 * @ioc: per adapter object
6963 * @event_data: event data payload
6969 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6970 Mpi2EventDataIrOperationStatus_t
*event_data
)
6972 char *reason_str
= NULL
;
6974 switch (event_data
->RAIDOperation
) {
6975 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6976 reason_str
= "resync";
6978 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6979 reason_str
= "online capacity expansion";
6981 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6982 reason_str
= "consistency check";
6984 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6985 reason_str
= "background init";
6987 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6988 reason_str
= "make data consistent";
6995 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6996 "\thandle(0x%04x), percent complete(%d)\n",
6997 ioc
->name
, reason_str
,
6998 le16_to_cpu(event_data
->VolDevHandle
),
6999 event_data
->PercentComplete
);
7003 * _scsih_sas_ir_operation_status_event - handle RAID operation events
7004 * @ioc: per adapter object
7005 * @fw_event: The fw_event_work object
7011 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
7012 struct fw_event_work
*fw_event
)
7014 Mpi2EventDataIrOperationStatus_t
*event_data
=
7015 (Mpi2EventDataIrOperationStatus_t
*)
7016 fw_event
->event_data
;
7017 static struct _raid_device
*raid_device
;
7018 unsigned long flags
;
7021 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
7022 (!ioc
->hide_ir_msg
))
7023 _scsih_sas_ir_operation_status_event_debug(ioc
,
7026 /* code added for raid transport support */
7027 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
7029 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7030 handle
= le16_to_cpu(event_data
->VolDevHandle
);
7031 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7033 raid_device
->percent_complete
=
7034 event_data
->PercentComplete
;
7035 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7040 * _scsih_prep_device_scan - initialize parameters prior to device scan
7041 * @ioc: per adapter object
7043 * Set the deleted flag prior to device scan. If the device is found during
7044 * the scan, then we clear the deleted flag.
7047 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
7049 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7050 struct scsi_device
*sdev
;
7052 shost_for_each_device(sdev
, ioc
->shost
) {
7053 sas_device_priv_data
= sdev
->hostdata
;
7054 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
7055 sas_device_priv_data
->sas_target
->deleted
= 1;
7060 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
7061 * @ioc: per adapter object
7062 * @sas_device_pg0: SAS Device page 0
7064 * After host reset, find out whether devices are still responding.
7065 * Used in _scsih_remove_unresponsive_sas_devices.
7070 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
7071 Mpi2SasDevicePage0_t
*sas_device_pg0
)
7073 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7074 struct scsi_target
*starget
;
7075 struct _sas_device
*sas_device
;
7076 unsigned long flags
;
7078 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7079 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
7080 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
7081 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
7082 sas_device
->responding
= 1;
7083 starget
= sas_device
->starget
;
7084 if (starget
&& starget
->hostdata
) {
7085 sas_target_priv_data
= starget
->hostdata
;
7086 sas_target_priv_data
->tm_busy
= 0;
7087 sas_target_priv_data
->deleted
= 0;
7089 sas_target_priv_data
= NULL
;
7091 starget_printk(KERN_INFO
, starget
,
7092 "handle(0x%04x), sas_addr(0x%016llx)\n",
7093 sas_device_pg0
->DevHandle
,
7094 (unsigned long long)
7095 sas_device
->sas_address
);
7097 if (sas_device
->enclosure_handle
!= 0)
7098 starget_printk(KERN_INFO
, starget
,
7099 "enclosure logical id(0x%016llx),"
7101 (unsigned long long)
7102 sas_device
->enclosure_logical_id
,
7105 if (sas_device_pg0
->Flags
&
7106 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
7107 sas_device
->enclosure_level
=
7108 sas_device_pg0
->EnclosureLevel
;
7109 memcpy(&sas_device
->connector_name
[0],
7110 &sas_device_pg0
->ConnectorName
[0], 4);
7112 sas_device
->enclosure_level
= 0;
7113 sas_device
->connector_name
[0] = '\0';
7116 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
7118 pr_info("\thandle changed from(0x%04x)!!!\n",
7119 sas_device
->handle
);
7120 sas_device
->handle
= sas_device_pg0
->DevHandle
;
7121 if (sas_target_priv_data
)
7122 sas_target_priv_data
->handle
=
7123 sas_device_pg0
->DevHandle
;
7128 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7132 * _scsih_search_responding_sas_devices -
7133 * @ioc: per adapter object
7135 * After host reset, find out whether devices are still responding.
7141 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7143 Mpi2SasDevicePage0_t sas_device_pg0
;
7144 Mpi2ConfigReply_t mpi_reply
;
7149 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
7151 if (list_empty(&ioc
->sas_device_list
))
7155 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7156 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7158 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7159 MPI2_IOCSTATUS_MASK
;
7160 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7162 handle
= sas_device_pg0
.DevHandle
=
7163 le16_to_cpu(sas_device_pg0
.DevHandle
);
7164 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
7165 if (!(_scsih_is_end_device(device_info
)))
7167 sas_device_pg0
.SASAddress
=
7168 le64_to_cpu(sas_device_pg0
.SASAddress
);
7169 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
7170 sas_device_pg0
.Flags
= le16_to_cpu(sas_device_pg0
.Flags
);
7171 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
7175 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
7180 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7181 * @ioc: per adapter object
7182 * @wwid: world wide identifier for raid volume
7183 * @handle: device handle
7185 * After host reset, find out whether devices are still responding.
7186 * Used in _scsih_remove_unresponsive_raid_devices.
7191 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
7194 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
7195 struct scsi_target
*starget
;
7196 struct _raid_device
*raid_device
;
7197 unsigned long flags
;
7199 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7200 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
7201 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
7202 starget
= raid_device
->starget
;
7203 if (starget
&& starget
->hostdata
) {
7204 sas_target_priv_data
= starget
->hostdata
;
7205 sas_target_priv_data
->deleted
= 0;
7207 sas_target_priv_data
= NULL
;
7208 raid_device
->responding
= 1;
7209 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7210 starget_printk(KERN_INFO
, raid_device
->starget
,
7211 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
7212 (unsigned long long)raid_device
->wwid
);
7215 * WARPDRIVE: The handles of the PDs might have changed
7216 * across the host reset so re-initialize the
7217 * required data for Direct IO
7219 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
7220 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7221 if (raid_device
->handle
== handle
) {
7222 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
7226 pr_info("\thandle changed from(0x%04x)!!!\n",
7227 raid_device
->handle
);
7228 raid_device
->handle
= handle
;
7229 if (sas_target_priv_data
)
7230 sas_target_priv_data
->handle
= handle
;
7231 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7235 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7239 * _scsih_search_responding_raid_devices -
7240 * @ioc: per adapter object
7242 * After host reset, find out whether devices are still responding.
7248 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
7250 Mpi2RaidVolPage1_t volume_pg1
;
7251 Mpi2RaidVolPage0_t volume_pg0
;
7252 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7253 Mpi2ConfigReply_t mpi_reply
;
7258 if (!ioc
->ir_firmware
)
7261 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
7264 if (list_empty(&ioc
->raid_device_list
))
7268 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7269 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7270 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7271 MPI2_IOCSTATUS_MASK
;
7272 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7274 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7276 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7277 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7278 sizeof(Mpi2RaidVolPage0_t
)))
7281 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7282 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7283 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
7284 _scsih_mark_responding_raid_device(ioc
,
7285 le64_to_cpu(volume_pg1
.WWID
), handle
);
7288 /* refresh the pd_handles */
7289 if (!ioc
->is_warpdrive
) {
7290 phys_disk_num
= 0xFF;
7291 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
7292 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7293 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7295 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7296 MPI2_IOCSTATUS_MASK
;
7297 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7299 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7300 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7301 set_bit(handle
, ioc
->pd_handles
);
7305 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
7310 * _scsih_mark_responding_expander - mark a expander as responding
7311 * @ioc: per adapter object
7312 * @sas_address: sas address
7315 * After host reset, find out whether devices are still responding.
7316 * Used in _scsih_remove_unresponsive_expanders.
7321 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
7324 struct _sas_node
*sas_expander
;
7325 unsigned long flags
;
7328 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7329 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
7330 if (sas_expander
->sas_address
!= sas_address
)
7332 sas_expander
->responding
= 1;
7333 if (sas_expander
->handle
== handle
)
7335 pr_info("\texpander(0x%016llx): handle changed" \
7336 " from(0x%04x) to (0x%04x)!!!\n",
7337 (unsigned long long)sas_expander
->sas_address
,
7338 sas_expander
->handle
, handle
);
7339 sas_expander
->handle
= handle
;
7340 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
7341 sas_expander
->phy
[i
].handle
= handle
;
7345 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7349 * _scsih_search_responding_expanders -
7350 * @ioc: per adapter object
7352 * After host reset, find out whether devices are still responding.
7358 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
7360 Mpi2ExpanderPage0_t expander_pg0
;
7361 Mpi2ConfigReply_t mpi_reply
;
7366 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
7368 if (list_empty(&ioc
->sas_expander_list
))
7372 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7373 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7375 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7376 MPI2_IOCSTATUS_MASK
;
7377 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7380 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7381 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7382 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7384 (unsigned long long)sas_address
);
7385 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7389 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
7393 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7394 * @ioc: per adapter object
7399 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
7401 struct _sas_device
*sas_device
, *sas_device_next
;
7402 struct _sas_node
*sas_expander
, *sas_expander_next
;
7403 struct _raid_device
*raid_device
, *raid_device_next
;
7404 struct list_head tmp_list
;
7405 unsigned long flags
;
7408 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
7411 /* removing unresponding end devices */
7412 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
7415 * Iterate, pulling off devices marked as non-responding. We become the
7416 * owner for the reference the list had on any object we prune.
7418 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7419 list_for_each_entry_safe(sas_device
, sas_device_next
,
7420 &ioc
->sas_device_list
, list
) {
7421 if (!sas_device
->responding
)
7422 list_move_tail(&sas_device
->list
, &head
);
7424 sas_device
->responding
= 0;
7426 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7429 * Now, uninitialize and remove the unresponding devices we pruned.
7431 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
7432 _scsih_remove_device(ioc
, sas_device
);
7433 list_del_init(&sas_device
->list
);
7434 sas_device_put(sas_device
);
7437 /* removing unresponding volumes */
7438 if (ioc
->ir_firmware
) {
7439 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
7441 list_for_each_entry_safe(raid_device
, raid_device_next
,
7442 &ioc
->raid_device_list
, list
) {
7443 if (!raid_device
->responding
)
7444 _scsih_sas_volume_delete(ioc
,
7445 raid_device
->handle
);
7447 raid_device
->responding
= 0;
7451 /* removing unresponding expanders */
7452 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
7454 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7455 INIT_LIST_HEAD(&tmp_list
);
7456 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7457 &ioc
->sas_expander_list
, list
) {
7458 if (!sas_expander
->responding
)
7459 list_move_tail(&sas_expander
->list
, &tmp_list
);
7461 sas_expander
->responding
= 0;
7463 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7464 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7466 list_del(&sas_expander
->list
);
7467 _scsih_expander_node_remove(ioc
, sas_expander
);
7470 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
7473 /* unblock devices */
7474 _scsih_ublock_io_all_device(ioc
);
7478 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
7479 struct _sas_node
*sas_expander
, u16 handle
)
7481 Mpi2ExpanderPage1_t expander_pg1
;
7482 Mpi2ConfigReply_t mpi_reply
;
7485 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7486 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7487 &expander_pg1
, i
, handle
))) {
7488 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7489 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7493 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7494 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7495 expander_pg1
.NegotiatedLinkRate
>> 4);
7500 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7501 * @ioc: per adapter object
7506 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
7508 Mpi2ExpanderPage0_t expander_pg0
;
7509 Mpi2SasDevicePage0_t sas_device_pg0
;
7510 Mpi2RaidVolPage1_t volume_pg1
;
7511 Mpi2RaidVolPage0_t volume_pg0
;
7512 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7513 Mpi2EventIrConfigElement_t element
;
7514 Mpi2ConfigReply_t mpi_reply
;
7517 u16 handle
, parent_handle
;
7519 struct _sas_device
*sas_device
;
7520 struct _sas_node
*expander_device
;
7521 static struct _raid_device
*raid_device
;
7523 unsigned long flags
;
7525 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7527 _scsih_sas_host_refresh(ioc
);
7529 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7533 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7534 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7535 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7536 MPI2_IOCSTATUS_MASK
;
7537 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7538 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7539 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7540 ioc
->name
, ioc_status
,
7541 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7544 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7545 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7546 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7547 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7548 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7549 if (expander_device
)
7550 _scsih_refresh_expander_links(ioc
, expander_device
,
7553 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7554 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7555 handle
, (unsigned long long)
7556 le64_to_cpu(expander_pg0
.SASAddress
));
7557 _scsih_expander_add(ioc
, handle
);
7558 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7559 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7560 handle
, (unsigned long long)
7561 le64_to_cpu(expander_pg0
.SASAddress
));
7565 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7568 if (!ioc
->ir_firmware
)
7571 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7574 phys_disk_num
= 0xFF;
7575 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7576 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7578 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7579 MPI2_IOCSTATUS_MASK
;
7580 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7581 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7582 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7583 ioc
->name
, ioc_status
,
7584 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7587 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7588 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7589 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7591 sas_device_put(sas_device
);
7594 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7595 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7598 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7599 MPI2_IOCSTATUS_MASK
;
7600 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7601 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7602 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7603 ioc
->name
, ioc_status
,
7604 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7607 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7608 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7610 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7611 " handle (0x%04x), sas_addr(0x%016llx)\n",
7612 ioc
->name
, handle
, (unsigned long long)
7613 le64_to_cpu(sas_device_pg0
.SASAddress
));
7614 mpt3sas_transport_update_links(ioc
, sas_address
,
7615 handle
, sas_device_pg0
.PhyNum
,
7616 MPI2_SAS_NEG_LINK_RATE_1_5
);
7617 set_bit(handle
, ioc
->pd_handles
);
7619 /* This will retry adding the end device.
7620 * _scsih_add_device() will decide on retries and
7621 * return "1" when it should be retried
7623 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7627 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7628 " handle (0x%04x), sas_addr(0x%016llx)\n",
7629 ioc
->name
, handle
, (unsigned long long)
7630 le64_to_cpu(sas_device_pg0
.SASAddress
));
7634 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7637 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7641 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7642 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7643 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7644 MPI2_IOCSTATUS_MASK
;
7645 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7646 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7647 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7648 ioc
->name
, ioc_status
,
7649 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7652 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7653 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7654 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7655 le64_to_cpu(volume_pg1
.WWID
));
7656 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7659 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7660 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7661 sizeof(Mpi2RaidVolPage0_t
)))
7663 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7664 MPI2_IOCSTATUS_MASK
;
7665 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7666 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7667 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7668 ioc
->name
, ioc_status
,
7669 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7672 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7673 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7674 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7675 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7676 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7677 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7679 "\tBEFORE adding volume: handle (0x%04x)\n",
7680 ioc
->name
, volume_pg1
.DevHandle
);
7681 _scsih_sas_volume_add(ioc
, &element
);
7683 "\tAFTER adding volume: handle (0x%04x)\n",
7684 ioc
->name
, volume_pg1
.DevHandle
);
7688 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7693 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7698 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7699 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7701 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7702 MPI2_IOCSTATUS_MASK
;
7703 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7704 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7705 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7706 ioc
->name
, ioc_status
,
7707 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7710 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7711 if (!(_scsih_is_end_device(
7712 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7714 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
7715 le64_to_cpu(sas_device_pg0
.SASAddress
));
7717 sas_device_put(sas_device
);
7720 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7721 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7722 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7723 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7724 handle
, (unsigned long long)
7725 le64_to_cpu(sas_device_pg0
.SASAddress
));
7726 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7727 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7729 /* This will retry adding the end device.
7730 * _scsih_add_device() will decide on retries and
7731 * return "1" when it should be retried
7733 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7737 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7738 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7739 handle
, (unsigned long long)
7740 le64_to_cpu(sas_device_pg0
.SASAddress
));
7743 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7746 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7749 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7750 * @ioc: per adapter object
7751 * @reset_phase: phase
7753 * The handler for doing any required cleanup or initialization.
7755 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7756 * MPT3_IOC_DONE_RESET
7761 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7763 switch (reset_phase
) {
7764 case MPT3_IOC_PRE_RESET
:
7765 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7766 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7768 case MPT3_IOC_AFTER_RESET
:
7769 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7770 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7771 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7772 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7773 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7774 complete(&ioc
->scsih_cmds
.done
);
7776 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7777 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7778 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7779 complete(&ioc
->tm_cmds
.done
);
7782 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
7783 memset(ioc
->device_remove_in_progress
, 0,
7784 ioc
->device_remove_in_progress_sz
);
7785 _scsih_fw_event_cleanup_queue(ioc
);
7786 _scsih_flush_running_cmds(ioc
);
7788 case MPT3_IOC_DONE_RESET
:
7789 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7790 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7791 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7792 !ioc
->sas_hba
.num_phys
)) {
7793 _scsih_prep_device_scan(ioc
);
7794 _scsih_search_responding_sas_devices(ioc
);
7795 _scsih_search_responding_raid_devices(ioc
);
7796 _scsih_search_responding_expanders(ioc
);
7797 _scsih_error_recovery_delete_devices(ioc
);
7804 * _mpt3sas_fw_work - delayed task for processing firmware events
7805 * @ioc: per adapter object
7806 * @fw_event: The fw_event_work object
7812 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7814 _scsih_fw_event_del_from_list(ioc
, fw_event
);
7816 /* the queue is being flushed so ignore this event */
7817 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
7818 fw_event_work_put(fw_event
);
7822 switch (fw_event
->event
) {
7823 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7824 mpt3sas_process_trigger_data(ioc
,
7825 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7826 fw_event
->event_data
);
7828 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7829 while (scsi_host_in_recovery(ioc
->shost
) ||
7830 ioc
->shost_recovery
) {
7832 * If we're unloading, bail. Otherwise, this can become
7835 if (ioc
->remove_host
)
7839 _scsih_remove_unresponding_sas_devices(ioc
);
7840 _scsih_scan_for_devices_after_reset(ioc
);
7842 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7843 ioc
->start_scan
= 0;
7844 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7845 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7847 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7848 "port enable: complete from worker thread\n",
7851 case MPT3SAS_TURN_ON_PFA_LED
:
7852 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7854 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7855 _scsih_sas_topology_change_event(ioc
, fw_event
);
7857 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7858 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7860 case MPI2_EVENT_SAS_DISCOVERY
:
7861 _scsih_sas_discovery_event(ioc
, fw_event
);
7863 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7864 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7866 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7867 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7870 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7871 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7873 case MPI2_EVENT_IR_VOLUME
:
7874 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7876 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7877 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7879 case MPI2_EVENT_IR_OPERATION_STATUS
:
7880 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7884 fw_event_work_put(fw_event
);
7888 * _firmware_event_work
7889 * @ioc: per adapter object
7890 * @work: The fw_event_work object
7893 * wrappers for the work thread handling firmware events
7899 _firmware_event_work(struct work_struct
*work
)
7901 struct fw_event_work
*fw_event
= container_of(work
,
7902 struct fw_event_work
, work
);
7904 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7908 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7909 * @ioc: per adapter object
7910 * @msix_index: MSIX table index supplied by the OS
7911 * @reply: reply message frame(lower 32bit addr)
7912 * Context: interrupt.
7914 * This function merely adds a new work task into ioc->firmware_event_thread.
7915 * The tasks are worked from _firmware_event_work in user context.
7917 * Return 1 meaning mf should be freed from _base_interrupt
7918 * 0 means the mf is freed from this function.
7921 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7924 struct fw_event_work
*fw_event
;
7925 Mpi2EventNotificationReply_t
*mpi_reply
;
7928 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
7930 /* events turned off due to host reset or driver unloading */
7931 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7934 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7936 if (unlikely(!mpi_reply
)) {
7937 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7938 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7942 event
= le16_to_cpu(mpi_reply
->Event
);
7944 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7945 mpt3sas_trigger_event(ioc
, event
, 0);
7949 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7951 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7952 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7953 mpi_reply
->EventData
;
7955 if (baen_data
->Primitive
!=
7956 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7959 if (ioc
->broadcast_aen_busy
) {
7960 ioc
->broadcast_aen_pending
++;
7963 ioc
->broadcast_aen_busy
= 1;
7967 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7968 _scsih_check_topo_delete_events(ioc
,
7969 (Mpi2EventDataSasTopologyChangeList_t
*)
7970 mpi_reply
->EventData
);
7972 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7973 _scsih_check_ir_config_unhide_events(ioc
,
7974 (Mpi2EventDataIrConfigChangeList_t
*)
7975 mpi_reply
->EventData
);
7977 case MPI2_EVENT_IR_VOLUME
:
7978 _scsih_check_volume_delete_events(ioc
,
7979 (Mpi2EventDataIrVolume_t
*)
7980 mpi_reply
->EventData
);
7982 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7984 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7987 if (!ioc
->is_warpdrive
)
7990 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7991 mpi_reply
->EventData
;
7992 log_code
= (u32
*)log_entry
->LogData
;
7994 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7995 != MPT2_WARPDRIVE_LOGENTRY
)
7998 switch (le32_to_cpu(*log_code
)) {
7999 case MPT2_WARPDRIVE_LC_SSDT
:
8000 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
8001 "IO Throttling has occurred in the WarpDrive "
8002 "subsystem. Check WarpDrive documentation for "
8003 "additional details.\n", ioc
->name
);
8005 case MPT2_WARPDRIVE_LC_SSDLW
:
8006 pr_warn(MPT3SAS_FMT
"WarpDrive Warning: "
8007 "Program/Erase Cycles for the WarpDrive subsystem "
8008 "in degraded range. Check WarpDrive documentation "
8009 "for additional details.\n", ioc
->name
);
8011 case MPT2_WARPDRIVE_LC_SSDLF
:
8012 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
8013 "There are no Program/Erase Cycles for the "
8014 "WarpDrive subsystem. The storage device will be "
8015 "in read-only mode. Check WarpDrive documentation "
8016 "for additional details.\n", ioc
->name
);
8018 case MPT2_WARPDRIVE_LC_BRMF
:
8019 pr_err(MPT3SAS_FMT
"WarpDrive Fatal Error: "
8020 "The Backup Rail Monitor has failed on the "
8021 "WarpDrive subsystem. Check WarpDrive "
8022 "documentation for additional details.\n",
8029 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
8030 case MPI2_EVENT_IR_OPERATION_STATUS
:
8031 case MPI2_EVENT_SAS_DISCOVERY
:
8032 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
8033 case MPI2_EVENT_IR_PHYSICAL_DISK
:
8036 case MPI2_EVENT_TEMP_THRESHOLD
:
8037 _scsih_temp_threshold_events(ioc
,
8038 (Mpi2EventDataTemperature_t
*)
8039 mpi_reply
->EventData
);
8041 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
8042 ActiveCableEventData
=
8043 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
8044 switch (ActiveCableEventData
->ReasonCode
) {
8045 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
8046 pr_notice(MPT3SAS_FMT
"Receptacle ID %d: This active cable"
8047 " requires %d mW of power\n", ioc
->name
,
8048 ActiveCableEventData
->ReceptacleID
,
8049 ActiveCableEventData
->ActiveCablePowerRequirement
);
8050 pr_notice(MPT3SAS_FMT
"Receptacle ID %d: Devices connected"
8051 " to this active cable will not be seen\n",
8052 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
8055 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
8056 pr_notice(MPT3SAS_FMT
"ReceptacleID %d: This cable",
8057 ioc
->name
, ActiveCableEventData
->ReceptacleID
);
8058 pr_notice(" is not running at an optimal speed(12 Gb/s)\n");
8064 default: /* ignore the rest */
8068 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
8069 fw_event
= alloc_fw_event_work(sz
);
8071 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8072 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8076 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
8077 fw_event
->ioc
= ioc
;
8078 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
8079 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
8080 fw_event
->event
= event
;
8081 _scsih_fw_event_add(ioc
, fw_event
);
8082 fw_event_work_put(fw_event
);
8087 * _scsih_expander_node_remove - removing expander device from list.
8088 * @ioc: per adapter object
8089 * @sas_expander: the sas_device object
8090 * Context: Calling function should acquire ioc->sas_node_lock.
8092 * Removing object and freeing associated memory from the
8093 * ioc->sas_expander_list.
8098 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
8099 struct _sas_node
*sas_expander
)
8101 struct _sas_port
*mpt3sas_port
, *next
;
8103 /* remove sibling ports attached to this expander */
8104 list_for_each_entry_safe(mpt3sas_port
, next
,
8105 &sas_expander
->sas_port_list
, port_list
) {
8106 if (ioc
->shost_recovery
)
8108 if (mpt3sas_port
->remote_identify
.device_type
==
8110 mpt3sas_device_remove_by_sas_address(ioc
,
8111 mpt3sas_port
->remote_identify
.sas_address
);
8112 else if (mpt3sas_port
->remote_identify
.device_type
==
8113 SAS_EDGE_EXPANDER_DEVICE
||
8114 mpt3sas_port
->remote_identify
.device_type
==
8115 SAS_FANOUT_EXPANDER_DEVICE
)
8116 mpt3sas_expander_remove(ioc
,
8117 mpt3sas_port
->remote_identify
.sas_address
);
8120 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
8121 sas_expander
->sas_address_parent
);
8124 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8126 sas_expander
->handle
, (unsigned long long)
8127 sas_expander
->sas_address
);
8129 kfree(sas_expander
->phy
);
8130 kfree(sas_expander
);
8134 * _scsih_ir_shutdown - IR shutdown notification
8135 * @ioc: per adapter object
8137 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8138 * the host system is shutting down.
8143 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
8145 Mpi2RaidActionRequest_t
*mpi_request
;
8146 Mpi2RaidActionReply_t
*mpi_reply
;
8149 /* is IR firmware build loaded ? */
8150 if (!ioc
->ir_firmware
)
8153 /* are there any volumes ? */
8154 if (list_empty(&ioc
->raid_device_list
))
8157 mutex_lock(&ioc
->scsih_cmds
.mutex
);
8159 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
8160 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
8161 ioc
->name
, __func__
);
8164 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
8166 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
8168 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
8169 ioc
->name
, __func__
);
8170 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8174 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
8175 ioc
->scsih_cmds
.smid
= smid
;
8176 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
8178 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
8179 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
8181 if (!ioc
->hide_ir_msg
)
8182 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
8183 init_completion(&ioc
->scsih_cmds
.done
);
8184 ioc
->put_smid_default(ioc
, smid
);
8185 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
8187 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
8188 pr_err(MPT3SAS_FMT
"%s: timeout\n",
8189 ioc
->name
, __func__
);
8193 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
8194 mpi_reply
= ioc
->scsih_cmds
.reply
;
8195 if (!ioc
->hide_ir_msg
)
8196 pr_info(MPT3SAS_FMT
"IR shutdown "
8197 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8198 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
8199 le32_to_cpu(mpi_reply
->IOCLogInfo
));
8203 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
8204 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
8208 * scsih_remove - detach and remove add host
8209 * @pdev: PCI device struct
8211 * Routine called when unloading the driver.
8214 static void scsih_remove(struct pci_dev
*pdev
)
8216 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8217 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8218 struct _sas_port
*mpt3sas_port
, *next_port
;
8219 struct _raid_device
*raid_device
, *next
;
8220 struct MPT3SAS_TARGET
*sas_target_priv_data
;
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 /* release all the volumes */
8235 _scsih_ir_shutdown(ioc
);
8236 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
8238 if (raid_device
->starget
) {
8239 sas_target_priv_data
=
8240 raid_device
->starget
->hostdata
;
8241 sas_target_priv_data
->deleted
= 1;
8242 scsi_remove_target(&raid_device
->starget
->dev
);
8244 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
8245 ioc
->name
, raid_device
->handle
,
8246 (unsigned long long) raid_device
->wwid
);
8247 _scsih_raid_device_remove(ioc
, raid_device
);
8250 /* free ports attached to the sas_host */
8251 list_for_each_entry_safe(mpt3sas_port
, next_port
,
8252 &ioc
->sas_hba
.sas_port_list
, port_list
) {
8253 if (mpt3sas_port
->remote_identify
.device_type
==
8255 mpt3sas_device_remove_by_sas_address(ioc
,
8256 mpt3sas_port
->remote_identify
.sas_address
);
8257 else if (mpt3sas_port
->remote_identify
.device_type
==
8258 SAS_EDGE_EXPANDER_DEVICE
||
8259 mpt3sas_port
->remote_identify
.device_type
==
8260 SAS_FANOUT_EXPANDER_DEVICE
)
8261 mpt3sas_expander_remove(ioc
,
8262 mpt3sas_port
->remote_identify
.sas_address
);
8265 /* free phys attached to the sas_host */
8266 if (ioc
->sas_hba
.num_phys
) {
8267 kfree(ioc
->sas_hba
.phy
);
8268 ioc
->sas_hba
.phy
= NULL
;
8269 ioc
->sas_hba
.num_phys
= 0;
8272 sas_remove_host(shost
);
8273 scsi_remove_host(shost
);
8274 mpt3sas_base_detach(ioc
);
8275 spin_lock(&gioc_lock
);
8276 list_del(&ioc
->list
);
8277 spin_unlock(&gioc_lock
);
8278 scsi_host_put(shost
);
8282 * scsih_shutdown - routine call during system shutdown
8283 * @pdev: PCI device struct
8288 scsih_shutdown(struct pci_dev
*pdev
)
8290 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8291 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8292 struct workqueue_struct
*wq
;
8293 unsigned long flags
;
8295 ioc
->remove_host
= 1;
8296 _scsih_fw_event_cleanup_queue(ioc
);
8298 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
8299 wq
= ioc
->firmware_event_thread
;
8300 ioc
->firmware_event_thread
= NULL
;
8301 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
8303 destroy_workqueue(wq
);
8305 _scsih_ir_shutdown(ioc
);
8306 mpt3sas_base_detach(ioc
);
8311 * _scsih_probe_boot_devices - reports 1st device
8312 * @ioc: per adapter object
8314 * If specified in bios page 2, this routine reports the 1st
8315 * device scsi-ml or sas transport for persistent boot device
8316 * purposes. Please refer to function _scsih_determine_boot_device()
8319 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
8323 struct _sas_device
*sas_device
;
8324 struct _raid_device
*raid_device
;
8326 u64 sas_address_parent
;
8328 unsigned long flags
;
8331 /* no Bios, return immediately */
8332 if (!ioc
->bios_pg3
.BiosVersion
)
8337 if (ioc
->req_boot_device
.device
) {
8338 device
= ioc
->req_boot_device
.device
;
8339 is_raid
= ioc
->req_boot_device
.is_raid
;
8340 } else if (ioc
->req_alt_boot_device
.device
) {
8341 device
= ioc
->req_alt_boot_device
.device
;
8342 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
8343 } else if (ioc
->current_boot_device
.device
) {
8344 device
= ioc
->current_boot_device
.device
;
8345 is_raid
= ioc
->current_boot_device
.is_raid
;
8352 raid_device
= device
;
8353 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8354 raid_device
->id
, 0);
8356 _scsih_raid_device_remove(ioc
, raid_device
);
8358 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8359 sas_device
= device
;
8360 handle
= sas_device
->handle
;
8361 sas_address_parent
= sas_device
->sas_address_parent
;
8362 sas_address
= sas_device
->sas_address
;
8363 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8364 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8366 if (ioc
->hide_drives
)
8368 if (!mpt3sas_transport_port_add(ioc
, handle
,
8369 sas_address_parent
)) {
8370 _scsih_sas_device_remove(ioc
, sas_device
);
8371 } else if (!sas_device
->starget
) {
8372 if (!ioc
->is_driver_loading
) {
8373 mpt3sas_transport_port_remove(ioc
,
8375 sas_address_parent
);
8376 _scsih_sas_device_remove(ioc
, sas_device
);
8383 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8384 * @ioc: per adapter object
8386 * Called during initial loading of the driver.
8389 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
8391 struct _raid_device
*raid_device
, *raid_next
;
8394 list_for_each_entry_safe(raid_device
, raid_next
,
8395 &ioc
->raid_device_list
, list
) {
8396 if (raid_device
->starget
)
8398 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8399 raid_device
->id
, 0);
8401 _scsih_raid_device_remove(ioc
, raid_device
);
8405 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
8407 struct _sas_device
*sas_device
= NULL
;
8408 unsigned long flags
;
8410 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8411 if (!list_empty(&ioc
->sas_device_init_list
)) {
8412 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
8413 struct _sas_device
, list
);
8414 sas_device_get(sas_device
);
8416 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8421 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
8422 struct _sas_device
*sas_device
)
8424 unsigned long flags
;
8426 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8429 * Since we dropped the lock during the call to port_add(), we need to
8430 * be careful here that somebody else didn't move or delete this item
8431 * while we were busy with other things.
8433 * If it was on the list, we need a put() for the reference the list
8434 * had. Either way, we need a get() for the destination list.
8436 if (!list_empty(&sas_device
->list
)) {
8437 list_del_init(&sas_device
->list
);
8438 sas_device_put(sas_device
);
8441 sas_device_get(sas_device
);
8442 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8444 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8448 * _scsih_probe_sas - reporting sas devices to sas transport
8449 * @ioc: per adapter object
8451 * Called during initial loading of the driver.
8454 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
8456 struct _sas_device
*sas_device
;
8458 if (ioc
->hide_drives
)
8461 while ((sas_device
= get_next_sas_device(ioc
))) {
8462 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
8463 sas_device
->sas_address_parent
)) {
8464 _scsih_sas_device_remove(ioc
, sas_device
);
8465 sas_device_put(sas_device
);
8467 } else if (!sas_device
->starget
) {
8469 * When asyn scanning is enabled, its not possible to
8470 * remove devices while scanning is turned on due to an
8471 * oops in scsi_sysfs_add_sdev()->add_device()->
8472 * sysfs_addrm_start()
8474 if (!ioc
->is_driver_loading
) {
8475 mpt3sas_transport_port_remove(ioc
,
8476 sas_device
->sas_address
,
8477 sas_device
->sas_address_parent
);
8478 _scsih_sas_device_remove(ioc
, sas_device
);
8479 sas_device_put(sas_device
);
8483 sas_device_make_active(ioc
, sas_device
);
8484 sas_device_put(sas_device
);
8489 * _scsih_probe_devices - probing for devices
8490 * @ioc: per adapter object
8492 * Called during initial loading of the driver.
8495 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
8497 u16 volume_mapping_flags
;
8499 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8500 return; /* return when IOC doesn't support initiator mode */
8502 _scsih_probe_boot_devices(ioc
);
8504 if (ioc
->ir_firmware
) {
8505 volume_mapping_flags
=
8506 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8507 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8508 if (volume_mapping_flags
==
8509 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8510 _scsih_probe_raid(ioc
);
8511 _scsih_probe_sas(ioc
);
8513 _scsih_probe_sas(ioc
);
8514 _scsih_probe_raid(ioc
);
8517 _scsih_probe_sas(ioc
);
8521 * scsih_scan_start - scsi lld callback for .scan_start
8522 * @shost: SCSI host pointer
8524 * The shost has the ability to discover targets on its own instead
8525 * of scanning the entire bus. In our implemention, we will kick off
8526 * firmware discovery.
8529 scsih_scan_start(struct Scsi_Host
*shost
)
8531 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8533 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8534 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8536 if (disable_discovery
> 0)
8539 ioc
->start_scan
= 1;
8540 rc
= mpt3sas_port_enable(ioc
);
8543 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
8547 * scsih_scan_finished - scsi lld callback for .scan_finished
8548 * @shost: SCSI host pointer
8549 * @time: elapsed time of the scan in jiffies
8551 * This function will be called periodicallyn until it returns 1 with the
8552 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8553 * we wait for firmware discovery to complete, then return 1.
8556 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8558 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8560 if (disable_discovery
> 0) {
8561 ioc
->is_driver_loading
= 0;
8562 ioc
->wait_for_discovery_to_complete
= 0;
8566 if (time
>= (300 * HZ
)) {
8567 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8569 "port enable: FAILED with timeout (timeout=300s)\n",
8571 ioc
->is_driver_loading
= 0;
8575 if (ioc
->start_scan
)
8578 if (ioc
->start_scan_failed
) {
8580 "port enable: FAILED with (ioc_status=0x%08x)\n",
8581 ioc
->name
, ioc
->start_scan_failed
);
8582 ioc
->is_driver_loading
= 0;
8583 ioc
->wait_for_discovery_to_complete
= 0;
8584 ioc
->remove_host
= 1;
8588 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
8589 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
8591 if (ioc
->wait_for_discovery_to_complete
) {
8592 ioc
->wait_for_discovery_to_complete
= 0;
8593 _scsih_probe_devices(ioc
);
8595 mpt3sas_base_start_watchdog(ioc
);
8596 ioc
->is_driver_loading
= 0;
8600 /* shost template for SAS 2.0 HBA devices */
8601 static struct scsi_host_template mpt2sas_driver_template
= {
8602 .module
= THIS_MODULE
,
8603 .name
= "Fusion MPT SAS Host",
8604 .proc_name
= MPT2SAS_DRIVER_NAME
,
8605 .queuecommand
= scsih_qcmd
,
8606 .target_alloc
= scsih_target_alloc
,
8607 .slave_alloc
= scsih_slave_alloc
,
8608 .slave_configure
= scsih_slave_configure
,
8609 .target_destroy
= scsih_target_destroy
,
8610 .slave_destroy
= scsih_slave_destroy
,
8611 .scan_finished
= scsih_scan_finished
,
8612 .scan_start
= scsih_scan_start
,
8613 .change_queue_depth
= scsih_change_queue_depth
,
8614 .eh_abort_handler
= scsih_abort
,
8615 .eh_device_reset_handler
= scsih_dev_reset
,
8616 .eh_target_reset_handler
= scsih_target_reset
,
8617 .eh_host_reset_handler
= scsih_host_reset
,
8618 .bios_param
= scsih_bios_param
,
8621 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
8622 .max_sectors
= 32767,
8624 .use_clustering
= ENABLE_CLUSTERING
,
8625 .shost_attrs
= mpt3sas_host_attrs
,
8626 .sdev_attrs
= mpt3sas_dev_attrs
,
8627 .track_queue_depth
= 1,
8630 /* raid transport support for SAS 2.0 HBA devices */
8631 static struct raid_function_template mpt2sas_raid_functions
= {
8632 .cookie
= &mpt2sas_driver_template
,
8633 .is_raid
= scsih_is_raid
,
8634 .get_resync
= scsih_get_resync
,
8635 .get_state
= scsih_get_state
,
8638 /* shost template for SAS 3.0 HBA devices */
8639 static struct scsi_host_template mpt3sas_driver_template
= {
8640 .module
= THIS_MODULE
,
8641 .name
= "Fusion MPT SAS Host",
8642 .proc_name
= MPT3SAS_DRIVER_NAME
,
8643 .queuecommand
= scsih_qcmd
,
8644 .target_alloc
= scsih_target_alloc
,
8645 .slave_alloc
= scsih_slave_alloc
,
8646 .slave_configure
= scsih_slave_configure
,
8647 .target_destroy
= scsih_target_destroy
,
8648 .slave_destroy
= scsih_slave_destroy
,
8649 .scan_finished
= scsih_scan_finished
,
8650 .scan_start
= scsih_scan_start
,
8651 .change_queue_depth
= scsih_change_queue_depth
,
8652 .eh_abort_handler
= scsih_abort
,
8653 .eh_device_reset_handler
= scsih_dev_reset
,
8654 .eh_target_reset_handler
= scsih_target_reset
,
8655 .eh_host_reset_handler
= scsih_host_reset
,
8656 .bios_param
= scsih_bios_param
,
8659 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
8660 .max_sectors
= 32767,
8662 .use_clustering
= ENABLE_CLUSTERING
,
8663 .shost_attrs
= mpt3sas_host_attrs
,
8664 .sdev_attrs
= mpt3sas_dev_attrs
,
8665 .track_queue_depth
= 1,
8668 /* raid transport support for SAS 3.0 HBA devices */
8669 static struct raid_function_template mpt3sas_raid_functions
= {
8670 .cookie
= &mpt3sas_driver_template
,
8671 .is_raid
= scsih_is_raid
,
8672 .get_resync
= scsih_get_resync
,
8673 .get_state
= scsih_get_state
,
8677 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8678 * this device belongs to.
8679 * @pdev: PCI device struct
8681 * return MPI2_VERSION for SAS 2.0 HBA devices,
8682 * MPI25_VERSION for SAS 3.0 HBA devices, and
8683 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8686 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
8689 switch (pdev
->device
) {
8690 case MPI2_MFGPAGE_DEVID_SSS6200
:
8691 case MPI2_MFGPAGE_DEVID_SAS2004
:
8692 case MPI2_MFGPAGE_DEVID_SAS2008
:
8693 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
8694 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
8695 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
8696 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
8697 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
8698 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
8699 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
8700 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
8701 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
8702 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
8703 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
8704 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
8705 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
8706 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
8707 return MPI2_VERSION
;
8708 case MPI25_MFGPAGE_DEVID_SAS3004
:
8709 case MPI25_MFGPAGE_DEVID_SAS3008
:
8710 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
8711 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
8712 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
8713 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
8714 return MPI25_VERSION
;
8715 case MPI26_MFGPAGE_DEVID_SAS3216
:
8716 case MPI26_MFGPAGE_DEVID_SAS3224
:
8717 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
8718 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
8719 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
8720 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
8721 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
8722 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
8723 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
8724 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
8725 case MPI26_MFGPAGE_DEVID_SAS3508
:
8726 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
8727 case MPI26_MFGPAGE_DEVID_SAS3408
:
8728 case MPI26_MFGPAGE_DEVID_SAS3516
:
8729 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
8730 case MPI26_MFGPAGE_DEVID_SAS3416
:
8731 return MPI26_VERSION
;
8737 * _scsih_probe - attach and add scsi host
8738 * @pdev: PCI device struct
8739 * @id: pci device id
8741 * Returns 0 success, anything else error.
8744 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8746 struct MPT3SAS_ADAPTER
*ioc
;
8747 struct Scsi_Host
*shost
= NULL
;
8749 u16 hba_mpi_version
;
8751 /* Determine in which MPI version class this pci device belongs */
8752 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
8753 if (hba_mpi_version
== 0)
8756 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8757 * for other generation HBA's return with -ENODEV
8759 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
8762 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8763 * for other generation HBA's return with -ENODEV
8765 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
8766 || hba_mpi_version
== MPI26_VERSION
)))
8769 switch (hba_mpi_version
) {
8771 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8772 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
8773 sizeof(struct MPT3SAS_ADAPTER
));
8776 ioc
= shost_priv(shost
);
8777 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8778 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8779 ioc
->id
= mpt2_ids
++;
8780 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
8781 if (pdev
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8782 ioc
->is_warpdrive
= 1;
8783 ioc
->hide_ir_msg
= 1;
8785 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8789 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8790 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
8791 sizeof(struct MPT3SAS_ADAPTER
));
8794 ioc
= shost_priv(shost
);
8795 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8796 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
8797 ioc
->id
= mpt3_ids
++;
8798 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
8799 switch (pdev
->device
) {
8800 case MPI26_MFGPAGE_DEVID_SAS3508
:
8801 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
8802 case MPI26_MFGPAGE_DEVID_SAS3408
:
8803 case MPI26_MFGPAGE_DEVID_SAS3516
:
8804 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
8805 case MPI26_MFGPAGE_DEVID_SAS3416
:
8806 ioc
->is_gen35_ioc
= 1;
8809 ioc
->is_gen35_ioc
= 0;
8811 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
8812 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
8813 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
8814 ioc
->combined_reply_queue
= 1;
8815 if (ioc
->is_gen35_ioc
)
8816 ioc
->combined_reply_index_count
=
8817 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
8819 ioc
->combined_reply_index_count
=
8820 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
8827 INIT_LIST_HEAD(&ioc
->list
);
8828 spin_lock(&gioc_lock
);
8829 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8830 spin_unlock(&gioc_lock
);
8833 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8834 ioc
->tm_cb_idx
= tm_cb_idx
;
8835 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8836 ioc
->base_cb_idx
= base_cb_idx
;
8837 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8838 ioc
->transport_cb_idx
= transport_cb_idx
;
8839 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8840 ioc
->config_cb_idx
= config_cb_idx
;
8841 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8842 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8843 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8844 ioc
->logging_level
= logging_level
;
8845 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8846 /* misc semaphores and spin locks */
8847 mutex_init(&ioc
->reset_in_progress_mutex
);
8848 /* initializing pci_access_mutex lock */
8849 mutex_init(&ioc
->pci_access_mutex
);
8850 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8851 spin_lock_init(&ioc
->scsi_lookup_lock
);
8852 spin_lock_init(&ioc
->sas_device_lock
);
8853 spin_lock_init(&ioc
->sas_node_lock
);
8854 spin_lock_init(&ioc
->fw_event_lock
);
8855 spin_lock_init(&ioc
->raid_device_lock
);
8856 spin_lock_init(&ioc
->diag_trigger_lock
);
8858 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8859 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8860 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8861 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8862 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8863 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8864 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8865 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
8866 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
8867 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8868 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8870 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
8872 /* init shost parameters */
8873 shost
->max_cmd_len
= 32;
8874 shost
->max_lun
= max_lun
;
8875 shost
->transportt
= mpt3sas_transport_template
;
8876 shost
->unique_id
= ioc
->id
;
8878 if (max_sectors
!= 0xFFFF) {
8879 if (max_sectors
< 64) {
8880 shost
->max_sectors
= 64;
8881 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8882 "for max_sectors, range is 64 to 32767. Assigning "
8883 "value of 64.\n", ioc
->name
, max_sectors
);
8884 } else if (max_sectors
> 32767) {
8885 shost
->max_sectors
= 32767;
8886 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8887 "for max_sectors, range is 64 to 32767. Assigning "
8888 "default value of 32767.\n", ioc
->name
,
8891 shost
->max_sectors
= max_sectors
& 0xFFFE;
8893 "The max_sectors value is set to %d\n",
8894 ioc
->name
, shost
->max_sectors
);
8898 /* register EEDP capabilities with SCSI layer */
8900 scsi_host_set_prot(shost
, prot_mask
);
8902 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8903 | SHOST_DIF_TYPE2_PROTECTION
8904 | SHOST_DIF_TYPE3_PROTECTION
);
8906 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8909 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8910 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
8911 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8912 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8913 if (!ioc
->firmware_event_thread
) {
8914 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8915 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8917 goto out_thread_fail
;
8920 ioc
->is_driver_loading
= 1;
8921 if ((mpt3sas_base_attach(ioc
))) {
8922 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8923 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8925 goto out_attach_fail
;
8928 if (ioc
->is_warpdrive
) {
8929 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8930 ioc
->hide_drives
= 0;
8931 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8932 ioc
->hide_drives
= 1;
8934 if (mpt3sas_get_num_volumes(ioc
))
8935 ioc
->hide_drives
= 1;
8937 ioc
->hide_drives
= 0;
8940 ioc
->hide_drives
= 0;
8942 rv
= scsi_add_host(shost
, &pdev
->dev
);
8944 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8945 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8946 goto out_add_shost_fail
;
8949 scsi_scan_host(shost
);
8952 mpt3sas_base_detach(ioc
);
8954 destroy_workqueue(ioc
->firmware_event_thread
);
8956 spin_lock(&gioc_lock
);
8957 list_del(&ioc
->list
);
8958 spin_unlock(&gioc_lock
);
8959 scsi_host_put(shost
);
8965 * scsih_suspend - power management suspend main entry point
8966 * @pdev: PCI device struct
8967 * @state: PM state change to (usually PCI_D3)
8969 * Returns 0 success, anything else error.
8972 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8974 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8975 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8976 pci_power_t device_state
;
8978 mpt3sas_base_stop_watchdog(ioc
);
8979 flush_scheduled_work();
8980 scsi_block_requests(shost
);
8981 device_state
= pci_choose_state(pdev
, state
);
8983 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8984 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8986 pci_save_state(pdev
);
8987 mpt3sas_base_free_resources(ioc
);
8988 pci_set_power_state(pdev
, device_state
);
8993 * scsih_resume - power management resume main entry point
8994 * @pdev: PCI device struct
8996 * Returns 0 success, anything else error.
8999 scsih_resume(struct pci_dev
*pdev
)
9001 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9002 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9003 pci_power_t device_state
= pdev
->current_state
;
9007 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
9008 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
9010 pci_set_power_state(pdev
, PCI_D0
);
9011 pci_enable_wake(pdev
, PCI_D0
, 0);
9012 pci_restore_state(pdev
);
9014 r
= mpt3sas_base_map_resources(ioc
);
9018 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
9019 scsi_unblock_requests(shost
);
9020 mpt3sas_base_start_watchdog(ioc
);
9023 #endif /* CONFIG_PM */
9026 * scsih_pci_error_detected - Called when a PCI error is detected.
9027 * @pdev: PCI device struct
9028 * @state: PCI channel state
9030 * Description: Called when a PCI error is detected.
9033 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
9035 static pci_ers_result_t
9036 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
9038 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9039 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9041 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
9045 case pci_channel_io_normal
:
9046 return PCI_ERS_RESULT_CAN_RECOVER
;
9047 case pci_channel_io_frozen
:
9048 /* Fatal error, prepare for slot reset */
9049 ioc
->pci_error_recovery
= 1;
9050 scsi_block_requests(ioc
->shost
);
9051 mpt3sas_base_stop_watchdog(ioc
);
9052 mpt3sas_base_free_resources(ioc
);
9053 return PCI_ERS_RESULT_NEED_RESET
;
9054 case pci_channel_io_perm_failure
:
9055 /* Permanent error, prepare for device removal */
9056 ioc
->pci_error_recovery
= 1;
9057 mpt3sas_base_stop_watchdog(ioc
);
9058 _scsih_flush_running_cmds(ioc
);
9059 return PCI_ERS_RESULT_DISCONNECT
;
9061 return PCI_ERS_RESULT_NEED_RESET
;
9065 * scsih_pci_slot_reset - Called when PCI slot has been reset.
9066 * @pdev: PCI device struct
9068 * Description: This routine is called by the pci error recovery
9069 * code after the PCI slot has been reset, just before we
9070 * should resume normal operations.
9072 static pci_ers_result_t
9073 scsih_pci_slot_reset(struct pci_dev
*pdev
)
9075 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9076 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9079 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
9082 ioc
->pci_error_recovery
= 0;
9084 pci_restore_state(pdev
);
9085 rc
= mpt3sas_base_map_resources(ioc
);
9087 return PCI_ERS_RESULT_DISCONNECT
;
9089 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
9091 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
9092 (rc
== 0) ? "success" : "failed");
9095 return PCI_ERS_RESULT_RECOVERED
;
9097 return PCI_ERS_RESULT_DISCONNECT
;
9101 * scsih_pci_resume() - resume normal ops after PCI reset
9102 * @pdev: pointer to PCI device
9104 * Called when the error recovery driver tells us that its
9105 * OK to resume normal operation. Use completion to allow
9106 * halted scsi ops to resume.
9109 scsih_pci_resume(struct pci_dev
*pdev
)
9111 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9112 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9114 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
9116 pci_cleanup_aer_uncorrect_error_status(pdev
);
9117 mpt3sas_base_start_watchdog(ioc
);
9118 scsi_unblock_requests(ioc
->shost
);
9122 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
9123 * @pdev: pointer to PCI device
9125 static pci_ers_result_t
9126 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
9128 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9129 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9131 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
9134 /* TODO - dump whatever for debugging purposes */
9136 /* This called only if scsih_pci_error_detected returns
9137 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
9138 * works, no need to reset slot.
9140 return PCI_ERS_RESULT_RECOVERED
;
9144 * scsih__ncq_prio_supp - Check for NCQ command priority support
9145 * @sdev: scsi device struct
9147 * This is called when a user indicates they would like to enable
9148 * ncq command priorities. This works only on SATA devices.
9150 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
9153 bool ncq_prio_supp
= false;
9155 if (!scsi_device_supports_vpd(sdev
))
9156 return ncq_prio_supp
;
9158 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
9160 return ncq_prio_supp
;
9162 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
9163 ncq_prio_supp
= (buf
[213] >> 4) & 1;
9166 return ncq_prio_supp
;
9169 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9171 static const struct pci_device_id mpt3sas_pci_table
[] = {
9172 /* Spitfire ~ 2004 */
9173 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
9174 PCI_ANY_ID
, PCI_ANY_ID
},
9176 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
9177 PCI_ANY_ID
, PCI_ANY_ID
},
9178 /* Liberator ~ 2108 */
9179 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
9180 PCI_ANY_ID
, PCI_ANY_ID
},
9181 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
9182 PCI_ANY_ID
, PCI_ANY_ID
},
9183 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
9184 PCI_ANY_ID
, PCI_ANY_ID
},
9186 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
9187 PCI_ANY_ID
, PCI_ANY_ID
},
9188 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
9189 PCI_ANY_ID
, PCI_ANY_ID
},
9190 /* Thunderbolt ~ 2208 */
9191 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
9192 PCI_ANY_ID
, PCI_ANY_ID
},
9193 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
9194 PCI_ANY_ID
, PCI_ANY_ID
},
9195 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
9196 PCI_ANY_ID
, PCI_ANY_ID
},
9197 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
9198 PCI_ANY_ID
, PCI_ANY_ID
},
9199 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
9200 PCI_ANY_ID
, PCI_ANY_ID
},
9201 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
9202 PCI_ANY_ID
, PCI_ANY_ID
},
9203 /* Mustang ~ 2308 */
9204 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
9205 PCI_ANY_ID
, PCI_ANY_ID
},
9206 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
9207 PCI_ANY_ID
, PCI_ANY_ID
},
9208 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
9209 PCI_ANY_ID
, PCI_ANY_ID
},
9211 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
9212 PCI_ANY_ID
, PCI_ANY_ID
},
9213 /* Fury ~ 3004 and 3008 */
9214 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
9215 PCI_ANY_ID
, PCI_ANY_ID
},
9216 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
9217 PCI_ANY_ID
, PCI_ANY_ID
},
9218 /* Invader ~ 3108 */
9219 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
9220 PCI_ANY_ID
, PCI_ANY_ID
},
9221 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
9222 PCI_ANY_ID
, PCI_ANY_ID
},
9223 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
9224 PCI_ANY_ID
, PCI_ANY_ID
},
9225 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
9226 PCI_ANY_ID
, PCI_ANY_ID
},
9227 /* Cutlass ~ 3216 and 3224 */
9228 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
9229 PCI_ANY_ID
, PCI_ANY_ID
},
9230 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
9231 PCI_ANY_ID
, PCI_ANY_ID
},
9232 /* Intruder ~ 3316 and 3324 */
9233 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
9234 PCI_ANY_ID
, PCI_ANY_ID
},
9235 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
9236 PCI_ANY_ID
, PCI_ANY_ID
},
9237 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
9238 PCI_ANY_ID
, PCI_ANY_ID
},
9239 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
9240 PCI_ANY_ID
, PCI_ANY_ID
},
9241 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
9242 PCI_ANY_ID
, PCI_ANY_ID
},
9243 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
9244 PCI_ANY_ID
, PCI_ANY_ID
},
9245 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
9246 PCI_ANY_ID
, PCI_ANY_ID
},
9247 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
9248 PCI_ANY_ID
, PCI_ANY_ID
},
9249 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
9250 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
9251 PCI_ANY_ID
, PCI_ANY_ID
},
9252 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
9253 PCI_ANY_ID
, PCI_ANY_ID
},
9254 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
9255 PCI_ANY_ID
, PCI_ANY_ID
},
9256 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
9257 PCI_ANY_ID
, PCI_ANY_ID
},
9258 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
9259 PCI_ANY_ID
, PCI_ANY_ID
},
9260 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
9261 PCI_ANY_ID
, PCI_ANY_ID
},
9262 {0} /* Terminating entry */
9264 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
9266 static struct pci_error_handlers _mpt3sas_err_handler
= {
9267 .error_detected
= scsih_pci_error_detected
,
9268 .mmio_enabled
= scsih_pci_mmio_enabled
,
9269 .slot_reset
= scsih_pci_slot_reset
,
9270 .resume
= scsih_pci_resume
,
9273 static struct pci_driver mpt3sas_driver
= {
9274 .name
= MPT3SAS_DRIVER_NAME
,
9275 .id_table
= mpt3sas_pci_table
,
9276 .probe
= _scsih_probe
,
9277 .remove
= scsih_remove
,
9278 .shutdown
= scsih_shutdown
,
9279 .err_handler
= &_mpt3sas_err_handler
,
9281 .suspend
= scsih_suspend
,
9282 .resume
= scsih_resume
,
9287 * scsih_init - main entry point for this driver.
9289 * Returns 0 success, anything else error.
9297 mpt3sas_base_initialize_callback_handler();
9299 /* queuecommand callback hander */
9300 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
9302 /* task management callback handler */
9303 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
9305 /* base internal commands callback handler */
9306 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
9307 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
9308 mpt3sas_port_enable_done
);
9310 /* transport internal commands callback handler */
9311 transport_cb_idx
= mpt3sas_base_register_callback_handler(
9312 mpt3sas_transport_done
);
9314 /* scsih internal commands callback handler */
9315 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
9317 /* configuration page API internal commands callback handler */
9318 config_cb_idx
= mpt3sas_base_register_callback_handler(
9319 mpt3sas_config_done
);
9321 /* ctl module callback handler */
9322 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
9324 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
9325 _scsih_tm_tr_complete
);
9327 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
9328 _scsih_tm_volume_tr_complete
);
9330 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
9331 _scsih_sas_control_complete
);
9337 * scsih_exit - exit point for this driver (when it is a module).
9339 * Returns 0 success, anything else error.
9345 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
9346 mpt3sas_base_release_callback_handler(tm_cb_idx
);
9347 mpt3sas_base_release_callback_handler(base_cb_idx
);
9348 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
9349 mpt3sas_base_release_callback_handler(transport_cb_idx
);
9350 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
9351 mpt3sas_base_release_callback_handler(config_cb_idx
);
9352 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
9354 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
9355 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
9356 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
9358 /* raid transport support */
9359 if (hbas_to_enumerate
!= 1)
9360 raid_class_release(mpt3sas_raid_template
);
9361 if (hbas_to_enumerate
!= 2)
9362 raid_class_release(mpt2sas_raid_template
);
9363 sas_release_transport(mpt3sas_transport_template
);
9367 * _mpt3sas_init - main entry point for this driver.
9369 * Returns 0 success, anything else error.
9376 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
9377 MPT3SAS_DRIVER_VERSION
);
9379 mpt3sas_transport_template
=
9380 sas_attach_transport(&mpt3sas_transport_functions
);
9381 if (!mpt3sas_transport_template
)
9384 /* No need attach mpt3sas raid functions template
9385 * if hbas_to_enumarate value is one.
9387 if (hbas_to_enumerate
!= 1) {
9388 mpt3sas_raid_template
=
9389 raid_class_attach(&mpt3sas_raid_functions
);
9390 if (!mpt3sas_raid_template
) {
9391 sas_release_transport(mpt3sas_transport_template
);
9396 /* No need to attach mpt2sas raid functions template
9397 * if hbas_to_enumarate value is two
9399 if (hbas_to_enumerate
!= 2) {
9400 mpt2sas_raid_template
=
9401 raid_class_attach(&mpt2sas_raid_functions
);
9402 if (!mpt2sas_raid_template
) {
9403 sas_release_transport(mpt3sas_transport_template
);
9408 error
= scsih_init();
9414 mpt3sas_ctl_init(hbas_to_enumerate
);
9416 error
= pci_register_driver(&mpt3sas_driver
);
9424 * _mpt3sas_exit - exit point for this driver (when it is a module).
9430 pr_info("mpt3sas version %s unloading\n",
9431 MPT3SAS_DRIVER_VERSION
);
9433 pci_unregister_driver(&mpt3sas_driver
);
9435 mpt3sas_ctl_exit(hbas_to_enumerate
);
9440 module_init(_mpt3sas_init
);
9441 module_exit(_mpt3sas_exit
);