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-2013 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
57 #include "mpt3sas_base.h"
59 MODULE_AUTHOR(MPT3SAS_AUTHOR
);
60 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION
);
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(MPT3SAS_DRIVER_VERSION
);
64 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
67 struct _sas_node
*sas_expander
);
68 static void _firmware_event_work(struct work_struct
*work
);
70 static void _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
71 struct _sas_device
*sas_device
);
72 static int _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
73 u8 retry_count
, u8 is_pd
);
75 static u8
_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
);
77 static void _scsih_scan_start(struct Scsi_Host
*shost
);
78 static int _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
);
80 /* global parameters */
81 LIST_HEAD(mpt3sas_ioc_list
);
83 /* local parameters */
84 static u8 scsi_io_cb_idx
= -1;
85 static u8 tm_cb_idx
= -1;
86 static u8 ctl_cb_idx
= -1;
87 static u8 base_cb_idx
= -1;
88 static u8 port_enable_cb_idx
= -1;
89 static u8 transport_cb_idx
= -1;
90 static u8 scsih_cb_idx
= -1;
91 static u8 config_cb_idx
= -1;
94 static u8 tm_tr_cb_idx
= -1 ;
95 static u8 tm_tr_volume_cb_idx
= -1 ;
96 static u8 tm_sas_control_cb_idx
= -1;
98 /* command line options */
99 static u32 logging_level
;
100 MODULE_PARM_DESC(logging_level
,
101 " bits for enabling additional logging info (default=0)");
104 static ushort max_sectors
= 0xFFFF;
105 module_param(max_sectors
, ushort
, 0);
106 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
109 static int missing_delay
[2] = {-1, -1};
110 module_param_array(missing_delay
, int, NULL
, 0);
111 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
113 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
114 #define MPT3SAS_MAX_LUN (16895)
115 static u64 max_lun
= MPT3SAS_MAX_LUN
;
116 module_param(max_lun
, ullong
, 0);
117 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
122 /* diag_buffer_enable is bitwise
124 * bit 1 set = SNAPSHOT
125 * bit 2 set = EXTENDED
127 * Either bit can be set, or both
129 static int diag_buffer_enable
= -1;
130 module_param(diag_buffer_enable
, int, 0);
131 MODULE_PARM_DESC(diag_buffer_enable
,
132 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
133 static int disable_discovery
= -1;
134 module_param(disable_discovery
, int, 0);
135 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
138 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
139 static int prot_mask
= -1;
140 module_param(prot_mask
, int, 0);
141 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
144 /* raid transport support */
146 static struct raid_template
*mpt3sas_raid_template
;
150 * struct sense_info - common structure for obtaining sense keys
152 * @asc: additional sense code
153 * @ascq: additional sense code qualifier
161 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
162 #define MPT3SAS_TURN_ON_FAULT_LED (0xFFFC)
163 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
164 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
165 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
167 * struct fw_event_work - firmware event struct
168 * @list: link list framework
169 * @work: work object (ioc->fault_reset_work_q)
170 * @cancel_pending_work: flag set during reset handling
171 * @ioc: per adapter object
172 * @device_handle: device handle
173 * @VF_ID: virtual function id
174 * @VP_ID: virtual port id
175 * @ignore: flag meaning this event has been marked to ignore
176 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
177 * @event_data: reply event data payload follows
179 * This object stored on ioc->fw_event_list.
181 struct fw_event_work
{
182 struct list_head list
;
183 struct work_struct work
;
184 u8 cancel_pending_work
;
185 struct delayed_work delayed_work
;
187 struct MPT3SAS_ADAPTER
*ioc
;
196 /* raid transport support */
197 static struct raid_template
*mpt3sas_raid_template
;
200 * struct _scsi_io_transfer - scsi io transfer
201 * @handle: sas device handle (assigned by firmware)
202 * @is_raid: flag set for hidden raid components
203 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
204 * @data_length: data transfer length
205 * @data_dma: dma pointer to data
208 * @cdb_length: cdb length
210 * @timeout: timeout for this command
211 * @VF_ID: virtual function id
212 * @VP_ID: virtual port id
213 * @valid_reply: flag set for reply message
214 * @sense_length: sense length
215 * @ioc_status: ioc status
216 * @scsi_state: scsi state
217 * @scsi_status: scsi staus
218 * @log_info: log information
219 * @transfer_length: data length transfer when there is a reply message
221 * Used for sending internal scsi commands to devices within this module.
222 * Refer to _scsi_send_scsi_io().
224 struct _scsi_io_transfer
{
227 enum dma_data_direction dir
;
230 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
238 /* the following bits are only valid when 'valid_reply = 1' */
248 * The pci device ids are defined in mpi/mpi2_cnfg.h.
250 static DEFINE_PCI_DEVICE_TABLE(scsih_pci_table
) = {
251 /* Fury ~ 3004 and 3008 */
252 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
253 PCI_ANY_ID
, PCI_ANY_ID
},
254 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
255 PCI_ANY_ID
, PCI_ANY_ID
},
257 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
258 PCI_ANY_ID
, PCI_ANY_ID
},
259 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
260 PCI_ANY_ID
, PCI_ANY_ID
},
261 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
262 PCI_ANY_ID
, PCI_ANY_ID
},
263 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
264 PCI_ANY_ID
, PCI_ANY_ID
},
265 {0} /* Terminating entry */
267 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
270 * _scsih_set_debug_level - global setting of ioc->logging_level.
272 * Note: The logging levels are defined in mpt3sas_debug.h.
275 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
277 int ret
= param_set_int(val
, kp
);
278 struct MPT3SAS_ADAPTER
*ioc
;
283 pr_info("setting logging_level(0x%08x)\n", logging_level
);
284 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
285 ioc
->logging_level
= logging_level
;
288 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
289 &logging_level
, 0644);
292 * _scsih_srch_boot_sas_address - search based on sas_address
293 * @sas_address: sas address
294 * @boot_device: boot device object from bios page 2
296 * Returns 1 when there's a match, 0 means no match.
299 _scsih_srch_boot_sas_address(u64 sas_address
,
300 Mpi2BootDeviceSasWwid_t
*boot_device
)
302 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
306 * _scsih_srch_boot_device_name - search based on device name
307 * @device_name: device name specified in INDENTIFY fram
308 * @boot_device: boot device object from bios page 2
310 * Returns 1 when there's a match, 0 means no match.
313 _scsih_srch_boot_device_name(u64 device_name
,
314 Mpi2BootDeviceDeviceName_t
*boot_device
)
316 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
320 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
321 * @enclosure_logical_id: enclosure logical id
322 * @slot_number: slot number
323 * @boot_device: boot device object from bios page 2
325 * Returns 1 when there's a match, 0 means no match.
328 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
329 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
331 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
332 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
333 SlotNumber
)) ? 1 : 0;
337 * _scsih_is_boot_device - search for matching boot device.
338 * @sas_address: sas address
339 * @device_name: device name specified in INDENTIFY fram
340 * @enclosure_logical_id: enclosure logical id
341 * @slot_number: slot number
342 * @form: specifies boot device form
343 * @boot_device: boot device object from bios page 2
345 * Returns 1 when there's a match, 0 means no match.
348 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
349 u64 enclosure_logical_id
, u16 slot
, u8 form
,
350 Mpi2BiosPage2BootDevice_t
*boot_device
)
355 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
358 rc
= _scsih_srch_boot_sas_address(
359 sas_address
, &boot_device
->SasWwid
);
361 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
362 if (!enclosure_logical_id
)
364 rc
= _scsih_srch_boot_encl_slot(
365 enclosure_logical_id
,
366 slot
, &boot_device
->EnclosureSlot
);
368 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
371 rc
= _scsih_srch_boot_device_name(
372 device_name
, &boot_device
->DeviceName
);
374 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
382 * _scsih_get_sas_address - set the sas_address for given device handle
383 * @handle: device handle
384 * @sas_address: sas address
386 * Returns 0 success, non-zero when failure
389 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
392 Mpi2SasDevicePage0_t sas_device_pg0
;
393 Mpi2ConfigReply_t mpi_reply
;
398 if (handle
<= ioc
->sas_hba
.num_phys
) {
399 *sas_address
= ioc
->sas_hba
.sas_address
;
403 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
404 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
405 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
406 __FILE__
, __LINE__
, __func__
);
410 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
411 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
412 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
416 /* we hit this becuase the given parent handle doesn't exist */
417 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
420 /* else error case */
422 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
423 ioc
->name
, handle
, ioc_status
,
424 __FILE__
, __LINE__
, __func__
);
429 * _scsih_determine_boot_device - determine boot device.
430 * @ioc: per adapter object
431 * @device: either sas_device or raid_device object
432 * @is_raid: [flag] 1 = raid object, 0 = sas object
434 * Determines whether this device should be first reported device to
435 * to scsi-ml or sas transport, this purpose is for persistent boot device.
436 * There are primary, alternate, and current entries in bios page 2. The order
437 * priority is primary, alternate, then current. This routine saves
438 * the corresponding device object and is_raid flag in the ioc object.
439 * The saved data to be used later in _scsih_probe_boot_devices().
442 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
,
443 void *device
, u8 is_raid
)
445 struct _sas_device
*sas_device
;
446 struct _raid_device
*raid_device
;
449 u64 enclosure_logical_id
;
452 /* only process this function when driver loads */
453 if (!ioc
->is_driver_loading
)
456 /* no Bios, return immediately */
457 if (!ioc
->bios_pg3
.BiosVersion
)
462 sas_address
= sas_device
->sas_address
;
463 device_name
= sas_device
->device_name
;
464 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
465 slot
= sas_device
->slot
;
467 raid_device
= device
;
468 sas_address
= raid_device
->wwid
;
470 enclosure_logical_id
= 0;
474 if (!ioc
->req_boot_device
.device
) {
475 if (_scsih_is_boot_device(sas_address
, device_name
,
476 enclosure_logical_id
, slot
,
477 (ioc
->bios_pg2
.ReqBootDeviceForm
&
478 MPI2_BIOSPAGE2_FORM_MASK
),
479 &ioc
->bios_pg2
.RequestedBootDevice
)) {
480 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
481 "%s: req_boot_device(0x%016llx)\n",
483 (unsigned long long)sas_address
));
484 ioc
->req_boot_device
.device
= device
;
485 ioc
->req_boot_device
.is_raid
= is_raid
;
489 if (!ioc
->req_alt_boot_device
.device
) {
490 if (_scsih_is_boot_device(sas_address
, device_name
,
491 enclosure_logical_id
, slot
,
492 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
493 MPI2_BIOSPAGE2_FORM_MASK
),
494 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
495 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
496 "%s: req_alt_boot_device(0x%016llx)\n",
498 (unsigned long long)sas_address
));
499 ioc
->req_alt_boot_device
.device
= device
;
500 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
504 if (!ioc
->current_boot_device
.device
) {
505 if (_scsih_is_boot_device(sas_address
, device_name
,
506 enclosure_logical_id
, slot
,
507 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
508 MPI2_BIOSPAGE2_FORM_MASK
),
509 &ioc
->bios_pg2
.CurrentBootDevice
)) {
510 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
511 "%s: current_boot_device(0x%016llx)\n",
513 (unsigned long long)sas_address
));
514 ioc
->current_boot_device
.device
= device
;
515 ioc
->current_boot_device
.is_raid
= is_raid
;
521 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
522 * @ioc: per adapter object
523 * @sas_address: sas address
524 * Context: Calling function should acquire ioc->sas_device_lock
526 * This searches for sas_device based on sas_address, then return sas_device
530 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
533 struct _sas_device
*sas_device
;
535 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
536 if (sas_device
->sas_address
== sas_address
)
539 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
540 if (sas_device
->sas_address
== sas_address
)
547 * _scsih_sas_device_find_by_handle - sas device search
548 * @ioc: per adapter object
549 * @handle: sas device handle (assigned by firmware)
550 * Context: Calling function should acquire ioc->sas_device_lock
552 * This searches for sas_device based on sas_address, then return sas_device
555 static struct _sas_device
*
556 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
558 struct _sas_device
*sas_device
;
560 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
561 if (sas_device
->handle
== handle
)
564 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
565 if (sas_device
->handle
== handle
)
572 * _scsih_sas_device_remove - remove sas_device from list.
573 * @ioc: per adapter object
574 * @sas_device: the sas_device object
575 * Context: This function will acquire ioc->sas_device_lock.
577 * Removing object and freeing associated memory from the ioc->sas_device_list.
580 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
581 struct _sas_device
*sas_device
)
588 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
589 list_del(&sas_device
->list
);
591 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
595 * _scsih_device_remove_by_handle - removing device object by handle
596 * @ioc: per adapter object
597 * @handle: device handle
602 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
604 struct _sas_device
*sas_device
;
607 if (ioc
->shost_recovery
)
610 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
611 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
613 list_del(&sas_device
->list
);
614 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
616 _scsih_remove_device(ioc
, sas_device
);
620 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
621 * @ioc: per adapter object
622 * @sas_address: device sas_address
627 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
630 struct _sas_device
*sas_device
;
633 if (ioc
->shost_recovery
)
636 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
637 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
640 list_del(&sas_device
->list
);
641 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
643 _scsih_remove_device(ioc
, sas_device
);
647 * _scsih_sas_device_add - insert sas_device to the list.
648 * @ioc: per adapter object
649 * @sas_device: the sas_device object
650 * Context: This function will acquire ioc->sas_device_lock.
652 * Adding new object to the ioc->sas_device_list.
655 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
656 struct _sas_device
*sas_device
)
660 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
661 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
662 ioc
->name
, __func__
, sas_device
->handle
,
663 (unsigned long long)sas_device
->sas_address
));
665 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
666 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
667 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
669 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
670 sas_device
->sas_address_parent
)) {
671 _scsih_sas_device_remove(ioc
, sas_device
);
672 } else if (!sas_device
->starget
) {
674 * When asyn scanning is enabled, its not possible to remove
675 * devices while scanning is turned on due to an oops in
676 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
678 if (!ioc
->is_driver_loading
) {
679 mpt3sas_transport_port_remove(ioc
,
680 sas_device
->sas_address
,
681 sas_device
->sas_address_parent
);
682 _scsih_sas_device_remove(ioc
, sas_device
);
688 * _scsih_sas_device_init_add - insert sas_device to the list.
689 * @ioc: per adapter object
690 * @sas_device: the sas_device object
691 * Context: This function will acquire ioc->sas_device_lock.
693 * Adding new object at driver load time to the ioc->sas_device_init_list.
696 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
697 struct _sas_device
*sas_device
)
701 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
702 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
703 __func__
, sas_device
->handle
,
704 (unsigned long long)sas_device
->sas_address
));
706 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
707 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
708 _scsih_determine_boot_device(ioc
, sas_device
, 0);
709 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
713 * _scsih_raid_device_find_by_id - raid device search
714 * @ioc: per adapter object
715 * @id: sas device target id
716 * @channel: sas device channel
717 * Context: Calling function should acquire ioc->raid_device_lock
719 * This searches for raid_device based on target id, then return raid_device
722 static struct _raid_device
*
723 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
725 struct _raid_device
*raid_device
, *r
;
728 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
729 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
740 * _scsih_raid_device_find_by_handle - raid device search
741 * @ioc: per adapter object
742 * @handle: sas device handle (assigned by firmware)
743 * Context: Calling function should acquire ioc->raid_device_lock
745 * This searches for raid_device based on handle, then return raid_device
748 static struct _raid_device
*
749 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
751 struct _raid_device
*raid_device
, *r
;
754 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
755 if (raid_device
->handle
!= handle
)
766 * _scsih_raid_device_find_by_wwid - raid device search
767 * @ioc: per adapter object
768 * @handle: sas device handle (assigned by firmware)
769 * Context: Calling function should acquire ioc->raid_device_lock
771 * This searches for raid_device based on wwid, then return raid_device
774 static struct _raid_device
*
775 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
777 struct _raid_device
*raid_device
, *r
;
780 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
781 if (raid_device
->wwid
!= wwid
)
792 * _scsih_raid_device_add - add raid_device object
793 * @ioc: per adapter object
794 * @raid_device: raid_device object
796 * This is added to the raid_device_list link list.
799 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
800 struct _raid_device
*raid_device
)
804 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
805 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
806 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
808 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
809 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
810 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
814 * _scsih_raid_device_remove - delete raid_device object
815 * @ioc: per adapter object
816 * @raid_device: raid_device object
820 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
821 struct _raid_device
*raid_device
)
825 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
826 list_del(&raid_device
->list
);
828 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
832 * mpt3sas_scsih_expander_find_by_handle - expander device search
833 * @ioc: per adapter object
834 * @handle: expander handle (assigned by firmware)
835 * Context: Calling function should acquire ioc->sas_device_lock
837 * This searches for expander device based on handle, then returns the
841 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
843 struct _sas_node
*sas_expander
, *r
;
846 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
847 if (sas_expander
->handle
!= handle
)
857 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
858 * @ioc: per adapter object
859 * @sas_address: sas address
860 * Context: Calling function should acquire ioc->sas_node_lock.
862 * This searches for expander device based on sas_address, then returns the
866 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
869 struct _sas_node
*sas_expander
, *r
;
872 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
873 if (sas_expander
->sas_address
!= sas_address
)
883 * _scsih_expander_node_add - insert expander device to the list.
884 * @ioc: per adapter object
885 * @sas_expander: the sas_device object
886 * Context: This function will acquire ioc->sas_node_lock.
888 * Adding new object to the ioc->sas_expander_list.
893 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
894 struct _sas_node
*sas_expander
)
898 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
899 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
900 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
904 * _scsih_is_end_device - determines if device is an end device
905 * @device_info: bitfield providing information about the device.
908 * Returns 1 if end device.
911 _scsih_is_end_device(u32 device_info
)
913 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
914 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
915 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
916 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
923 * _scsih_scsi_lookup_get - returns scmd entry
924 * @ioc: per adapter object
925 * @smid: system request message index
927 * Returns the smid stored scmd pointer.
929 static struct scsi_cmnd
*
930 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
932 return ioc
->scsi_lookup
[smid
- 1].scmd
;
936 * _scsih_scsi_lookup_get_clear - returns scmd entry
937 * @ioc: per adapter object
938 * @smid: system request message index
940 * Returns the smid stored scmd pointer.
941 * Then will derefrence the stored scmd pointer.
943 static inline struct scsi_cmnd
*
944 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
947 struct scsi_cmnd
*scmd
;
949 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
950 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
951 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
952 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
958 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
959 * @ioc: per adapter object
960 * @smid: system request message index
961 * @scmd: pointer to scsi command object
962 * Context: This function will acquire ioc->scsi_lookup_lock.
964 * This will search for a scmd pointer in the scsi_lookup array,
965 * returning the revelent smid. A returned value of zero means invalid.
968 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
975 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
977 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
978 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
979 smid
= ioc
->scsi_lookup
[i
].smid
;
984 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
989 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
990 * @ioc: per adapter object
993 * Context: This function will acquire ioc->scsi_lookup_lock.
995 * This will search for a matching channel:id in the scsi_lookup array,
996 * returning 1 if found.
999 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1003 unsigned long flags
;
1006 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1008 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1009 if (ioc
->scsi_lookup
[i
].scmd
&&
1010 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1011 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1017 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1022 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1023 * @ioc: per adapter object
1027 * Context: This function will acquire ioc->scsi_lookup_lock.
1029 * This will search for a matching channel:id:lun in the scsi_lookup array,
1030 * returning 1 if found.
1033 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1034 unsigned int lun
, int channel
)
1037 unsigned long flags
;
1040 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1042 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1043 if (ioc
->scsi_lookup
[i
].scmd
&&
1044 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1045 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1046 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1052 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1058 _scsih_adjust_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1060 struct Scsi_Host
*shost
= sdev
->host
;
1062 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1063 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1064 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1065 struct _sas_device
*sas_device
;
1066 unsigned long flags
;
1068 max_depth
= shost
->can_queue
;
1070 /* limit max device queue for SATA to 32 */
1071 sas_device_priv_data
= sdev
->hostdata
;
1072 if (!sas_device_priv_data
)
1074 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1075 if (!sas_target_priv_data
)
1077 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1079 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1080 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1081 sas_device_priv_data
->sas_target
->sas_address
);
1082 if (sas_device
&& sas_device
->device_info
&
1083 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1084 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1085 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1089 if (!sdev
->tagged_supported
)
1091 if (qdepth
> max_depth
)
1093 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1097 * _scsih_change_queue_depth - setting device queue depth
1098 * @sdev: scsi device struct
1099 * @qdepth: requested queue depth
1100 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1101 * (see include/scsi/scsi_host.h for definition)
1103 * Returns queue depth.
1106 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1108 if (reason
== SCSI_QDEPTH_DEFAULT
|| reason
== SCSI_QDEPTH_RAMP_UP
)
1109 _scsih_adjust_queue_depth(sdev
, qdepth
);
1110 else if (reason
== SCSI_QDEPTH_QFULL
)
1111 scsi_track_queue_full(sdev
, qdepth
);
1115 if (sdev
->inquiry_len
> 7)
1116 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), " \
1117 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1118 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1119 sdev
->ordered_tags
, sdev
->scsi_level
,
1120 (sdev
->inquiry
[7] & 2) >> 1);
1122 return sdev
->queue_depth
;
1126 * _scsih_change_queue_type - changing device queue tag type
1127 * @sdev: scsi device struct
1128 * @tag_type: requested tag type
1130 * Returns queue tag type.
1133 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1135 if (sdev
->tagged_supported
) {
1136 scsi_set_tag_type(sdev
, tag_type
);
1138 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1140 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1149 * _scsih_target_alloc - target add routine
1150 * @starget: scsi target struct
1152 * Returns 0 if ok. Any other return is assumed to be an error and
1153 * the device is ignored.
1156 _scsih_target_alloc(struct scsi_target
*starget
)
1158 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1159 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1160 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1161 struct _sas_device
*sas_device
;
1162 struct _raid_device
*raid_device
;
1163 unsigned long flags
;
1164 struct sas_rphy
*rphy
;
1166 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1167 if (!sas_target_priv_data
)
1170 starget
->hostdata
= sas_target_priv_data
;
1171 sas_target_priv_data
->starget
= starget
;
1172 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1175 if (starget
->channel
== RAID_CHANNEL
) {
1176 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1177 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1180 sas_target_priv_data
->handle
= raid_device
->handle
;
1181 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1182 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1183 raid_device
->starget
= starget
;
1185 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1189 /* sas/sata devices */
1190 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1191 rphy
= dev_to_rphy(starget
->dev
.parent
);
1192 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1193 rphy
->identify
.sas_address
);
1196 sas_target_priv_data
->handle
= sas_device
->handle
;
1197 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1198 sas_device
->starget
= starget
;
1199 sas_device
->id
= starget
->id
;
1200 sas_device
->channel
= starget
->channel
;
1201 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1202 sas_target_priv_data
->flags
|=
1203 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1204 if (sas_device
->fast_path
)
1205 sas_target_priv_data
->flags
|= MPT_TARGET_FASTPATH_IO
;
1207 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1213 * _scsih_target_destroy - target destroy routine
1214 * @starget: scsi target struct
1219 _scsih_target_destroy(struct scsi_target
*starget
)
1221 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1222 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1223 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1224 struct _sas_device
*sas_device
;
1225 struct _raid_device
*raid_device
;
1226 unsigned long flags
;
1227 struct sas_rphy
*rphy
;
1229 sas_target_priv_data
= starget
->hostdata
;
1230 if (!sas_target_priv_data
)
1233 if (starget
->channel
== RAID_CHANNEL
) {
1234 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1235 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1238 raid_device
->starget
= NULL
;
1239 raid_device
->sdev
= NULL
;
1241 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1245 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1246 rphy
= dev_to_rphy(starget
->dev
.parent
);
1247 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1248 rphy
->identify
.sas_address
);
1249 if (sas_device
&& (sas_device
->starget
== starget
) &&
1250 (sas_device
->id
== starget
->id
) &&
1251 (sas_device
->channel
== starget
->channel
))
1252 sas_device
->starget
= NULL
;
1254 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1257 kfree(sas_target_priv_data
);
1258 starget
->hostdata
= NULL
;
1262 * _scsih_slave_alloc - device add routine
1263 * @sdev: scsi device struct
1265 * Returns 0 if ok. Any other return is assumed to be an error and
1266 * the device is ignored.
1269 _scsih_slave_alloc(struct scsi_device
*sdev
)
1271 struct Scsi_Host
*shost
;
1272 struct MPT3SAS_ADAPTER
*ioc
;
1273 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1274 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1275 struct scsi_target
*starget
;
1276 struct _raid_device
*raid_device
;
1277 struct _sas_device
*sas_device
;
1278 unsigned long flags
;
1280 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1281 if (!sas_device_priv_data
)
1284 sas_device_priv_data
->lun
= sdev
->lun
;
1285 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1287 starget
= scsi_target(sdev
);
1288 sas_target_priv_data
= starget
->hostdata
;
1289 sas_target_priv_data
->num_luns
++;
1290 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1291 sdev
->hostdata
= sas_device_priv_data
;
1292 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1293 sdev
->no_uld_attach
= 1;
1295 shost
= dev_to_shost(&starget
->dev
);
1296 ioc
= shost_priv(shost
);
1297 if (starget
->channel
== RAID_CHANNEL
) {
1298 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1299 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1300 starget
->id
, starget
->channel
);
1302 raid_device
->sdev
= sdev
; /* raid is single lun */
1303 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1306 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1307 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1308 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1309 sas_target_priv_data
->sas_address
);
1310 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1311 sdev_printk(KERN_INFO
, sdev
,
1312 "%s : sas_device->starget set to starget @ %d\n",
1313 __func__
, __LINE__
);
1314 sas_device
->starget
= starget
;
1316 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1323 * _scsih_slave_destroy - device destroy routine
1324 * @sdev: scsi device struct
1329 _scsih_slave_destroy(struct scsi_device
*sdev
)
1331 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1332 struct scsi_target
*starget
;
1333 struct Scsi_Host
*shost
;
1334 struct MPT3SAS_ADAPTER
*ioc
;
1335 struct _sas_device
*sas_device
;
1336 unsigned long flags
;
1338 if (!sdev
->hostdata
)
1341 starget
= scsi_target(sdev
);
1342 sas_target_priv_data
= starget
->hostdata
;
1343 sas_target_priv_data
->num_luns
--;
1345 shost
= dev_to_shost(&starget
->dev
);
1346 ioc
= shost_priv(shost
);
1348 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1349 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1350 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1351 sas_target_priv_data
->sas_address
);
1352 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1353 sas_device
->starget
= NULL
;
1354 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1357 kfree(sdev
->hostdata
);
1358 sdev
->hostdata
= NULL
;
1362 * _scsih_display_sata_capabilities - sata capabilities
1363 * @ioc: per adapter object
1364 * @handle: device handle
1365 * @sdev: scsi device struct
1368 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1369 u16 handle
, struct scsi_device
*sdev
)
1371 Mpi2ConfigReply_t mpi_reply
;
1372 Mpi2SasDevicePage0_t sas_device_pg0
;
1377 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1378 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1379 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1380 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1384 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1385 MPI2_IOCSTATUS_MASK
;
1386 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1387 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1388 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1392 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1393 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1395 sdev_printk(KERN_INFO
, sdev
,
1396 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1397 "sw_preserve(%s)\n",
1398 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1399 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1400 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1402 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1403 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1404 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1408 * raid transport support -
1409 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1410 * unloading the driver followed by a load - I beleive that the subroutine
1411 * raid_class_release() is not cleaning up properly.
1415 * _scsih_is_raid - return boolean indicating device is raid volume
1416 * @dev the device struct object
1419 _scsih_is_raid(struct device
*dev
)
1421 struct scsi_device
*sdev
= to_scsi_device(dev
);
1423 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1427 * _scsih_get_resync - get raid volume resync percent complete
1428 * @dev the device struct object
1431 _scsih_get_resync(struct device
*dev
)
1433 struct scsi_device
*sdev
= to_scsi_device(dev
);
1434 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1435 static struct _raid_device
*raid_device
;
1436 unsigned long flags
;
1437 Mpi2RaidVolPage0_t vol_pg0
;
1438 Mpi2ConfigReply_t mpi_reply
;
1439 u32 volume_status_flags
;
1440 u8 percent_complete
;
1443 percent_complete
= 0;
1445 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1446 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1449 handle
= raid_device
->handle
;
1450 percent_complete
= raid_device
->percent_complete
;
1452 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1457 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1458 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1459 sizeof(Mpi2RaidVolPage0_t
))) {
1460 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1461 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1462 percent_complete
= 0;
1466 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1467 if (!(volume_status_flags
&
1468 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1469 percent_complete
= 0;
1472 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1476 * _scsih_get_state - get raid volume level
1477 * @dev the device struct object
1480 _scsih_get_state(struct device
*dev
)
1482 struct scsi_device
*sdev
= to_scsi_device(dev
);
1483 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1484 static struct _raid_device
*raid_device
;
1485 unsigned long flags
;
1486 Mpi2RaidVolPage0_t vol_pg0
;
1487 Mpi2ConfigReply_t mpi_reply
;
1489 enum raid_state state
= RAID_STATE_UNKNOWN
;
1492 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1493 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1496 handle
= raid_device
->handle
;
1497 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1502 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1503 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1504 sizeof(Mpi2RaidVolPage0_t
))) {
1505 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1506 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1510 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1511 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1512 state
= RAID_STATE_RESYNCING
;
1516 switch (vol_pg0
.VolumeState
) {
1517 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1518 case MPI2_RAID_VOL_STATE_ONLINE
:
1519 state
= RAID_STATE_ACTIVE
;
1521 case MPI2_RAID_VOL_STATE_DEGRADED
:
1522 state
= RAID_STATE_DEGRADED
;
1524 case MPI2_RAID_VOL_STATE_FAILED
:
1525 case MPI2_RAID_VOL_STATE_MISSING
:
1526 state
= RAID_STATE_OFFLINE
;
1530 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1534 * _scsih_set_level - set raid level
1535 * @sdev: scsi device struct
1536 * @volume_type: volume type
1539 _scsih_set_level(struct scsi_device
*sdev
, u8 volume_type
)
1541 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1543 switch (volume_type
) {
1544 case MPI2_RAID_VOL_TYPE_RAID0
:
1545 level
= RAID_LEVEL_0
;
1547 case MPI2_RAID_VOL_TYPE_RAID10
:
1548 level
= RAID_LEVEL_10
;
1550 case MPI2_RAID_VOL_TYPE_RAID1E
:
1551 level
= RAID_LEVEL_1E
;
1553 case MPI2_RAID_VOL_TYPE_RAID1
:
1554 level
= RAID_LEVEL_1
;
1558 raid_set_level(mpt3sas_raid_template
, &sdev
->sdev_gendev
, level
);
1563 * _scsih_get_volume_capabilities - volume capabilities
1564 * @ioc: per adapter object
1565 * @sas_device: the raid_device object
1567 * Returns 0 for success, else 1
1570 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1571 struct _raid_device
*raid_device
)
1573 Mpi2RaidVolPage0_t
*vol_pg0
;
1574 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1575 Mpi2SasDevicePage0_t sas_device_pg0
;
1576 Mpi2ConfigReply_t mpi_reply
;
1580 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1581 &num_pds
)) || !num_pds
) {
1582 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1583 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1588 raid_device
->num_pds
= num_pds
;
1589 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1590 sizeof(Mpi2RaidVol0PhysDisk_t
));
1591 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1593 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1594 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1599 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1600 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1601 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1602 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1608 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1610 /* figure out what the underlying devices are by
1611 * obtaining the device_info bits for the 1st device
1613 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1614 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1615 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1616 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1617 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1618 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1619 raid_device
->device_info
=
1620 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1631 * _scsih_enable_tlr - setting TLR flags
1632 * @ioc: per adapter object
1633 * @sdev: scsi device struct
1635 * Enabling Transaction Layer Retries for tape devices when
1636 * vpd page 0x90 is present
1640 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1644 if (sdev
->type
!= TYPE_TAPE
)
1647 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1650 sas_enable_tlr(sdev
);
1651 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1652 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1658 * _scsih_slave_configure - device configure routine.
1659 * @sdev: scsi device struct
1661 * Returns 0 if ok. Any other return is assumed to be an error and
1662 * the device is ignored.
1665 _scsih_slave_configure(struct scsi_device
*sdev
)
1667 struct Scsi_Host
*shost
= sdev
->host
;
1668 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1669 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1670 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1671 struct _sas_device
*sas_device
;
1672 struct _raid_device
*raid_device
;
1673 unsigned long flags
;
1678 u16 handle
, volume_handle
= 0;
1679 u64 volume_wwid
= 0;
1682 sas_device_priv_data
= sdev
->hostdata
;
1683 sas_device_priv_data
->configured_lun
= 1;
1684 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1685 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1686 handle
= sas_target_priv_data
->handle
;
1688 /* raid volume handling */
1689 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1691 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1692 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1693 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1695 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1696 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1697 __LINE__
, __func__
));
1701 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1702 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1703 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1704 __LINE__
, __func__
));
1709 /* RAID Queue Depth Support
1710 * IS volume = underlying qdepth of drive type, either
1711 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1712 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1714 if (raid_device
->device_info
&
1715 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1716 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1719 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1720 if (raid_device
->device_info
&
1721 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1727 switch (raid_device
->volume_type
) {
1728 case MPI2_RAID_VOL_TYPE_RAID0
:
1731 case MPI2_RAID_VOL_TYPE_RAID1E
:
1732 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1733 if (ioc
->manu_pg10
.OEMIdentifier
&&
1734 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1735 MFG10_GF0_R10_DISPLAY
) &&
1736 !(raid_device
->num_pds
% 2))
1741 case MPI2_RAID_VOL_TYPE_RAID1
:
1742 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1745 case MPI2_RAID_VOL_TYPE_RAID10
:
1746 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1749 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1751 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1756 sdev_printk(KERN_INFO
, sdev
,
1757 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1758 r_level
, raid_device
->handle
,
1759 (unsigned long long)raid_device
->wwid
,
1760 raid_device
->num_pds
, ds
);
1763 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1765 /* raid transport support */
1766 _scsih_set_level(sdev
, raid_device
->volume_type
);
1770 /* non-raid handling */
1771 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1772 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1774 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1775 "failure at %s:%d/%s()!\n", ioc
->name
,
1776 __FILE__
, __LINE__
, __func__
));
1779 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1780 volume_handle
, &volume_wwid
)) {
1781 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1782 "failure at %s:%d/%s()!\n", ioc
->name
,
1783 __FILE__
, __LINE__
, __func__
));
1788 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1789 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1790 sas_device_priv_data
->sas_target
->sas_address
);
1792 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1793 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1794 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1799 sas_device
->volume_handle
= volume_handle
;
1800 sas_device
->volume_wwid
= volume_wwid
;
1801 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1802 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1806 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1807 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1809 else if (sas_device
->device_info
&
1810 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1814 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
1815 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1816 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
1817 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
1818 sdev_printk(KERN_INFO
, sdev
,
1819 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1820 ds
, (unsigned long long)
1821 sas_device
->enclosure_logical_id
, sas_device
->slot
);
1823 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1826 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
1829 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
1832 sas_read_port_mode_page(sdev
);
1833 _scsih_enable_tlr(ioc
, sdev
);
1840 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1841 * @sdev: scsi device struct
1842 * @bdev: pointer to block device context
1843 * @capacity: device size (in 512 byte sectors)
1844 * @params: three element array to place output:
1845 * params[0] number of heads (max 255)
1846 * params[1] number of sectors (max 63)
1847 * params[2] number of cylinders
1852 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1853 sector_t capacity
, int params
[])
1863 dummy
= heads
* sectors
;
1864 cylinders
= capacity
;
1865 sector_div(cylinders
, dummy
);
1868 * Handle extended translation size for logical drives
1871 if ((ulong
)capacity
>= 0x200000) {
1874 dummy
= heads
* sectors
;
1875 cylinders
= capacity
;
1876 sector_div(cylinders
, dummy
);
1881 params
[1] = sectors
;
1882 params
[2] = cylinders
;
1888 * _scsih_response_code - translation of device response code
1889 * @ioc: per adapter object
1890 * @response_code: response code returned by the device
1895 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
1899 switch (response_code
) {
1900 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1901 desc
= "task management request completed";
1903 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1904 desc
= "invalid frame";
1906 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1907 desc
= "task management request not supported";
1909 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1910 desc
= "task management request failed";
1912 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1913 desc
= "task management request succeeded";
1915 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1916 desc
= "invalid lun";
1919 desc
= "overlapped tag attempted";
1921 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1922 desc
= "task queued, however not sent to target";
1928 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
1929 ioc
->name
, response_code
, desc
);
1933 * _scsih_tm_done - tm completion routine
1934 * @ioc: per adapter object
1935 * @smid: system request message index
1936 * @msix_index: MSIX table index supplied by the OS
1937 * @reply: reply message frame(lower 32bit addr)
1940 * The callback handler when using scsih_issue_tm.
1942 * Return 1 meaning mf should be freed from _base_interrupt
1943 * 0 means the mf is freed from this function.
1946 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1948 MPI2DefaultReply_t
*mpi_reply
;
1950 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
1952 if (ioc
->tm_cmds
.smid
!= smid
)
1954 mpt3sas_base_flush_reply_queues(ioc
);
1955 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
1956 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
1958 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1959 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
1961 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
1962 complete(&ioc
->tm_cmds
.done
);
1967 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1968 * @ioc: per adapter object
1969 * @handle: device handle
1971 * During taskmangement request, we need to freeze the device queue.
1974 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1976 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1977 struct scsi_device
*sdev
;
1980 shost_for_each_device(sdev
, ioc
->shost
) {
1983 sas_device_priv_data
= sdev
->hostdata
;
1984 if (!sas_device_priv_data
)
1986 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1987 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1989 ioc
->ignore_loginfos
= 1;
1995 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1996 * @ioc: per adapter object
1997 * @handle: device handle
1999 * During taskmangement request, we need to freeze the device queue.
2002 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2004 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2005 struct scsi_device
*sdev
;
2008 shost_for_each_device(sdev
, ioc
->shost
) {
2011 sas_device_priv_data
= sdev
->hostdata
;
2012 if (!sas_device_priv_data
)
2014 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2015 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2017 ioc
->ignore_loginfos
= 0;
2023 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2024 * @ioc: per adapter struct
2025 * @device_handle: device handle
2026 * @channel: the channel assigned by the OS
2027 * @id: the id assigned by the OS
2029 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2030 * @smid_task: smid assigned to the task
2031 * @timeout: timeout in seconds
2032 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2035 * A generic API for sending task management requests to firmware.
2037 * The callback index is set inside `ioc->tm_cb_idx`.
2039 * Return SUCCESS or FAILED.
2042 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2043 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2044 enum mutex_type m_type
)
2046 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2047 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2050 unsigned long timeleft
;
2051 struct scsiio_tracker
*scsi_lookup
= NULL
;
2054 if (m_type
== TM_MUTEX_ON
)
2055 mutex_lock(&ioc
->tm_cmds
.mutex
);
2056 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2057 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2058 __func__
, ioc
->name
);
2063 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2064 ioc
->pci_error_recovery
) {
2065 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2066 __func__
, ioc
->name
);
2071 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2072 if (ioc_state
& MPI2_DOORBELL_USED
) {
2073 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2074 "unexpected doorbell active!\n", ioc
->name
));
2075 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2077 rc
= (!rc
) ? SUCCESS
: FAILED
;
2081 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2082 mpt3sas_base_fault_info(ioc
, ioc_state
&
2083 MPI2_DOORBELL_DATA_MASK
);
2084 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2086 rc
= (!rc
) ? SUCCESS
: FAILED
;
2090 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2092 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2093 ioc
->name
, __func__
);
2098 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2099 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2101 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2102 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2103 ioc
->name
, handle
, type
, smid_task
));
2104 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2105 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2106 ioc
->tm_cmds
.smid
= smid
;
2107 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2108 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2109 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2110 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2111 mpi_request
->TaskType
= type
;
2112 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2113 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2114 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2115 init_completion(&ioc
->tm_cmds
.done
);
2116 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
2117 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2118 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2119 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2120 ioc
->name
, __func__
);
2121 _debug_dump_mf(mpi_request
,
2122 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2123 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2124 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2126 rc
= (!rc
) ? SUCCESS
: FAILED
;
2127 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2128 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2133 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2134 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2135 mpi_reply
= ioc
->tm_cmds
.reply
;
2136 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2137 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2138 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2139 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2140 le32_to_cpu(mpi_reply
->TerminationCount
)));
2141 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2142 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2143 if (mpi_reply
->IOCStatus
)
2144 _debug_dump_mf(mpi_request
,
2145 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2150 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2152 if (scsi_lookup
->scmd
== NULL
)
2157 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2158 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2163 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2164 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2165 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2170 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2178 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2179 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2180 if (m_type
== TM_MUTEX_ON
)
2181 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2186 if (m_type
== TM_MUTEX_ON
)
2187 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2192 * _scsih_tm_display_info - displays info about the device
2193 * @ioc: per adapter struct
2194 * @scmd: pointer to scsi command object
2196 * Called by task management callback handlers.
2199 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2201 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2202 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2203 struct _sas_device
*sas_device
= NULL
;
2204 unsigned long flags
;
2205 char *device_str
= NULL
;
2209 device_str
= "volume";
2211 scsi_print_command(scmd
);
2212 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2213 starget_printk(KERN_INFO
, starget
,
2214 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2215 device_str
, priv_target
->handle
,
2216 device_str
, (unsigned long long)priv_target
->sas_address
);
2218 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2219 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
2220 priv_target
->sas_address
);
2222 if (priv_target
->flags
&
2223 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2224 starget_printk(KERN_INFO
, starget
,
2225 "volume handle(0x%04x), "
2226 "volume wwid(0x%016llx)\n",
2227 sas_device
->volume_handle
,
2228 (unsigned long long)sas_device
->volume_wwid
);
2230 starget_printk(KERN_INFO
, starget
,
2231 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2233 (unsigned long long)sas_device
->sas_address
,
2235 starget_printk(KERN_INFO
, starget
,
2236 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2237 (unsigned long long)sas_device
->enclosure_logical_id
,
2240 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2245 * _scsih_abort - eh threads main abort routine
2246 * @scmd: pointer to scsi command object
2248 * Returns SUCCESS if command aborted else FAILED
2251 _scsih_abort(struct scsi_cmnd
*scmd
)
2253 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2254 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2259 sdev_printk(KERN_INFO
, scmd
->device
,
2260 "attempting task abort! scmd(%p)\n", scmd
);
2261 _scsih_tm_display_info(ioc
, scmd
);
2263 sas_device_priv_data
= scmd
->device
->hostdata
;
2264 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2265 sdev_printk(KERN_INFO
, scmd
->device
,
2266 "device been deleted! scmd(%p)\n", scmd
);
2267 scmd
->result
= DID_NO_CONNECT
<< 16;
2268 scmd
->scsi_done(scmd
);
2273 /* search for the command */
2274 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2276 scmd
->result
= DID_RESET
<< 16;
2281 /* for hidden raid components and volumes this is not supported */
2282 if (sas_device_priv_data
->sas_target
->flags
&
2283 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2284 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2285 scmd
->result
= DID_RESET
<< 16;
2290 mpt3sas_halt_firmware(ioc
);
2292 handle
= sas_device_priv_data
->sas_target
->handle
;
2293 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2294 scmd
->device
->id
, scmd
->device
->lun
,
2295 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, TM_MUTEX_ON
);
2298 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2299 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2304 * _scsih_dev_reset - eh threads main device reset routine
2305 * @scmd: pointer to scsi command object
2307 * Returns SUCCESS if command aborted else FAILED
2310 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2312 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2313 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2314 struct _sas_device
*sas_device
;
2315 unsigned long flags
;
2319 sdev_printk(KERN_INFO
, scmd
->device
,
2320 "attempting device reset! scmd(%p)\n", scmd
);
2321 _scsih_tm_display_info(ioc
, scmd
);
2323 sas_device_priv_data
= scmd
->device
->hostdata
;
2324 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2325 sdev_printk(KERN_INFO
, scmd
->device
,
2326 "device been deleted! scmd(%p)\n", scmd
);
2327 scmd
->result
= DID_NO_CONNECT
<< 16;
2328 scmd
->scsi_done(scmd
);
2333 /* for hidden raid components obtain the volume_handle */
2335 if (sas_device_priv_data
->sas_target
->flags
&
2336 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2337 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2338 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2339 sas_device_priv_data
->sas_target
->handle
);
2341 handle
= sas_device
->volume_handle
;
2342 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2344 handle
= sas_device_priv_data
->sas_target
->handle
;
2347 scmd
->result
= DID_RESET
<< 16;
2352 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2353 scmd
->device
->id
, scmd
->device
->lun
,
2354 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, TM_MUTEX_ON
);
2357 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2358 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2363 * _scsih_target_reset - eh threads main target reset routine
2364 * @scmd: pointer to scsi command object
2366 * Returns SUCCESS if command aborted else FAILED
2369 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2371 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2372 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2373 struct _sas_device
*sas_device
;
2374 unsigned long flags
;
2377 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2379 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2381 _scsih_tm_display_info(ioc
, scmd
);
2383 sas_device_priv_data
= scmd
->device
->hostdata
;
2384 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2385 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2387 scmd
->result
= DID_NO_CONNECT
<< 16;
2388 scmd
->scsi_done(scmd
);
2393 /* for hidden raid components obtain the volume_handle */
2395 if (sas_device_priv_data
->sas_target
->flags
&
2396 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2397 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2398 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2399 sas_device_priv_data
->sas_target
->handle
);
2401 handle
= sas_device
->volume_handle
;
2402 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2404 handle
= sas_device_priv_data
->sas_target
->handle
;
2407 scmd
->result
= DID_RESET
<< 16;
2412 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2413 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2417 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2418 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2424 * _scsih_host_reset - eh threads main host reset routine
2425 * @scmd: pointer to scsi command object
2427 * Returns SUCCESS if command aborted else FAILED
2430 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2432 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2435 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
2437 scsi_print_command(scmd
);
2439 retval
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2441 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2442 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2443 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2449 * _scsih_fw_event_add - insert and queue up fw_event
2450 * @ioc: per adapter object
2451 * @fw_event: object describing the event
2452 * Context: This function will acquire ioc->fw_event_lock.
2454 * This adds the firmware event object into link list, then queues it up to
2455 * be processed from user context.
2460 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2462 unsigned long flags
;
2464 if (ioc
->firmware_event_thread
== NULL
)
2467 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2468 INIT_LIST_HEAD(&fw_event
->list
);
2469 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2470 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2471 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2472 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2476 * _scsih_fw_event_free - delete fw_event
2477 * @ioc: per adapter object
2478 * @fw_event: object describing the event
2479 * Context: This function will acquire ioc->fw_event_lock.
2481 * This removes firmware event object from link list, frees associated memory.
2486 _scsih_fw_event_free(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2489 unsigned long flags
;
2491 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2492 list_del(&fw_event
->list
);
2493 kfree(fw_event
->event_data
);
2495 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2500 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2501 * @ioc: per adapter object
2502 * @event_data: trigger event data
2507 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2508 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2510 struct fw_event_work
*fw_event
;
2512 if (ioc
->is_driver_loading
)
2514 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2517 fw_event
->event_data
= kzalloc(sizeof(*event_data
), GFP_ATOMIC
);
2518 if (!fw_event
->event_data
)
2520 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2521 fw_event
->ioc
= ioc
;
2522 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2523 _scsih_fw_event_add(ioc
, fw_event
);
2527 * _scsih_error_recovery_delete_devices - remove devices not responding
2528 * @ioc: per adapter object
2533 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2535 struct fw_event_work
*fw_event
;
2537 if (ioc
->is_driver_loading
)
2539 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2542 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2543 fw_event
->ioc
= ioc
;
2544 _scsih_fw_event_add(ioc
, fw_event
);
2548 * mpt3sas_port_enable_complete - port enable completed (fake event)
2549 * @ioc: per adapter object
2554 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2556 struct fw_event_work
*fw_event
;
2558 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2561 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2562 fw_event
->ioc
= ioc
;
2563 _scsih_fw_event_add(ioc
, fw_event
);
2567 * _scsih_fw_event_cleanup_queue - cleanup event queue
2568 * @ioc: per adapter object
2570 * Walk the firmware event queue, either killing timers, or waiting
2571 * for outstanding events to complete
2576 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2578 struct fw_event_work
*fw_event
, *next
;
2580 if (list_empty(&ioc
->fw_event_list
) ||
2581 !ioc
->firmware_event_thread
|| in_interrupt())
2584 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2585 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2586 _scsih_fw_event_free(ioc
, fw_event
);
2589 fw_event
->cancel_pending_work
= 1;
2594 * _scsih_ublock_io_all_device - unblock every device
2595 * @ioc: per adapter object
2597 * change the device state from block to running
2600 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2602 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2603 struct scsi_device
*sdev
;
2605 shost_for_each_device(sdev
, ioc
->shost
) {
2606 sas_device_priv_data
= sdev
->hostdata
;
2607 if (!sas_device_priv_data
)
2609 if (!sas_device_priv_data
->block
)
2612 sas_device_priv_data
->block
= 0;
2613 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2614 "device_running, handle(0x%04x)\n",
2615 sas_device_priv_data
->sas_target
->handle
));
2616 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2622 * _scsih_ublock_io_device - prepare device to be deleted
2623 * @ioc: per adapter object
2624 * @sas_addr: sas address
2626 * unblock then put device in offline state
2629 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2631 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2632 struct scsi_device
*sdev
;
2634 shost_for_each_device(sdev
, ioc
->shost
) {
2635 sas_device_priv_data
= sdev
->hostdata
;
2636 if (!sas_device_priv_data
)
2638 if (sas_device_priv_data
->sas_target
->sas_address
2641 if (sas_device_priv_data
->block
) {
2642 sas_device_priv_data
->block
= 0;
2643 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2649 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2650 * @ioc: per adapter object
2651 * @handle: device handle
2653 * During device pull we need to appropiately set the sdev state.
2656 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2658 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2659 struct scsi_device
*sdev
;
2661 shost_for_each_device(sdev
, ioc
->shost
) {
2662 sas_device_priv_data
= sdev
->hostdata
;
2663 if (!sas_device_priv_data
)
2665 if (sas_device_priv_data
->block
)
2667 sas_device_priv_data
->block
= 1;
2668 scsi_internal_device_block(sdev
);
2669 sdev_printk(KERN_INFO
, sdev
, "device_blocked, handle(0x%04x)\n",
2670 sas_device_priv_data
->sas_target
->handle
);
2675 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2676 * @ioc: per adapter object
2677 * @handle: device handle
2679 * During device pull we need to appropiately set the sdev state.
2682 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2684 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2685 struct scsi_device
*sdev
;
2687 shost_for_each_device(sdev
, ioc
->shost
) {
2688 sas_device_priv_data
= sdev
->hostdata
;
2689 if (!sas_device_priv_data
)
2691 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
2693 if (sas_device_priv_data
->block
)
2695 sas_device_priv_data
->block
= 1;
2696 scsi_internal_device_block(sdev
);
2697 sdev_printk(KERN_INFO
, sdev
,
2698 "device_blocked, handle(0x%04x)\n", handle
);
2703 * _scsih_block_io_to_children_attached_to_ex
2704 * @ioc: per adapter object
2705 * @sas_expander: the sas_device object
2707 * This routine set sdev state to SDEV_BLOCK for all devices
2708 * attached to this expander. This function called when expander is
2712 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
2713 struct _sas_node
*sas_expander
)
2715 struct _sas_port
*mpt3sas_port
;
2716 struct _sas_device
*sas_device
;
2717 struct _sas_node
*expander_sibling
;
2718 unsigned long flags
;
2723 list_for_each_entry(mpt3sas_port
,
2724 &sas_expander
->sas_port_list
, port_list
) {
2725 if (mpt3sas_port
->remote_identify
.device_type
==
2727 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2729 mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
2730 mpt3sas_port
->remote_identify
.sas_address
);
2732 set_bit(sas_device
->handle
,
2733 ioc
->blocking_handles
);
2734 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2738 list_for_each_entry(mpt3sas_port
,
2739 &sas_expander
->sas_port_list
, port_list
) {
2741 if (mpt3sas_port
->remote_identify
.device_type
==
2742 SAS_EDGE_EXPANDER_DEVICE
||
2743 mpt3sas_port
->remote_identify
.device_type
==
2744 SAS_FANOUT_EXPANDER_DEVICE
) {
2746 mpt3sas_scsih_expander_find_by_sas_address(
2747 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
2748 _scsih_block_io_to_children_attached_to_ex(ioc
,
2755 * _scsih_block_io_to_children_attached_directly
2756 * @ioc: per adapter object
2757 * @event_data: topology change event data
2759 * This routine set sdev state to SDEV_BLOCK for all devices
2760 * direct attached during device pull.
2763 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
2764 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2770 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2771 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2774 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2775 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2776 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2777 _scsih_block_io_device(ioc
, handle
);
2782 * _scsih_tm_tr_send - send task management request
2783 * @ioc: per adapter object
2784 * @handle: device handle
2785 * Context: interrupt time.
2787 * This code is to initiate the device removal handshake protocol
2788 * with controller firmware. This function will issue target reset
2789 * using high priority request queue. It will send a sas iounit
2790 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2792 * This is designed to send muliple task management request at the same
2793 * time to the fifo. If the fifo is full, we will append the request,
2794 * and process it in a future completion.
2797 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2799 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2801 struct _sas_device
*sas_device
;
2802 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
2803 u64 sas_address
= 0;
2804 unsigned long flags
;
2805 struct _tr_list
*delayed_tr
;
2808 if (ioc
->remove_host
) {
2809 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2810 "%s: host has been removed: handle(0x%04x)\n",
2811 __func__
, ioc
->name
, handle
));
2813 } else if (ioc
->pci_error_recovery
) {
2814 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2815 "%s: host in pci error recovery: handle(0x%04x)\n",
2816 __func__
, ioc
->name
,
2820 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
2821 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
2822 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2823 "%s: host is not operational: handle(0x%04x)\n",
2824 __func__
, ioc
->name
,
2829 /* if PD, then return */
2830 if (test_bit(handle
, ioc
->pd_handles
))
2833 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2834 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2835 if (sas_device
&& sas_device
->starget
&&
2836 sas_device
->starget
->hostdata
) {
2837 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2838 sas_target_priv_data
->deleted
= 1;
2839 sas_address
= sas_device
->sas_address
;
2841 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2843 if (sas_target_priv_data
) {
2844 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2845 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2847 (unsigned long long)sas_address
));
2848 _scsih_ublock_io_device(ioc
, sas_address
);
2849 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
2852 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2854 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2857 INIT_LIST_HEAD(&delayed_tr
->list
);
2858 delayed_tr
->handle
= handle
;
2859 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2860 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2861 "DELAYED:tr:handle(0x%04x), (open)\n",
2862 ioc
->name
, handle
));
2866 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2867 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2868 ioc
->name
, handle
, smid
,
2869 ioc
->tm_tr_cb_idx
));
2870 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2871 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2872 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2873 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2874 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2875 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
2876 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
2880 * _scsih_tm_tr_complete -
2881 * @ioc: per adapter object
2882 * @smid: system request message index
2883 * @msix_index: MSIX table index supplied by the OS
2884 * @reply: reply message frame(lower 32bit addr)
2885 * Context: interrupt time.
2887 * This is the target reset completion routine.
2888 * This code is part of the code to initiate the device removal
2889 * handshake protocol with controller firmware.
2890 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2892 * Return 1 meaning mf should be freed from _base_interrupt
2893 * 0 means the mf is freed from this function.
2896 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2900 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2901 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2902 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2903 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2907 if (ioc
->remove_host
) {
2908 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2909 "%s: host has been removed\n", __func__
, ioc
->name
));
2911 } else if (ioc
->pci_error_recovery
) {
2912 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2913 "%s: host in pci error recovery\n", __func__
,
2917 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
2918 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
2919 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2920 "%s: host is not operational\n", __func__
, ioc
->name
));
2923 if (unlikely(!mpi_reply
)) {
2924 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
2925 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2928 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2929 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
2930 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
2931 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
2932 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2934 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
2938 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2939 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2940 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2941 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
2942 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
2943 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2944 le32_to_cpu(mpi_reply
->TerminationCount
)));
2946 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
2947 if (!smid_sas_ctrl
) {
2948 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2949 ioc
->name
, __func__
);
2953 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2954 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2955 ioc
->name
, handle
, smid_sas_ctrl
,
2956 ioc
->tm_sas_control_cb_idx
));
2957 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
2958 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
2959 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
2960 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
2961 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
2962 mpt3sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
2964 return _scsih_check_for_pending_tm(ioc
, smid
);
2969 * _scsih_sas_control_complete - completion routine
2970 * @ioc: per adapter object
2971 * @smid: system request message index
2972 * @msix_index: MSIX table index supplied by the OS
2973 * @reply: reply message frame(lower 32bit addr)
2974 * Context: interrupt time.
2976 * This is the sas iounit control completion routine.
2977 * This code is part of the code to initiate the device removal
2978 * handshake protocol with controller firmware.
2980 * Return 1 meaning mf should be freed from _base_interrupt
2981 * 0 means the mf is freed from this function.
2984 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
2985 u8 msix_index
, u32 reply
)
2987 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
2988 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2990 if (likely(mpi_reply
)) {
2991 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2992 "sc_complete:handle(0x%04x), (open) "
2993 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2994 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
2995 le16_to_cpu(mpi_reply
->IOCStatus
),
2996 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
2998 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
2999 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3005 * _scsih_tm_tr_volume_send - send target reset request for volumes
3006 * @ioc: per adapter object
3007 * @handle: device handle
3008 * Context: interrupt time.
3010 * This is designed to send muliple task management request at the same
3011 * time to the fifo. If the fifo is full, we will append the request,
3012 * and process it in a future completion.
3015 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3017 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3019 struct _tr_list
*delayed_tr
;
3021 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3022 ioc
->pci_error_recovery
) {
3023 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3024 "%s: host reset in progress!\n",
3025 __func__
, ioc
->name
));
3029 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3031 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3034 INIT_LIST_HEAD(&delayed_tr
->list
);
3035 delayed_tr
->handle
= handle
;
3036 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3037 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3038 "DELAYED:tr:handle(0x%04x), (open)\n",
3039 ioc
->name
, handle
));
3043 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3044 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3045 ioc
->name
, handle
, smid
,
3046 ioc
->tm_tr_volume_cb_idx
));
3047 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3048 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3049 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3050 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3051 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3052 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
3056 * _scsih_tm_volume_tr_complete - target reset completion
3057 * @ioc: per adapter object
3058 * @smid: system request message index
3059 * @msix_index: MSIX table index supplied by the OS
3060 * @reply: reply message frame(lower 32bit addr)
3061 * Context: interrupt time.
3063 * Return 1 meaning mf should be freed from _base_interrupt
3064 * 0 means the mf is freed from this function.
3067 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3068 u8 msix_index
, u32 reply
)
3071 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3072 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3073 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3075 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3076 ioc
->pci_error_recovery
) {
3077 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3078 "%s: host reset in progress!\n",
3079 __func__
, ioc
->name
));
3082 if (unlikely(!mpi_reply
)) {
3083 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3084 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3088 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3089 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3090 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3091 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3092 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3094 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3098 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3099 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3100 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3101 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3102 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3103 le32_to_cpu(mpi_reply
->TerminationCount
)));
3105 return _scsih_check_for_pending_tm(ioc
, smid
);
3110 * _scsih_check_for_pending_tm - check for pending task management
3111 * @ioc: per adapter object
3112 * @smid: system request message index
3114 * This will check delayed target reset list, and feed the
3117 * Return 1 meaning mf should be freed from _base_interrupt
3118 * 0 means the mf is freed from this function.
3121 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3123 struct _tr_list
*delayed_tr
;
3125 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3126 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3127 struct _tr_list
, list
);
3128 mpt3sas_base_free_smid(ioc
, smid
);
3129 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3130 list_del(&delayed_tr
->list
);
3135 if (!list_empty(&ioc
->delayed_tr_list
)) {
3136 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3137 struct _tr_list
, list
);
3138 mpt3sas_base_free_smid(ioc
, smid
);
3139 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3140 list_del(&delayed_tr
->list
);
3149 * _scsih_check_topo_delete_events - sanity check on topo events
3150 * @ioc: per adapter object
3151 * @event_data: the event data payload
3153 * This routine added to better handle cable breaker.
3155 * This handles the case where driver receives multiple expander
3156 * add and delete events in a single shot. When there is a delete event
3157 * the routine will void any pending add events waiting in the event queue.
3162 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3163 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3165 struct fw_event_work
*fw_event
;
3166 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3167 u16 expander_handle
;
3168 struct _sas_node
*sas_expander
;
3169 unsigned long flags
;
3173 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3174 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3177 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3178 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3179 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3180 _scsih_tm_tr_send(ioc
, handle
);
3183 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3184 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3185 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3188 if (event_data
->ExpStatus
==
3189 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3190 /* put expander attached devices into blocking state */
3191 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3192 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3194 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3195 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3197 handle
= find_first_bit(ioc
->blocking_handles
,
3198 ioc
->facts
.MaxDevHandle
);
3199 if (handle
< ioc
->facts
.MaxDevHandle
)
3200 _scsih_block_io_device(ioc
, handle
);
3201 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3202 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3203 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3205 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3208 /* mark ignore flag for pending events */
3209 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3210 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3211 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3214 local_event_data
= fw_event
->event_data
;
3215 if (local_event_data
->ExpStatus
==
3216 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3217 local_event_data
->ExpStatus
==
3218 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3219 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3221 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3222 "setting ignoring flag\n", ioc
->name
));
3223 fw_event
->ignore
= 1;
3227 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3231 * _scsih_set_volume_delete_flag - setting volume delete flag
3232 * @ioc: per adapter object
3233 * @handle: device handle
3235 * This returns nothing.
3238 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3240 struct _raid_device
*raid_device
;
3241 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3242 unsigned long flags
;
3244 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3245 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3246 if (raid_device
&& raid_device
->starget
&&
3247 raid_device
->starget
->hostdata
) {
3248 sas_target_priv_data
=
3249 raid_device
->starget
->hostdata
;
3250 sas_target_priv_data
->deleted
= 1;
3251 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3252 "setting delete flag: handle(0x%04x), "
3253 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3254 (unsigned long long) raid_device
->wwid
));
3256 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3260 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3261 * @handle: input handle
3262 * @a: handle for volume a
3263 * @b: handle for volume b
3265 * IR firmware only supports two raid volumes. The purpose of this
3266 * routine is to set the volume handle in either a or b. When the given
3267 * input handle is non-zero, or when a and b have not been set before.
3270 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3272 if (!handle
|| handle
== *a
|| handle
== *b
)
3281 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3282 * @ioc: per adapter object
3283 * @event_data: the event data payload
3284 * Context: interrupt time.
3286 * This routine will send target reset to volume, followed by target
3287 * resets to the PDs. This is called when a PD has been removed, or
3288 * volume has been deleted or removed. When the target reset is sent
3289 * to volume, the PD target resets need to be queued to start upon
3290 * completion of the volume target reset.
3295 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3296 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3298 Mpi2EventIrConfigElement_t
*element
;
3300 u16 handle
, volume_handle
, a
, b
;
3301 struct _tr_list
*delayed_tr
;
3306 /* Volume Resets for Deleted or Removed */
3307 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3308 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3309 if (le32_to_cpu(event_data
->Flags
) &
3310 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3312 if (element
->ReasonCode
==
3313 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3314 element
->ReasonCode
==
3315 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3316 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3317 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3318 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3322 /* Volume Resets for UNHIDE events */
3323 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3324 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3325 if (le32_to_cpu(event_data
->Flags
) &
3326 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3328 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3329 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3330 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3335 _scsih_tm_tr_volume_send(ioc
, a
);
3337 _scsih_tm_tr_volume_send(ioc
, b
);
3339 /* PD target resets */
3340 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3341 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3342 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3344 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3345 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3346 clear_bit(handle
, ioc
->pd_handles
);
3348 _scsih_tm_tr_send(ioc
, handle
);
3349 else if (volume_handle
== a
|| volume_handle
== b
) {
3350 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3351 BUG_ON(!delayed_tr
);
3352 INIT_LIST_HEAD(&delayed_tr
->list
);
3353 delayed_tr
->handle
= handle
;
3354 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3355 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3356 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3359 _scsih_tm_tr_send(ioc
, handle
);
3365 * _scsih_check_volume_delete_events - set delete flag for volumes
3366 * @ioc: per adapter object
3367 * @event_data: the event data payload
3368 * Context: interrupt time.
3370 * This will handle the case when the cable connected to entire volume is
3371 * pulled. We will take care of setting the deleted flag so normal IO will
3377 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3378 Mpi2EventDataIrVolume_t
*event_data
)
3382 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3384 state
= le32_to_cpu(event_data
->NewValue
);
3385 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3386 MPI2_RAID_VOL_STATE_FAILED
)
3387 _scsih_set_volume_delete_flag(ioc
,
3388 le16_to_cpu(event_data
->VolDevHandle
));
3392 * _scsih_flush_running_cmds - completing outstanding commands.
3393 * @ioc: per adapter object
3395 * The flushing out of all pending scmd commands following host reset,
3396 * where all IO is dropped to the floor.
3401 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3403 struct scsi_cmnd
*scmd
;
3407 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3408 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3412 mpt3sas_base_free_smid(ioc
, smid
);
3413 scsi_dma_unmap(scmd
);
3414 if (ioc
->pci_error_recovery
)
3415 scmd
->result
= DID_NO_CONNECT
<< 16;
3417 scmd
->result
= DID_RESET
<< 16;
3418 scmd
->scsi_done(scmd
);
3420 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3425 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3426 * @ioc: per adapter object
3427 * @scmd: pointer to scsi command object
3428 * @mpi_request: pointer to the SCSI_IO reqest message frame
3430 * Supporting protection 1 and 3.
3435 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3436 Mpi2SCSIIORequest_t
*mpi_request
)
3439 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3440 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3441 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3442 (Mpi25SCSIIORequest_t
*)mpi_request
;
3444 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3447 if (prot_op
== SCSI_PROT_READ_STRIP
)
3448 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3449 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3450 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3454 switch (prot_type
) {
3455 case SCSI_PROT_DIF_TYPE1
:
3456 case SCSI_PROT_DIF_TYPE2
:
3459 * enable ref/guard checking
3460 * auto increment ref tag
3462 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3463 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3464 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3465 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3466 cpu_to_be32(scsi_get_lba(scmd
));
3469 case SCSI_PROT_DIF_TYPE3
:
3472 * enable guard checking
3474 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3479 mpi_request_3v
->EEDPBlockSize
=
3480 cpu_to_le16(scmd
->device
->sector_size
);
3481 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3485 * _scsih_eedp_error_handling - return sense code for EEDP errors
3486 * @scmd: pointer to scsi command object
3487 * @ioc_status: ioc status
3492 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3496 switch (ioc_status
) {
3497 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3500 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3503 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3510 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
3512 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
3513 SAM_STAT_CHECK_CONDITION
;
3518 * _scsih_qcmd - main scsi request entry point
3519 * @scmd: pointer to scsi command object
3520 * @done: function pointer to be invoked on completion
3522 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3524 * Returns 0 on success. If there's a failure, return either:
3525 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3526 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3529 _scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
3531 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3532 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3533 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3534 Mpi2SCSIIORequest_t
*mpi_request
;
3539 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3540 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
3541 scsi_print_command(scmd
);
3544 sas_device_priv_data
= scmd
->device
->hostdata
;
3545 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3546 scmd
->result
= DID_NO_CONNECT
<< 16;
3547 scmd
->scsi_done(scmd
);
3551 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3552 scmd
->result
= DID_NO_CONNECT
<< 16;
3553 scmd
->scsi_done(scmd
);
3557 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3559 /* invalid device handle */
3560 handle
= sas_target_priv_data
->handle
;
3561 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
3562 scmd
->result
= DID_NO_CONNECT
<< 16;
3563 scmd
->scsi_done(scmd
);
3568 /* host recovery or link resets sent via IOCTLs */
3569 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3570 return SCSI_MLQUEUE_HOST_BUSY
;
3572 /* device has been deleted */
3573 else if (sas_target_priv_data
->deleted
) {
3574 scmd
->result
= DID_NO_CONNECT
<< 16;
3575 scmd
->scsi_done(scmd
);
3577 /* device busy with task managment */
3578 } else if (sas_target_priv_data
->tm_busy
||
3579 sas_device_priv_data
->block
)
3580 return SCSI_MLQUEUE_DEVICE_BUSY
;
3582 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3583 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3584 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3585 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3587 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3590 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3591 if (scmd
->device
->tagged_supported
) {
3592 if (scmd
->device
->ordered_tags
)
3593 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3595 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3597 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3599 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3601 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) &&
3602 scmd
->cmd_len
!= 32)
3603 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3605 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3607 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3608 ioc
->name
, __func__
);
3611 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3612 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3613 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
3615 if (scmd
->cmd_len
== 32)
3616 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3617 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3618 if (sas_device_priv_data
->sas_target
->flags
&
3619 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3620 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3622 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3623 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3624 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3625 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3626 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3627 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3628 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3629 mpi_request
->SenseBufferLowAddress
=
3630 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
3631 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3632 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3634 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3636 if (mpi_request
->DataLength
) {
3637 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
3638 mpt3sas_base_free_smid(ioc
, smid
);
3642 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3644 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
3645 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
3646 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
3647 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
3648 mpt3sas_base_put_smid_fast_path(ioc
, smid
, handle
);
3650 mpt3sas_base_put_smid_scsi_io(ioc
, smid
, handle
);
3652 mpt3sas_base_put_smid_default(ioc
, smid
);
3656 return SCSI_MLQUEUE_HOST_BUSY
;
3660 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3661 * @sense_buffer: sense data returned by target
3662 * @data: normalized skey/asc/ascq
3667 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3669 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3670 /* descriptor format */
3671 data
->skey
= sense_buffer
[1] & 0x0F;
3672 data
->asc
= sense_buffer
[2];
3673 data
->ascq
= sense_buffer
[3];
3676 data
->skey
= sense_buffer
[2] & 0x0F;
3677 data
->asc
= sense_buffer
[12];
3678 data
->ascq
= sense_buffer
[13];
3682 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3684 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3685 * @ioc: per adapter object
3686 * @scmd: pointer to scsi command object
3687 * @mpi_reply: reply mf payload returned from firmware
3689 * scsi_status - SCSI Status code returned from target device
3690 * scsi_state - state info associated with SCSI_IO determined by ioc
3691 * ioc_status - ioc supplied status info
3696 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3697 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3701 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3702 MPI2_IOCSTATUS_MASK
;
3703 u8 scsi_state
= mpi_reply
->SCSIState
;
3704 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3705 char *desc_ioc_state
= NULL
;
3706 char *desc_scsi_status
= NULL
;
3707 char *desc_scsi_state
= ioc
->tmp_string
;
3708 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3709 struct _sas_device
*sas_device
= NULL
;
3710 unsigned long flags
;
3711 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3712 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
3713 char *device_str
= NULL
;
3717 device_str
= "volume";
3719 if (log_info
== 0x31170000)
3722 switch (ioc_status
) {
3723 case MPI2_IOCSTATUS_SUCCESS
:
3724 desc_ioc_state
= "success";
3726 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3727 desc_ioc_state
= "invalid function";
3729 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3730 desc_ioc_state
= "scsi recovered error";
3732 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3733 desc_ioc_state
= "scsi invalid dev handle";
3735 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3736 desc_ioc_state
= "scsi device not there";
3738 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3739 desc_ioc_state
= "scsi data overrun";
3741 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3742 desc_ioc_state
= "scsi data underrun";
3744 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3745 desc_ioc_state
= "scsi io data error";
3747 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3748 desc_ioc_state
= "scsi protocol error";
3750 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3751 desc_ioc_state
= "scsi task terminated";
3753 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3754 desc_ioc_state
= "scsi residual mismatch";
3756 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3757 desc_ioc_state
= "scsi task mgmt failed";
3759 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3760 desc_ioc_state
= "scsi ioc terminated";
3762 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3763 desc_ioc_state
= "scsi ext terminated";
3765 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3766 desc_ioc_state
= "eedp guard error";
3768 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3769 desc_ioc_state
= "eedp ref tag error";
3771 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3772 desc_ioc_state
= "eedp app tag error";
3775 desc_ioc_state
= "unknown";
3779 switch (scsi_status
) {
3780 case MPI2_SCSI_STATUS_GOOD
:
3781 desc_scsi_status
= "good";
3783 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3784 desc_scsi_status
= "check condition";
3786 case MPI2_SCSI_STATUS_CONDITION_MET
:
3787 desc_scsi_status
= "condition met";
3789 case MPI2_SCSI_STATUS_BUSY
:
3790 desc_scsi_status
= "busy";
3792 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3793 desc_scsi_status
= "intermediate";
3795 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3796 desc_scsi_status
= "intermediate condmet";
3798 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3799 desc_scsi_status
= "reservation conflict";
3801 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3802 desc_scsi_status
= "command terminated";
3804 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3805 desc_scsi_status
= "task set full";
3807 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3808 desc_scsi_status
= "aca active";
3810 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3811 desc_scsi_status
= "task aborted";
3814 desc_scsi_status
= "unknown";
3818 desc_scsi_state
[0] = '\0';
3820 desc_scsi_state
= " ";
3821 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3822 strcat(desc_scsi_state
, "response info ");
3823 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3824 strcat(desc_scsi_state
, "state terminated ");
3825 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3826 strcat(desc_scsi_state
, "no status ");
3827 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3828 strcat(desc_scsi_state
, "autosense failed ");
3829 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3830 strcat(desc_scsi_state
, "autosense valid ");
3832 scsi_print_command(scmd
);
3834 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3835 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
3836 device_str
, (unsigned long long)priv_target
->sas_address
);
3838 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3839 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
3840 priv_target
->sas_address
);
3843 "\tsas_address(0x%016llx), phy(%d)\n",
3844 ioc
->name
, (unsigned long long)
3845 sas_device
->sas_address
, sas_device
->phy
);
3847 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3848 ioc
->name
, (unsigned long long)
3849 sas_device
->enclosure_logical_id
, sas_device
->slot
);
3851 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3855 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3856 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
3857 desc_ioc_state
, ioc_status
, smid
);
3859 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3860 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3861 scsi_get_resid(scmd
));
3863 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3864 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3865 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3867 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3868 ioc
->name
, desc_scsi_status
,
3869 scsi_status
, desc_scsi_state
, scsi_state
);
3871 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3872 struct sense_info data
;
3873 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3875 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3876 ioc
->name
, data
.skey
,
3877 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3880 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3881 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
3882 response_bytes
= (u8
*)&response_info
;
3883 _scsih_response_code(ioc
, response_bytes
[0]);
3889 * _scsih_turn_on_fault_led - illuminate Fault LED
3890 * @ioc: per adapter object
3891 * @handle: device handle
3897 _scsih_turn_on_fault_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3899 Mpi2SepReply_t mpi_reply
;
3900 Mpi2SepRequest_t mpi_request
;
3902 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
3903 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
3904 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
3905 mpi_request
.SlotStatus
=
3906 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
3907 mpi_request
.DevHandle
= cpu_to_le16(handle
);
3908 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
3909 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
3910 &mpi_request
)) != 0) {
3911 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
3912 __FILE__
, __LINE__
, __func__
);
3916 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
3917 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3918 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3919 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
3920 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
3926 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
3927 * @ioc: per adapter object
3928 * @handle: device handle
3929 * Context: interrupt.
3934 _scsih_send_event_to_turn_on_fault_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3936 struct fw_event_work
*fw_event
;
3938 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
3941 fw_event
->event
= MPT3SAS_TURN_ON_FAULT_LED
;
3942 fw_event
->device_handle
= handle
;
3943 fw_event
->ioc
= ioc
;
3944 _scsih_fw_event_add(ioc
, fw_event
);
3948 * _scsih_smart_predicted_fault - process smart errors
3949 * @ioc: per adapter object
3950 * @handle: device handle
3951 * Context: interrupt.
3956 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3958 struct scsi_target
*starget
;
3959 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3960 Mpi2EventNotificationReply_t
*event_reply
;
3961 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
3962 struct _sas_device
*sas_device
;
3964 unsigned long flags
;
3966 /* only handle non-raid devices */
3967 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3968 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3970 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3973 starget
= sas_device
->starget
;
3974 sas_target_priv_data
= starget
->hostdata
;
3976 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
3977 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
3978 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3981 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
3982 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3984 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
3985 _scsih_send_event_to_turn_on_fault_led(ioc
, handle
);
3987 /* insert into event log */
3988 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
3989 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
3990 event_reply
= kzalloc(sz
, GFP_KERNEL
);
3992 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
3993 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3997 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3998 event_reply
->Event
=
3999 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4000 event_reply
->MsgLength
= sz
/4;
4001 event_reply
->EventDataLength
=
4002 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4003 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4004 event_reply
->EventData
;
4005 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4006 event_data
->ASC
= 0x5D;
4007 event_data
->DevHandle
= cpu_to_le16(handle
);
4008 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4009 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4014 * _scsih_io_done - scsi request callback
4015 * @ioc: per adapter object
4016 * @smid: system request message index
4017 * @msix_index: MSIX table index supplied by the OS
4018 * @reply: reply message frame(lower 32bit addr)
4020 * Callback handler when using _scsih_qcmd.
4022 * Return 1 meaning mf should be freed from _base_interrupt
4023 * 0 means the mf is freed from this function.
4026 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4028 Mpi2SCSIIORequest_t
*mpi_request
;
4029 Mpi2SCSIIOReply_t
*mpi_reply
;
4030 struct scsi_cmnd
*scmd
;
4036 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4037 u32 response_code
= 0;
4039 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4040 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4044 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4046 if (mpi_reply
== NULL
) {
4047 scmd
->result
= DID_OK
<< 16;
4051 sas_device_priv_data
= scmd
->device
->hostdata
;
4052 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4053 sas_device_priv_data
->sas_target
->deleted
) {
4054 scmd
->result
= DID_NO_CONNECT
<< 16;
4057 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4059 /* turning off TLR */
4060 scsi_state
= mpi_reply
->SCSIState
;
4061 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4063 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4064 if (!sas_device_priv_data
->tlr_snoop_check
) {
4065 sas_device_priv_data
->tlr_snoop_check
++;
4066 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) &&
4067 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
4068 sas_device_priv_data
->flags
&=
4072 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4073 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4074 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4075 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4078 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4079 scsi_status
= mpi_reply
->SCSIStatus
;
4081 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4082 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4083 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4084 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4085 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4088 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4089 struct sense_info data
;
4090 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4092 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4093 le32_to_cpu(mpi_reply
->SenseCount
));
4094 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4095 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4096 /* failure prediction threshold exceeded */
4097 if (data
.asc
== 0x5D)
4098 _scsih_smart_predicted_fault(ioc
,
4099 le16_to_cpu(mpi_reply
->DevHandle
));
4100 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4103 switch (ioc_status
) {
4104 case MPI2_IOCSTATUS_BUSY
:
4105 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4106 scmd
->result
= SAM_STAT_BUSY
;
4109 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4110 scmd
->result
= DID_NO_CONNECT
<< 16;
4113 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4114 if (sas_device_priv_data
->block
) {
4115 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4118 if (log_info
== 0x31110630) {
4119 if (scmd
->retries
> 2) {
4120 scmd
->result
= DID_NO_CONNECT
<< 16;
4121 scsi_device_set_state(scmd
->device
,
4124 scmd
->result
= DID_SOFT_ERROR
<< 16;
4125 scmd
->device
->expecting_cc_ua
= 1;
4129 scmd
->result
= DID_SOFT_ERROR
<< 16;
4131 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4132 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4133 scmd
->result
= DID_RESET
<< 16;
4136 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4137 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4138 scmd
->result
= DID_SOFT_ERROR
<< 16;
4140 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4143 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4144 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4146 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4149 if (xfer_cnt
< scmd
->underflow
) {
4150 if (scsi_status
== SAM_STAT_BUSY
)
4151 scmd
->result
= SAM_STAT_BUSY
;
4153 scmd
->result
= DID_SOFT_ERROR
<< 16;
4154 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4155 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4156 scmd
->result
= DID_SOFT_ERROR
<< 16;
4157 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4158 scmd
->result
= DID_RESET
<< 16;
4159 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4160 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4161 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4162 scmd
->result
= (DRIVER_SENSE
<< 24) |
4163 SAM_STAT_CHECK_CONDITION
;
4164 scmd
->sense_buffer
[0] = 0x70;
4165 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4166 scmd
->sense_buffer
[12] = 0x20;
4167 scmd
->sense_buffer
[13] = 0;
4171 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4172 scsi_set_resid(scmd
, 0);
4173 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4174 case MPI2_IOCSTATUS_SUCCESS
:
4175 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4176 if (response_code
==
4177 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4178 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4179 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4180 scmd
->result
= DID_SOFT_ERROR
<< 16;
4181 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4182 scmd
->result
= DID_RESET
<< 16;
4185 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4186 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4187 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4188 _scsih_eedp_error_handling(scmd
, ioc_status
);
4191 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4192 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4193 case MPI2_IOCSTATUS_INVALID_SGL
:
4194 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4195 case MPI2_IOCSTATUS_INVALID_FIELD
:
4196 case MPI2_IOCSTATUS_INVALID_STATE
:
4197 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4198 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4200 scmd
->result
= DID_SOFT_ERROR
<< 16;
4205 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4206 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4207 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4212 scsi_dma_unmap(scmd
);
4214 scmd
->scsi_done(scmd
);
4219 * _scsih_sas_host_refresh - refreshing sas host object contents
4220 * @ioc: per adapter object
4223 * During port enable, fw will send topology events for every device. Its
4224 * possible that the handles may change from the previous setting, so this
4225 * code keeping handles updating if changed.
4230 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4235 Mpi2ConfigReply_t mpi_reply
;
4236 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4237 u16 attached_handle
;
4240 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4241 "updating handles for sas_host(0x%016llx)\n",
4242 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4244 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4245 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4246 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4247 if (!sas_iounit_pg0
) {
4248 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4249 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4253 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4254 sas_iounit_pg0
, sz
)) != 0)
4256 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4257 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4259 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4260 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4262 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4263 PhyData
[0].ControllerDevHandle
);
4264 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4265 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4267 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4268 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4269 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4270 attached_handle
, i
, link_rate
);
4273 kfree(sas_iounit_pg0
);
4277 * _scsih_sas_host_add - create sas host object
4278 * @ioc: per adapter object
4280 * Creating host side data object, stored in ioc->sas_hba
4285 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4288 Mpi2ConfigReply_t mpi_reply
;
4289 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4290 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4291 Mpi2SasPhyPage0_t phy_pg0
;
4292 Mpi2SasDevicePage0_t sas_device_pg0
;
4293 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4296 u8 device_missing_delay
;
4298 mpt3sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4299 if (!ioc
->sas_hba
.num_phys
) {
4300 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4301 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4305 /* sas_iounit page 0 */
4306 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4307 sizeof(Mpi2SasIOUnit0PhyData_t
));
4308 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4309 if (!sas_iounit_pg0
) {
4310 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4311 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4314 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4315 sas_iounit_pg0
, sz
))) {
4316 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4317 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4320 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4321 MPI2_IOCSTATUS_MASK
;
4322 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4323 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4324 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4328 /* sas_iounit page 1 */
4329 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4330 sizeof(Mpi2SasIOUnit1PhyData_t
));
4331 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4332 if (!sas_iounit_pg1
) {
4333 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4334 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4337 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4338 sas_iounit_pg1
, sz
))) {
4339 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4340 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4343 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4344 MPI2_IOCSTATUS_MASK
;
4345 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4346 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4347 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4351 ioc
->io_missing_delay
=
4352 sas_iounit_pg1
->IODeviceMissingDelay
;
4353 device_missing_delay
=
4354 sas_iounit_pg1
->ReportDeviceMissingDelay
;
4355 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4356 ioc
->device_missing_delay
= (device_missing_delay
&
4357 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4359 ioc
->device_missing_delay
= device_missing_delay
&
4360 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4362 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4363 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4364 sizeof(struct _sas_phy
), GFP_KERNEL
);
4365 if (!ioc
->sas_hba
.phy
) {
4366 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4367 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4370 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4371 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4373 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4374 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4377 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4378 MPI2_IOCSTATUS_MASK
;
4379 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4380 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4381 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4386 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4387 PhyData
[0].ControllerDevHandle
);
4388 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4389 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4390 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4391 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4393 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4394 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4395 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4396 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4399 ioc
->sas_hba
.enclosure_handle
=
4400 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4401 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4403 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4404 ioc
->name
, ioc
->sas_hba
.handle
,
4405 (unsigned long long) ioc
->sas_hba
.sas_address
,
4406 ioc
->sas_hba
.num_phys
) ;
4408 if (ioc
->sas_hba
.enclosure_handle
) {
4409 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4410 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4411 ioc
->sas_hba
.enclosure_handle
)))
4412 ioc
->sas_hba
.enclosure_logical_id
=
4413 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4417 kfree(sas_iounit_pg1
);
4418 kfree(sas_iounit_pg0
);
4422 * _scsih_expander_add - creating expander object
4423 * @ioc: per adapter object
4424 * @handle: expander handle
4426 * Creating expander object, stored in ioc->sas_expander_list.
4428 * Return 0 for success, else error.
4431 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4433 struct _sas_node
*sas_expander
;
4434 Mpi2ConfigReply_t mpi_reply
;
4435 Mpi2ExpanderPage0_t expander_pg0
;
4436 Mpi2ExpanderPage1_t expander_pg1
;
4437 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4440 u64 sas_address
, sas_address_parent
= 0;
4442 unsigned long flags
;
4443 struct _sas_port
*mpt3sas_port
= NULL
;
4450 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4453 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4454 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4455 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4456 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4460 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4461 MPI2_IOCSTATUS_MASK
;
4462 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4463 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4464 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4468 /* handle out of order topology events */
4469 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4470 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4472 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4473 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4476 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4477 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4478 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4479 sas_address_parent
);
4480 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4481 if (!sas_expander
) {
4482 rc
= _scsih_expander_add(ioc
, parent_handle
);
4488 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4489 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4490 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4492 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4497 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4499 if (!sas_expander
) {
4500 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4501 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4505 sas_expander
->handle
= handle
;
4506 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4507 sas_expander
->sas_address_parent
= sas_address_parent
;
4508 sas_expander
->sas_address
= sas_address
;
4510 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
4511 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4512 handle
, parent_handle
, (unsigned long long)
4513 sas_expander
->sas_address
, sas_expander
->num_phys
);
4515 if (!sas_expander
->num_phys
)
4517 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4518 sizeof(struct _sas_phy
), GFP_KERNEL
);
4519 if (!sas_expander
->phy
) {
4520 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4521 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4526 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4527 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
4528 sas_address_parent
);
4529 if (!mpt3sas_port
) {
4530 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4531 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4535 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
4537 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4538 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4539 &expander_pg1
, i
, handle
))) {
4540 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4541 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4545 sas_expander
->phy
[i
].handle
= handle
;
4546 sas_expander
->phy
[i
].phy_id
= i
;
4548 if ((mpt3sas_transport_add_expander_phy(ioc
,
4549 &sas_expander
->phy
[i
], expander_pg1
,
4550 sas_expander
->parent_dev
))) {
4551 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4552 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4558 if (sas_expander
->enclosure_handle
) {
4559 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4560 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4561 sas_expander
->enclosure_handle
)))
4562 sas_expander
->enclosure_logical_id
=
4563 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4566 _scsih_expander_node_add(ioc
, sas_expander
);
4572 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4573 sas_address_parent
);
4574 kfree(sas_expander
);
4579 * mpt3sas_expander_remove - removing expander object
4580 * @ioc: per adapter object
4581 * @sas_address: expander sas_address
4586 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
4588 struct _sas_node
*sas_expander
;
4589 unsigned long flags
;
4591 if (ioc
->shost_recovery
)
4594 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4595 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4598 list_del(&sas_expander
->list
);
4599 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4601 _scsih_expander_node_remove(ioc
, sas_expander
);
4605 * _scsih_done - internal SCSI_IO callback handler.
4606 * @ioc: per adapter object
4607 * @smid: system request message index
4608 * @msix_index: MSIX table index supplied by the OS
4609 * @reply: reply message frame(lower 32bit addr)
4611 * Callback handler when sending internal generated SCSI_IO.
4612 * The callback index passed is `ioc->scsih_cb_idx`
4614 * Return 1 meaning mf should be freed from _base_interrupt
4615 * 0 means the mf is freed from this function.
4618 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4620 MPI2DefaultReply_t
*mpi_reply
;
4622 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4623 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
4625 if (ioc
->scsih_cmds
.smid
!= smid
)
4627 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
4629 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4630 mpi_reply
->MsgLength
*4);
4631 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
4633 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
4634 complete(&ioc
->scsih_cmds
.done
);
4641 #define MPT3_MAX_LUNS (255)
4645 * _scsih_check_access_status - check access flags
4646 * @ioc: per adapter object
4647 * @sas_address: sas address
4648 * @handle: sas device handle
4649 * @access_flags: errors returned during discovery of the device
4651 * Return 0 for success, else failure
4654 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
4655 u16 handle
, u8 access_status
)
4660 switch (access_status
) {
4661 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4662 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4665 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4666 desc
= "sata capability failed";
4668 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4669 desc
= "sata affiliation conflict";
4671 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4672 desc
= "route not addressable";
4674 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4675 desc
= "smp error not addressable";
4677 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4678 desc
= "device blocked";
4680 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4681 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4682 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4683 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4684 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4685 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4686 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4687 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4688 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4689 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4690 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4691 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4692 desc
= "sata initialization failed";
4703 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4704 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
4709 * _scsih_check_device - checking device responsiveness
4710 * @ioc: per adapter object
4711 * @parent_sas_address: sas address of parent expander or sas host
4712 * @handle: attached device handle
4713 * @phy_numberv: phy number
4714 * @link_rate: new link rate
4719 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
4720 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
4722 Mpi2ConfigReply_t mpi_reply
;
4723 Mpi2SasDevicePage0_t sas_device_pg0
;
4724 struct _sas_device
*sas_device
;
4726 unsigned long flags
;
4728 struct scsi_target
*starget
;
4729 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4733 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4734 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4737 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4738 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4741 /* wide port handling ~ we need only handle device once for the phy that
4742 * is matched in sas device page zero
4744 if (phy_number
!= sas_device_pg0
.PhyNum
)
4747 /* check if this is end device */
4748 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4749 if (!(_scsih_is_end_device(device_info
)))
4752 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4753 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4754 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
4758 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4762 if (unlikely(sas_device
->handle
!= handle
)) {
4763 starget
= sas_device
->starget
;
4764 sas_target_priv_data
= starget
->hostdata
;
4765 starget_printk(KERN_INFO
, starget
,
4766 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4767 sas_device
->handle
, handle
);
4768 sas_target_priv_data
->handle
= handle
;
4769 sas_device
->handle
= handle
;
4772 /* check if device is present */
4773 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4774 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4776 "device is not present handle(0x%04x), flags!!!\n",
4778 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4782 /* check if there were any issues with discovery */
4783 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4784 sas_device_pg0
.AccessStatus
)) {
4785 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4789 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4790 _scsih_ublock_io_device(ioc
, sas_address
);
4795 * _scsih_add_device - creating sas device object
4796 * @ioc: per adapter object
4797 * @handle: sas device handle
4798 * @phy_num: phy number end device attached to
4799 * @is_pd: is this hidden raid component
4801 * Creating end device object, stored in ioc->sas_device_list.
4803 * Returns 0 for success, non-zero for failure.
4806 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
4809 Mpi2ConfigReply_t mpi_reply
;
4810 Mpi2SasDevicePage0_t sas_device_pg0
;
4811 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4812 struct _sas_device
*sas_device
;
4816 unsigned long flags
;
4818 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4819 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
4820 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4821 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4825 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4826 MPI2_IOCSTATUS_MASK
;
4827 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4828 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4829 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4833 /* check if this is end device */
4834 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4835 if (!(_scsih_is_end_device(device_info
)))
4837 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4839 /* check if device is present */
4840 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4841 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4842 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
4847 /* check if there were any issues with discovery */
4848 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4849 sas_device_pg0
.AccessStatus
))
4852 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4853 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
4855 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4860 sas_device
= kzalloc(sizeof(struct _sas_device
),
4863 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4864 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4868 sas_device
->handle
= handle
;
4869 if (_scsih_get_sas_address(ioc
,
4870 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
4871 &sas_device
->sas_address_parent
) != 0)
4872 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4873 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4874 sas_device
->enclosure_handle
=
4875 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4877 le16_to_cpu(sas_device_pg0
.Slot
);
4878 sas_device
->device_info
= device_info
;
4879 sas_device
->sas_address
= sas_address
;
4880 sas_device
->phy
= sas_device_pg0
.PhyNum
;
4881 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
4882 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
4884 /* get enclosure_logical_id */
4885 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
4886 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4887 sas_device
->enclosure_handle
)))
4888 sas_device
->enclosure_logical_id
=
4889 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4891 /* get device name */
4892 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
4894 if (ioc
->wait_for_discovery_to_complete
)
4895 _scsih_sas_device_init_add(ioc
, sas_device
);
4897 _scsih_sas_device_add(ioc
, sas_device
);
4903 * _scsih_remove_device - removing sas device object
4904 * @ioc: per adapter object
4905 * @sas_device_delete: the sas_device object
4910 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
4911 struct _sas_device
*sas_device
)
4913 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4916 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4917 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4918 ioc
->name
, __func__
,
4919 sas_device
->handle
, (unsigned long long)
4920 sas_device
->sas_address
));
4922 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
4923 sas_target_priv_data
= sas_device
->starget
->hostdata
;
4924 sas_target_priv_data
->deleted
= 1;
4925 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
4926 sas_target_priv_data
->handle
=
4927 MPT3SAS_INVALID_DEVICE_HANDLE
;
4929 mpt3sas_transport_port_remove(ioc
,
4930 sas_device
->sas_address
,
4931 sas_device
->sas_address_parent
);
4934 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4935 ioc
->name
, sas_device
->handle
,
4936 (unsigned long long) sas_device
->sas_address
);
4938 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4939 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4940 ioc
->name
, __func__
,
4941 sas_device
->handle
, (unsigned long long)
4942 sas_device
->sas_address
));
4947 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4949 * _scsih_sas_topology_change_event_debug - debug for topology event
4950 * @ioc: per adapter object
4951 * @event_data: event data payload
4955 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
4956 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4962 char *status_str
= NULL
;
4963 u8 link_rate
, prev_link_rate
;
4965 switch (event_data
->ExpStatus
) {
4966 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
4969 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
4970 status_str
= "remove";
4972 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
4974 status_str
= "responding";
4976 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
4977 status_str
= "remove delay";
4980 status_str
= "unknown status";
4983 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
4984 ioc
->name
, status_str
);
4985 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
4986 "start_phy(%02d), count(%d)\n",
4987 le16_to_cpu(event_data
->ExpanderDevHandle
),
4988 le16_to_cpu(event_data
->EnclosureHandle
),
4989 event_data
->StartPhyNum
, event_data
->NumEntries
);
4990 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4991 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4994 phy_number
= event_data
->StartPhyNum
+ i
;
4995 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4996 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4997 switch (reason_code
) {
4998 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
4999 status_str
= "target add";
5001 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5002 status_str
= "target remove";
5004 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5005 status_str
= "delay target remove";
5007 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5008 status_str
= "link rate change";
5010 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5011 status_str
= "target responding";
5014 status_str
= "unknown";
5017 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5018 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5019 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5020 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5021 handle
, status_str
, link_rate
, prev_link_rate
);
5028 * _scsih_sas_topology_change_event - handle topology changes
5029 * @ioc: per adapter object
5030 * @fw_event: The fw_event_work object
5035 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5036 struct fw_event_work
*fw_event
)
5039 u16 parent_handle
, handle
;
5041 u8 phy_number
, max_phys
;
5042 struct _sas_node
*sas_expander
;
5044 unsigned long flags
;
5045 u8 link_rate
, prev_link_rate
;
5046 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
5048 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5049 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5050 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5053 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5056 if (!ioc
->sas_hba
.num_phys
)
5057 _scsih_sas_host_add(ioc
);
5059 _scsih_sas_host_refresh(ioc
);
5061 if (fw_event
->ignore
) {
5062 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5063 "ignoring expander event\n", ioc
->name
));
5067 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5069 /* handle expander add */
5070 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5071 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5074 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5075 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5078 sas_address
= sas_expander
->sas_address
;
5079 max_phys
= sas_expander
->num_phys
;
5080 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5081 sas_address
= ioc
->sas_hba
.sas_address
;
5082 max_phys
= ioc
->sas_hba
.num_phys
;
5084 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5087 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5089 /* handle siblings events */
5090 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5091 if (fw_event
->ignore
) {
5092 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5093 "ignoring expander event\n", ioc
->name
));
5096 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5098 phy_number
= event_data
->StartPhyNum
+ i
;
5099 if (phy_number
>= max_phys
)
5101 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5102 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5103 if ((event_data
->PHY
[i
].PhyStatus
&
5104 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5105 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5107 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5110 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5111 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5112 switch (reason_code
) {
5113 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5115 if (ioc
->shost_recovery
)
5118 if (link_rate
== prev_link_rate
)
5121 mpt3sas_transport_update_links(ioc
, sas_address
,
5122 handle
, phy_number
, link_rate
);
5124 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5127 _scsih_check_device(ioc
, sas_address
, handle
,
5128 phy_number
, link_rate
);
5131 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5133 if (ioc
->shost_recovery
)
5136 mpt3sas_transport_update_links(ioc
, sas_address
,
5137 handle
, phy_number
, link_rate
);
5139 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5142 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5144 _scsih_device_remove_by_handle(ioc
, handle
);
5149 /* handle expander removal */
5150 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5152 mpt3sas_expander_remove(ioc
, sas_address
);
5157 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5159 * _scsih_sas_device_status_change_event_debug - debug for device event
5160 * @event_data: event data payload
5166 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5167 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5169 char *reason_str
= NULL
;
5171 switch (event_data
->ReasonCode
) {
5172 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5173 reason_str
= "smart data";
5175 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5176 reason_str
= "unsupported device discovered";
5178 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5179 reason_str
= "internal device reset";
5181 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5182 reason_str
= "internal task abort";
5184 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5185 reason_str
= "internal task abort set";
5187 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5188 reason_str
= "internal clear task set";
5190 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5191 reason_str
= "internal query task";
5193 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5194 reason_str
= "sata init failure";
5196 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5197 reason_str
= "internal device reset complete";
5199 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5200 reason_str
= "internal task abort complete";
5202 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5203 reason_str
= "internal async notification";
5205 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5206 reason_str
= "expander reduced functionality";
5208 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5209 reason_str
= "expander reduced functionality complete";
5212 reason_str
= "unknown reason";
5215 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5216 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5217 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5218 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5219 le16_to_cpu(event_data
->TaskTag
));
5220 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5221 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5222 event_data
->ASC
, event_data
->ASCQ
);
5228 * _scsih_sas_device_status_change_event - handle device status change
5229 * @ioc: per adapter object
5230 * @fw_event: The fw_event_work object
5236 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5237 struct fw_event_work
*fw_event
)
5239 struct MPT3SAS_TARGET
*target_priv_data
;
5240 struct _sas_device
*sas_device
;
5242 unsigned long flags
;
5243 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5244 fw_event
->event_data
;
5246 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5247 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5248 _scsih_sas_device_status_change_event_debug(ioc
,
5252 /* In MPI Revision K (0xC), the internal device reset complete was
5253 * implemented, so avoid setting tm_busy flag for older firmware.
5255 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5258 if (event_data
->ReasonCode
!=
5259 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5260 event_data
->ReasonCode
!=
5261 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5264 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5265 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5266 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
5269 if (!sas_device
|| !sas_device
->starget
) {
5270 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5274 target_priv_data
= sas_device
->starget
->hostdata
;
5275 if (!target_priv_data
) {
5276 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5280 if (event_data
->ReasonCode
==
5281 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5282 target_priv_data
->tm_busy
= 1;
5284 target_priv_data
->tm_busy
= 0;
5285 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5288 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5290 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5292 * @ioc: per adapter object
5293 * @event_data: event data payload
5299 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5300 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5302 char *reason_str
= NULL
;
5304 switch (event_data
->ReasonCode
) {
5305 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5306 reason_str
= "enclosure add";
5308 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5309 reason_str
= "enclosure remove";
5312 reason_str
= "unknown reason";
5316 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
5317 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5318 " number slots(%d)\n", ioc
->name
, reason_str
,
5319 le16_to_cpu(event_data
->EnclosureHandle
),
5320 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5321 le16_to_cpu(event_data
->StartSlot
));
5326 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5327 * @ioc: per adapter object
5328 * @fw_event: The fw_event_work object
5334 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5335 struct fw_event_work
*fw_event
)
5337 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5338 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5339 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5340 fw_event
->event_data
);
5345 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5346 * @ioc: per adapter object
5347 * @fw_event: The fw_event_work object
5353 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
5354 struct fw_event_work
*fw_event
)
5356 struct scsi_cmnd
*scmd
;
5357 struct scsi_device
*sdev
;
5360 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5361 u32 termination_count
;
5363 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5364 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5366 unsigned long flags
;
5369 u8 task_abort_retries
;
5371 mutex_lock(&ioc
->tm_cmds
.mutex
);
5373 "%s: enter: phy number(%d), width(%d)\n",
5374 ioc
->name
, __func__
, event_data
->PhyNum
,
5375 event_data
->PortWidth
);
5377 _scsih_block_io_all_device(ioc
);
5379 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5380 mpi_reply
= ioc
->tm_cmds
.reply
;
5381 broadcast_aen_retry
:
5383 /* sanity checks for retrying this loop */
5384 if (max_retries
++ == 5) {
5385 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
5386 ioc
->name
, __func__
));
5388 } else if (max_retries
> 1)
5389 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
5390 ioc
->name
, __func__
, max_retries
- 1));
5392 termination_count
= 0;
5394 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5395 if (ioc
->shost_recovery
)
5397 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5400 sdev
= scmd
->device
;
5401 sas_device_priv_data
= sdev
->hostdata
;
5402 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5404 /* skip hidden raid components */
5405 if (sas_device_priv_data
->sas_target
->flags
&
5406 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5409 if (sas_device_priv_data
->sas_target
->flags
&
5410 MPT_TARGET_FLAGS_VOLUME
)
5413 handle
= sas_device_priv_data
->sas_target
->handle
;
5414 lun
= sas_device_priv_data
->lun
;
5417 if (ioc
->shost_recovery
)
5420 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5421 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5422 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
5425 sdev_printk(KERN_WARNING
, sdev
,
5426 "mpt3sas_scsih_issue_tm: FAILED when sending "
5427 "QUERY_TASK: scmd(%p)\n", scmd
);
5428 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5429 goto broadcast_aen_retry
;
5431 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5432 & MPI2_IOCSTATUS_MASK
;
5433 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5434 sdev_printk(KERN_WARNING
, sdev
,
5435 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5437 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5438 goto broadcast_aen_retry
;
5441 /* see if IO is still owned by IOC and target */
5442 if (mpi_reply
->ResponseCode
==
5443 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5444 mpi_reply
->ResponseCode
==
5445 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5446 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5449 task_abort_retries
= 0;
5451 if (task_abort_retries
++ == 60) {
5452 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5453 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5455 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5456 goto broadcast_aen_retry
;
5459 if (ioc
->shost_recovery
)
5462 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5463 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5466 sdev_printk(KERN_WARNING
, sdev
,
5467 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5468 "scmd(%p)\n", scmd
);
5472 if (task_abort_retries
> 1)
5473 sdev_printk(KERN_WARNING
, sdev
,
5474 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5476 task_abort_retries
- 1, scmd
);
5478 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5479 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5482 if (ioc
->broadcast_aen_pending
) {
5483 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5484 "%s: loop back due to pending AEN\n",
5485 ioc
->name
, __func__
));
5486 ioc
->broadcast_aen_pending
= 0;
5487 goto broadcast_aen_retry
;
5491 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5494 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5495 "%s - exit, query_count = %d termination_count = %d\n",
5496 ioc
->name
, __func__
, query_count
, termination_count
));
5498 ioc
->broadcast_aen_busy
= 0;
5499 if (!ioc
->shost_recovery
)
5500 _scsih_ublock_io_all_device(ioc
);
5501 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5505 * _scsih_sas_discovery_event - handle discovery events
5506 * @ioc: per adapter object
5507 * @fw_event: The fw_event_work object
5513 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
5514 struct fw_event_work
*fw_event
)
5516 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5518 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5519 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5520 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
5521 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5523 if (event_data
->DiscoveryStatus
)
5524 pr_info("discovery_status(0x%08x)",
5525 le32_to_cpu(event_data
->DiscoveryStatus
));
5530 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5531 !ioc
->sas_hba
.num_phys
) {
5532 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
5533 /* Wait for the reset to complete */
5534 while (ioc
->shost_recovery
)
5537 _scsih_sas_host_add(ioc
);
5542 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5543 * @ioc: per adapter object
5544 * @handle: device handle for physical disk
5545 * @phys_disk_num: physical disk number
5547 * Return 0 for success, else failure.
5550 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
5552 Mpi2RaidActionRequest_t
*mpi_request
;
5553 Mpi2RaidActionReply_t
*mpi_reply
;
5561 mutex_lock(&ioc
->scsih_cmds
.mutex
);
5563 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
5564 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
5565 ioc
->name
, __func__
);
5569 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
5571 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
5573 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
5574 ioc
->name
, __func__
);
5575 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
5580 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5581 ioc
->scsih_cmds
.smid
= smid
;
5582 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
5584 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
5585 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
5586 mpi_request
->PhysDiskNum
= phys_disk_num
;
5588 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
5589 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
5590 handle
, phys_disk_num
));
5592 init_completion(&ioc
->scsih_cmds
.done
);
5593 mpt3sas_base_put_smid_default(ioc
, smid
);
5594 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
5596 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
5597 pr_err(MPT3SAS_FMT
"%s: timeout\n",
5598 ioc
->name
, __func__
);
5599 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
5605 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
5607 mpi_reply
= ioc
->scsih_cmds
.reply
;
5608 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5609 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5610 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5613 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5614 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5615 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5616 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5617 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
5621 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5622 "IR RAID_ACTION: completed successfully\n",
5627 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
5628 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
5631 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
5637 * _scsih_reprobe_lun - reprobing lun
5638 * @sdev: scsi device struct
5639 * @no_uld_attach: sdev->no_uld_attach flag setting
5643 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5646 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5647 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5648 sdev
->no_uld_attach
? "hidding" : "exposing");
5649 rc
= scsi_device_reprobe(sdev
);
5653 * _scsih_sas_volume_add - add new volume
5654 * @ioc: per adapter object
5655 * @element: IR config element data
5661 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
5662 Mpi2EventIrConfigElement_t
*element
)
5664 struct _raid_device
*raid_device
;
5665 unsigned long flags
;
5667 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5670 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5673 "failure at %s:%d/%s()!\n", ioc
->name
,
5674 __FILE__
, __LINE__
, __func__
);
5678 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5679 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5680 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5685 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5688 "failure at %s:%d/%s()!\n", ioc
->name
,
5689 __FILE__
, __LINE__
, __func__
);
5693 raid_device
->id
= ioc
->sas_id
++;
5694 raid_device
->channel
= RAID_CHANNEL
;
5695 raid_device
->handle
= handle
;
5696 raid_device
->wwid
= wwid
;
5697 _scsih_raid_device_add(ioc
, raid_device
);
5698 if (!ioc
->wait_for_discovery_to_complete
) {
5699 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5700 raid_device
->id
, 0);
5702 _scsih_raid_device_remove(ioc
, raid_device
);
5704 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5705 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5706 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5711 * _scsih_sas_volume_delete - delete volume
5712 * @ioc: per adapter object
5713 * @handle: volume device handle
5719 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5721 struct _raid_device
*raid_device
;
5722 unsigned long flags
;
5723 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5724 struct scsi_target
*starget
= NULL
;
5726 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5727 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5729 if (raid_device
->starget
) {
5730 starget
= raid_device
->starget
;
5731 sas_target_priv_data
= starget
->hostdata
;
5732 sas_target_priv_data
->deleted
= 1;
5734 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
5735 ioc
->name
, raid_device
->handle
,
5736 (unsigned long long) raid_device
->wwid
);
5737 list_del(&raid_device
->list
);
5740 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5742 scsi_remove_target(&starget
->dev
);
5746 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5747 * @ioc: per adapter object
5748 * @element: IR config element data
5754 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
5755 Mpi2EventIrConfigElement_t
*element
)
5757 struct _sas_device
*sas_device
;
5758 struct scsi_target
*starget
= NULL
;
5759 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5760 unsigned long flags
;
5761 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5763 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5764 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5766 sas_device
->volume_handle
= 0;
5767 sas_device
->volume_wwid
= 0;
5768 clear_bit(handle
, ioc
->pd_handles
);
5769 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5770 starget
= sas_device
->starget
;
5771 sas_target_priv_data
= starget
->hostdata
;
5772 sas_target_priv_data
->flags
&=
5773 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5776 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5780 /* exposing raid component */
5782 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
5786 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5787 * @ioc: per adapter object
5788 * @element: IR config element data
5794 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
5795 Mpi2EventIrConfigElement_t
*element
)
5797 struct _sas_device
*sas_device
;
5798 struct scsi_target
*starget
= NULL
;
5799 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5800 unsigned long flags
;
5801 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5802 u16 volume_handle
= 0;
5803 u64 volume_wwid
= 0;
5805 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
5807 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
5810 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5811 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5813 set_bit(handle
, ioc
->pd_handles
);
5814 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5815 starget
= sas_device
->starget
;
5816 sas_target_priv_data
= starget
->hostdata
;
5817 sas_target_priv_data
->flags
|=
5818 MPT_TARGET_FLAGS_RAID_COMPONENT
;
5819 sas_device
->volume_handle
= volume_handle
;
5820 sas_device
->volume_wwid
= volume_wwid
;
5823 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5827 /* hiding raid component */
5828 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
5830 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
5834 * _scsih_sas_pd_delete - delete pd component
5835 * @ioc: per adapter object
5836 * @element: IR config element data
5842 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
5843 Mpi2EventIrConfigElement_t
*element
)
5845 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5847 _scsih_device_remove_by_handle(ioc
, handle
);
5851 * _scsih_sas_pd_add - remove pd component
5852 * @ioc: per adapter object
5853 * @element: IR config element data
5859 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
5860 Mpi2EventIrConfigElement_t
*element
)
5862 struct _sas_device
*sas_device
;
5863 unsigned long flags
;
5864 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5865 Mpi2ConfigReply_t mpi_reply
;
5866 Mpi2SasDevicePage0_t sas_device_pg0
;
5871 set_bit(handle
, ioc
->pd_handles
);
5873 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5874 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5875 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5877 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
5881 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5882 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5883 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5884 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5888 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5889 MPI2_IOCSTATUS_MASK
;
5890 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5891 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5892 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5896 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
5897 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
5898 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
5899 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
5901 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
5902 _scsih_add_device(ioc
, handle
, 0, 1);
5905 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5907 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5908 * @ioc: per adapter object
5909 * @event_data: event data payload
5915 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5916 Mpi2EventDataIrConfigChangeList_t
*event_data
)
5918 Mpi2EventIrConfigElement_t
*element
;
5921 char *reason_str
= NULL
, *element_str
= NULL
;
5923 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
5925 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
5926 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
5927 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
5928 "foreign" : "native", event_data
->NumElements
);
5929 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
5930 switch (element
->ReasonCode
) {
5931 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
5934 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
5935 reason_str
= "remove";
5937 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
5938 reason_str
= "no change";
5940 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
5941 reason_str
= "hide";
5943 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
5944 reason_str
= "unhide";
5946 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
5947 reason_str
= "volume_created";
5949 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
5950 reason_str
= "volume_deleted";
5952 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
5953 reason_str
= "pd_created";
5955 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
5956 reason_str
= "pd_deleted";
5959 reason_str
= "unknown reason";
5962 element_type
= le16_to_cpu(element
->ElementFlags
) &
5963 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
5964 switch (element_type
) {
5965 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
5966 element_str
= "volume";
5968 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
5969 element_str
= "phys disk";
5971 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
5972 element_str
= "hot spare";
5975 element_str
= "unknown element";
5978 pr_info("\t(%s:%s), vol handle(0x%04x), " \
5979 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
5980 reason_str
, le16_to_cpu(element
->VolDevHandle
),
5981 le16_to_cpu(element
->PhysDiskDevHandle
),
5982 element
->PhysDiskNum
);
5988 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5989 * @ioc: per adapter object
5990 * @fw_event: The fw_event_work object
5996 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5997 struct fw_event_work
*fw_event
)
5999 Mpi2EventIrConfigElement_t
*element
;
6002 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
6004 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6005 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6006 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6010 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6011 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6013 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6014 if (ioc
->shost_recovery
) {
6016 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6017 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6018 _scsih_ir_fastpath(ioc
,
6019 le16_to_cpu(element
->PhysDiskDevHandle
),
6020 element
->PhysDiskNum
);
6024 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6026 switch (element
->ReasonCode
) {
6027 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6028 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6029 if (!foreign_config
)
6030 _scsih_sas_volume_add(ioc
, element
);
6032 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6033 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6034 if (!foreign_config
)
6035 _scsih_sas_volume_delete(ioc
,
6036 le16_to_cpu(element
->VolDevHandle
));
6038 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6039 _scsih_sas_pd_hide(ioc
, element
);
6041 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6042 _scsih_sas_pd_expose(ioc
, element
);
6044 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6045 _scsih_sas_pd_add(ioc
, element
);
6047 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6048 _scsih_sas_pd_delete(ioc
, element
);
6055 * _scsih_sas_ir_volume_event - IR volume event
6056 * @ioc: per adapter object
6057 * @fw_event: The fw_event_work object
6063 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6064 struct fw_event_work
*fw_event
)
6067 unsigned long flags
;
6068 struct _raid_device
*raid_device
;
6072 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
6074 if (ioc
->shost_recovery
)
6077 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6080 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6081 state
= le32_to_cpu(event_data
->NewValue
);
6082 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6083 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6084 ioc
->name
, __func__
, handle
,
6085 le32_to_cpu(event_data
->PreviousValue
), state
));
6087 case MPI2_RAID_VOL_STATE_MISSING
:
6088 case MPI2_RAID_VOL_STATE_FAILED
:
6089 _scsih_sas_volume_delete(ioc
, handle
);
6092 case MPI2_RAID_VOL_STATE_ONLINE
:
6093 case MPI2_RAID_VOL_STATE_DEGRADED
:
6094 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6096 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6097 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6098 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6103 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6106 "failure at %s:%d/%s()!\n", ioc
->name
,
6107 __FILE__
, __LINE__
, __func__
);
6111 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6114 "failure at %s:%d/%s()!\n", ioc
->name
,
6115 __FILE__
, __LINE__
, __func__
);
6119 raid_device
->id
= ioc
->sas_id
++;
6120 raid_device
->channel
= RAID_CHANNEL
;
6121 raid_device
->handle
= handle
;
6122 raid_device
->wwid
= wwid
;
6123 _scsih_raid_device_add(ioc
, raid_device
);
6124 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6125 raid_device
->id
, 0);
6127 _scsih_raid_device_remove(ioc
, raid_device
);
6130 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6137 * _scsih_sas_ir_physical_disk_event - PD event
6138 * @ioc: per adapter object
6139 * @fw_event: The fw_event_work object
6145 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6146 struct fw_event_work
*fw_event
)
6148 u16 handle
, parent_handle
;
6150 struct _sas_device
*sas_device
;
6151 unsigned long flags
;
6152 Mpi2ConfigReply_t mpi_reply
;
6153 Mpi2SasDevicePage0_t sas_device_pg0
;
6155 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
6158 if (ioc
->shost_recovery
)
6161 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6164 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6165 state
= le32_to_cpu(event_data
->NewValue
);
6167 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6168 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6169 ioc
->name
, __func__
, handle
,
6170 le32_to_cpu(event_data
->PreviousValue
), state
));
6172 case MPI2_RAID_PD_STATE_ONLINE
:
6173 case MPI2_RAID_PD_STATE_DEGRADED
:
6174 case MPI2_RAID_PD_STATE_REBUILDING
:
6175 case MPI2_RAID_PD_STATE_OPTIMAL
:
6176 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6178 set_bit(handle
, ioc
->pd_handles
);
6179 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6180 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6181 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6186 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6187 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6189 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6190 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6194 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6195 MPI2_IOCSTATUS_MASK
;
6196 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6197 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6198 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6202 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6203 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6204 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6205 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6207 _scsih_add_device(ioc
, handle
, 0, 1);
6211 case MPI2_RAID_PD_STATE_OFFLINE
:
6212 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6213 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6219 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6221 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6222 * @ioc: per adapter object
6223 * @event_data: event data payload
6229 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6230 Mpi2EventDataIrOperationStatus_t
*event_data
)
6232 char *reason_str
= NULL
;
6234 switch (event_data
->RAIDOperation
) {
6235 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6236 reason_str
= "resync";
6238 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6239 reason_str
= "online capacity expansion";
6241 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6242 reason_str
= "consistency check";
6244 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6245 reason_str
= "background init";
6247 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6248 reason_str
= "make data consistent";
6255 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6256 "\thandle(0x%04x), percent complete(%d)\n",
6257 ioc
->name
, reason_str
,
6258 le16_to_cpu(event_data
->VolDevHandle
),
6259 event_data
->PercentComplete
);
6264 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6265 * @ioc: per adapter object
6266 * @fw_event: The fw_event_work object
6272 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
6273 struct fw_event_work
*fw_event
)
6275 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
6276 static struct _raid_device
*raid_device
;
6277 unsigned long flags
;
6280 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6281 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6282 _scsih_sas_ir_operation_status_event_debug(ioc
,
6286 /* code added for raid transport support */
6287 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6289 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6290 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6291 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6293 raid_device
->percent_complete
=
6294 event_data
->PercentComplete
;
6295 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6300 * _scsih_prep_device_scan - initialize parameters prior to device scan
6301 * @ioc: per adapter object
6303 * Set the deleted flag prior to device scan. If the device is found during
6304 * the scan, then we clear the deleted flag.
6307 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
6309 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6310 struct scsi_device
*sdev
;
6312 shost_for_each_device(sdev
, ioc
->shost
) {
6313 sas_device_priv_data
= sdev
->hostdata
;
6314 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6315 sas_device_priv_data
->sas_target
->deleted
= 1;
6320 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6321 * @ioc: per adapter object
6322 * @sas_address: sas address
6323 * @slot: enclosure slot id
6324 * @handle: device handle
6326 * After host reset, find out whether devices are still responding.
6327 * Used in _scsih_remove_unresponsive_sas_devices.
6332 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
6333 u16 slot
, u16 handle
)
6335 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
6336 struct scsi_target
*starget
;
6337 struct _sas_device
*sas_device
;
6338 unsigned long flags
;
6340 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6341 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6342 if (sas_device
->sas_address
== sas_address
&&
6343 sas_device
->slot
== slot
) {
6344 sas_device
->responding
= 1;
6345 starget
= sas_device
->starget
;
6346 if (starget
&& starget
->hostdata
) {
6347 sas_target_priv_data
= starget
->hostdata
;
6348 sas_target_priv_data
->tm_busy
= 0;
6349 sas_target_priv_data
->deleted
= 0;
6351 sas_target_priv_data
= NULL
;
6353 starget_printk(KERN_INFO
, starget
,
6354 "handle(0x%04x), sas_addr(0x%016llx), "
6355 "enclosure logical id(0x%016llx), "
6356 "slot(%d)\n", handle
,
6357 (unsigned long long)sas_device
->sas_address
,
6358 (unsigned long long)
6359 sas_device
->enclosure_logical_id
,
6361 if (sas_device
->handle
== handle
)
6363 pr_info("\thandle changed from(0x%04x)!!!\n",
6364 sas_device
->handle
);
6365 sas_device
->handle
= handle
;
6366 if (sas_target_priv_data
)
6367 sas_target_priv_data
->handle
= handle
;
6372 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6376 * _scsih_search_responding_sas_devices -
6377 * @ioc: per adapter object
6379 * After host reset, find out whether devices are still responding.
6385 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
6387 Mpi2SasDevicePage0_t sas_device_pg0
;
6388 Mpi2ConfigReply_t mpi_reply
;
6393 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
6395 if (list_empty(&ioc
->sas_device_list
))
6399 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6400 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6402 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6403 MPI2_IOCSTATUS_MASK
;
6404 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6406 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6407 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6408 if (!(_scsih_is_end_device(device_info
)))
6410 _scsih_mark_responding_sas_device(ioc
,
6411 le64_to_cpu(sas_device_pg0
.SASAddress
),
6412 le16_to_cpu(sas_device_pg0
.Slot
), handle
);
6416 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
6421 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6422 * @ioc: per adapter object
6423 * @wwid: world wide identifier for raid volume
6424 * @handle: device handle
6426 * After host reset, find out whether devices are still responding.
6427 * Used in _scsih_remove_unresponsive_raid_devices.
6432 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6435 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6436 struct scsi_target
*starget
;
6437 struct _raid_device
*raid_device
;
6438 unsigned long flags
;
6440 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6441 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6442 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6443 starget
= raid_device
->starget
;
6444 if (starget
&& starget
->hostdata
) {
6445 sas_target_priv_data
= starget
->hostdata
;
6446 sas_target_priv_data
->deleted
= 0;
6448 sas_target_priv_data
= NULL
;
6449 raid_device
->responding
= 1;
6450 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6451 starget_printk(KERN_INFO
, raid_device
->starget
,
6452 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6453 (unsigned long long)raid_device
->wwid
);
6454 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6455 if (raid_device
->handle
== handle
) {
6456 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
6460 pr_info("\thandle changed from(0x%04x)!!!\n",
6461 raid_device
->handle
);
6462 raid_device
->handle
= handle
;
6463 if (sas_target_priv_data
)
6464 sas_target_priv_data
->handle
= handle
;
6465 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6469 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6473 * _scsih_search_responding_raid_devices -
6474 * @ioc: per adapter object
6476 * After host reset, find out whether devices are still responding.
6482 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
6484 Mpi2RaidVolPage1_t volume_pg1
;
6485 Mpi2RaidVolPage0_t volume_pg0
;
6486 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6487 Mpi2ConfigReply_t mpi_reply
;
6492 if (!ioc
->ir_firmware
)
6495 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
6498 if (list_empty(&ioc
->raid_device_list
))
6502 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6503 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6504 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6505 MPI2_IOCSTATUS_MASK
;
6506 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6508 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6510 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6511 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6512 sizeof(Mpi2RaidVolPage0_t
)))
6515 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6516 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6517 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6518 _scsih_mark_responding_raid_device(ioc
,
6519 le64_to_cpu(volume_pg1
.WWID
), handle
);
6522 /* refresh the pd_handles */
6523 phys_disk_num
= 0xFF;
6524 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6525 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6526 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6528 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6529 MPI2_IOCSTATUS_MASK
;
6530 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6532 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6533 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6534 set_bit(handle
, ioc
->pd_handles
);
6537 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
6542 * _scsih_mark_responding_expander - mark a expander as responding
6543 * @ioc: per adapter object
6544 * @sas_address: sas address
6547 * After host reset, find out whether devices are still responding.
6548 * Used in _scsih_remove_unresponsive_expanders.
6553 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
6556 struct _sas_node
*sas_expander
;
6557 unsigned long flags
;
6560 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6561 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6562 if (sas_expander
->sas_address
!= sas_address
)
6564 sas_expander
->responding
= 1;
6565 if (sas_expander
->handle
== handle
)
6567 pr_info("\texpander(0x%016llx): handle changed" \
6568 " from(0x%04x) to (0x%04x)!!!\n",
6569 (unsigned long long)sas_expander
->sas_address
,
6570 sas_expander
->handle
, handle
);
6571 sas_expander
->handle
= handle
;
6572 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6573 sas_expander
->phy
[i
].handle
= handle
;
6577 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6581 * _scsih_search_responding_expanders -
6582 * @ioc: per adapter object
6584 * After host reset, find out whether devices are still responding.
6590 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
6592 Mpi2ExpanderPage0_t expander_pg0
;
6593 Mpi2ConfigReply_t mpi_reply
;
6598 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
6600 if (list_empty(&ioc
->sas_expander_list
))
6604 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6605 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6607 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6608 MPI2_IOCSTATUS_MASK
;
6609 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6612 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6613 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6614 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6616 (unsigned long long)sas_address
);
6617 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6621 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
6625 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6626 * @ioc: per adapter object
6631 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
6633 struct _sas_device
*sas_device
, *sas_device_next
;
6634 struct _sas_node
*sas_expander
, *sas_expander_next
;
6635 struct _raid_device
*raid_device
, *raid_device_next
;
6636 struct list_head tmp_list
;
6637 unsigned long flags
;
6639 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
6642 /* removing unresponding end devices */
6643 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
6645 list_for_each_entry_safe(sas_device
, sas_device_next
,
6646 &ioc
->sas_device_list
, list
) {
6647 if (!sas_device
->responding
)
6648 mpt3sas_device_remove_by_sas_address(ioc
,
6649 sas_device
->sas_address
);
6651 sas_device
->responding
= 0;
6654 /* removing unresponding volumes */
6655 if (ioc
->ir_firmware
) {
6656 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
6658 list_for_each_entry_safe(raid_device
, raid_device_next
,
6659 &ioc
->raid_device_list
, list
) {
6660 if (!raid_device
->responding
)
6661 _scsih_sas_volume_delete(ioc
,
6662 raid_device
->handle
);
6664 raid_device
->responding
= 0;
6668 /* removing unresponding expanders */
6669 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
6671 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6672 INIT_LIST_HEAD(&tmp_list
);
6673 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
6674 &ioc
->sas_expander_list
, list
) {
6675 if (!sas_expander
->responding
)
6676 list_move_tail(&sas_expander
->list
, &tmp_list
);
6678 sas_expander
->responding
= 0;
6680 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6681 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
6683 list_del(&sas_expander
->list
);
6684 _scsih_expander_node_remove(ioc
, sas_expander
);
6687 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
6690 /* unblock devices */
6691 _scsih_ublock_io_all_device(ioc
);
6695 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
6696 struct _sas_node
*sas_expander
, u16 handle
)
6698 Mpi2ExpanderPage1_t expander_pg1
;
6699 Mpi2ConfigReply_t mpi_reply
;
6702 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
6703 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
6704 &expander_pg1
, i
, handle
))) {
6705 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6706 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6710 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
6711 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
6712 expander_pg1
.NegotiatedLinkRate
>> 4);
6717 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6718 * @ioc: per adapter object
6723 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
6725 Mpi2ExpanderPage0_t expander_pg0
;
6726 Mpi2SasDevicePage0_t sas_device_pg0
;
6727 Mpi2RaidVolPage1_t volume_pg1
;
6728 Mpi2RaidVolPage0_t volume_pg0
;
6729 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6730 Mpi2EventIrConfigElement_t element
;
6731 Mpi2ConfigReply_t mpi_reply
;
6734 u16 handle
, parent_handle
;
6736 struct _sas_device
*sas_device
;
6737 struct _sas_node
*expander_device
;
6738 static struct _raid_device
*raid_device
;
6740 unsigned long flags
;
6742 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
6744 _scsih_sas_host_refresh(ioc
);
6746 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
6750 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6751 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6752 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6753 MPI2_IOCSTATUS_MASK
;
6754 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6755 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
6756 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6757 ioc
->name
, ioc_status
,
6758 le32_to_cpu(mpi_reply
.IOCLogInfo
));
6761 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6762 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6763 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
6764 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
6765 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6766 if (expander_device
)
6767 _scsih_refresh_expander_links(ioc
, expander_device
,
6770 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
6771 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6772 handle
, (unsigned long long)
6773 le64_to_cpu(expander_pg0
.SASAddress
));
6774 _scsih_expander_add(ioc
, handle
);
6775 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
6776 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6777 handle
, (unsigned long long)
6778 le64_to_cpu(expander_pg0
.SASAddress
));
6782 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
6785 if (!ioc
->ir_firmware
)
6788 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
6791 phys_disk_num
= 0xFF;
6792 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6793 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6795 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6796 MPI2_IOCSTATUS_MASK
;
6797 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6798 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
6799 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6800 ioc
->name
, ioc_status
,
6801 le32_to_cpu(mpi_reply
.IOCLogInfo
));
6804 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6805 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6806 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6807 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6808 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6811 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6812 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6815 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6816 MPI2_IOCSTATUS_MASK
;
6817 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6818 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
6819 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6820 ioc
->name
, ioc_status
,
6821 le32_to_cpu(mpi_reply
.IOCLogInfo
));
6824 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6825 if (!_scsih_get_sas_address(ioc
, parent_handle
,
6827 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
6828 " handle (0x%04x), sas_addr(0x%016llx)\n",
6829 ioc
->name
, handle
, (unsigned long long)
6830 le64_to_cpu(sas_device_pg0
.SASAddress
));
6831 mpt3sas_transport_update_links(ioc
, sas_address
,
6832 handle
, sas_device_pg0
.PhyNum
,
6833 MPI2_SAS_NEG_LINK_RATE_1_5
);
6834 set_bit(handle
, ioc
->pd_handles
);
6836 /* This will retry adding the end device.
6837 * _scsih_add_device() will decide on retries and
6838 * return "1" when it should be retried
6840 while (_scsih_add_device(ioc
, handle
, retry_count
++,
6844 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
6845 " handle (0x%04x), sas_addr(0x%016llx)\n",
6846 ioc
->name
, handle
, (unsigned long long)
6847 le64_to_cpu(sas_device_pg0
.SASAddress
));
6851 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
6854 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
6858 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6859 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6860 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6861 MPI2_IOCSTATUS_MASK
;
6862 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6863 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
6864 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6865 ioc
->name
, ioc_status
,
6866 le32_to_cpu(mpi_reply
.IOCLogInfo
));
6869 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6870 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6871 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
6872 le64_to_cpu(volume_pg1
.WWID
));
6873 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6876 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6877 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6878 sizeof(Mpi2RaidVolPage0_t
)))
6880 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6881 MPI2_IOCSTATUS_MASK
;
6882 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6883 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
6884 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6885 ioc
->name
, ioc_status
,
6886 le32_to_cpu(mpi_reply
.IOCLogInfo
));
6889 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6890 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6891 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
6892 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
6893 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
6894 element
.VolDevHandle
= volume_pg1
.DevHandle
;
6896 "\tBEFORE adding volume: handle (0x%04x)\n",
6897 ioc
->name
, volume_pg1
.DevHandle
);
6898 _scsih_sas_volume_add(ioc
, &element
);
6900 "\tAFTER adding volume: handle (0x%04x)\n",
6901 ioc
->name
, volume_pg1
.DevHandle
);
6905 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
6910 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
6915 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6916 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6918 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6919 MPI2_IOCSTATUS_MASK
;
6920 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6921 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
6922 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6923 ioc
->name
, ioc_status
,
6924 le32_to_cpu(mpi_reply
.IOCLogInfo
));
6927 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6928 if (!(_scsih_is_end_device(
6929 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
6931 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6932 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
6933 le64_to_cpu(sas_device_pg0
.SASAddress
));
6934 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6937 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6938 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
6939 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
6940 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6941 handle
, (unsigned long long)
6942 le64_to_cpu(sas_device_pg0
.SASAddress
));
6943 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6944 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6946 /* This will retry adding the end device.
6947 * _scsih_add_device() will decide on retries and
6948 * return "1" when it should be retried
6950 while (_scsih_add_device(ioc
, handle
, retry_count
++,
6954 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
6955 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
6956 handle
, (unsigned long long)
6957 le64_to_cpu(sas_device_pg0
.SASAddress
));
6960 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
6963 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
6966 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
6967 * @ioc: per adapter object
6968 * @reset_phase: phase
6970 * The handler for doing any required cleanup or initialization.
6972 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
6973 * MPT3_IOC_DONE_RESET
6978 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
6980 switch (reset_phase
) {
6981 case MPT3_IOC_PRE_RESET
:
6982 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
6983 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6985 case MPT3_IOC_AFTER_RESET
:
6986 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
6987 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6988 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
6989 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
6990 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
6991 complete(&ioc
->scsih_cmds
.done
);
6993 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
6994 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
6995 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
6996 complete(&ioc
->tm_cmds
.done
);
6999 _scsih_fw_event_cleanup_queue(ioc
);
7000 _scsih_flush_running_cmds(ioc
);
7002 case MPT3_IOC_DONE_RESET
:
7003 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7004 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7005 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7006 !ioc
->sas_hba
.num_phys
)) {
7007 _scsih_prep_device_scan(ioc
);
7008 _scsih_search_responding_sas_devices(ioc
);
7009 _scsih_search_responding_raid_devices(ioc
);
7010 _scsih_search_responding_expanders(ioc
);
7011 _scsih_error_recovery_delete_devices(ioc
);
7018 * _mpt3sas_fw_work - delayed task for processing firmware events
7019 * @ioc: per adapter object
7020 * @fw_event: The fw_event_work object
7026 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7028 /* the queue is being flushed so ignore this event */
7029 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
7030 ioc
->pci_error_recovery
) {
7031 _scsih_fw_event_free(ioc
, fw_event
);
7035 switch (fw_event
->event
) {
7036 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7037 mpt3sas_process_trigger_data(ioc
, fw_event
->event_data
);
7039 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7040 while (scsi_host_in_recovery(ioc
->shost
) || ioc
->shost_recovery
)
7042 _scsih_remove_unresponding_sas_devices(ioc
);
7043 _scsih_scan_for_devices_after_reset(ioc
);
7045 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7046 ioc
->start_scan
= 0;
7047 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7048 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7050 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7051 "port enable: complete from worker thread\n",
7054 case MPT3SAS_TURN_ON_FAULT_LED
:
7055 _scsih_turn_on_fault_led(ioc
, fw_event
->device_handle
);
7057 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7058 _scsih_sas_topology_change_event(ioc
, fw_event
);
7060 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7061 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7063 case MPI2_EVENT_SAS_DISCOVERY
:
7064 _scsih_sas_discovery_event(ioc
, fw_event
);
7066 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7067 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7069 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7070 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7073 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7074 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7076 case MPI2_EVENT_IR_VOLUME
:
7077 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7079 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7080 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7082 case MPI2_EVENT_IR_OPERATION_STATUS
:
7083 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7086 _scsih_fw_event_free(ioc
, fw_event
);
7090 * _firmware_event_work
7091 * @ioc: per adapter object
7092 * @work: The fw_event_work object
7095 * wrappers for the work thread handling firmware events
7101 _firmware_event_work(struct work_struct
*work
)
7103 struct fw_event_work
*fw_event
= container_of(work
,
7104 struct fw_event_work
, work
);
7106 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7110 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7111 * @ioc: per adapter object
7112 * @msix_index: MSIX table index supplied by the OS
7113 * @reply: reply message frame(lower 32bit addr)
7114 * Context: interrupt.
7116 * This function merely adds a new work task into ioc->firmware_event_thread.
7117 * The tasks are worked from _firmware_event_work in user context.
7119 * Return 1 meaning mf should be freed from _base_interrupt
7120 * 0 means the mf is freed from this function.
7123 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7126 struct fw_event_work
*fw_event
;
7127 Mpi2EventNotificationReply_t
*mpi_reply
;
7131 /* events turned off due to host reset or driver unloading */
7132 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7135 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7137 if (unlikely(!mpi_reply
)) {
7138 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7139 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7143 event
= le16_to_cpu(mpi_reply
->Event
);
7145 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7146 mpt3sas_trigger_event(ioc
, event
, 0);
7150 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7152 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7153 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7154 mpi_reply
->EventData
;
7156 if (baen_data
->Primitive
!=
7157 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7160 if (ioc
->broadcast_aen_busy
) {
7161 ioc
->broadcast_aen_pending
++;
7164 ioc
->broadcast_aen_busy
= 1;
7168 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7169 _scsih_check_topo_delete_events(ioc
,
7170 (Mpi2EventDataSasTopologyChangeList_t
*)
7171 mpi_reply
->EventData
);
7173 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7174 _scsih_check_ir_config_unhide_events(ioc
,
7175 (Mpi2EventDataIrConfigChangeList_t
*)
7176 mpi_reply
->EventData
);
7178 case MPI2_EVENT_IR_VOLUME
:
7179 _scsih_check_volume_delete_events(ioc
,
7180 (Mpi2EventDataIrVolume_t
*)
7181 mpi_reply
->EventData
);
7184 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7185 case MPI2_EVENT_IR_OPERATION_STATUS
:
7186 case MPI2_EVENT_SAS_DISCOVERY
:
7187 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7188 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7191 default: /* ignore the rest */
7195 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
7197 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7198 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7201 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7202 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
7203 if (!fw_event
->event_data
) {
7204 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7205 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7210 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
7211 fw_event
->ioc
= ioc
;
7212 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7213 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7214 fw_event
->event
= event
;
7215 _scsih_fw_event_add(ioc
, fw_event
);
7219 /* shost template */
7220 static struct scsi_host_template scsih_driver_template
= {
7221 .module
= THIS_MODULE
,
7222 .name
= "Fusion MPT SAS Host",
7223 .proc_name
= MPT3SAS_DRIVER_NAME
,
7224 .queuecommand
= _scsih_qcmd
,
7225 .target_alloc
= _scsih_target_alloc
,
7226 .slave_alloc
= _scsih_slave_alloc
,
7227 .slave_configure
= _scsih_slave_configure
,
7228 .target_destroy
= _scsih_target_destroy
,
7229 .slave_destroy
= _scsih_slave_destroy
,
7230 .scan_finished
= _scsih_scan_finished
,
7231 .scan_start
= _scsih_scan_start
,
7232 .change_queue_depth
= _scsih_change_queue_depth
,
7233 .change_queue_type
= _scsih_change_queue_type
,
7234 .eh_abort_handler
= _scsih_abort
,
7235 .eh_device_reset_handler
= _scsih_dev_reset
,
7236 .eh_target_reset_handler
= _scsih_target_reset
,
7237 .eh_host_reset_handler
= _scsih_host_reset
,
7238 .bios_param
= _scsih_bios_param
,
7241 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
7242 .max_sectors
= 32767,
7244 .use_clustering
= ENABLE_CLUSTERING
,
7245 .shost_attrs
= mpt3sas_host_attrs
,
7246 .sdev_attrs
= mpt3sas_dev_attrs
,
7250 * _scsih_expander_node_remove - removing expander device from list.
7251 * @ioc: per adapter object
7252 * @sas_expander: the sas_device object
7253 * Context: Calling function should acquire ioc->sas_node_lock.
7255 * Removing object and freeing associated memory from the
7256 * ioc->sas_expander_list.
7261 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
7262 struct _sas_node
*sas_expander
)
7264 struct _sas_port
*mpt3sas_port
, *next
;
7266 /* remove sibling ports attached to this expander */
7267 list_for_each_entry_safe(mpt3sas_port
, next
,
7268 &sas_expander
->sas_port_list
, port_list
) {
7269 if (ioc
->shost_recovery
)
7271 if (mpt3sas_port
->remote_identify
.device_type
==
7273 mpt3sas_device_remove_by_sas_address(ioc
,
7274 mpt3sas_port
->remote_identify
.sas_address
);
7275 else if (mpt3sas_port
->remote_identify
.device_type
==
7276 SAS_EDGE_EXPANDER_DEVICE
||
7277 mpt3sas_port
->remote_identify
.device_type
==
7278 SAS_FANOUT_EXPANDER_DEVICE
)
7279 mpt3sas_expander_remove(ioc
,
7280 mpt3sas_port
->remote_identify
.sas_address
);
7283 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7284 sas_expander
->sas_address_parent
);
7287 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7289 sas_expander
->handle
, (unsigned long long)
7290 sas_expander
->sas_address
);
7292 kfree(sas_expander
->phy
);
7293 kfree(sas_expander
);
7297 * _scsih_ir_shutdown - IR shutdown notification
7298 * @ioc: per adapter object
7300 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7301 * the host system is shutting down.
7306 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
7308 Mpi2RaidActionRequest_t
*mpi_request
;
7309 Mpi2RaidActionReply_t
*mpi_reply
;
7312 /* is IR firmware build loaded ? */
7313 if (!ioc
->ir_firmware
)
7316 /* are there any volumes ? */
7317 if (list_empty(&ioc
->raid_device_list
))
7320 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7322 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7323 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7324 ioc
->name
, __func__
);
7327 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7329 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7331 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7332 ioc
->name
, __func__
);
7333 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7337 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7338 ioc
->scsih_cmds
.smid
= smid
;
7339 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7341 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7342 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7344 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
7345 init_completion(&ioc
->scsih_cmds
.done
);
7346 mpt3sas_base_put_smid_default(ioc
, smid
);
7347 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7349 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7350 pr_err(MPT3SAS_FMT
"%s: timeout\n",
7351 ioc
->name
, __func__
);
7355 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7356 mpi_reply
= ioc
->scsih_cmds
.reply
;
7358 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7359 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7360 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7364 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7365 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7369 * _scsih_remove - detach and remove add host
7370 * @pdev: PCI device struct
7372 * Routine called when unloading the driver.
7375 static void _scsih_remove(struct pci_dev
*pdev
)
7377 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7378 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7379 struct _sas_port
*mpt3sas_port
, *next_port
;
7380 struct _raid_device
*raid_device
, *next
;
7381 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7382 struct workqueue_struct
*wq
;
7383 unsigned long flags
;
7385 ioc
->remove_host
= 1;
7386 _scsih_fw_event_cleanup_queue(ioc
);
7388 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7389 wq
= ioc
->firmware_event_thread
;
7390 ioc
->firmware_event_thread
= NULL
;
7391 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7393 destroy_workqueue(wq
);
7395 /* release all the volumes */
7396 _scsih_ir_shutdown(ioc
);
7397 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7399 if (raid_device
->starget
) {
7400 sas_target_priv_data
=
7401 raid_device
->starget
->hostdata
;
7402 sas_target_priv_data
->deleted
= 1;
7403 scsi_remove_target(&raid_device
->starget
->dev
);
7405 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7406 ioc
->name
, raid_device
->handle
,
7407 (unsigned long long) raid_device
->wwid
);
7408 _scsih_raid_device_remove(ioc
, raid_device
);
7411 /* free ports attached to the sas_host */
7412 list_for_each_entry_safe(mpt3sas_port
, next_port
,
7413 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7414 if (mpt3sas_port
->remote_identify
.device_type
==
7416 mpt3sas_device_remove_by_sas_address(ioc
,
7417 mpt3sas_port
->remote_identify
.sas_address
);
7418 else if (mpt3sas_port
->remote_identify
.device_type
==
7419 SAS_EDGE_EXPANDER_DEVICE
||
7420 mpt3sas_port
->remote_identify
.device_type
==
7421 SAS_FANOUT_EXPANDER_DEVICE
)
7422 mpt3sas_expander_remove(ioc
,
7423 mpt3sas_port
->remote_identify
.sas_address
);
7426 /* free phys attached to the sas_host */
7427 if (ioc
->sas_hba
.num_phys
) {
7428 kfree(ioc
->sas_hba
.phy
);
7429 ioc
->sas_hba
.phy
= NULL
;
7430 ioc
->sas_hba
.num_phys
= 0;
7433 sas_remove_host(shost
);
7434 mpt3sas_base_detach(ioc
);
7435 list_del(&ioc
->list
);
7436 scsi_remove_host(shost
);
7437 scsi_host_put(shost
);
7441 * _scsih_shutdown - routine call during system shutdown
7442 * @pdev: PCI device struct
7447 _scsih_shutdown(struct pci_dev
*pdev
)
7449 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7450 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7451 struct workqueue_struct
*wq
;
7452 unsigned long flags
;
7454 ioc
->remove_host
= 1;
7455 _scsih_fw_event_cleanup_queue(ioc
);
7457 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7458 wq
= ioc
->firmware_event_thread
;
7459 ioc
->firmware_event_thread
= NULL
;
7460 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7462 destroy_workqueue(wq
);
7464 _scsih_ir_shutdown(ioc
);
7465 mpt3sas_base_detach(ioc
);
7470 * _scsih_probe_boot_devices - reports 1st device
7471 * @ioc: per adapter object
7473 * If specified in bios page 2, this routine reports the 1st
7474 * device scsi-ml or sas transport for persistent boot device
7475 * purposes. Please refer to function _scsih_determine_boot_device()
7478 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
7482 struct _sas_device
*sas_device
;
7483 struct _raid_device
*raid_device
;
7485 u64 sas_address_parent
;
7487 unsigned long flags
;
7490 /* no Bios, return immediately */
7491 if (!ioc
->bios_pg3
.BiosVersion
)
7496 if (ioc
->req_boot_device
.device
) {
7497 device
= ioc
->req_boot_device
.device
;
7498 is_raid
= ioc
->req_boot_device
.is_raid
;
7499 } else if (ioc
->req_alt_boot_device
.device
) {
7500 device
= ioc
->req_alt_boot_device
.device
;
7501 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7502 } else if (ioc
->current_boot_device
.device
) {
7503 device
= ioc
->current_boot_device
.device
;
7504 is_raid
= ioc
->current_boot_device
.is_raid
;
7511 raid_device
= device
;
7512 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7513 raid_device
->id
, 0);
7515 _scsih_raid_device_remove(ioc
, raid_device
);
7517 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7518 sas_device
= device
;
7519 handle
= sas_device
->handle
;
7520 sas_address_parent
= sas_device
->sas_address_parent
;
7521 sas_address
= sas_device
->sas_address
;
7522 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7523 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7525 if (!mpt3sas_transport_port_add(ioc
, handle
,
7526 sas_address_parent
)) {
7527 _scsih_sas_device_remove(ioc
, sas_device
);
7528 } else if (!sas_device
->starget
) {
7529 if (!ioc
->is_driver_loading
) {
7530 mpt3sas_transport_port_remove(ioc
,
7532 sas_address_parent
);
7533 _scsih_sas_device_remove(ioc
, sas_device
);
7540 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7541 * @ioc: per adapter object
7543 * Called during initial loading of the driver.
7546 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
7548 struct _raid_device
*raid_device
, *raid_next
;
7551 list_for_each_entry_safe(raid_device
, raid_next
,
7552 &ioc
->raid_device_list
, list
) {
7553 if (raid_device
->starget
)
7555 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7556 raid_device
->id
, 0);
7558 _scsih_raid_device_remove(ioc
, raid_device
);
7563 * _scsih_probe_sas - reporting sas devices to sas transport
7564 * @ioc: per adapter object
7566 * Called during initial loading of the driver.
7569 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
7571 struct _sas_device
*sas_device
, *next
;
7572 unsigned long flags
;
7574 /* SAS Device List */
7575 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
7578 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
7579 sas_device
->sas_address_parent
)) {
7580 list_del(&sas_device
->list
);
7583 } else if (!sas_device
->starget
) {
7585 * When asyn scanning is enabled, its not possible to
7586 * remove devices while scanning is turned on due to an
7587 * oops in scsi_sysfs_add_sdev()->add_device()->
7588 * sysfs_addrm_start()
7590 if (!ioc
->is_driver_loading
) {
7591 mpt3sas_transport_port_remove(ioc
,
7592 sas_device
->sas_address
,
7593 sas_device
->sas_address_parent
);
7594 list_del(&sas_device
->list
);
7600 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7601 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7602 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7607 * _scsih_probe_devices - probing for devices
7608 * @ioc: per adapter object
7610 * Called during initial loading of the driver.
7613 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
7615 u16 volume_mapping_flags
;
7617 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
7618 return; /* return when IOC doesn't support initiator mode */
7620 _scsih_probe_boot_devices(ioc
);
7622 if (ioc
->ir_firmware
) {
7623 volume_mapping_flags
=
7624 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
7625 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
7626 if (volume_mapping_flags
==
7627 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
7628 _scsih_probe_raid(ioc
);
7629 _scsih_probe_sas(ioc
);
7631 _scsih_probe_sas(ioc
);
7632 _scsih_probe_raid(ioc
);
7635 _scsih_probe_sas(ioc
);
7639 * _scsih_scan_start - scsi lld callback for .scan_start
7640 * @shost: SCSI host pointer
7642 * The shost has the ability to discover targets on its own instead
7643 * of scanning the entire bus. In our implemention, we will kick off
7644 * firmware discovery.
7647 _scsih_scan_start(struct Scsi_Host
*shost
)
7649 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7651 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
7652 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
7654 if (disable_discovery
> 0)
7657 ioc
->start_scan
= 1;
7658 rc
= mpt3sas_port_enable(ioc
);
7661 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
7665 * _scsih_scan_finished - scsi lld callback for .scan_finished
7666 * @shost: SCSI host pointer
7667 * @time: elapsed time of the scan in jiffies
7669 * This function will be called periodicallyn until it returns 1 with the
7670 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7671 * we wait for firmware discovery to complete, then return 1.
7674 _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
7676 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7678 if (disable_discovery
> 0) {
7679 ioc
->is_driver_loading
= 0;
7680 ioc
->wait_for_discovery_to_complete
= 0;
7684 if (time
>= (300 * HZ
)) {
7685 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
7687 "port enable: FAILED with timeout (timeout=300s)\n",
7689 ioc
->is_driver_loading
= 0;
7693 if (ioc
->start_scan
)
7696 if (ioc
->start_scan_failed
) {
7698 "port enable: FAILED with (ioc_status=0x%08x)\n",
7699 ioc
->name
, ioc
->start_scan_failed
);
7700 ioc
->is_driver_loading
= 0;
7701 ioc
->wait_for_discovery_to_complete
= 0;
7702 ioc
->remove_host
= 1;
7706 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
7707 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
7709 if (ioc
->wait_for_discovery_to_complete
) {
7710 ioc
->wait_for_discovery_to_complete
= 0;
7711 _scsih_probe_devices(ioc
);
7713 mpt3sas_base_start_watchdog(ioc
);
7714 ioc
->is_driver_loading
= 0;
7719 * _scsih_probe - attach and add scsi host
7720 * @pdev: PCI device struct
7721 * @id: pci device id
7723 * Returns 0 success, anything else error.
7726 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
7728 struct MPT3SAS_ADAPTER
*ioc
;
7729 struct Scsi_Host
*shost
;
7731 shost
= scsi_host_alloc(&scsih_driver_template
,
7732 sizeof(struct MPT3SAS_ADAPTER
));
7736 /* init local params */
7737 ioc
= shost_priv(shost
);
7738 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
7739 INIT_LIST_HEAD(&ioc
->list
);
7740 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
7742 ioc
->id
= mpt_ids
++;
7743 sprintf(ioc
->name
, "%s%d", MPT3SAS_DRIVER_NAME
, ioc
->id
);
7745 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
7746 ioc
->tm_cb_idx
= tm_cb_idx
;
7747 ioc
->ctl_cb_idx
= ctl_cb_idx
;
7748 ioc
->base_cb_idx
= base_cb_idx
;
7749 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
7750 ioc
->transport_cb_idx
= transport_cb_idx
;
7751 ioc
->scsih_cb_idx
= scsih_cb_idx
;
7752 ioc
->config_cb_idx
= config_cb_idx
;
7753 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
7754 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
7755 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
7756 ioc
->logging_level
= logging_level
;
7757 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
7758 /* misc semaphores and spin locks */
7759 mutex_init(&ioc
->reset_in_progress_mutex
);
7760 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
7761 spin_lock_init(&ioc
->scsi_lookup_lock
);
7762 spin_lock_init(&ioc
->sas_device_lock
);
7763 spin_lock_init(&ioc
->sas_node_lock
);
7764 spin_lock_init(&ioc
->fw_event_lock
);
7765 spin_lock_init(&ioc
->raid_device_lock
);
7766 spin_lock_init(&ioc
->diag_trigger_lock
);
7768 INIT_LIST_HEAD(&ioc
->sas_device_list
);
7769 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
7770 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
7771 INIT_LIST_HEAD(&ioc
->fw_event_list
);
7772 INIT_LIST_HEAD(&ioc
->raid_device_list
);
7773 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
7774 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
7775 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
7776 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
7778 /* init shost parameters */
7779 shost
->max_cmd_len
= 32;
7780 shost
->max_lun
= max_lun
;
7781 shost
->transportt
= mpt3sas_transport_template
;
7782 shost
->unique_id
= ioc
->id
;
7784 if (max_sectors
!= 0xFFFF) {
7785 if (max_sectors
< 64) {
7786 shost
->max_sectors
= 64;
7787 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
7788 "for max_sectors, range is 64 to 32767. Assigning "
7789 "value of 64.\n", ioc
->name
, max_sectors
);
7790 } else if (max_sectors
> 32767) {
7791 shost
->max_sectors
= 32767;
7792 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
7793 "for max_sectors, range is 64 to 32767. Assigning "
7794 "default value of 32767.\n", ioc
->name
,
7797 shost
->max_sectors
= max_sectors
& 0xFFFE;
7799 "The max_sectors value is set to %d\n",
7800 ioc
->name
, shost
->max_sectors
);
7804 if ((scsi_add_host(shost
, &pdev
->dev
))) {
7805 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7806 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7807 list_del(&ioc
->list
);
7808 goto out_add_shost_fail
;
7811 /* register EEDP capabilities with SCSI layer */
7813 scsi_host_set_prot(shost
, prot_mask
);
7815 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
7816 | SHOST_DIF_TYPE2_PROTECTION
7817 | SHOST_DIF_TYPE3_PROTECTION
);
7819 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
7822 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
7823 "fw_event%d", ioc
->id
);
7824 ioc
->firmware_event_thread
= create_singlethread_workqueue(
7825 ioc
->firmware_event_name
);
7826 if (!ioc
->firmware_event_thread
) {
7827 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7828 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7829 goto out_thread_fail
;
7832 ioc
->is_driver_loading
= 1;
7833 if ((mpt3sas_base_attach(ioc
))) {
7834 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7835 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7836 goto out_attach_fail
;
7838 scsi_scan_host(shost
);
7842 destroy_workqueue(ioc
->firmware_event_thread
);
7844 list_del(&ioc
->list
);
7845 scsi_remove_host(shost
);
7847 scsi_host_put(shost
);
7853 * _scsih_suspend - power management suspend main entry point
7854 * @pdev: PCI device struct
7855 * @state: PM state change to (usually PCI_D3)
7857 * Returns 0 success, anything else error.
7860 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7862 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7863 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7864 pci_power_t device_state
;
7866 mpt3sas_base_stop_watchdog(ioc
);
7867 flush_scheduled_work();
7868 scsi_block_requests(shost
);
7869 device_state
= pci_choose_state(pdev
, state
);
7871 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7872 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
7874 pci_save_state(pdev
);
7875 mpt3sas_base_free_resources(ioc
);
7876 pci_set_power_state(pdev
, device_state
);
7881 * _scsih_resume - power management resume main entry point
7882 * @pdev: PCI device struct
7884 * Returns 0 success, anything else error.
7887 _scsih_resume(struct pci_dev
*pdev
)
7889 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7890 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7891 pci_power_t device_state
= pdev
->current_state
;
7895 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7896 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
7898 pci_set_power_state(pdev
, PCI_D0
);
7899 pci_enable_wake(pdev
, PCI_D0
, 0);
7900 pci_restore_state(pdev
);
7902 r
= mpt3sas_base_map_resources(ioc
);
7906 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
7907 scsi_unblock_requests(shost
);
7908 mpt3sas_base_start_watchdog(ioc
);
7911 #endif /* CONFIG_PM */
7914 * _scsih_pci_error_detected - Called when a PCI error is detected.
7915 * @pdev: PCI device struct
7916 * @state: PCI channel state
7918 * Description: Called when a PCI error is detected.
7921 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7923 static pci_ers_result_t
7924 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
7926 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7927 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7929 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
7933 case pci_channel_io_normal
:
7934 return PCI_ERS_RESULT_CAN_RECOVER
;
7935 case pci_channel_io_frozen
:
7936 /* Fatal error, prepare for slot reset */
7937 ioc
->pci_error_recovery
= 1;
7938 scsi_block_requests(ioc
->shost
);
7939 mpt3sas_base_stop_watchdog(ioc
);
7940 mpt3sas_base_free_resources(ioc
);
7941 return PCI_ERS_RESULT_NEED_RESET
;
7942 case pci_channel_io_perm_failure
:
7943 /* Permanent error, prepare for device removal */
7944 ioc
->pci_error_recovery
= 1;
7945 mpt3sas_base_stop_watchdog(ioc
);
7946 _scsih_flush_running_cmds(ioc
);
7947 return PCI_ERS_RESULT_DISCONNECT
;
7949 return PCI_ERS_RESULT_NEED_RESET
;
7953 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7954 * @pdev: PCI device struct
7956 * Description: This routine is called by the pci error recovery
7957 * code after the PCI slot has been reset, just before we
7958 * should resume normal operations.
7960 static pci_ers_result_t
7961 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
7963 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7964 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7967 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
7970 ioc
->pci_error_recovery
= 0;
7972 pci_restore_state(pdev
);
7973 rc
= mpt3sas_base_map_resources(ioc
);
7975 return PCI_ERS_RESULT_DISCONNECT
;
7977 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
7980 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
7981 (rc
== 0) ? "success" : "failed");
7984 return PCI_ERS_RESULT_RECOVERED
;
7986 return PCI_ERS_RESULT_DISCONNECT
;
7990 * _scsih_pci_resume() - resume normal ops after PCI reset
7991 * @pdev: pointer to PCI device
7993 * Called when the error recovery driver tells us that its
7994 * OK to resume normal operation. Use completion to allow
7995 * halted scsi ops to resume.
7998 _scsih_pci_resume(struct pci_dev
*pdev
)
8000 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8001 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8003 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8005 pci_cleanup_aer_uncorrect_error_status(pdev
);
8006 mpt3sas_base_start_watchdog(ioc
);
8007 scsi_unblock_requests(ioc
->shost
);
8011 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8012 * @pdev: pointer to PCI device
8014 static pci_ers_result_t
8015 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8017 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8018 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8020 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
8023 /* TODO - dump whatever for debugging purposes */
8025 /* Request a slot reset. */
8026 return PCI_ERS_RESULT_NEED_RESET
;
8029 /* raid transport support */
8030 static struct raid_function_template mpt3sas_raid_functions
= {
8031 .cookie
= &scsih_driver_template
,
8032 .is_raid
= _scsih_is_raid
,
8033 .get_resync
= _scsih_get_resync
,
8034 .get_state
= _scsih_get_state
,
8037 static struct pci_error_handlers _scsih_err_handler
= {
8038 .error_detected
= _scsih_pci_error_detected
,
8039 .mmio_enabled
= _scsih_pci_mmio_enabled
,
8040 .slot_reset
= _scsih_pci_slot_reset
,
8041 .resume
= _scsih_pci_resume
,
8044 static struct pci_driver scsih_driver
= {
8045 .name
= MPT3SAS_DRIVER_NAME
,
8046 .id_table
= scsih_pci_table
,
8047 .probe
= _scsih_probe
,
8048 .remove
= _scsih_remove
,
8049 .shutdown
= _scsih_shutdown
,
8050 .err_handler
= &_scsih_err_handler
,
8052 .suspend
= _scsih_suspend
,
8053 .resume
= _scsih_resume
,
8059 * _scsih_init - main entry point for this driver.
8061 * Returns 0 success, anything else error.
8070 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
8071 MPT3SAS_DRIVER_VERSION
);
8073 mpt3sas_transport_template
=
8074 sas_attach_transport(&mpt3sas_transport_functions
);
8075 if (!mpt3sas_transport_template
)
8078 /* raid transport support */
8079 mpt3sas_raid_template
= raid_class_attach(&mpt3sas_raid_functions
);
8080 if (!mpt3sas_raid_template
) {
8081 sas_release_transport(mpt3sas_transport_template
);
8085 mpt3sas_base_initialize_callback_handler();
8087 /* queuecommand callback hander */
8088 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
8090 /* task managment callback handler */
8091 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
8093 /* base internal commands callback handler */
8094 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
8095 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
8096 mpt3sas_port_enable_done
);
8098 /* transport internal commands callback handler */
8099 transport_cb_idx
= mpt3sas_base_register_callback_handler(
8100 mpt3sas_transport_done
);
8102 /* scsih internal commands callback handler */
8103 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
8105 /* configuration page API internal commands callback handler */
8106 config_cb_idx
= mpt3sas_base_register_callback_handler(
8107 mpt3sas_config_done
);
8109 /* ctl module callback handler */
8110 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
8112 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
8113 _scsih_tm_tr_complete
);
8115 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
8116 _scsih_tm_volume_tr_complete
);
8118 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
8119 _scsih_sas_control_complete
);
8123 error
= pci_register_driver(&scsih_driver
);
8125 /* raid transport support */
8126 raid_class_release(mpt3sas_raid_template
);
8127 sas_release_transport(mpt3sas_transport_template
);
8134 * _scsih_exit - exit point for this driver (when it is a module).
8136 * Returns 0 success, anything else error.
8141 pr_info("mpt3sas version %s unloading\n",
8142 MPT3SAS_DRIVER_VERSION
);
8146 pci_unregister_driver(&scsih_driver
);
8149 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
8150 mpt3sas_base_release_callback_handler(tm_cb_idx
);
8151 mpt3sas_base_release_callback_handler(base_cb_idx
);
8152 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
8153 mpt3sas_base_release_callback_handler(transport_cb_idx
);
8154 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
8155 mpt3sas_base_release_callback_handler(config_cb_idx
);
8156 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
8158 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
8159 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8160 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8162 /* raid transport support */
8163 raid_class_release(mpt3sas_raid_template
);
8164 sas_release_transport(mpt3sas_transport_template
);
8167 module_init(_scsih_init
);
8168 module_exit(_scsih_exit
);