2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
58 #include "mpt3sas_base.h"
60 MODULE_AUTHOR(MPT3SAS_AUTHOR
);
61 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION
);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT3SAS_DRIVER_VERSION
);
65 #define RAID_CHANNEL 1
67 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
68 struct _sas_node
*sas_expander
);
69 static void _firmware_event_work(struct work_struct
*work
);
71 static void _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
72 struct _sas_device
*sas_device
);
73 static int _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
74 u8 retry_count
, u8 is_pd
);
76 static u8
_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
);
79 /* global parameters */
80 LIST_HEAD(mpt3sas_ioc_list
);
82 /* local parameters */
83 static u8 scsi_io_cb_idx
= -1;
84 static u8 tm_cb_idx
= -1;
85 static u8 ctl_cb_idx
= -1;
86 static u8 base_cb_idx
= -1;
87 static u8 port_enable_cb_idx
= -1;
88 static u8 transport_cb_idx
= -1;
89 static u8 scsih_cb_idx
= -1;
90 static u8 config_cb_idx
= -1;
93 static u8 tm_tr_cb_idx
= -1 ;
94 static u8 tm_tr_volume_cb_idx
= -1 ;
95 static u8 tm_sas_control_cb_idx
= -1;
97 /* command line options */
98 static u32 logging_level
;
99 MODULE_PARM_DESC(logging_level
,
100 " bits for enabling additional logging info (default=0)");
103 static ushort max_sectors
= 0xFFFF;
104 module_param(max_sectors
, ushort
, 0);
105 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
108 static int missing_delay
[2] = {-1, -1};
109 module_param_array(missing_delay
, int, NULL
, 0);
110 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
112 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
113 #define MPT3SAS_MAX_LUN (16895)
114 static u64 max_lun
= MPT3SAS_MAX_LUN
;
115 module_param(max_lun
, ullong
, 0);
116 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
121 /* diag_buffer_enable is bitwise
123 * bit 1 set = SNAPSHOT
124 * bit 2 set = EXTENDED
126 * Either bit can be set, or both
128 static int diag_buffer_enable
= -1;
129 module_param(diag_buffer_enable
, int, 0);
130 MODULE_PARM_DESC(diag_buffer_enable
,
131 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
132 static int disable_discovery
= -1;
133 module_param(disable_discovery
, int, 0);
134 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
137 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
138 static int prot_mask
= -1;
139 module_param(prot_mask
, int, 0);
140 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
143 /* raid transport support */
145 static struct raid_template
*mpt3sas_raid_template
;
149 * struct sense_info - common structure for obtaining sense keys
151 * @asc: additional sense code
152 * @ascq: additional sense code qualifier
160 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
161 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
162 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
163 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
164 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
166 * struct fw_event_work - firmware event struct
167 * @list: link list framework
168 * @work: work object (ioc->fault_reset_work_q)
169 * @cancel_pending_work: flag set during reset handling
170 * @ioc: per adapter object
171 * @device_handle: device handle
172 * @VF_ID: virtual function id
173 * @VP_ID: virtual port id
174 * @ignore: flag meaning this event has been marked to ignore
175 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
176 * @event_data: reply event data payload follows
178 * This object stored on ioc->fw_event_list.
180 struct fw_event_work
{
181 struct list_head list
;
182 struct work_struct work
;
183 u8 cancel_pending_work
;
184 struct delayed_work delayed_work
;
186 struct MPT3SAS_ADAPTER
*ioc
;
192 char event_data
[0] __aligned(4);
195 /* raid transport support */
196 static struct raid_template
*mpt3sas_raid_template
;
199 * struct _scsi_io_transfer - scsi io transfer
200 * @handle: sas device handle (assigned by firmware)
201 * @is_raid: flag set for hidden raid components
202 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
203 * @data_length: data transfer length
204 * @data_dma: dma pointer to data
207 * @cdb_length: cdb length
209 * @timeout: timeout for this command
210 * @VF_ID: virtual function id
211 * @VP_ID: virtual port id
212 * @valid_reply: flag set for reply message
213 * @sense_length: sense length
214 * @ioc_status: ioc status
215 * @scsi_state: scsi state
216 * @scsi_status: scsi staus
217 * @log_info: log information
218 * @transfer_length: data length transfer when there is a reply message
220 * Used for sending internal scsi commands to devices within this module.
221 * Refer to _scsi_send_scsi_io().
223 struct _scsi_io_transfer
{
226 enum dma_data_direction dir
;
229 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
237 /* the following bits are only valid when 'valid_reply = 1' */
247 * The pci device ids are defined in mpi/mpi2_cnfg.h.
249 static const struct pci_device_id scsih_pci_table
[] = {
250 /* Fury ~ 3004 and 3008 */
251 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
252 PCI_ANY_ID
, PCI_ANY_ID
},
253 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
254 PCI_ANY_ID
, PCI_ANY_ID
},
256 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
257 PCI_ANY_ID
, PCI_ANY_ID
},
258 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
259 PCI_ANY_ID
, PCI_ANY_ID
},
260 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
261 PCI_ANY_ID
, PCI_ANY_ID
},
262 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
263 PCI_ANY_ID
, PCI_ANY_ID
},
264 {0} /* Terminating entry */
266 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
269 * _scsih_set_debug_level - global setting of ioc->logging_level.
271 * Note: The logging levels are defined in mpt3sas_debug.h.
274 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
276 int ret
= param_set_int(val
, kp
);
277 struct MPT3SAS_ADAPTER
*ioc
;
282 pr_info("setting logging_level(0x%08x)\n", logging_level
);
283 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
284 ioc
->logging_level
= logging_level
;
287 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
288 &logging_level
, 0644);
291 * _scsih_srch_boot_sas_address - search based on sas_address
292 * @sas_address: sas address
293 * @boot_device: boot device object from bios page 2
295 * Returns 1 when there's a match, 0 means no match.
298 _scsih_srch_boot_sas_address(u64 sas_address
,
299 Mpi2BootDeviceSasWwid_t
*boot_device
)
301 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
305 * _scsih_srch_boot_device_name - search based on device name
306 * @device_name: device name specified in INDENTIFY fram
307 * @boot_device: boot device object from bios page 2
309 * Returns 1 when there's a match, 0 means no match.
312 _scsih_srch_boot_device_name(u64 device_name
,
313 Mpi2BootDeviceDeviceName_t
*boot_device
)
315 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
319 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
320 * @enclosure_logical_id: enclosure logical id
321 * @slot_number: slot number
322 * @boot_device: boot device object from bios page 2
324 * Returns 1 when there's a match, 0 means no match.
327 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
328 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
330 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
331 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
332 SlotNumber
)) ? 1 : 0;
336 * _scsih_is_boot_device - search for matching boot device.
337 * @sas_address: sas address
338 * @device_name: device name specified in INDENTIFY fram
339 * @enclosure_logical_id: enclosure logical id
340 * @slot_number: slot number
341 * @form: specifies boot device form
342 * @boot_device: boot device object from bios page 2
344 * Returns 1 when there's a match, 0 means no match.
347 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
348 u64 enclosure_logical_id
, u16 slot
, u8 form
,
349 Mpi2BiosPage2BootDevice_t
*boot_device
)
354 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
357 rc
= _scsih_srch_boot_sas_address(
358 sas_address
, &boot_device
->SasWwid
);
360 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
361 if (!enclosure_logical_id
)
363 rc
= _scsih_srch_boot_encl_slot(
364 enclosure_logical_id
,
365 slot
, &boot_device
->EnclosureSlot
);
367 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
370 rc
= _scsih_srch_boot_device_name(
371 device_name
, &boot_device
->DeviceName
);
373 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
381 * _scsih_get_sas_address - set the sas_address for given device handle
382 * @handle: device handle
383 * @sas_address: sas address
385 * Returns 0 success, non-zero when failure
388 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
391 Mpi2SasDevicePage0_t sas_device_pg0
;
392 Mpi2ConfigReply_t mpi_reply
;
397 if (handle
<= ioc
->sas_hba
.num_phys
) {
398 *sas_address
= ioc
->sas_hba
.sas_address
;
402 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
403 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
404 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
405 __FILE__
, __LINE__
, __func__
);
409 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
410 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
411 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
415 /* we hit this becuase the given parent handle doesn't exist */
416 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
419 /* else error case */
421 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
422 ioc
->name
, handle
, ioc_status
,
423 __FILE__
, __LINE__
, __func__
);
428 * _scsih_determine_boot_device - determine boot device.
429 * @ioc: per adapter object
430 * @device: either sas_device or raid_device object
431 * @is_raid: [flag] 1 = raid object, 0 = sas object
433 * Determines whether this device should be first reported device to
434 * to scsi-ml or sas transport, this purpose is for persistent boot device.
435 * There are primary, alternate, and current entries in bios page 2. The order
436 * priority is primary, alternate, then current. This routine saves
437 * the corresponding device object and is_raid flag in the ioc object.
438 * The saved data to be used later in _scsih_probe_boot_devices().
441 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
,
442 void *device
, u8 is_raid
)
444 struct _sas_device
*sas_device
;
445 struct _raid_device
*raid_device
;
448 u64 enclosure_logical_id
;
451 /* only process this function when driver loads */
452 if (!ioc
->is_driver_loading
)
455 /* no Bios, return immediately */
456 if (!ioc
->bios_pg3
.BiosVersion
)
461 sas_address
= sas_device
->sas_address
;
462 device_name
= sas_device
->device_name
;
463 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
464 slot
= sas_device
->slot
;
466 raid_device
= device
;
467 sas_address
= raid_device
->wwid
;
469 enclosure_logical_id
= 0;
473 if (!ioc
->req_boot_device
.device
) {
474 if (_scsih_is_boot_device(sas_address
, device_name
,
475 enclosure_logical_id
, slot
,
476 (ioc
->bios_pg2
.ReqBootDeviceForm
&
477 MPI2_BIOSPAGE2_FORM_MASK
),
478 &ioc
->bios_pg2
.RequestedBootDevice
)) {
479 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
480 "%s: req_boot_device(0x%016llx)\n",
482 (unsigned long long)sas_address
));
483 ioc
->req_boot_device
.device
= device
;
484 ioc
->req_boot_device
.is_raid
= is_raid
;
488 if (!ioc
->req_alt_boot_device
.device
) {
489 if (_scsih_is_boot_device(sas_address
, device_name
,
490 enclosure_logical_id
, slot
,
491 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
492 MPI2_BIOSPAGE2_FORM_MASK
),
493 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
494 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
495 "%s: req_alt_boot_device(0x%016llx)\n",
497 (unsigned long long)sas_address
));
498 ioc
->req_alt_boot_device
.device
= device
;
499 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
503 if (!ioc
->current_boot_device
.device
) {
504 if (_scsih_is_boot_device(sas_address
, device_name
,
505 enclosure_logical_id
, slot
,
506 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
507 MPI2_BIOSPAGE2_FORM_MASK
),
508 &ioc
->bios_pg2
.CurrentBootDevice
)) {
509 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
510 "%s: current_boot_device(0x%016llx)\n",
512 (unsigned long long)sas_address
));
513 ioc
->current_boot_device
.device
= device
;
514 ioc
->current_boot_device
.is_raid
= is_raid
;
520 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
521 * @ioc: per adapter object
522 * @sas_address: sas address
523 * Context: Calling function should acquire ioc->sas_device_lock
525 * This searches for sas_device based on sas_address, then return sas_device
529 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
532 struct _sas_device
*sas_device
;
534 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
535 if (sas_device
->sas_address
== sas_address
)
538 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
539 if (sas_device
->sas_address
== sas_address
)
546 * _scsih_sas_device_find_by_handle - sas device search
547 * @ioc: per adapter object
548 * @handle: sas device handle (assigned by firmware)
549 * Context: Calling function should acquire ioc->sas_device_lock
551 * This searches for sas_device based on sas_address, then return sas_device
554 static struct _sas_device
*
555 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
557 struct _sas_device
*sas_device
;
559 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
560 if (sas_device
->handle
== handle
)
563 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
564 if (sas_device
->handle
== handle
)
571 * _scsih_sas_device_remove - remove sas_device from list.
572 * @ioc: per adapter object
573 * @sas_device: the sas_device object
574 * Context: This function will acquire ioc->sas_device_lock.
576 * Removing object and freeing associated memory from the ioc->sas_device_list.
579 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
580 struct _sas_device
*sas_device
)
587 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
588 ioc
->name
, sas_device
->handle
,
589 (unsigned long long) sas_device
->sas_address
);
591 if (sas_device
->enclosure_handle
!= 0)
593 "removing enclosure logical id(0x%016llx), slot(%d)\n",
594 ioc
->name
, (unsigned long long)
595 sas_device
->enclosure_logical_id
, sas_device
->slot
);
597 if (sas_device
->connector_name
[0] != '\0')
599 "removing enclosure level(0x%04x), connector name( %s)\n",
600 ioc
->name
, sas_device
->enclosure_level
,
601 sas_device
->connector_name
);
603 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
604 list_del(&sas_device
->list
);
606 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
610 * _scsih_device_remove_by_handle - removing device object by handle
611 * @ioc: per adapter object
612 * @handle: device handle
617 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
619 struct _sas_device
*sas_device
;
622 if (ioc
->shost_recovery
)
625 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
626 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
628 list_del(&sas_device
->list
);
629 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
631 _scsih_remove_device(ioc
, sas_device
);
635 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
636 * @ioc: per adapter object
637 * @sas_address: device sas_address
642 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
645 struct _sas_device
*sas_device
;
648 if (ioc
->shost_recovery
)
651 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
652 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
655 list_del(&sas_device
->list
);
656 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
658 _scsih_remove_device(ioc
, sas_device
);
662 * _scsih_sas_device_add - insert sas_device to the list.
663 * @ioc: per adapter object
664 * @sas_device: the sas_device object
665 * Context: This function will acquire ioc->sas_device_lock.
667 * Adding new object to the ioc->sas_device_list.
670 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
671 struct _sas_device
*sas_device
)
675 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
676 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
677 ioc
->name
, __func__
, sas_device
->handle
,
678 (unsigned long long)sas_device
->sas_address
));
680 if (sas_device
->enclosure_handle
!= 0)
681 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
682 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
683 ioc
->name
, __func__
, (unsigned long long)
684 sas_device
->enclosure_logical_id
, sas_device
->slot
));
686 if (sas_device
->connector_name
[0] != '\0')
687 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
688 "%s: enclosure level(0x%04x), connector name( %s)\n",
690 sas_device
->enclosure_level
, sas_device
->connector_name
));
692 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
693 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
694 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
696 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
697 sas_device
->sas_address_parent
)) {
698 _scsih_sas_device_remove(ioc
, sas_device
);
699 } else if (!sas_device
->starget
) {
701 * When asyn scanning is enabled, its not possible to remove
702 * devices while scanning is turned on due to an oops in
703 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
705 if (!ioc
->is_driver_loading
) {
706 mpt3sas_transport_port_remove(ioc
,
707 sas_device
->sas_address
,
708 sas_device
->sas_address_parent
);
709 _scsih_sas_device_remove(ioc
, sas_device
);
715 * _scsih_sas_device_init_add - insert sas_device to the list.
716 * @ioc: per adapter object
717 * @sas_device: the sas_device object
718 * Context: This function will acquire ioc->sas_device_lock.
720 * Adding new object at driver load time to the ioc->sas_device_init_list.
723 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
724 struct _sas_device
*sas_device
)
728 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
729 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
730 __func__
, sas_device
->handle
,
731 (unsigned long long)sas_device
->sas_address
));
733 if (sas_device
->enclosure_handle
!= 0)
734 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
735 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
736 ioc
->name
, __func__
, (unsigned long long)
737 sas_device
->enclosure_logical_id
, sas_device
->slot
));
739 if (sas_device
->connector_name
[0] != '\0')
740 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
741 "%s: enclosure level(0x%04x), connector name( %s)\n",
742 ioc
->name
, __func__
, sas_device
->enclosure_level
,
743 sas_device
->connector_name
));
745 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
746 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
747 _scsih_determine_boot_device(ioc
, sas_device
, 0);
748 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
752 * _scsih_raid_device_find_by_id - raid device search
753 * @ioc: per adapter object
754 * @id: sas device target id
755 * @channel: sas device channel
756 * Context: Calling function should acquire ioc->raid_device_lock
758 * This searches for raid_device based on target id, then return raid_device
761 static struct _raid_device
*
762 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
764 struct _raid_device
*raid_device
, *r
;
767 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
768 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
779 * _scsih_raid_device_find_by_handle - raid device search
780 * @ioc: per adapter object
781 * @handle: sas device handle (assigned by firmware)
782 * Context: Calling function should acquire ioc->raid_device_lock
784 * This searches for raid_device based on handle, then return raid_device
787 static struct _raid_device
*
788 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
790 struct _raid_device
*raid_device
, *r
;
793 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
794 if (raid_device
->handle
!= handle
)
805 * _scsih_raid_device_find_by_wwid - raid device search
806 * @ioc: per adapter object
807 * @handle: sas device handle (assigned by firmware)
808 * Context: Calling function should acquire ioc->raid_device_lock
810 * This searches for raid_device based on wwid, then return raid_device
813 static struct _raid_device
*
814 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
816 struct _raid_device
*raid_device
, *r
;
819 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
820 if (raid_device
->wwid
!= wwid
)
831 * _scsih_raid_device_add - add raid_device object
832 * @ioc: per adapter object
833 * @raid_device: raid_device object
835 * This is added to the raid_device_list link list.
838 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
839 struct _raid_device
*raid_device
)
843 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
844 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
845 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
847 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
848 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
849 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
853 * _scsih_raid_device_remove - delete raid_device object
854 * @ioc: per adapter object
855 * @raid_device: raid_device object
859 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
860 struct _raid_device
*raid_device
)
864 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
865 list_del(&raid_device
->list
);
867 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
871 * mpt3sas_scsih_expander_find_by_handle - expander device search
872 * @ioc: per adapter object
873 * @handle: expander handle (assigned by firmware)
874 * Context: Calling function should acquire ioc->sas_device_lock
876 * This searches for expander device based on handle, then returns the
880 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
882 struct _sas_node
*sas_expander
, *r
;
885 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
886 if (sas_expander
->handle
!= handle
)
896 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
897 * @ioc: per adapter object
898 * @sas_address: sas address
899 * Context: Calling function should acquire ioc->sas_node_lock.
901 * This searches for expander device based on sas_address, then returns the
905 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
908 struct _sas_node
*sas_expander
, *r
;
911 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
912 if (sas_expander
->sas_address
!= sas_address
)
922 * _scsih_expander_node_add - insert expander device to the list.
923 * @ioc: per adapter object
924 * @sas_expander: the sas_device object
925 * Context: This function will acquire ioc->sas_node_lock.
927 * Adding new object to the ioc->sas_expander_list.
932 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
933 struct _sas_node
*sas_expander
)
937 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
938 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
939 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
943 * _scsih_is_end_device - determines if device is an end device
944 * @device_info: bitfield providing information about the device.
947 * Returns 1 if end device.
950 _scsih_is_end_device(u32 device_info
)
952 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
953 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
954 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
955 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
962 * _scsih_scsi_lookup_get - returns scmd entry
963 * @ioc: per adapter object
964 * @smid: system request message index
966 * Returns the smid stored scmd pointer.
968 static struct scsi_cmnd
*
969 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
971 return ioc
->scsi_lookup
[smid
- 1].scmd
;
975 * _scsih_scsi_lookup_get_clear - returns scmd entry
976 * @ioc: per adapter object
977 * @smid: system request message index
979 * Returns the smid stored scmd pointer.
980 * Then will derefrence the stored scmd pointer.
982 static inline struct scsi_cmnd
*
983 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
986 struct scsi_cmnd
*scmd
;
988 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
989 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
990 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
991 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
997 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
998 * @ioc: per adapter object
999 * @smid: system request message index
1000 * @scmd: pointer to scsi command object
1001 * Context: This function will acquire ioc->scsi_lookup_lock.
1003 * This will search for a scmd pointer in the scsi_lookup array,
1004 * returning the revelent smid. A returned value of zero means invalid.
1007 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
1011 unsigned long flags
;
1014 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1016 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
1017 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
1018 smid
= ioc
->scsi_lookup
[i
].smid
;
1023 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1028 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1029 * @ioc: per adapter object
1032 * Context: This function will acquire ioc->scsi_lookup_lock.
1034 * This will search for a matching channel:id in the scsi_lookup array,
1035 * returning 1 if found.
1038 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1042 unsigned long flags
;
1045 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1047 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1048 if (ioc
->scsi_lookup
[i
].scmd
&&
1049 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1050 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
1056 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1061 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1062 * @ioc: per adapter object
1066 * Context: This function will acquire ioc->scsi_lookup_lock.
1068 * This will search for a matching channel:id:lun in the scsi_lookup array,
1069 * returning 1 if found.
1072 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER
*ioc
, int id
,
1073 unsigned int lun
, int channel
)
1076 unsigned long flags
;
1079 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1081 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
1082 if (ioc
->scsi_lookup
[i
].scmd
&&
1083 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1084 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1085 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1091 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1096 * scsih_change_queue_depth - setting device queue depth
1097 * @sdev: scsi device struct
1098 * @qdepth: requested queue depth
1100 * Returns queue depth.
1103 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1105 struct Scsi_Host
*shost
= sdev
->host
;
1107 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1108 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1109 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1110 struct _sas_device
*sas_device
;
1111 unsigned long flags
;
1113 max_depth
= shost
->can_queue
;
1115 /* limit max device queue for SATA to 32 */
1116 sas_device_priv_data
= sdev
->hostdata
;
1117 if (!sas_device_priv_data
)
1119 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1120 if (!sas_target_priv_data
)
1122 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1124 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1125 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1126 sas_device_priv_data
->sas_target
->sas_address
);
1127 if (sas_device
&& sas_device
->device_info
&
1128 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1129 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1130 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1134 if (!sdev
->tagged_supported
)
1136 if (qdepth
> max_depth
)
1138 return scsi_change_queue_depth(sdev
, qdepth
);
1142 * scsih_target_alloc - target add routine
1143 * @starget: scsi target struct
1145 * Returns 0 if ok. Any other return is assumed to be an error and
1146 * the device is ignored.
1149 scsih_target_alloc(struct scsi_target
*starget
)
1151 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1152 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1153 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1154 struct _sas_device
*sas_device
;
1155 struct _raid_device
*raid_device
;
1156 unsigned long flags
;
1157 struct sas_rphy
*rphy
;
1159 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1161 if (!sas_target_priv_data
)
1164 starget
->hostdata
= sas_target_priv_data
;
1165 sas_target_priv_data
->starget
= starget
;
1166 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1169 if (starget
->channel
== RAID_CHANNEL
) {
1170 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1171 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1174 sas_target_priv_data
->handle
= raid_device
->handle
;
1175 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1176 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1177 raid_device
->starget
= starget
;
1179 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1183 /* sas/sata devices */
1184 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1185 rphy
= dev_to_rphy(starget
->dev
.parent
);
1186 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1187 rphy
->identify
.sas_address
);
1190 sas_target_priv_data
->handle
= sas_device
->handle
;
1191 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1192 sas_device
->starget
= starget
;
1193 sas_device
->id
= starget
->id
;
1194 sas_device
->channel
= starget
->channel
;
1195 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1196 sas_target_priv_data
->flags
|=
1197 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1198 if (sas_device
->fast_path
)
1199 sas_target_priv_data
->flags
|= MPT_TARGET_FASTPATH_IO
;
1201 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1207 * scsih_target_destroy - target destroy routine
1208 * @starget: scsi target struct
1213 scsih_target_destroy(struct scsi_target
*starget
)
1215 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1216 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1217 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1218 struct _sas_device
*sas_device
;
1219 struct _raid_device
*raid_device
;
1220 unsigned long flags
;
1221 struct sas_rphy
*rphy
;
1223 sas_target_priv_data
= starget
->hostdata
;
1224 if (!sas_target_priv_data
)
1227 if (starget
->channel
== RAID_CHANNEL
) {
1228 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1229 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1232 raid_device
->starget
= NULL
;
1233 raid_device
->sdev
= NULL
;
1235 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1239 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1240 rphy
= dev_to_rphy(starget
->dev
.parent
);
1241 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1242 rphy
->identify
.sas_address
);
1243 if (sas_device
&& (sas_device
->starget
== starget
) &&
1244 (sas_device
->id
== starget
->id
) &&
1245 (sas_device
->channel
== starget
->channel
))
1246 sas_device
->starget
= NULL
;
1248 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1251 kfree(sas_target_priv_data
);
1252 starget
->hostdata
= NULL
;
1256 * scsih_slave_alloc - device add routine
1257 * @sdev: scsi device struct
1259 * Returns 0 if ok. Any other return is assumed to be an error and
1260 * the device is ignored.
1263 scsih_slave_alloc(struct scsi_device
*sdev
)
1265 struct Scsi_Host
*shost
;
1266 struct MPT3SAS_ADAPTER
*ioc
;
1267 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1268 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1269 struct scsi_target
*starget
;
1270 struct _raid_device
*raid_device
;
1271 struct _sas_device
*sas_device
;
1272 unsigned long flags
;
1274 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1276 if (!sas_device_priv_data
)
1279 sas_device_priv_data
->lun
= sdev
->lun
;
1280 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1282 starget
= scsi_target(sdev
);
1283 sas_target_priv_data
= starget
->hostdata
;
1284 sas_target_priv_data
->num_luns
++;
1285 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1286 sdev
->hostdata
= sas_device_priv_data
;
1287 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1288 sdev
->no_uld_attach
= 1;
1290 shost
= dev_to_shost(&starget
->dev
);
1291 ioc
= shost_priv(shost
);
1292 if (starget
->channel
== RAID_CHANNEL
) {
1293 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1294 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1295 starget
->id
, starget
->channel
);
1297 raid_device
->sdev
= sdev
; /* raid is single lun */
1298 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1301 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1302 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1303 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1304 sas_target_priv_data
->sas_address
);
1305 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1306 sdev_printk(KERN_INFO
, sdev
,
1307 "%s : sas_device->starget set to starget @ %d\n",
1308 __func__
, __LINE__
);
1309 sas_device
->starget
= starget
;
1311 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1318 * scsih_slave_destroy - device destroy routine
1319 * @sdev: scsi device struct
1324 scsih_slave_destroy(struct scsi_device
*sdev
)
1326 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1327 struct scsi_target
*starget
;
1328 struct Scsi_Host
*shost
;
1329 struct MPT3SAS_ADAPTER
*ioc
;
1330 struct _sas_device
*sas_device
;
1331 unsigned long flags
;
1333 if (!sdev
->hostdata
)
1336 starget
= scsi_target(sdev
);
1337 sas_target_priv_data
= starget
->hostdata
;
1338 sas_target_priv_data
->num_luns
--;
1340 shost
= dev_to_shost(&starget
->dev
);
1341 ioc
= shost_priv(shost
);
1343 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1344 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1345 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1346 sas_target_priv_data
->sas_address
);
1347 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1348 sas_device
->starget
= NULL
;
1349 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1352 kfree(sdev
->hostdata
);
1353 sdev
->hostdata
= NULL
;
1357 * _scsih_display_sata_capabilities - sata capabilities
1358 * @ioc: per adapter object
1359 * @handle: device handle
1360 * @sdev: scsi device struct
1363 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1364 u16 handle
, struct scsi_device
*sdev
)
1366 Mpi2ConfigReply_t mpi_reply
;
1367 Mpi2SasDevicePage0_t sas_device_pg0
;
1372 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1373 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1374 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1375 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1379 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1380 MPI2_IOCSTATUS_MASK
;
1381 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1382 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1383 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1387 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1388 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1390 sdev_printk(KERN_INFO
, sdev
,
1391 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1392 "sw_preserve(%s)\n",
1393 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1394 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1395 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1397 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1398 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1399 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1403 * raid transport support -
1404 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1405 * unloading the driver followed by a load - I beleive that the subroutine
1406 * raid_class_release() is not cleaning up properly.
1410 * scsih_is_raid - return boolean indicating device is raid volume
1411 * @dev the device struct object
1414 scsih_is_raid(struct device
*dev
)
1416 struct scsi_device
*sdev
= to_scsi_device(dev
);
1418 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1422 * scsih_get_resync - get raid volume resync percent complete
1423 * @dev the device struct object
1426 scsih_get_resync(struct device
*dev
)
1428 struct scsi_device
*sdev
= to_scsi_device(dev
);
1429 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1430 static struct _raid_device
*raid_device
;
1431 unsigned long flags
;
1432 Mpi2RaidVolPage0_t vol_pg0
;
1433 Mpi2ConfigReply_t mpi_reply
;
1434 u32 volume_status_flags
;
1435 u8 percent_complete
;
1438 percent_complete
= 0;
1440 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1441 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1444 handle
= raid_device
->handle
;
1445 percent_complete
= raid_device
->percent_complete
;
1447 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1452 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1453 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1454 sizeof(Mpi2RaidVolPage0_t
))) {
1455 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1456 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1457 percent_complete
= 0;
1461 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1462 if (!(volume_status_flags
&
1463 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1464 percent_complete
= 0;
1467 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
1471 * scsih_get_state - get raid volume level
1472 * @dev the device struct object
1475 scsih_get_state(struct device
*dev
)
1477 struct scsi_device
*sdev
= to_scsi_device(dev
);
1478 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1479 static struct _raid_device
*raid_device
;
1480 unsigned long flags
;
1481 Mpi2RaidVolPage0_t vol_pg0
;
1482 Mpi2ConfigReply_t mpi_reply
;
1484 enum raid_state state
= RAID_STATE_UNKNOWN
;
1487 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1488 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1491 handle
= raid_device
->handle
;
1492 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1497 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1498 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1499 sizeof(Mpi2RaidVolPage0_t
))) {
1500 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
1501 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1505 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1506 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1507 state
= RAID_STATE_RESYNCING
;
1511 switch (vol_pg0
.VolumeState
) {
1512 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1513 case MPI2_RAID_VOL_STATE_ONLINE
:
1514 state
= RAID_STATE_ACTIVE
;
1516 case MPI2_RAID_VOL_STATE_DEGRADED
:
1517 state
= RAID_STATE_DEGRADED
;
1519 case MPI2_RAID_VOL_STATE_FAILED
:
1520 case MPI2_RAID_VOL_STATE_MISSING
:
1521 state
= RAID_STATE_OFFLINE
;
1525 raid_set_state(mpt3sas_raid_template
, dev
, state
);
1529 * _scsih_set_level - set raid level
1530 * @sdev: scsi device struct
1531 * @volume_type: volume type
1534 _scsih_set_level(struct scsi_device
*sdev
, u8 volume_type
)
1536 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1538 switch (volume_type
) {
1539 case MPI2_RAID_VOL_TYPE_RAID0
:
1540 level
= RAID_LEVEL_0
;
1542 case MPI2_RAID_VOL_TYPE_RAID10
:
1543 level
= RAID_LEVEL_10
;
1545 case MPI2_RAID_VOL_TYPE_RAID1E
:
1546 level
= RAID_LEVEL_1E
;
1548 case MPI2_RAID_VOL_TYPE_RAID1
:
1549 level
= RAID_LEVEL_1
;
1553 raid_set_level(mpt3sas_raid_template
, &sdev
->sdev_gendev
, level
);
1558 * _scsih_get_volume_capabilities - volume capabilities
1559 * @ioc: per adapter object
1560 * @sas_device: the raid_device object
1562 * Returns 0 for success, else 1
1565 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1566 struct _raid_device
*raid_device
)
1568 Mpi2RaidVolPage0_t
*vol_pg0
;
1569 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1570 Mpi2SasDevicePage0_t sas_device_pg0
;
1571 Mpi2ConfigReply_t mpi_reply
;
1575 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
1576 &num_pds
)) || !num_pds
) {
1577 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1578 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1583 raid_device
->num_pds
= num_pds
;
1584 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1585 sizeof(Mpi2RaidVol0PhysDisk_t
));
1586 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1588 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1589 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1594 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1595 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1596 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1597 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1603 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1605 /* figure out what the underlying devices are by
1606 * obtaining the device_info bits for the 1st device
1608 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1609 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1610 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1611 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1612 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1613 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1614 raid_device
->device_info
=
1615 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1626 * _scsih_enable_tlr - setting TLR flags
1627 * @ioc: per adapter object
1628 * @sdev: scsi device struct
1630 * Enabling Transaction Layer Retries for tape devices when
1631 * vpd page 0x90 is present
1635 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1639 if (sdev
->type
!= TYPE_TAPE
)
1642 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1645 sas_enable_tlr(sdev
);
1646 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1647 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1653 * scsih_slave_configure - device configure routine.
1654 * @sdev: scsi device struct
1656 * Returns 0 if ok. Any other return is assumed to be an error and
1657 * the device is ignored.
1660 scsih_slave_configure(struct scsi_device
*sdev
)
1662 struct Scsi_Host
*shost
= sdev
->host
;
1663 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1664 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1665 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1666 struct _sas_device
*sas_device
;
1667 struct _raid_device
*raid_device
;
1668 unsigned long flags
;
1673 u16 handle
, volume_handle
= 0;
1674 u64 volume_wwid
= 0;
1677 sas_device_priv_data
= sdev
->hostdata
;
1678 sas_device_priv_data
->configured_lun
= 1;
1679 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1680 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1681 handle
= sas_target_priv_data
->handle
;
1683 /* raid volume handling */
1684 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1686 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1687 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1688 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1690 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1691 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1692 __LINE__
, __func__
));
1696 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1697 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1698 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1699 __LINE__
, __func__
));
1704 /* RAID Queue Depth Support
1705 * IS volume = underlying qdepth of drive type, either
1706 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1707 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1709 if (raid_device
->device_info
&
1710 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1711 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1714 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1715 if (raid_device
->device_info
&
1716 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1722 switch (raid_device
->volume_type
) {
1723 case MPI2_RAID_VOL_TYPE_RAID0
:
1726 case MPI2_RAID_VOL_TYPE_RAID1E
:
1727 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1728 if (ioc
->manu_pg10
.OEMIdentifier
&&
1729 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1730 MFG10_GF0_R10_DISPLAY
) &&
1731 !(raid_device
->num_pds
% 2))
1736 case MPI2_RAID_VOL_TYPE_RAID1
:
1737 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1740 case MPI2_RAID_VOL_TYPE_RAID10
:
1741 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1744 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
1746 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
1751 sdev_printk(KERN_INFO
, sdev
,
1752 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1753 r_level
, raid_device
->handle
,
1754 (unsigned long long)raid_device
->wwid
,
1755 raid_device
->num_pds
, ds
);
1758 scsih_change_queue_depth(sdev
, qdepth
);
1760 /* raid transport support */
1761 _scsih_set_level(sdev
, raid_device
->volume_type
);
1765 /* non-raid handling */
1766 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
1767 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
1769 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1770 "failure at %s:%d/%s()!\n", ioc
->name
,
1771 __FILE__
, __LINE__
, __func__
));
1774 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
1775 volume_handle
, &volume_wwid
)) {
1776 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1777 "failure at %s:%d/%s()!\n", ioc
->name
,
1778 __FILE__
, __LINE__
, __func__
));
1783 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1784 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
1785 sas_device_priv_data
->sas_target
->sas_address
);
1787 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1788 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1789 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1794 sas_device
->volume_handle
= volume_handle
;
1795 sas_device
->volume_wwid
= volume_wwid
;
1796 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1797 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
1801 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1802 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
1804 else if (sas_device
->device_info
&
1805 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1809 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
1810 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1811 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
1812 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
1813 if (sas_device
->enclosure_handle
!= 0)
1814 sdev_printk(KERN_INFO
, sdev
,
1815 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1816 ds
, (unsigned long long)
1817 sas_device
->enclosure_logical_id
, sas_device
->slot
);
1818 if (sas_device
->connector_name
[0] != '\0')
1819 sdev_printk(KERN_INFO
, sdev
,
1820 "%s: enclosure level(0x%04x), connector name( %s)\n",
1821 ds
, sas_device
->enclosure_level
,
1822 sas_device
->connector_name
);
1824 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1827 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
1830 scsih_change_queue_depth(sdev
, qdepth
);
1833 sas_read_port_mode_page(sdev
);
1834 _scsih_enable_tlr(ioc
, sdev
);
1841 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1842 * @sdev: scsi device struct
1843 * @bdev: pointer to block device context
1844 * @capacity: device size (in 512 byte sectors)
1845 * @params: three element array to place output:
1846 * params[0] number of heads (max 255)
1847 * params[1] number of sectors (max 63)
1848 * params[2] number of cylinders
1853 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
1854 sector_t capacity
, int params
[])
1864 dummy
= heads
* sectors
;
1865 cylinders
= capacity
;
1866 sector_div(cylinders
, dummy
);
1869 * Handle extended translation size for logical drives
1872 if ((ulong
)capacity
>= 0x200000) {
1875 dummy
= heads
* sectors
;
1876 cylinders
= capacity
;
1877 sector_div(cylinders
, dummy
);
1882 params
[1] = sectors
;
1883 params
[2] = cylinders
;
1889 * _scsih_response_code - translation of device response code
1890 * @ioc: per adapter object
1891 * @response_code: response code returned by the device
1896 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
1900 switch (response_code
) {
1901 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
1902 desc
= "task management request completed";
1904 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
1905 desc
= "invalid frame";
1907 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
1908 desc
= "task management request not supported";
1910 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
1911 desc
= "task management request failed";
1913 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
1914 desc
= "task management request succeeded";
1916 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
1917 desc
= "invalid lun";
1920 desc
= "overlapped tag attempted";
1922 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
1923 desc
= "task queued, however not sent to target";
1929 pr_warn(MPT3SAS_FMT
"response_code(0x%01x): %s\n",
1930 ioc
->name
, response_code
, desc
);
1934 * _scsih_tm_done - tm completion routine
1935 * @ioc: per adapter object
1936 * @smid: system request message index
1937 * @msix_index: MSIX table index supplied by the OS
1938 * @reply: reply message frame(lower 32bit addr)
1941 * The callback handler when using scsih_issue_tm.
1943 * Return 1 meaning mf should be freed from _base_interrupt
1944 * 0 means the mf is freed from this function.
1947 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
1949 MPI2DefaultReply_t
*mpi_reply
;
1951 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
1953 if (ioc
->tm_cmds
.smid
!= smid
)
1955 mpt3sas_base_flush_reply_queues(ioc
);
1956 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
1957 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
1959 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
1960 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
1962 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
1963 complete(&ioc
->tm_cmds
.done
);
1968 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1969 * @ioc: per adapter object
1970 * @handle: device handle
1972 * During taskmangement request, we need to freeze the device queue.
1975 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1977 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1978 struct scsi_device
*sdev
;
1981 shost_for_each_device(sdev
, ioc
->shost
) {
1984 sas_device_priv_data
= sdev
->hostdata
;
1985 if (!sas_device_priv_data
)
1987 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
1988 sas_device_priv_data
->sas_target
->tm_busy
= 1;
1990 ioc
->ignore_loginfos
= 1;
1996 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1997 * @ioc: per adapter object
1998 * @handle: device handle
2000 * During taskmangement request, we need to freeze the device queue.
2003 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2005 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2006 struct scsi_device
*sdev
;
2009 shost_for_each_device(sdev
, ioc
->shost
) {
2012 sas_device_priv_data
= sdev
->hostdata
;
2013 if (!sas_device_priv_data
)
2015 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2016 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2018 ioc
->ignore_loginfos
= 0;
2024 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2025 * @ioc: per adapter struct
2026 * @device_handle: device handle
2027 * @channel: the channel assigned by the OS
2028 * @id: the id assigned by the OS
2030 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2031 * @smid_task: smid assigned to the task
2032 * @timeout: timeout in seconds
2033 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2036 * A generic API for sending task management requests to firmware.
2038 * The callback index is set inside `ioc->tm_cb_idx`.
2040 * Return SUCCESS or FAILED.
2043 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2044 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2045 enum mutex_type m_type
)
2047 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2048 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2051 unsigned long timeleft
;
2052 struct scsiio_tracker
*scsi_lookup
= NULL
;
2055 if (m_type
== TM_MUTEX_ON
)
2056 mutex_lock(&ioc
->tm_cmds
.mutex
);
2057 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2058 pr_info(MPT3SAS_FMT
"%s: tm_cmd busy!!!\n",
2059 __func__
, ioc
->name
);
2064 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2065 ioc
->pci_error_recovery
) {
2066 pr_info(MPT3SAS_FMT
"%s: host reset in progress!\n",
2067 __func__
, ioc
->name
);
2072 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2073 if (ioc_state
& MPI2_DOORBELL_USED
) {
2074 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
2075 "unexpected doorbell active!\n", ioc
->name
));
2076 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2078 rc
= (!rc
) ? SUCCESS
: FAILED
;
2082 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2083 mpt3sas_base_fault_info(ioc
, ioc_state
&
2084 MPI2_DOORBELL_DATA_MASK
);
2085 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2087 rc
= (!rc
) ? SUCCESS
: FAILED
;
2091 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2093 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2094 ioc
->name
, __func__
);
2099 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2100 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2102 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
2103 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2104 ioc
->name
, handle
, type
, smid_task
));
2105 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2106 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2107 ioc
->tm_cmds
.smid
= smid
;
2108 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2109 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2110 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2111 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2112 mpi_request
->TaskType
= type
;
2113 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2114 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2115 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2116 init_completion(&ioc
->tm_cmds
.done
);
2117 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
2118 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2119 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2120 pr_err(MPT3SAS_FMT
"%s: timeout\n",
2121 ioc
->name
, __func__
);
2122 _debug_dump_mf(mpi_request
,
2123 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2124 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_RESET
)) {
2125 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2127 rc
= (!rc
) ? SUCCESS
: FAILED
;
2128 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2129 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2134 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2135 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2136 mpi_reply
= ioc
->tm_cmds
.reply
;
2137 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"complete tm: " \
2138 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2139 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2140 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2141 le32_to_cpu(mpi_reply
->TerminationCount
)));
2142 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2143 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2144 if (mpi_reply
->IOCStatus
)
2145 _debug_dump_mf(mpi_request
,
2146 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2151 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2153 if (scsi_lookup
->scmd
== NULL
)
2158 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2159 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2164 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2165 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2166 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2171 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2179 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2180 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2181 if (m_type
== TM_MUTEX_ON
)
2182 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2187 if (m_type
== TM_MUTEX_ON
)
2188 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2193 * _scsih_tm_display_info - displays info about the device
2194 * @ioc: per adapter struct
2195 * @scmd: pointer to scsi command object
2197 * Called by task management callback handlers.
2200 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2202 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2203 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2204 struct _sas_device
*sas_device
= NULL
;
2205 unsigned long flags
;
2206 char *device_str
= NULL
;
2210 device_str
= "volume";
2212 scsi_print_command(scmd
);
2213 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2214 starget_printk(KERN_INFO
, starget
,
2215 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2216 device_str
, priv_target
->handle
,
2217 device_str
, (unsigned long long)priv_target
->sas_address
);
2219 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2220 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
2221 priv_target
->sas_address
);
2223 if (priv_target
->flags
&
2224 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2225 starget_printk(KERN_INFO
, starget
,
2226 "volume handle(0x%04x), "
2227 "volume wwid(0x%016llx)\n",
2228 sas_device
->volume_handle
,
2229 (unsigned long long)sas_device
->volume_wwid
);
2231 starget_printk(KERN_INFO
, starget
,
2232 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2234 (unsigned long long)sas_device
->sas_address
,
2236 if (sas_device
->enclosure_handle
!= 0)
2237 starget_printk(KERN_INFO
, starget
,
2238 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2239 (unsigned long long)
2240 sas_device
->enclosure_logical_id
,
2242 if (sas_device
->connector_name
)
2243 starget_printk(KERN_INFO
, starget
,
2244 "enclosure level(0x%04x),connector name(%s)\n",
2245 sas_device
->enclosure_level
,
2246 sas_device
->connector_name
);
2248 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2253 * scsih_abort - eh threads main abort routine
2254 * @scmd: pointer to scsi command object
2256 * Returns SUCCESS if command aborted else FAILED
2259 scsih_abort(struct scsi_cmnd
*scmd
)
2261 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2262 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2267 sdev_printk(KERN_INFO
, scmd
->device
,
2268 "attempting task abort! scmd(%p)\n", scmd
);
2269 _scsih_tm_display_info(ioc
, scmd
);
2271 sas_device_priv_data
= scmd
->device
->hostdata
;
2272 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2273 sdev_printk(KERN_INFO
, scmd
->device
,
2274 "device been deleted! scmd(%p)\n", scmd
);
2275 scmd
->result
= DID_NO_CONNECT
<< 16;
2276 scmd
->scsi_done(scmd
);
2281 /* search for the command */
2282 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2284 scmd
->result
= DID_RESET
<< 16;
2289 /* for hidden raid components and volumes this is not supported */
2290 if (sas_device_priv_data
->sas_target
->flags
&
2291 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2292 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2293 scmd
->result
= DID_RESET
<< 16;
2298 mpt3sas_halt_firmware(ioc
);
2300 handle
= sas_device_priv_data
->sas_target
->handle
;
2301 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2302 scmd
->device
->id
, scmd
->device
->lun
,
2303 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, TM_MUTEX_ON
);
2306 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2307 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2312 * scsih_dev_reset - eh threads main device reset routine
2313 * @scmd: pointer to scsi command object
2315 * Returns SUCCESS if command aborted else FAILED
2318 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2320 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2321 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2322 struct _sas_device
*sas_device
;
2323 unsigned long flags
;
2327 sdev_printk(KERN_INFO
, scmd
->device
,
2328 "attempting device reset! scmd(%p)\n", scmd
);
2329 _scsih_tm_display_info(ioc
, scmd
);
2331 sas_device_priv_data
= scmd
->device
->hostdata
;
2332 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2333 sdev_printk(KERN_INFO
, scmd
->device
,
2334 "device been deleted! scmd(%p)\n", scmd
);
2335 scmd
->result
= DID_NO_CONNECT
<< 16;
2336 scmd
->scsi_done(scmd
);
2341 /* for hidden raid components obtain the volume_handle */
2343 if (sas_device_priv_data
->sas_target
->flags
&
2344 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2345 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2346 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2347 sas_device_priv_data
->sas_target
->handle
);
2349 handle
= sas_device
->volume_handle
;
2350 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2352 handle
= sas_device_priv_data
->sas_target
->handle
;
2355 scmd
->result
= DID_RESET
<< 16;
2360 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2361 scmd
->device
->id
, scmd
->device
->lun
,
2362 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, TM_MUTEX_ON
);
2365 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2366 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2371 * scsih_target_reset - eh threads main target reset routine
2372 * @scmd: pointer to scsi command object
2374 * Returns SUCCESS if command aborted else FAILED
2377 scsih_target_reset(struct scsi_cmnd
*scmd
)
2379 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2380 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2381 struct _sas_device
*sas_device
;
2382 unsigned long flags
;
2385 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2387 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
2389 _scsih_tm_display_info(ioc
, scmd
);
2391 sas_device_priv_data
= scmd
->device
->hostdata
;
2392 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2393 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
2395 scmd
->result
= DID_NO_CONNECT
<< 16;
2396 scmd
->scsi_done(scmd
);
2401 /* for hidden raid components obtain the volume_handle */
2403 if (sas_device_priv_data
->sas_target
->flags
&
2404 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2405 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2406 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2407 sas_device_priv_data
->sas_target
->handle
);
2409 handle
= sas_device
->volume_handle
;
2410 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2412 handle
= sas_device_priv_data
->sas_target
->handle
;
2415 scmd
->result
= DID_RESET
<< 16;
2420 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2421 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2425 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2426 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2432 * scsih_host_reset - eh threads main host reset routine
2433 * @scmd: pointer to scsi command object
2435 * Returns SUCCESS if command aborted else FAILED
2438 scsih_host_reset(struct scsi_cmnd
*scmd
)
2440 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2443 pr_info(MPT3SAS_FMT
"attempting host reset! scmd(%p)\n",
2445 scsi_print_command(scmd
);
2447 if (ioc
->is_driver_loading
) {
2448 pr_info(MPT3SAS_FMT
"Blocking the host reset\n",
2454 retval
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2456 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2458 pr_info(MPT3SAS_FMT
"host reset: %s scmd(%p)\n",
2459 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2465 * _scsih_fw_event_add - insert and queue up fw_event
2466 * @ioc: per adapter object
2467 * @fw_event: object describing the event
2468 * Context: This function will acquire ioc->fw_event_lock.
2470 * This adds the firmware event object into link list, then queues it up to
2471 * be processed from user context.
2476 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2478 unsigned long flags
;
2480 if (ioc
->firmware_event_thread
== NULL
)
2483 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2484 INIT_LIST_HEAD(&fw_event
->list
);
2485 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2486 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
2487 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
2488 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2492 * _scsih_fw_event_free - delete fw_event
2493 * @ioc: per adapter object
2494 * @fw_event: object describing the event
2495 * Context: This function will acquire ioc->fw_event_lock.
2497 * This removes firmware event object from link list, frees associated memory.
2502 _scsih_fw_event_free(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
2505 unsigned long flags
;
2507 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2508 list_del(&fw_event
->list
);
2510 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2515 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2516 * @ioc: per adapter object
2517 * @event_data: trigger event data
2522 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
2523 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
2525 struct fw_event_work
*fw_event
;
2527 if (ioc
->is_driver_loading
)
2529 fw_event
= kzalloc(sizeof(*fw_event
) + sizeof(*event_data
),
2533 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
2534 fw_event
->ioc
= ioc
;
2535 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
2536 _scsih_fw_event_add(ioc
, fw_event
);
2540 * _scsih_error_recovery_delete_devices - remove devices not responding
2541 * @ioc: per adapter object
2546 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
2548 struct fw_event_work
*fw_event
;
2550 if (ioc
->is_driver_loading
)
2552 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2555 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
2556 fw_event
->ioc
= ioc
;
2557 _scsih_fw_event_add(ioc
, fw_event
);
2561 * mpt3sas_port_enable_complete - port enable completed (fake event)
2562 * @ioc: per adapter object
2567 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
2569 struct fw_event_work
*fw_event
;
2571 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2574 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
2575 fw_event
->ioc
= ioc
;
2576 _scsih_fw_event_add(ioc
, fw_event
);
2580 * _scsih_fw_event_cleanup_queue - cleanup event queue
2581 * @ioc: per adapter object
2583 * Walk the firmware event queue, either killing timers, or waiting
2584 * for outstanding events to complete
2589 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
2591 struct fw_event_work
*fw_event
, *next
;
2593 if (list_empty(&ioc
->fw_event_list
) ||
2594 !ioc
->firmware_event_thread
|| in_interrupt())
2597 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2598 if (cancel_delayed_work_sync(&fw_event
->delayed_work
)) {
2599 _scsih_fw_event_free(ioc
, fw_event
);
2606 * _scsih_internal_device_block - block the sdev device
2607 * @sdev: per device object
2608 * @sas_device_priv_data : per device driver private data
2610 * make sure device is blocked without error, if not
2614 _scsih_internal_device_block(struct scsi_device
*sdev
,
2615 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2619 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
2620 sas_device_priv_data
->sas_target
->handle
);
2621 sas_device_priv_data
->block
= 1;
2623 r
= scsi_internal_device_block(sdev
);
2625 sdev_printk(KERN_WARNING
, sdev
,
2626 "device_block failed with return(%d) for handle(0x%04x)\n",
2627 sas_device_priv_data
->sas_target
->handle
, r
);
2631 * _scsih_internal_device_unblock - unblock the sdev device
2632 * @sdev: per device object
2633 * @sas_device_priv_data : per device driver private data
2634 * make sure device is unblocked without error, if not retry
2635 * by blocking and then unblocking
2639 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
2640 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
2644 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
2645 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
2646 sas_device_priv_data
->block
= 0;
2647 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2649 /* The device has been set to SDEV_RUNNING by SD layer during
2650 * device addition but the request queue is still stopped by
2651 * our earlier block call. We need to perform a block again
2652 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2654 sdev_printk(KERN_WARNING
, sdev
,
2655 "device_unblock failed with return(%d) for handle(0x%04x) "
2656 "performing a block followed by an unblock\n",
2657 sas_device_priv_data
->sas_target
->handle
, r
);
2658 sas_device_priv_data
->block
= 1;
2659 r
= scsi_internal_device_block(sdev
);
2661 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
2662 "failed with return(%d) for handle(0x%04x)\n",
2663 sas_device_priv_data
->sas_target
->handle
, r
);
2665 sas_device_priv_data
->block
= 0;
2666 r
= scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2668 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
2669 " failed with return(%d) for handle(0x%04x)\n",
2670 sas_device_priv_data
->sas_target
->handle
, r
);
2675 * _scsih_ublock_io_all_device - unblock every device
2676 * @ioc: per adapter object
2678 * change the device state from block to running
2681 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2683 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2684 struct scsi_device
*sdev
;
2686 shost_for_each_device(sdev
, ioc
->shost
) {
2687 sas_device_priv_data
= sdev
->hostdata
;
2688 if (!sas_device_priv_data
)
2690 if (!sas_device_priv_data
->block
)
2693 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2694 "device_running, handle(0x%04x)\n",
2695 sas_device_priv_data
->sas_target
->handle
));
2696 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
2702 * _scsih_ublock_io_device - prepare device to be deleted
2703 * @ioc: per adapter object
2704 * @sas_addr: sas address
2706 * unblock then put device in offline state
2709 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
2711 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2712 struct scsi_device
*sdev
;
2714 shost_for_each_device(sdev
, ioc
->shost
) {
2715 sas_device_priv_data
= sdev
->hostdata
;
2716 if (!sas_device_priv_data
)
2718 if (sas_device_priv_data
->sas_target
->sas_address
2721 if (sas_device_priv_data
->block
)
2722 _scsih_internal_device_unblock(sdev
,
2723 sas_device_priv_data
);
2728 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2729 * @ioc: per adapter object
2730 * @handle: device handle
2732 * During device pull we need to appropiately set the sdev state.
2735 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
2737 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2738 struct scsi_device
*sdev
;
2740 shost_for_each_device(sdev
, ioc
->shost
) {
2741 sas_device_priv_data
= sdev
->hostdata
;
2742 if (!sas_device_priv_data
)
2744 if (sas_device_priv_data
->block
)
2746 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2751 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2752 * @ioc: per adapter object
2753 * @handle: device handle
2755 * During device pull we need to appropiately set the sdev state.
2758 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2760 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2761 struct scsi_device
*sdev
;
2762 struct _sas_device
*sas_device
;
2764 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2768 shost_for_each_device(sdev
, ioc
->shost
) {
2769 sas_device_priv_data
= sdev
->hostdata
;
2770 if (!sas_device_priv_data
)
2772 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
2774 if (sas_device_priv_data
->block
)
2776 if (sas_device
->pend_sas_rphy_add
)
2778 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
2783 * _scsih_block_io_to_children_attached_to_ex
2784 * @ioc: per adapter object
2785 * @sas_expander: the sas_device object
2787 * This routine set sdev state to SDEV_BLOCK for all devices
2788 * attached to this expander. This function called when expander is
2792 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
2793 struct _sas_node
*sas_expander
)
2795 struct _sas_port
*mpt3sas_port
;
2796 struct _sas_device
*sas_device
;
2797 struct _sas_node
*expander_sibling
;
2798 unsigned long flags
;
2803 list_for_each_entry(mpt3sas_port
,
2804 &sas_expander
->sas_port_list
, port_list
) {
2805 if (mpt3sas_port
->remote_identify
.device_type
==
2807 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2809 mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
2810 mpt3sas_port
->remote_identify
.sas_address
);
2812 set_bit(sas_device
->handle
,
2813 ioc
->blocking_handles
);
2814 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2818 list_for_each_entry(mpt3sas_port
,
2819 &sas_expander
->sas_port_list
, port_list
) {
2821 if (mpt3sas_port
->remote_identify
.device_type
==
2822 SAS_EDGE_EXPANDER_DEVICE
||
2823 mpt3sas_port
->remote_identify
.device_type
==
2824 SAS_FANOUT_EXPANDER_DEVICE
) {
2826 mpt3sas_scsih_expander_find_by_sas_address(
2827 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
2828 _scsih_block_io_to_children_attached_to_ex(ioc
,
2835 * _scsih_block_io_to_children_attached_directly
2836 * @ioc: per adapter object
2837 * @event_data: topology change event data
2839 * This routine set sdev state to SDEV_BLOCK for all devices
2840 * direct attached during device pull.
2843 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
2844 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2850 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2851 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2854 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2855 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2856 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2857 _scsih_block_io_device(ioc
, handle
);
2862 * _scsih_tm_tr_send - send task management request
2863 * @ioc: per adapter object
2864 * @handle: device handle
2865 * Context: interrupt time.
2867 * This code is to initiate the device removal handshake protocol
2868 * with controller firmware. This function will issue target reset
2869 * using high priority request queue. It will send a sas iounit
2870 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2872 * This is designed to send muliple task management request at the same
2873 * time to the fifo. If the fifo is full, we will append the request,
2874 * and process it in a future completion.
2877 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2879 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2881 struct _sas_device
*sas_device
;
2882 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
2883 u64 sas_address
= 0;
2884 unsigned long flags
;
2885 struct _tr_list
*delayed_tr
;
2888 if (ioc
->remove_host
) {
2889 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2890 "%s: host has been removed: handle(0x%04x)\n",
2891 __func__
, ioc
->name
, handle
));
2893 } else if (ioc
->pci_error_recovery
) {
2894 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2895 "%s: host in pci error recovery: handle(0x%04x)\n",
2896 __func__
, ioc
->name
,
2900 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
2901 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
2902 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2903 "%s: host is not operational: handle(0x%04x)\n",
2904 __func__
, ioc
->name
,
2909 /* if PD, then return */
2910 if (test_bit(handle
, ioc
->pd_handles
))
2913 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2914 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
2915 if (sas_device
&& sas_device
->starget
&&
2916 sas_device
->starget
->hostdata
) {
2917 sas_target_priv_data
= sas_device
->starget
->hostdata
;
2918 sas_target_priv_data
->deleted
= 1;
2919 sas_address
= sas_device
->sas_address
;
2921 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2923 if (sas_target_priv_data
) {
2924 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2925 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2927 (unsigned long long)sas_address
));
2928 if (sas_device
->enclosure_handle
!= 0)
2929 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2930 "setting delete flag:enclosure logical id(0x%016llx),"
2931 " slot(%d)\n", ioc
->name
, (unsigned long long)
2932 sas_device
->enclosure_logical_id
,
2934 if (sas_device
->connector_name
)
2935 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2936 "setting delete flag: enclosure level(0x%04x),"
2937 " connector name( %s)\n", ioc
->name
,
2938 sas_device
->enclosure_level
,
2939 sas_device
->connector_name
));
2940 _scsih_ublock_io_device(ioc
, sas_address
);
2941 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
2944 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
2946 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
2949 INIT_LIST_HEAD(&delayed_tr
->list
);
2950 delayed_tr
->handle
= handle
;
2951 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
2952 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2953 "DELAYED:tr:handle(0x%04x), (open)\n",
2954 ioc
->name
, handle
));
2958 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
2959 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2960 ioc
->name
, handle
, smid
,
2961 ioc
->tm_tr_cb_idx
));
2962 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2963 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2964 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2965 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2966 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
2967 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
2968 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
2972 * _scsih_tm_tr_complete -
2973 * @ioc: per adapter object
2974 * @smid: system request message index
2975 * @msix_index: MSIX table index supplied by the OS
2976 * @reply: reply message frame(lower 32bit addr)
2977 * Context: interrupt time.
2979 * This is the target reset completion routine.
2980 * This code is part of the code to initiate the device removal
2981 * handshake protocol with controller firmware.
2982 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2984 * Return 1 meaning mf should be freed from _base_interrupt
2985 * 0 means the mf is freed from this function.
2988 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
2992 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
2993 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
2994 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2995 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
2999 if (ioc
->remove_host
) {
3000 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3001 "%s: host has been removed\n", __func__
, ioc
->name
));
3003 } else if (ioc
->pci_error_recovery
) {
3004 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3005 "%s: host in pci error recovery\n", __func__
,
3009 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3010 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3011 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3012 "%s: host is not operational\n", __func__
, ioc
->name
));
3015 if (unlikely(!mpi_reply
)) {
3016 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3017 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3020 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3021 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3022 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3023 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3024 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3026 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3030 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3031 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3032 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3033 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3034 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3035 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3036 le32_to_cpu(mpi_reply
->TerminationCount
)));
3038 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3039 if (!smid_sas_ctrl
) {
3040 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3041 ioc
->name
, __func__
);
3045 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3046 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3047 ioc
->name
, handle
, smid_sas_ctrl
,
3048 ioc
->tm_sas_control_cb_idx
));
3049 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3050 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3051 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3052 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3053 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3054 mpt3sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3056 return _scsih_check_for_pending_tm(ioc
, smid
);
3061 * _scsih_sas_control_complete - completion routine
3062 * @ioc: per adapter object
3063 * @smid: system request message index
3064 * @msix_index: MSIX table index supplied by the OS
3065 * @reply: reply message frame(lower 32bit addr)
3066 * Context: interrupt time.
3068 * This is the sas iounit control completion routine.
3069 * This code is part of the code to initiate the device removal
3070 * handshake protocol with controller firmware.
3072 * Return 1 meaning mf should be freed from _base_interrupt
3073 * 0 means the mf is freed from this function.
3076 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3077 u8 msix_index
, u32 reply
)
3079 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3080 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3082 if (likely(mpi_reply
)) {
3083 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3084 "sc_complete:handle(0x%04x), (open) "
3085 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3086 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3087 le16_to_cpu(mpi_reply
->IOCStatus
),
3088 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3090 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3091 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3097 * _scsih_tm_tr_volume_send - send target reset request for volumes
3098 * @ioc: per adapter object
3099 * @handle: device handle
3100 * Context: interrupt time.
3102 * This is designed to send muliple task management request at the same
3103 * time to the fifo. If the fifo is full, we will append the request,
3104 * and process it in a future completion.
3107 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3109 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3111 struct _tr_list
*delayed_tr
;
3113 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3114 ioc
->pci_error_recovery
) {
3115 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3116 "%s: host reset in progress!\n",
3117 __func__
, ioc
->name
));
3121 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3123 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3126 INIT_LIST_HEAD(&delayed_tr
->list
);
3127 delayed_tr
->handle
= handle
;
3128 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3129 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3130 "DELAYED:tr:handle(0x%04x), (open)\n",
3131 ioc
->name
, handle
));
3135 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3136 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3137 ioc
->name
, handle
, smid
,
3138 ioc
->tm_tr_volume_cb_idx
));
3139 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3140 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3141 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3142 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3143 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3144 mpt3sas_base_put_smid_hi_priority(ioc
, smid
);
3148 * _scsih_tm_volume_tr_complete - target reset completion
3149 * @ioc: per adapter object
3150 * @smid: system request message index
3151 * @msix_index: MSIX table index supplied by the OS
3152 * @reply: reply message frame(lower 32bit addr)
3153 * Context: interrupt time.
3155 * Return 1 meaning mf should be freed from _base_interrupt
3156 * 0 means the mf is freed from this function.
3159 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3160 u8 msix_index
, u32 reply
)
3163 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3164 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3165 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3167 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3168 ioc
->pci_error_recovery
) {
3169 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3170 "%s: host reset in progress!\n",
3171 __func__
, ioc
->name
));
3174 if (unlikely(!mpi_reply
)) {
3175 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3176 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3180 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3181 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3182 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3183 dewtprintk(ioc
, pr_err(MPT3SAS_FMT
3184 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3186 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3190 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3191 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3192 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3193 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3194 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3195 le32_to_cpu(mpi_reply
->TerminationCount
)));
3197 return _scsih_check_for_pending_tm(ioc
, smid
);
3202 * _scsih_check_for_pending_tm - check for pending task management
3203 * @ioc: per adapter object
3204 * @smid: system request message index
3206 * This will check delayed target reset list, and feed the
3209 * Return 1 meaning mf should be freed from _base_interrupt
3210 * 0 means the mf is freed from this function.
3213 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3215 struct _tr_list
*delayed_tr
;
3217 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3218 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3219 struct _tr_list
, list
);
3220 mpt3sas_base_free_smid(ioc
, smid
);
3221 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3222 list_del(&delayed_tr
->list
);
3227 if (!list_empty(&ioc
->delayed_tr_list
)) {
3228 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3229 struct _tr_list
, list
);
3230 mpt3sas_base_free_smid(ioc
, smid
);
3231 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3232 list_del(&delayed_tr
->list
);
3241 * _scsih_check_topo_delete_events - sanity check on topo events
3242 * @ioc: per adapter object
3243 * @event_data: the event data payload
3245 * This routine added to better handle cable breaker.
3247 * This handles the case where driver receives multiple expander
3248 * add and delete events in a single shot. When there is a delete event
3249 * the routine will void any pending add events waiting in the event queue.
3254 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3255 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3257 struct fw_event_work
*fw_event
;
3258 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3259 u16 expander_handle
;
3260 struct _sas_node
*sas_expander
;
3261 unsigned long flags
;
3265 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3266 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3269 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3270 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3271 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3272 _scsih_tm_tr_send(ioc
, handle
);
3275 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3276 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3277 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3280 if (event_data
->ExpStatus
==
3281 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3282 /* put expander attached devices into blocking state */
3283 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3284 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
3286 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3287 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3289 handle
= find_first_bit(ioc
->blocking_handles
,
3290 ioc
->facts
.MaxDevHandle
);
3291 if (handle
< ioc
->facts
.MaxDevHandle
)
3292 _scsih_block_io_device(ioc
, handle
);
3293 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3294 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3295 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3297 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3300 /* mark ignore flag for pending events */
3301 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3302 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3303 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3306 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3307 fw_event
->event_data
;
3308 if (local_event_data
->ExpStatus
==
3309 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3310 local_event_data
->ExpStatus
==
3311 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3312 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3314 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3315 "setting ignoring flag\n", ioc
->name
));
3316 fw_event
->ignore
= 1;
3320 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3324 * _scsih_set_volume_delete_flag - setting volume delete flag
3325 * @ioc: per adapter object
3326 * @handle: device handle
3328 * This returns nothing.
3331 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3333 struct _raid_device
*raid_device
;
3334 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3335 unsigned long flags
;
3337 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3338 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3339 if (raid_device
&& raid_device
->starget
&&
3340 raid_device
->starget
->hostdata
) {
3341 sas_target_priv_data
=
3342 raid_device
->starget
->hostdata
;
3343 sas_target_priv_data
->deleted
= 1;
3344 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3345 "setting delete flag: handle(0x%04x), "
3346 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3347 (unsigned long long) raid_device
->wwid
));
3349 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3353 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3354 * @handle: input handle
3355 * @a: handle for volume a
3356 * @b: handle for volume b
3358 * IR firmware only supports two raid volumes. The purpose of this
3359 * routine is to set the volume handle in either a or b. When the given
3360 * input handle is non-zero, or when a and b have not been set before.
3363 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3365 if (!handle
|| handle
== *a
|| handle
== *b
)
3374 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3375 * @ioc: per adapter object
3376 * @event_data: the event data payload
3377 * Context: interrupt time.
3379 * This routine will send target reset to volume, followed by target
3380 * resets to the PDs. This is called when a PD has been removed, or
3381 * volume has been deleted or removed. When the target reset is sent
3382 * to volume, the PD target resets need to be queued to start upon
3383 * completion of the volume target reset.
3388 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
3389 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3391 Mpi2EventIrConfigElement_t
*element
;
3393 u16 handle
, volume_handle
, a
, b
;
3394 struct _tr_list
*delayed_tr
;
3399 /* Volume Resets for Deleted or Removed */
3400 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3401 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3402 if (le32_to_cpu(event_data
->Flags
) &
3403 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3405 if (element
->ReasonCode
==
3406 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3407 element
->ReasonCode
==
3408 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3409 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3410 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3411 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3415 /* Volume Resets for UNHIDE events */
3416 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3417 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3418 if (le32_to_cpu(event_data
->Flags
) &
3419 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3421 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3422 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3423 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3428 _scsih_tm_tr_volume_send(ioc
, a
);
3430 _scsih_tm_tr_volume_send(ioc
, b
);
3432 /* PD target resets */
3433 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3434 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3435 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3437 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3438 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3439 clear_bit(handle
, ioc
->pd_handles
);
3441 _scsih_tm_tr_send(ioc
, handle
);
3442 else if (volume_handle
== a
|| volume_handle
== b
) {
3443 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3444 BUG_ON(!delayed_tr
);
3445 INIT_LIST_HEAD(&delayed_tr
->list
);
3446 delayed_tr
->handle
= handle
;
3447 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3448 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
3449 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3452 _scsih_tm_tr_send(ioc
, handle
);
3458 * _scsih_check_volume_delete_events - set delete flag for volumes
3459 * @ioc: per adapter object
3460 * @event_data: the event data payload
3461 * Context: interrupt time.
3463 * This will handle the case when the cable connected to entire volume is
3464 * pulled. We will take care of setting the deleted flag so normal IO will
3470 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
3471 Mpi2EventDataIrVolume_t
*event_data
)
3475 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3477 state
= le32_to_cpu(event_data
->NewValue
);
3478 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3479 MPI2_RAID_VOL_STATE_FAILED
)
3480 _scsih_set_volume_delete_flag(ioc
,
3481 le16_to_cpu(event_data
->VolDevHandle
));
3485 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3486 * @ioc: per adapter object
3487 * @event_data: the temp threshold event data
3488 * Context: interrupt time.
3493 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
3494 Mpi2EventDataTemperature_t
*event_data
)
3496 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3497 pr_err(MPT3SAS_FMT
"Temperature Threshold flags %s%s%s%s"
3498 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3499 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3500 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3501 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3502 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3503 event_data
->SensorNum
);
3504 pr_err(MPT3SAS_FMT
"Current Temp In Celsius: %d\n",
3505 ioc
->name
, event_data
->CurrentTemperature
);
3510 * _scsih_flush_running_cmds - completing outstanding commands.
3511 * @ioc: per adapter object
3513 * The flushing out of all pending scmd commands following host reset,
3514 * where all IO is dropped to the floor.
3519 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
3521 struct scsi_cmnd
*scmd
;
3525 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3526 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3530 mpt3sas_base_free_smid(ioc
, smid
);
3531 scsi_dma_unmap(scmd
);
3532 if (ioc
->pci_error_recovery
)
3533 scmd
->result
= DID_NO_CONNECT
<< 16;
3535 scmd
->result
= DID_RESET
<< 16;
3536 scmd
->scsi_done(scmd
);
3538 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"completing %d cmds\n",
3543 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3544 * @ioc: per adapter object
3545 * @scmd: pointer to scsi command object
3546 * @mpi_request: pointer to the SCSI_IO reqest message frame
3548 * Supporting protection 1 and 3.
3553 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3554 Mpi2SCSIIORequest_t
*mpi_request
)
3557 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3558 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3559 Mpi25SCSIIORequest_t
*mpi_request_3v
=
3560 (Mpi25SCSIIORequest_t
*)mpi_request
;
3562 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3565 if (prot_op
== SCSI_PROT_READ_STRIP
)
3566 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3567 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3568 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3572 switch (prot_type
) {
3573 case SCSI_PROT_DIF_TYPE1
:
3574 case SCSI_PROT_DIF_TYPE2
:
3577 * enable ref/guard checking
3578 * auto increment ref tag
3580 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3581 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3582 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3583 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3584 cpu_to_be32(scsi_get_lba(scmd
));
3587 case SCSI_PROT_DIF_TYPE3
:
3590 * enable guard checking
3592 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3597 mpi_request_3v
->EEDPBlockSize
=
3598 cpu_to_le16(scmd
->device
->sector_size
);
3599 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3603 * _scsih_eedp_error_handling - return sense code for EEDP errors
3604 * @scmd: pointer to scsi command object
3605 * @ioc_status: ioc status
3610 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3614 switch (ioc_status
) {
3615 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3618 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3621 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3628 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
3630 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
3631 SAM_STAT_CHECK_CONDITION
;
3636 * scsih_qcmd - main scsi request entry point
3637 * @scmd: pointer to scsi command object
3638 * @done: function pointer to be invoked on completion
3640 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3642 * Returns 0 on success. If there's a failure, return either:
3643 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3644 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3647 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
3649 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3650 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3651 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3652 Mpi2SCSIIORequest_t
*mpi_request
;
3657 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3658 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
3659 scsi_print_command(scmd
);
3662 sas_device_priv_data
= scmd
->device
->hostdata
;
3663 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3664 scmd
->result
= DID_NO_CONNECT
<< 16;
3665 scmd
->scsi_done(scmd
);
3669 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3670 scmd
->result
= DID_NO_CONNECT
<< 16;
3671 scmd
->scsi_done(scmd
);
3675 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3677 /* invalid device handle */
3678 handle
= sas_target_priv_data
->handle
;
3679 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
3680 scmd
->result
= DID_NO_CONNECT
<< 16;
3681 scmd
->scsi_done(scmd
);
3686 /* host recovery or link resets sent via IOCTLs */
3687 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3688 return SCSI_MLQUEUE_HOST_BUSY
;
3690 /* device has been deleted */
3691 else if (sas_target_priv_data
->deleted
) {
3692 scmd
->result
= DID_NO_CONNECT
<< 16;
3693 scmd
->scsi_done(scmd
);
3695 /* device busy with task managment */
3696 } else if (sas_target_priv_data
->tm_busy
||
3697 sas_device_priv_data
->block
)
3698 return SCSI_MLQUEUE_DEVICE_BUSY
;
3700 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3701 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3702 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3703 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3705 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3708 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3710 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) &&
3711 scmd
->cmd_len
!= 32)
3712 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3714 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3716 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3717 ioc
->name
, __func__
);
3720 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3721 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3722 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
3724 if (scmd
->cmd_len
== 32)
3725 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3726 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3727 if (sas_device_priv_data
->sas_target
->flags
&
3728 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3729 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3731 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3732 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3733 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3734 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3735 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3736 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3737 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3738 mpi_request
->SenseBufferLowAddress
=
3739 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
3740 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3741 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3743 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3745 if (mpi_request
->DataLength
) {
3746 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
)) {
3747 mpt3sas_base_free_smid(ioc
, smid
);
3751 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3753 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
3754 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
3755 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
3756 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
3757 mpt3sas_base_put_smid_fast_path(ioc
, smid
, handle
);
3759 mpt3sas_base_put_smid_scsi_io(ioc
, smid
, handle
);
3761 mpt3sas_base_put_smid_default(ioc
, smid
);
3765 return SCSI_MLQUEUE_HOST_BUSY
;
3769 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3770 * @sense_buffer: sense data returned by target
3771 * @data: normalized skey/asc/ascq
3776 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3778 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3779 /* descriptor format */
3780 data
->skey
= sense_buffer
[1] & 0x0F;
3781 data
->asc
= sense_buffer
[2];
3782 data
->ascq
= sense_buffer
[3];
3785 data
->skey
= sense_buffer
[2] & 0x0F;
3786 data
->asc
= sense_buffer
[12];
3787 data
->ascq
= sense_buffer
[13];
3791 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3793 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3794 * @ioc: per adapter object
3795 * @scmd: pointer to scsi command object
3796 * @mpi_reply: reply mf payload returned from firmware
3798 * scsi_status - SCSI Status code returned from target device
3799 * scsi_state - state info associated with SCSI_IO determined by ioc
3800 * ioc_status - ioc supplied status info
3805 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3806 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3810 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3811 MPI2_IOCSTATUS_MASK
;
3812 u8 scsi_state
= mpi_reply
->SCSIState
;
3813 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3814 char *desc_ioc_state
= NULL
;
3815 char *desc_scsi_status
= NULL
;
3816 char *desc_scsi_state
= ioc
->tmp_string
;
3817 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
3818 struct _sas_device
*sas_device
= NULL
;
3819 unsigned long flags
;
3820 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3821 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
3822 char *device_str
= NULL
;
3826 device_str
= "volume";
3828 if (log_info
== 0x31170000)
3831 switch (ioc_status
) {
3832 case MPI2_IOCSTATUS_SUCCESS
:
3833 desc_ioc_state
= "success";
3835 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
3836 desc_ioc_state
= "invalid function";
3838 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
3839 desc_ioc_state
= "scsi recovered error";
3841 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
3842 desc_ioc_state
= "scsi invalid dev handle";
3844 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
3845 desc_ioc_state
= "scsi device not there";
3847 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
3848 desc_ioc_state
= "scsi data overrun";
3850 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
3851 desc_ioc_state
= "scsi data underrun";
3853 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
3854 desc_ioc_state
= "scsi io data error";
3856 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
3857 desc_ioc_state
= "scsi protocol error";
3859 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
3860 desc_ioc_state
= "scsi task terminated";
3862 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
3863 desc_ioc_state
= "scsi residual mismatch";
3865 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
3866 desc_ioc_state
= "scsi task mgmt failed";
3868 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
3869 desc_ioc_state
= "scsi ioc terminated";
3871 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
3872 desc_ioc_state
= "scsi ext terminated";
3874 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3875 desc_ioc_state
= "eedp guard error";
3877 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3878 desc_ioc_state
= "eedp ref tag error";
3880 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3881 desc_ioc_state
= "eedp app tag error";
3884 desc_ioc_state
= "unknown";
3888 switch (scsi_status
) {
3889 case MPI2_SCSI_STATUS_GOOD
:
3890 desc_scsi_status
= "good";
3892 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
3893 desc_scsi_status
= "check condition";
3895 case MPI2_SCSI_STATUS_CONDITION_MET
:
3896 desc_scsi_status
= "condition met";
3898 case MPI2_SCSI_STATUS_BUSY
:
3899 desc_scsi_status
= "busy";
3901 case MPI2_SCSI_STATUS_INTERMEDIATE
:
3902 desc_scsi_status
= "intermediate";
3904 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
3905 desc_scsi_status
= "intermediate condmet";
3907 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
3908 desc_scsi_status
= "reservation conflict";
3910 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
3911 desc_scsi_status
= "command terminated";
3913 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
3914 desc_scsi_status
= "task set full";
3916 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
3917 desc_scsi_status
= "aca active";
3919 case MPI2_SCSI_STATUS_TASK_ABORTED
:
3920 desc_scsi_status
= "task aborted";
3923 desc_scsi_status
= "unknown";
3927 desc_scsi_state
[0] = '\0';
3929 desc_scsi_state
= " ";
3930 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
3931 strcat(desc_scsi_state
, "response info ");
3932 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
3933 strcat(desc_scsi_state
, "state terminated ");
3934 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
3935 strcat(desc_scsi_state
, "no status ");
3936 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
3937 strcat(desc_scsi_state
, "autosense failed ");
3938 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
3939 strcat(desc_scsi_state
, "autosense valid ");
3941 scsi_print_command(scmd
);
3943 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
3944 pr_warn(MPT3SAS_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
3945 device_str
, (unsigned long long)priv_target
->sas_address
);
3947 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3948 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
3949 priv_target
->sas_address
);
3952 "\tsas_address(0x%016llx), phy(%d)\n",
3953 ioc
->name
, (unsigned long long)
3954 sas_device
->sas_address
, sas_device
->phy
);
3955 if (sas_device
->enclosure_handle
!= 0)
3957 "\tenclosure_logical_id(0x%016llx),"
3958 "slot(%d)\n", ioc
->name
,
3959 (unsigned long long)
3960 sas_device
->enclosure_logical_id
,
3962 if (sas_device
->connector_name
[0])
3964 "\tenclosure level(0x%04x),"
3965 " connector name( %s)\n", ioc
->name
,
3966 sas_device
->enclosure_level
,
3967 sas_device
->connector_name
);
3969 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3973 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3974 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
3975 desc_ioc_state
, ioc_status
, smid
);
3977 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3978 ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
3979 scsi_get_resid(scmd
));
3981 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3982 ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
3983 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
3985 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3986 ioc
->name
, desc_scsi_status
,
3987 scsi_status
, desc_scsi_state
, scsi_state
);
3989 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
3990 struct sense_info data
;
3991 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
3993 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3994 ioc
->name
, data
.skey
,
3995 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
3998 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
3999 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4000 response_bytes
= (u8
*)&response_info
;
4001 _scsih_response_code(ioc
, response_bytes
[0]);
4007 * _scsih_turn_on_pfa_led - illuminate PFA LED
4008 * @ioc: per adapter object
4009 * @handle: device handle
4015 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4017 Mpi2SepReply_t mpi_reply
;
4018 Mpi2SepRequest_t mpi_request
;
4019 struct _sas_device
*sas_device
;
4021 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4025 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4026 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4027 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4028 mpi_request
.SlotStatus
=
4029 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4030 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4031 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4032 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4033 &mpi_request
)) != 0) {
4034 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4035 __FILE__
, __LINE__
, __func__
);
4038 sas_device
->pfa_led_on
= 1;
4040 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4041 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
4042 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4043 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4044 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4049 * _scsih_turn_off_pfa_led - turn off Fault LED
4050 * @ioc: per adapter object
4051 * @sas_device: sas device whose PFA LED has to turned off
4057 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
4058 struct _sas_device
*sas_device
)
4060 Mpi2SepReply_t mpi_reply
;
4061 Mpi2SepRequest_t mpi_request
;
4063 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4064 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4065 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4066 mpi_request
.SlotStatus
= 0;
4067 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4068 mpi_request
.DevHandle
= 0;
4069 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4070 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4071 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4072 &mpi_request
)) != 0) {
4073 printk(MPT3SAS_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4074 __FILE__
, __LINE__
, __func__
);
4078 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4079 dewtprintk(ioc
, printk(MPT3SAS_FMT
4080 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4081 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4082 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4087 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4088 * @ioc: per adapter object
4089 * @handle: device handle
4090 * Context: interrupt.
4095 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4097 struct fw_event_work
*fw_event
;
4099 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
4102 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
4103 fw_event
->device_handle
= handle
;
4104 fw_event
->ioc
= ioc
;
4105 _scsih_fw_event_add(ioc
, fw_event
);
4109 * _scsih_smart_predicted_fault - process smart errors
4110 * @ioc: per adapter object
4111 * @handle: device handle
4112 * Context: interrupt.
4117 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4119 struct scsi_target
*starget
;
4120 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4121 Mpi2EventNotificationReply_t
*event_reply
;
4122 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4123 struct _sas_device
*sas_device
;
4125 unsigned long flags
;
4127 /* only handle non-raid devices */
4128 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4129 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4131 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4134 starget
= sas_device
->starget
;
4135 sas_target_priv_data
= starget
->hostdata
;
4137 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4138 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
4139 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4142 if (sas_device
->enclosure_handle
!= 0)
4143 starget_printk(KERN_INFO
, starget
, "predicted fault, "
4144 "enclosure logical id(0x%016llx), slot(%d)\n",
4145 (unsigned long long)sas_device
->enclosure_logical_id
,
4147 if (sas_device
->connector_name
[0] != '\0')
4148 starget_printk(KERN_WARNING
, starget
, "predicted fault, "
4149 "enclosure level(0x%04x), connector name( %s)\n",
4150 sas_device
->enclosure_level
,
4151 sas_device
->connector_name
);
4152 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4154 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4155 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4157 /* insert into event log */
4158 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4159 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4160 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4162 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4163 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4167 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4168 event_reply
->Event
=
4169 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4170 event_reply
->MsgLength
= sz
/4;
4171 event_reply
->EventDataLength
=
4172 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4173 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4174 event_reply
->EventData
;
4175 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4176 event_data
->ASC
= 0x5D;
4177 event_data
->DevHandle
= cpu_to_le16(handle
);
4178 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4179 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
4184 * _scsih_io_done - scsi request callback
4185 * @ioc: per adapter object
4186 * @smid: system request message index
4187 * @msix_index: MSIX table index supplied by the OS
4188 * @reply: reply message frame(lower 32bit addr)
4190 * Callback handler when using _scsih_qcmd.
4192 * Return 1 meaning mf should be freed from _base_interrupt
4193 * 0 means the mf is freed from this function.
4196 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4198 Mpi2SCSIIORequest_t
*mpi_request
;
4199 Mpi2SCSIIOReply_t
*mpi_reply
;
4200 struct scsi_cmnd
*scmd
;
4206 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4207 u32 response_code
= 0;
4209 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4210 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4214 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4216 if (mpi_reply
== NULL
) {
4217 scmd
->result
= DID_OK
<< 16;
4221 sas_device_priv_data
= scmd
->device
->hostdata
;
4222 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4223 sas_device_priv_data
->sas_target
->deleted
) {
4224 scmd
->result
= DID_NO_CONNECT
<< 16;
4227 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4229 /* turning off TLR */
4230 scsi_state
= mpi_reply
->SCSIState
;
4231 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4233 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4234 if (!sas_device_priv_data
->tlr_snoop_check
) {
4235 sas_device_priv_data
->tlr_snoop_check
++;
4236 if ((sas_device_priv_data
->flags
& MPT_DEVICE_TLR_ON
) &&
4237 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
)
4238 sas_device_priv_data
->flags
&=
4242 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4243 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4244 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4245 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4248 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4249 scsi_status
= mpi_reply
->SCSIStatus
;
4251 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4252 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4253 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4254 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4255 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4258 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4259 struct sense_info data
;
4260 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
4262 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4263 le32_to_cpu(mpi_reply
->SenseCount
));
4264 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4265 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4266 /* failure prediction threshold exceeded */
4267 if (data
.asc
== 0x5D)
4268 _scsih_smart_predicted_fault(ioc
,
4269 le16_to_cpu(mpi_reply
->DevHandle
));
4270 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
4272 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4273 if (!(ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
4274 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
4275 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
4276 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
4277 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4280 switch (ioc_status
) {
4281 case MPI2_IOCSTATUS_BUSY
:
4282 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4283 scmd
->result
= SAM_STAT_BUSY
;
4286 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4287 scmd
->result
= DID_NO_CONNECT
<< 16;
4290 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4291 if (sas_device_priv_data
->block
) {
4292 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4295 if (log_info
== 0x31110630) {
4296 if (scmd
->retries
> 2) {
4297 scmd
->result
= DID_NO_CONNECT
<< 16;
4298 scsi_device_set_state(scmd
->device
,
4301 scmd
->result
= DID_SOFT_ERROR
<< 16;
4302 scmd
->device
->expecting_cc_ua
= 1;
4305 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
4306 scmd
->result
= DID_RESET
<< 16;
4309 scmd
->result
= DID_SOFT_ERROR
<< 16;
4311 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4312 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4313 scmd
->result
= DID_RESET
<< 16;
4316 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4317 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4318 scmd
->result
= DID_SOFT_ERROR
<< 16;
4320 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4323 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4324 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4326 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4329 if (xfer_cnt
< scmd
->underflow
) {
4330 if (scsi_status
== SAM_STAT_BUSY
)
4331 scmd
->result
= SAM_STAT_BUSY
;
4333 scmd
->result
= DID_SOFT_ERROR
<< 16;
4334 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4335 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4336 scmd
->result
= DID_SOFT_ERROR
<< 16;
4337 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4338 scmd
->result
= DID_RESET
<< 16;
4339 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4340 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4341 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4342 scmd
->result
= (DRIVER_SENSE
<< 24) |
4343 SAM_STAT_CHECK_CONDITION
;
4344 scmd
->sense_buffer
[0] = 0x70;
4345 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4346 scmd
->sense_buffer
[12] = 0x20;
4347 scmd
->sense_buffer
[13] = 0;
4351 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4352 scsi_set_resid(scmd
, 0);
4353 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4354 case MPI2_IOCSTATUS_SUCCESS
:
4355 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4356 if (response_code
==
4357 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4358 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4359 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4360 scmd
->result
= DID_SOFT_ERROR
<< 16;
4361 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4362 scmd
->result
= DID_RESET
<< 16;
4365 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4366 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4367 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4368 _scsih_eedp_error_handling(scmd
, ioc_status
);
4371 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4372 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4373 case MPI2_IOCSTATUS_INVALID_SGL
:
4374 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4375 case MPI2_IOCSTATUS_INVALID_FIELD
:
4376 case MPI2_IOCSTATUS_INVALID_STATE
:
4377 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4378 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4380 scmd
->result
= DID_SOFT_ERROR
<< 16;
4385 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4386 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4387 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4392 scsi_dma_unmap(scmd
);
4394 scmd
->scsi_done(scmd
);
4399 * _scsih_sas_host_refresh - refreshing sas host object contents
4400 * @ioc: per adapter object
4403 * During port enable, fw will send topology events for every device. Its
4404 * possible that the handles may change from the previous setting, so this
4405 * code keeping handles updating if changed.
4410 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
4415 Mpi2ConfigReply_t mpi_reply
;
4416 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4417 u16 attached_handle
;
4420 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4421 "updating handles for sas_host(0x%016llx)\n",
4422 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4424 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4425 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4426 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4427 if (!sas_iounit_pg0
) {
4428 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4429 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4433 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4434 sas_iounit_pg0
, sz
)) != 0)
4436 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4437 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4439 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4440 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4442 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4443 PhyData
[0].ControllerDevHandle
);
4444 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4445 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4447 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4448 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4449 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4450 attached_handle
, i
, link_rate
);
4453 kfree(sas_iounit_pg0
);
4457 * _scsih_sas_host_add - create sas host object
4458 * @ioc: per adapter object
4460 * Creating host side data object, stored in ioc->sas_hba
4465 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
4468 Mpi2ConfigReply_t mpi_reply
;
4469 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4470 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4471 Mpi2SasPhyPage0_t phy_pg0
;
4472 Mpi2SasDevicePage0_t sas_device_pg0
;
4473 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4476 u8 device_missing_delay
;
4478 mpt3sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4479 if (!ioc
->sas_hba
.num_phys
) {
4480 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4481 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4485 /* sas_iounit page 0 */
4486 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4487 sizeof(Mpi2SasIOUnit0PhyData_t
));
4488 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4489 if (!sas_iounit_pg0
) {
4490 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4491 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4494 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4495 sas_iounit_pg0
, sz
))) {
4496 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4497 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4500 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4501 MPI2_IOCSTATUS_MASK
;
4502 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4503 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4504 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4508 /* sas_iounit page 1 */
4509 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4510 sizeof(Mpi2SasIOUnit1PhyData_t
));
4511 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4512 if (!sas_iounit_pg1
) {
4513 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4514 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4517 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4518 sas_iounit_pg1
, sz
))) {
4519 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4520 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4523 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4524 MPI2_IOCSTATUS_MASK
;
4525 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4526 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4527 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4531 ioc
->io_missing_delay
=
4532 sas_iounit_pg1
->IODeviceMissingDelay
;
4533 device_missing_delay
=
4534 sas_iounit_pg1
->ReportDeviceMissingDelay
;
4535 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4536 ioc
->device_missing_delay
= (device_missing_delay
&
4537 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4539 ioc
->device_missing_delay
= device_missing_delay
&
4540 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4542 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4543 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4544 sizeof(struct _sas_phy
), GFP_KERNEL
);
4545 if (!ioc
->sas_hba
.phy
) {
4546 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4547 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4550 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4551 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4553 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4554 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4557 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4558 MPI2_IOCSTATUS_MASK
;
4559 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4560 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4561 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4566 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4567 PhyData
[0].ControllerDevHandle
);
4568 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4569 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4570 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4571 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4573 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4574 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4575 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4576 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4579 ioc
->sas_hba
.enclosure_handle
=
4580 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4581 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4583 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4584 ioc
->name
, ioc
->sas_hba
.handle
,
4585 (unsigned long long) ioc
->sas_hba
.sas_address
,
4586 ioc
->sas_hba
.num_phys
) ;
4588 if (ioc
->sas_hba
.enclosure_handle
) {
4589 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4590 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4591 ioc
->sas_hba
.enclosure_handle
)))
4592 ioc
->sas_hba
.enclosure_logical_id
=
4593 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4597 kfree(sas_iounit_pg1
);
4598 kfree(sas_iounit_pg0
);
4602 * _scsih_expander_add - creating expander object
4603 * @ioc: per adapter object
4604 * @handle: expander handle
4606 * Creating expander object, stored in ioc->sas_expander_list.
4608 * Return 0 for success, else error.
4611 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4613 struct _sas_node
*sas_expander
;
4614 Mpi2ConfigReply_t mpi_reply
;
4615 Mpi2ExpanderPage0_t expander_pg0
;
4616 Mpi2ExpanderPage1_t expander_pg1
;
4617 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4620 u64 sas_address
, sas_address_parent
= 0;
4622 unsigned long flags
;
4623 struct _sas_port
*mpt3sas_port
= NULL
;
4630 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4633 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4634 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4635 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4636 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4640 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4641 MPI2_IOCSTATUS_MASK
;
4642 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4643 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4644 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4648 /* handle out of order topology events */
4649 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4650 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4652 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4653 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4656 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4657 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4658 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4659 sas_address_parent
);
4660 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4661 if (!sas_expander
) {
4662 rc
= _scsih_expander_add(ioc
, parent_handle
);
4668 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4669 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4670 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4672 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4677 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4679 if (!sas_expander
) {
4680 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4681 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4685 sas_expander
->handle
= handle
;
4686 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4687 sas_expander
->sas_address_parent
= sas_address_parent
;
4688 sas_expander
->sas_address
= sas_address
;
4690 pr_info(MPT3SAS_FMT
"expander_add: handle(0x%04x)," \
4691 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4692 handle
, parent_handle
, (unsigned long long)
4693 sas_expander
->sas_address
, sas_expander
->num_phys
);
4695 if (!sas_expander
->num_phys
)
4697 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4698 sizeof(struct _sas_phy
), GFP_KERNEL
);
4699 if (!sas_expander
->phy
) {
4700 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4701 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4706 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4707 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
4708 sas_address_parent
);
4709 if (!mpt3sas_port
) {
4710 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4711 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4715 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
4717 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4718 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4719 &expander_pg1
, i
, handle
))) {
4720 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4721 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4725 sas_expander
->phy
[i
].handle
= handle
;
4726 sas_expander
->phy
[i
].phy_id
= i
;
4728 if ((mpt3sas_transport_add_expander_phy(ioc
,
4729 &sas_expander
->phy
[i
], expander_pg1
,
4730 sas_expander
->parent_dev
))) {
4731 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
4732 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4738 if (sas_expander
->enclosure_handle
) {
4739 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4740 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4741 sas_expander
->enclosure_handle
)))
4742 sas_expander
->enclosure_logical_id
=
4743 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4746 _scsih_expander_node_add(ioc
, sas_expander
);
4752 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4753 sas_address_parent
);
4754 kfree(sas_expander
);
4759 * mpt3sas_expander_remove - removing expander object
4760 * @ioc: per adapter object
4761 * @sas_address: expander sas_address
4766 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
4768 struct _sas_node
*sas_expander
;
4769 unsigned long flags
;
4771 if (ioc
->shost_recovery
)
4774 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4775 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
4778 list_del(&sas_expander
->list
);
4779 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4781 _scsih_expander_node_remove(ioc
, sas_expander
);
4785 * _scsih_done - internal SCSI_IO callback handler.
4786 * @ioc: per adapter object
4787 * @smid: system request message index
4788 * @msix_index: MSIX table index supplied by the OS
4789 * @reply: reply message frame(lower 32bit addr)
4791 * Callback handler when sending internal generated SCSI_IO.
4792 * The callback index passed is `ioc->scsih_cb_idx`
4794 * Return 1 meaning mf should be freed from _base_interrupt
4795 * 0 means the mf is freed from this function.
4798 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4800 MPI2DefaultReply_t
*mpi_reply
;
4802 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4803 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
4805 if (ioc
->scsih_cmds
.smid
!= smid
)
4807 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
4809 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4810 mpi_reply
->MsgLength
*4);
4811 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
4813 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
4814 complete(&ioc
->scsih_cmds
.done
);
4821 #define MPT3_MAX_LUNS (255)
4825 * _scsih_check_access_status - check access flags
4826 * @ioc: per adapter object
4827 * @sas_address: sas address
4828 * @handle: sas device handle
4829 * @access_flags: errors returned during discovery of the device
4831 * Return 0 for success, else failure
4834 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
4835 u16 handle
, u8 access_status
)
4840 switch (access_status
) {
4841 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4842 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4845 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4846 desc
= "sata capability failed";
4848 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4849 desc
= "sata affiliation conflict";
4851 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4852 desc
= "route not addressable";
4854 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4855 desc
= "smp error not addressable";
4857 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4858 desc
= "device blocked";
4860 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4861 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4862 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4863 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4864 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4865 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4866 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4867 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4868 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4869 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4870 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4871 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4872 desc
= "sata initialization failed";
4883 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4884 ioc
->name
, desc
, (unsigned long long)sas_address
, handle
);
4889 * _scsih_check_device - checking device responsiveness
4890 * @ioc: per adapter object
4891 * @parent_sas_address: sas address of parent expander or sas host
4892 * @handle: attached device handle
4893 * @phy_numberv: phy number
4894 * @link_rate: new link rate
4899 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
4900 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
4902 Mpi2ConfigReply_t mpi_reply
;
4903 Mpi2SasDevicePage0_t sas_device_pg0
;
4904 struct _sas_device
*sas_device
;
4906 unsigned long flags
;
4908 struct scsi_target
*starget
;
4909 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4913 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4914 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
4917 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4918 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4921 /* wide port handling ~ we need only handle device once for the phy that
4922 * is matched in sas device page zero
4924 if (phy_number
!= sas_device_pg0
.PhyNum
)
4927 /* check if this is end device */
4928 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
4929 if (!(_scsih_is_end_device(device_info
)))
4932 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4933 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4934 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
4938 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4942 if (unlikely(sas_device
->handle
!= handle
)) {
4943 starget
= sas_device
->starget
;
4944 sas_target_priv_data
= starget
->hostdata
;
4945 starget_printk(KERN_INFO
, starget
,
4946 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4947 sas_device
->handle
, handle
);
4948 sas_target_priv_data
->handle
= handle
;
4949 sas_device
->handle
= handle
;
4950 if (sas_device_pg0
.Flags
&
4951 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
4952 sas_device
->enclosure_level
=
4953 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
4954 memcpy(&sas_device
->connector_name
[0],
4955 &sas_device_pg0
.ConnectorName
[0], 4);
4957 sas_device
->enclosure_level
= 0;
4958 sas_device
->connector_name
[0] = '\0';
4962 /* check if device is present */
4963 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
4964 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
4966 "device is not present handle(0x%04x), flags!!!\n",
4968 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4972 /* check if there were any issues with discovery */
4973 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
4974 sas_device_pg0
.AccessStatus
)) {
4975 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4979 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4980 _scsih_ublock_io_device(ioc
, sas_address
);
4985 * _scsih_add_device - creating sas device object
4986 * @ioc: per adapter object
4987 * @handle: sas device handle
4988 * @phy_num: phy number end device attached to
4989 * @is_pd: is this hidden raid component
4991 * Creating end device object, stored in ioc->sas_device_list.
4993 * Returns 0 for success, non-zero for failure.
4996 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
4999 Mpi2ConfigReply_t mpi_reply
;
5000 Mpi2SasDevicePage0_t sas_device_pg0
;
5001 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5002 struct _sas_device
*sas_device
;
5006 unsigned long flags
;
5008 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5009 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5010 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5011 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5015 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5016 MPI2_IOCSTATUS_MASK
;
5017 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5018 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5019 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5023 /* check if this is end device */
5024 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5025 if (!(_scsih_is_end_device(device_info
)))
5027 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5029 /* check if device is present */
5030 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5031 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5032 pr_err(MPT3SAS_FMT
"device is not present handle(0x04%x)!!!\n",
5037 /* check if there were any issues with discovery */
5038 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5039 sas_device_pg0
.AccessStatus
))
5042 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5043 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
5045 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5050 sas_device
= kzalloc(sizeof(struct _sas_device
),
5053 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5054 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5058 sas_device
->handle
= handle
;
5059 if (_scsih_get_sas_address(ioc
,
5060 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
5061 &sas_device
->sas_address_parent
) != 0)
5062 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
5063 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5064 sas_device
->enclosure_handle
=
5065 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5066 if (sas_device
->enclosure_handle
!= 0)
5068 le16_to_cpu(sas_device_pg0
.Slot
);
5069 sas_device
->device_info
= device_info
;
5070 sas_device
->sas_address
= sas_address
;
5071 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5072 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
5073 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
5075 if (sas_device_pg0
.Flags
& MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5076 sas_device
->enclosure_level
=
5077 le16_to_cpu(sas_device_pg0
.EnclosureLevel
);
5078 memcpy(&sas_device
->connector_name
[0],
5079 &sas_device_pg0
.ConnectorName
[0], 4);
5081 sas_device
->enclosure_level
= 0;
5082 sas_device
->connector_name
[0] = '\0';
5084 /* get enclosure_logical_id */
5085 if (sas_device
->enclosure_handle
&& !(mpt3sas_config_get_enclosure_pg0(
5086 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5087 sas_device
->enclosure_handle
)))
5088 sas_device
->enclosure_logical_id
=
5089 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5091 /* get device name */
5092 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5094 if (ioc
->wait_for_discovery_to_complete
)
5095 _scsih_sas_device_init_add(ioc
, sas_device
);
5097 _scsih_sas_device_add(ioc
, sas_device
);
5103 * _scsih_remove_device - removing sas device object
5104 * @ioc: per adapter object
5105 * @sas_device_delete: the sas_device object
5110 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
5111 struct _sas_device
*sas_device
)
5113 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5115 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5116 (sas_device
->pfa_led_on
)) {
5117 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5118 sas_device
->pfa_led_on
= 0;
5120 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5121 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5122 ioc
->name
, __func__
,
5123 sas_device
->handle
, (unsigned long long)
5124 sas_device
->sas_address
));
5125 if (sas_device
->enclosure_handle
!= 0)
5126 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5127 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5128 ioc
->name
, __func__
,
5129 (unsigned long long)sas_device
->enclosure_logical_id
,
5131 if (sas_device
->connector_name
[0] != '\0')
5132 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5133 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5134 ioc
->name
, __func__
,
5135 sas_device
->enclosure_level
,
5136 sas_device
->connector_name
));
5138 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5139 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5140 sas_target_priv_data
->deleted
= 1;
5141 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5142 sas_target_priv_data
->handle
=
5143 MPT3SAS_INVALID_DEVICE_HANDLE
;
5145 mpt3sas_transport_port_remove(ioc
,
5146 sas_device
->sas_address
,
5147 sas_device
->sas_address_parent
);
5150 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5151 ioc
->name
, sas_device
->handle
,
5152 (unsigned long long) sas_device
->sas_address
);
5153 if (sas_device
->enclosure_handle
!= 0)
5155 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5157 (unsigned long long)sas_device
->enclosure_logical_id
,
5159 if (sas_device
->connector_name
[0] != '\0')
5161 "removing enclosure level(0x%04x), connector name( %s)\n",
5162 ioc
->name
, sas_device
->enclosure_level
,
5163 sas_device
->connector_name
);
5165 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5166 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5167 ioc
->name
, __func__
,
5168 sas_device
->handle
, (unsigned long long)
5169 sas_device
->sas_address
));
5170 if (sas_device
->enclosure_handle
!= 0)
5171 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5172 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5173 ioc
->name
, __func__
,
5174 (unsigned long long)sas_device
->enclosure_logical_id
,
5176 if (sas_device
->connector_name
[0] != '\0')
5177 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5178 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5179 ioc
->name
, __func__
, sas_device
->enclosure_level
,
5180 sas_device
->connector_name
));
5185 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5187 * _scsih_sas_topology_change_event_debug - debug for topology event
5188 * @ioc: per adapter object
5189 * @event_data: event data payload
5193 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5194 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5200 char *status_str
= NULL
;
5201 u8 link_rate
, prev_link_rate
;
5203 switch (event_data
->ExpStatus
) {
5204 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5207 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5208 status_str
= "remove";
5210 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5212 status_str
= "responding";
5214 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5215 status_str
= "remove delay";
5218 status_str
= "unknown status";
5221 pr_info(MPT3SAS_FMT
"sas topology change: (%s)\n",
5222 ioc
->name
, status_str
);
5223 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5224 "start_phy(%02d), count(%d)\n",
5225 le16_to_cpu(event_data
->ExpanderDevHandle
),
5226 le16_to_cpu(event_data
->EnclosureHandle
),
5227 event_data
->StartPhyNum
, event_data
->NumEntries
);
5228 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5229 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5232 phy_number
= event_data
->StartPhyNum
+ i
;
5233 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5234 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5235 switch (reason_code
) {
5236 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5237 status_str
= "target add";
5239 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5240 status_str
= "target remove";
5242 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5243 status_str
= "delay target remove";
5245 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5246 status_str
= "link rate change";
5248 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5249 status_str
= "target responding";
5252 status_str
= "unknown";
5255 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5256 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5257 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5258 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5259 handle
, status_str
, link_rate
, prev_link_rate
);
5266 * _scsih_sas_topology_change_event - handle topology changes
5267 * @ioc: per adapter object
5268 * @fw_event: The fw_event_work object
5273 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5274 struct fw_event_work
*fw_event
)
5277 u16 parent_handle
, handle
;
5279 u8 phy_number
, max_phys
;
5280 struct _sas_node
*sas_expander
;
5282 unsigned long flags
;
5283 u8 link_rate
, prev_link_rate
;
5284 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5285 (Mpi2EventDataSasTopologyChangeList_t
*)
5286 fw_event
->event_data
;
5288 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5289 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5290 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5293 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
5296 if (!ioc
->sas_hba
.num_phys
)
5297 _scsih_sas_host_add(ioc
);
5299 _scsih_sas_host_refresh(ioc
);
5301 if (fw_event
->ignore
) {
5302 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5303 "ignoring expander event\n", ioc
->name
));
5307 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5309 /* handle expander add */
5310 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5311 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5314 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5315 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
5318 sas_address
= sas_expander
->sas_address
;
5319 max_phys
= sas_expander
->num_phys
;
5320 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5321 sas_address
= ioc
->sas_hba
.sas_address
;
5322 max_phys
= ioc
->sas_hba
.num_phys
;
5324 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5327 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5329 /* handle siblings events */
5330 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5331 if (fw_event
->ignore
) {
5332 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5333 "ignoring expander event\n", ioc
->name
));
5336 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5338 phy_number
= event_data
->StartPhyNum
+ i
;
5339 if (phy_number
>= max_phys
)
5341 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5342 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5343 if ((event_data
->PHY
[i
].PhyStatus
&
5344 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5345 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5347 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5350 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5351 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5352 switch (reason_code
) {
5353 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5355 if (ioc
->shost_recovery
)
5358 if (link_rate
== prev_link_rate
)
5361 mpt3sas_transport_update_links(ioc
, sas_address
,
5362 handle
, phy_number
, link_rate
);
5364 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5367 _scsih_check_device(ioc
, sas_address
, handle
,
5368 phy_number
, link_rate
);
5371 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5373 if (ioc
->shost_recovery
)
5376 mpt3sas_transport_update_links(ioc
, sas_address
,
5377 handle
, phy_number
, link_rate
);
5379 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5382 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5384 _scsih_device_remove_by_handle(ioc
, handle
);
5389 /* handle expander removal */
5390 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5392 mpt3sas_expander_remove(ioc
, sas_address
);
5397 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5399 * _scsih_sas_device_status_change_event_debug - debug for device event
5400 * @event_data: event data payload
5406 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5407 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5409 char *reason_str
= NULL
;
5411 switch (event_data
->ReasonCode
) {
5412 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5413 reason_str
= "smart data";
5415 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5416 reason_str
= "unsupported device discovered";
5418 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5419 reason_str
= "internal device reset";
5421 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5422 reason_str
= "internal task abort";
5424 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5425 reason_str
= "internal task abort set";
5427 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5428 reason_str
= "internal clear task set";
5430 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5431 reason_str
= "internal query task";
5433 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5434 reason_str
= "sata init failure";
5436 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5437 reason_str
= "internal device reset complete";
5439 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5440 reason_str
= "internal task abort complete";
5442 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5443 reason_str
= "internal async notification";
5445 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5446 reason_str
= "expander reduced functionality";
5448 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5449 reason_str
= "expander reduced functionality complete";
5452 reason_str
= "unknown reason";
5455 pr_info(MPT3SAS_FMT
"device status change: (%s)\n"
5456 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5457 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5458 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5459 le16_to_cpu(event_data
->TaskTag
));
5460 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5461 pr_info(MPT3SAS_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5462 event_data
->ASC
, event_data
->ASCQ
);
5468 * _scsih_sas_device_status_change_event - handle device status change
5469 * @ioc: per adapter object
5470 * @fw_event: The fw_event_work object
5476 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5477 struct fw_event_work
*fw_event
)
5479 struct MPT3SAS_TARGET
*target_priv_data
;
5480 struct _sas_device
*sas_device
;
5482 unsigned long flags
;
5483 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5484 (Mpi2EventDataSasDeviceStatusChange_t
*)
5485 fw_event
->event_data
;
5487 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5488 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5489 _scsih_sas_device_status_change_event_debug(ioc
,
5493 /* In MPI Revision K (0xC), the internal device reset complete was
5494 * implemented, so avoid setting tm_busy flag for older firmware.
5496 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5499 if (event_data
->ReasonCode
!=
5500 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5501 event_data
->ReasonCode
!=
5502 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5505 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5506 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5507 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
5510 if (!sas_device
|| !sas_device
->starget
) {
5511 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5515 target_priv_data
= sas_device
->starget
->hostdata
;
5516 if (!target_priv_data
) {
5517 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5521 if (event_data
->ReasonCode
==
5522 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5523 target_priv_data
->tm_busy
= 1;
5525 target_priv_data
->tm_busy
= 0;
5526 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5529 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5531 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5533 * @ioc: per adapter object
5534 * @event_data: event data payload
5540 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
5541 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5543 char *reason_str
= NULL
;
5545 switch (event_data
->ReasonCode
) {
5546 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5547 reason_str
= "enclosure add";
5549 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5550 reason_str
= "enclosure remove";
5553 reason_str
= "unknown reason";
5557 pr_info(MPT3SAS_FMT
"enclosure status change: (%s)\n"
5558 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5559 " number slots(%d)\n", ioc
->name
, reason_str
,
5560 le16_to_cpu(event_data
->EnclosureHandle
),
5561 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5562 le16_to_cpu(event_data
->StartSlot
));
5567 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5568 * @ioc: per adapter object
5569 * @fw_event: The fw_event_work object
5575 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
5576 struct fw_event_work
*fw_event
)
5578 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5579 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5580 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5581 (Mpi2EventDataSasEnclDevStatusChange_t
*)
5582 fw_event
->event_data
);
5587 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5588 * @ioc: per adapter object
5589 * @fw_event: The fw_event_work object
5595 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
5596 struct fw_event_work
*fw_event
)
5598 struct scsi_cmnd
*scmd
;
5599 struct scsi_device
*sdev
;
5602 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5603 u32 termination_count
;
5605 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5606 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
5607 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5608 fw_event
->event_data
;
5610 unsigned long flags
;
5613 u8 task_abort_retries
;
5615 mutex_lock(&ioc
->tm_cmds
.mutex
);
5617 "%s: enter: phy number(%d), width(%d)\n",
5618 ioc
->name
, __func__
, event_data
->PhyNum
,
5619 event_data
->PortWidth
);
5621 _scsih_block_io_all_device(ioc
);
5623 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5624 mpi_reply
= ioc
->tm_cmds
.reply
;
5625 broadcast_aen_retry
:
5627 /* sanity checks for retrying this loop */
5628 if (max_retries
++ == 5) {
5629 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: giving up\n",
5630 ioc
->name
, __func__
));
5632 } else if (max_retries
> 1)
5633 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %d retry\n",
5634 ioc
->name
, __func__
, max_retries
- 1));
5636 termination_count
= 0;
5638 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5639 if (ioc
->shost_recovery
)
5641 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5644 sdev
= scmd
->device
;
5645 sas_device_priv_data
= sdev
->hostdata
;
5646 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5648 /* skip hidden raid components */
5649 if (sas_device_priv_data
->sas_target
->flags
&
5650 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5653 if (sas_device_priv_data
->sas_target
->flags
&
5654 MPT_TARGET_FLAGS_VOLUME
)
5657 handle
= sas_device_priv_data
->sas_target
->handle
;
5658 lun
= sas_device_priv_data
->lun
;
5661 if (ioc
->shost_recovery
)
5664 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5665 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5666 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
5669 sdev_printk(KERN_WARNING
, sdev
,
5670 "mpt3sas_scsih_issue_tm: FAILED when sending "
5671 "QUERY_TASK: scmd(%p)\n", scmd
);
5672 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5673 goto broadcast_aen_retry
;
5675 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5676 & MPI2_IOCSTATUS_MASK
;
5677 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5678 sdev_printk(KERN_WARNING
, sdev
,
5679 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5681 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5682 goto broadcast_aen_retry
;
5685 /* see if IO is still owned by IOC and target */
5686 if (mpi_reply
->ResponseCode
==
5687 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5688 mpi_reply
->ResponseCode
==
5689 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5690 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5693 task_abort_retries
= 0;
5695 if (task_abort_retries
++ == 60) {
5696 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5697 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5699 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5700 goto broadcast_aen_retry
;
5703 if (ioc
->shost_recovery
)
5706 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5707 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5710 sdev_printk(KERN_WARNING
, sdev
,
5711 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5712 "scmd(%p)\n", scmd
);
5716 if (task_abort_retries
> 1)
5717 sdev_printk(KERN_WARNING
, sdev
,
5718 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5720 task_abort_retries
- 1, scmd
);
5722 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5723 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5726 if (ioc
->broadcast_aen_pending
) {
5727 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5728 "%s: loop back due to pending AEN\n",
5729 ioc
->name
, __func__
));
5730 ioc
->broadcast_aen_pending
= 0;
5731 goto broadcast_aen_retry
;
5735 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5738 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5739 "%s - exit, query_count = %d termination_count = %d\n",
5740 ioc
->name
, __func__
, query_count
, termination_count
));
5742 ioc
->broadcast_aen_busy
= 0;
5743 if (!ioc
->shost_recovery
)
5744 _scsih_ublock_io_all_device(ioc
);
5745 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5749 * _scsih_sas_discovery_event - handle discovery events
5750 * @ioc: per adapter object
5751 * @fw_event: The fw_event_work object
5757 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
5758 struct fw_event_work
*fw_event
)
5760 Mpi2EventDataSasDiscovery_t
*event_data
=
5761 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
5763 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5764 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5765 pr_info(MPT3SAS_FMT
"discovery event: (%s)", ioc
->name
,
5766 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5768 if (event_data
->DiscoveryStatus
)
5769 pr_info("discovery_status(0x%08x)",
5770 le32_to_cpu(event_data
->DiscoveryStatus
));
5775 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5776 !ioc
->sas_hba
.num_phys
) {
5777 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
5778 /* Wait for the reset to complete */
5779 while (ioc
->shost_recovery
)
5782 _scsih_sas_host_add(ioc
);
5787 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5788 * @ioc: per adapter object
5789 * @handle: device handle for physical disk
5790 * @phys_disk_num: physical disk number
5792 * Return 0 for success, else failure.
5795 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
5797 Mpi2RaidActionRequest_t
*mpi_request
;
5798 Mpi2RaidActionReply_t
*mpi_reply
;
5806 mutex_lock(&ioc
->scsih_cmds
.mutex
);
5808 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
5809 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
5810 ioc
->name
, __func__
);
5814 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
5816 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
5818 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
5819 ioc
->name
, __func__
);
5820 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
5825 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5826 ioc
->scsih_cmds
.smid
= smid
;
5827 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
5829 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
5830 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
5831 mpi_request
->PhysDiskNum
= phys_disk_num
;
5833 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
"IR RAID_ACTION: turning fast "\
5834 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc
->name
,
5835 handle
, phys_disk_num
));
5837 init_completion(&ioc
->scsih_cmds
.done
);
5838 mpt3sas_base_put_smid_default(ioc
, smid
);
5839 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
5841 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
5842 pr_err(MPT3SAS_FMT
"%s: timeout\n",
5843 ioc
->name
, __func__
);
5844 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_RESET
))
5850 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
5852 mpi_reply
= ioc
->scsih_cmds
.reply
;
5853 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5854 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5855 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5858 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5859 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5860 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5861 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5862 "loginfo(0x%08x)!!!\n", ioc
->name
, ioc_status
,
5866 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
5867 "IR RAID_ACTION: completed successfully\n",
5872 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
5873 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
5876 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
5882 * _scsih_reprobe_lun - reprobing lun
5883 * @sdev: scsi device struct
5884 * @no_uld_attach: sdev->no_uld_attach flag setting
5888 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5891 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5892 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5893 sdev
->no_uld_attach
? "hidding" : "exposing");
5894 rc
= scsi_device_reprobe(sdev
);
5898 * _scsih_sas_volume_add - add new volume
5899 * @ioc: per adapter object
5900 * @element: IR config element data
5906 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
5907 Mpi2EventIrConfigElement_t
*element
)
5909 struct _raid_device
*raid_device
;
5910 unsigned long flags
;
5912 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5915 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5918 "failure at %s:%d/%s()!\n", ioc
->name
,
5919 __FILE__
, __LINE__
, __func__
);
5923 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5924 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5925 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5930 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5933 "failure at %s:%d/%s()!\n", ioc
->name
,
5934 __FILE__
, __LINE__
, __func__
);
5938 raid_device
->id
= ioc
->sas_id
++;
5939 raid_device
->channel
= RAID_CHANNEL
;
5940 raid_device
->handle
= handle
;
5941 raid_device
->wwid
= wwid
;
5942 _scsih_raid_device_add(ioc
, raid_device
);
5943 if (!ioc
->wait_for_discovery_to_complete
) {
5944 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5945 raid_device
->id
, 0);
5947 _scsih_raid_device_remove(ioc
, raid_device
);
5949 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5950 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5951 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5956 * _scsih_sas_volume_delete - delete volume
5957 * @ioc: per adapter object
5958 * @handle: volume device handle
5964 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5966 struct _raid_device
*raid_device
;
5967 unsigned long flags
;
5968 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5969 struct scsi_target
*starget
= NULL
;
5971 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5972 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5974 if (raid_device
->starget
) {
5975 starget
= raid_device
->starget
;
5976 sas_target_priv_data
= starget
->hostdata
;
5977 sas_target_priv_data
->deleted
= 1;
5979 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
5980 ioc
->name
, raid_device
->handle
,
5981 (unsigned long long) raid_device
->wwid
);
5982 list_del(&raid_device
->list
);
5985 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5987 scsi_remove_target(&starget
->dev
);
5991 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5992 * @ioc: per adapter object
5993 * @element: IR config element data
5999 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
6000 Mpi2EventIrConfigElement_t
*element
)
6002 struct _sas_device
*sas_device
;
6003 struct scsi_target
*starget
= NULL
;
6004 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6005 unsigned long flags
;
6006 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6008 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6009 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6011 sas_device
->volume_handle
= 0;
6012 sas_device
->volume_wwid
= 0;
6013 clear_bit(handle
, ioc
->pd_handles
);
6014 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6015 starget
= sas_device
->starget
;
6016 sas_target_priv_data
= starget
->hostdata
;
6017 sas_target_priv_data
->flags
&=
6018 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6021 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6025 /* exposing raid component */
6027 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6031 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6032 * @ioc: per adapter object
6033 * @element: IR config element data
6039 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
6040 Mpi2EventIrConfigElement_t
*element
)
6042 struct _sas_device
*sas_device
;
6043 struct scsi_target
*starget
= NULL
;
6044 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6045 unsigned long flags
;
6046 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6047 u16 volume_handle
= 0;
6048 u64 volume_wwid
= 0;
6050 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6052 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
6055 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6056 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6058 set_bit(handle
, ioc
->pd_handles
);
6059 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6060 starget
= sas_device
->starget
;
6061 sas_target_priv_data
= starget
->hostdata
;
6062 sas_target_priv_data
->flags
|=
6063 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6064 sas_device
->volume_handle
= volume_handle
;
6065 sas_device
->volume_wwid
= volume_wwid
;
6068 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6072 /* hiding raid component */
6073 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6075 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6079 * _scsih_sas_pd_delete - delete pd component
6080 * @ioc: per adapter object
6081 * @element: IR config element data
6087 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
6088 Mpi2EventIrConfigElement_t
*element
)
6090 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6092 _scsih_device_remove_by_handle(ioc
, handle
);
6096 * _scsih_sas_pd_add - remove pd component
6097 * @ioc: per adapter object
6098 * @element: IR config element data
6104 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
6105 Mpi2EventIrConfigElement_t
*element
)
6107 struct _sas_device
*sas_device
;
6108 unsigned long flags
;
6109 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6110 Mpi2ConfigReply_t mpi_reply
;
6111 Mpi2SasDevicePage0_t sas_device_pg0
;
6116 set_bit(handle
, ioc
->pd_handles
);
6118 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6119 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6120 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6122 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6126 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6127 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6128 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6129 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6133 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6134 MPI2_IOCSTATUS_MASK
;
6135 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6136 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6137 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6141 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6142 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6143 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6144 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6146 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
6147 _scsih_add_device(ioc
, handle
, 0, 1);
6150 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6152 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6153 * @ioc: per adapter object
6154 * @event_data: event data payload
6160 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6161 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6163 Mpi2EventIrConfigElement_t
*element
;
6166 char *reason_str
= NULL
, *element_str
= NULL
;
6168 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6170 pr_info(MPT3SAS_FMT
"raid config change: (%s), elements(%d)\n",
6171 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6172 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6173 "foreign" : "native", event_data
->NumElements
);
6174 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6175 switch (element
->ReasonCode
) {
6176 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6179 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6180 reason_str
= "remove";
6182 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6183 reason_str
= "no change";
6185 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6186 reason_str
= "hide";
6188 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6189 reason_str
= "unhide";
6191 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6192 reason_str
= "volume_created";
6194 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6195 reason_str
= "volume_deleted";
6197 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6198 reason_str
= "pd_created";
6200 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6201 reason_str
= "pd_deleted";
6204 reason_str
= "unknown reason";
6207 element_type
= le16_to_cpu(element
->ElementFlags
) &
6208 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6209 switch (element_type
) {
6210 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6211 element_str
= "volume";
6213 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6214 element_str
= "phys disk";
6216 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6217 element_str
= "hot spare";
6220 element_str
= "unknown element";
6223 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6224 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6225 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6226 le16_to_cpu(element
->PhysDiskDevHandle
),
6227 element
->PhysDiskNum
);
6233 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6234 * @ioc: per adapter object
6235 * @fw_event: The fw_event_work object
6241 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6242 struct fw_event_work
*fw_event
)
6244 Mpi2EventIrConfigElement_t
*element
;
6247 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6248 (Mpi2EventDataIrConfigChangeList_t
*)
6249 fw_event
->event_data
;
6251 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6252 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6253 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6257 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6258 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6260 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6261 if (ioc
->shost_recovery
) {
6263 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6264 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
6265 _scsih_ir_fastpath(ioc
,
6266 le16_to_cpu(element
->PhysDiskDevHandle
),
6267 element
->PhysDiskNum
);
6271 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6273 switch (element
->ReasonCode
) {
6274 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6275 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6276 if (!foreign_config
)
6277 _scsih_sas_volume_add(ioc
, element
);
6279 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6280 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6281 if (!foreign_config
)
6282 _scsih_sas_volume_delete(ioc
,
6283 le16_to_cpu(element
->VolDevHandle
));
6285 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6286 _scsih_sas_pd_hide(ioc
, element
);
6288 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6289 _scsih_sas_pd_expose(ioc
, element
);
6291 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6292 _scsih_sas_pd_add(ioc
, element
);
6294 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6295 _scsih_sas_pd_delete(ioc
, element
);
6302 * _scsih_sas_ir_volume_event - IR volume event
6303 * @ioc: per adapter object
6304 * @fw_event: The fw_event_work object
6310 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
6311 struct fw_event_work
*fw_event
)
6314 unsigned long flags
;
6315 struct _raid_device
*raid_device
;
6319 Mpi2EventDataIrVolume_t
*event_data
=
6320 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
6322 if (ioc
->shost_recovery
)
6325 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6328 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6329 state
= le32_to_cpu(event_data
->NewValue
);
6330 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6331 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6332 ioc
->name
, __func__
, handle
,
6333 le32_to_cpu(event_data
->PreviousValue
), state
));
6335 case MPI2_RAID_VOL_STATE_MISSING
:
6336 case MPI2_RAID_VOL_STATE_FAILED
:
6337 _scsih_sas_volume_delete(ioc
, handle
);
6340 case MPI2_RAID_VOL_STATE_ONLINE
:
6341 case MPI2_RAID_VOL_STATE_DEGRADED
:
6342 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6344 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6345 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6346 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6351 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6354 "failure at %s:%d/%s()!\n", ioc
->name
,
6355 __FILE__
, __LINE__
, __func__
);
6359 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6362 "failure at %s:%d/%s()!\n", ioc
->name
,
6363 __FILE__
, __LINE__
, __func__
);
6367 raid_device
->id
= ioc
->sas_id
++;
6368 raid_device
->channel
= RAID_CHANNEL
;
6369 raid_device
->handle
= handle
;
6370 raid_device
->wwid
= wwid
;
6371 _scsih_raid_device_add(ioc
, raid_device
);
6372 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6373 raid_device
->id
, 0);
6375 _scsih_raid_device_remove(ioc
, raid_device
);
6378 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6385 * _scsih_sas_ir_physical_disk_event - PD event
6386 * @ioc: per adapter object
6387 * @fw_event: The fw_event_work object
6393 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
6394 struct fw_event_work
*fw_event
)
6396 u16 handle
, parent_handle
;
6398 struct _sas_device
*sas_device
;
6399 unsigned long flags
;
6400 Mpi2ConfigReply_t mpi_reply
;
6401 Mpi2SasDevicePage0_t sas_device_pg0
;
6403 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6404 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
6407 if (ioc
->shost_recovery
)
6410 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6413 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6414 state
= le32_to_cpu(event_data
->NewValue
);
6416 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
6417 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6418 ioc
->name
, __func__
, handle
,
6419 le32_to_cpu(event_data
->PreviousValue
), state
));
6421 case MPI2_RAID_PD_STATE_ONLINE
:
6422 case MPI2_RAID_PD_STATE_DEGRADED
:
6423 case MPI2_RAID_PD_STATE_REBUILDING
:
6424 case MPI2_RAID_PD_STATE_OPTIMAL
:
6425 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6427 set_bit(handle
, ioc
->pd_handles
);
6428 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6429 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6430 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6435 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6436 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6438 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6439 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6443 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6444 MPI2_IOCSTATUS_MASK
;
6445 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6446 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6447 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6451 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6452 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6453 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
6454 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6456 _scsih_add_device(ioc
, handle
, 0, 1);
6460 case MPI2_RAID_PD_STATE_OFFLINE
:
6461 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6462 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6468 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6470 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6471 * @ioc: per adapter object
6472 * @event_data: event data payload
6478 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6479 Mpi2EventDataIrOperationStatus_t
*event_data
)
6481 char *reason_str
= NULL
;
6483 switch (event_data
->RAIDOperation
) {
6484 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6485 reason_str
= "resync";
6487 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6488 reason_str
= "online capacity expansion";
6490 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6491 reason_str
= "consistency check";
6493 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6494 reason_str
= "background init";
6496 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6497 reason_str
= "make data consistent";
6504 pr_info(MPT3SAS_FMT
"raid operational status: (%s)" \
6505 "\thandle(0x%04x), percent complete(%d)\n",
6506 ioc
->name
, reason_str
,
6507 le16_to_cpu(event_data
->VolDevHandle
),
6508 event_data
->PercentComplete
);
6513 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6514 * @ioc: per adapter object
6515 * @fw_event: The fw_event_work object
6521 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
6522 struct fw_event_work
*fw_event
)
6524 Mpi2EventDataIrOperationStatus_t
*event_data
=
6525 (Mpi2EventDataIrOperationStatus_t
*)
6526 fw_event
->event_data
;
6527 static struct _raid_device
*raid_device
;
6528 unsigned long flags
;
6531 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6532 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6533 _scsih_sas_ir_operation_status_event_debug(ioc
,
6537 /* code added for raid transport support */
6538 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6540 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6541 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6542 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6544 raid_device
->percent_complete
=
6545 event_data
->PercentComplete
;
6546 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6551 * _scsih_prep_device_scan - initialize parameters prior to device scan
6552 * @ioc: per adapter object
6554 * Set the deleted flag prior to device scan. If the device is found during
6555 * the scan, then we clear the deleted flag.
6558 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
6560 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
6561 struct scsi_device
*sdev
;
6563 shost_for_each_device(sdev
, ioc
->shost
) {
6564 sas_device_priv_data
= sdev
->hostdata
;
6565 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6566 sas_device_priv_data
->sas_target
->deleted
= 1;
6571 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6572 * @ioc: per adapter object
6573 * @sas_device_pg0: SAS Device page 0
6575 * After host reset, find out whether devices are still responding.
6576 * Used in _scsih_remove_unresponsive_sas_devices.
6581 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
6582 Mpi2SasDevicePage0_t
*sas_device_pg0
)
6584 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
6585 struct scsi_target
*starget
;
6586 struct _sas_device
*sas_device
;
6587 unsigned long flags
;
6589 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6590 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6591 if ((sas_device
->sas_address
== sas_device_pg0
->SASAddress
) &&
6592 (sas_device
->slot
== sas_device_pg0
->Slot
)) {
6593 sas_device
->responding
= 1;
6594 starget
= sas_device
->starget
;
6595 if (starget
&& starget
->hostdata
) {
6596 sas_target_priv_data
= starget
->hostdata
;
6597 sas_target_priv_data
->tm_busy
= 0;
6598 sas_target_priv_data
->deleted
= 0;
6600 sas_target_priv_data
= NULL
;
6602 starget_printk(KERN_INFO
, starget
,
6603 "handle(0x%04x), sas_addr(0x%016llx)\n",
6604 sas_device_pg0
->DevHandle
,
6605 (unsigned long long)
6606 sas_device
->sas_address
);
6608 if (sas_device
->enclosure_handle
!= 0)
6609 starget_printk(KERN_INFO
, starget
,
6610 "enclosure logical id(0x%016llx),"
6612 (unsigned long long)
6613 sas_device
->enclosure_logical_id
,
6616 if (sas_device_pg0
->Flags
&
6617 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6618 sas_device
->enclosure_level
=
6619 le16_to_cpu(sas_device_pg0
->EnclosureLevel
);
6620 memcpy(&sas_device
->connector_name
[0],
6621 &sas_device_pg0
->ConnectorName
[0], 4);
6623 sas_device
->enclosure_level
= 0;
6624 sas_device
->connector_name
[0] = '\0';
6627 if (sas_device
->handle
== sas_device_pg0
->DevHandle
)
6629 pr_info("\thandle changed from(0x%04x)!!!\n",
6630 sas_device
->handle
);
6631 sas_device
->handle
= sas_device_pg0
->DevHandle
;
6632 if (sas_target_priv_data
)
6633 sas_target_priv_data
->handle
=
6634 sas_device_pg0
->DevHandle
;
6639 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6643 * _scsih_search_responding_sas_devices -
6644 * @ioc: per adapter object
6646 * After host reset, find out whether devices are still responding.
6652 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
6654 Mpi2SasDevicePage0_t sas_device_pg0
;
6655 Mpi2ConfigReply_t mpi_reply
;
6660 pr_info(MPT3SAS_FMT
"search for end-devices: start\n", ioc
->name
);
6662 if (list_empty(&ioc
->sas_device_list
))
6666 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6667 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6669 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6670 MPI2_IOCSTATUS_MASK
;
6671 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6673 handle
= sas_device_pg0
.DevHandle
=
6674 le16_to_cpu(sas_device_pg0
.DevHandle
);
6675 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6676 if (!(_scsih_is_end_device(device_info
)))
6678 sas_device_pg0
.SASAddress
=
6679 le64_to_cpu(sas_device_pg0
.SASAddress
);
6680 sas_device_pg0
.Slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6681 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
6685 pr_info(MPT3SAS_FMT
"search for end-devices: complete\n",
6690 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6691 * @ioc: per adapter object
6692 * @wwid: world wide identifier for raid volume
6693 * @handle: device handle
6695 * After host reset, find out whether devices are still responding.
6696 * Used in _scsih_remove_unresponsive_raid_devices.
6701 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6704 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6705 struct scsi_target
*starget
;
6706 struct _raid_device
*raid_device
;
6707 unsigned long flags
;
6709 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6710 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6711 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6712 starget
= raid_device
->starget
;
6713 if (starget
&& starget
->hostdata
) {
6714 sas_target_priv_data
= starget
->hostdata
;
6715 sas_target_priv_data
->deleted
= 0;
6717 sas_target_priv_data
= NULL
;
6718 raid_device
->responding
= 1;
6719 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6720 starget_printk(KERN_INFO
, raid_device
->starget
,
6721 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6722 (unsigned long long)raid_device
->wwid
);
6723 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6724 if (raid_device
->handle
== handle
) {
6725 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
6729 pr_info("\thandle changed from(0x%04x)!!!\n",
6730 raid_device
->handle
);
6731 raid_device
->handle
= handle
;
6732 if (sas_target_priv_data
)
6733 sas_target_priv_data
->handle
= handle
;
6734 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6738 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6742 * _scsih_search_responding_raid_devices -
6743 * @ioc: per adapter object
6745 * After host reset, find out whether devices are still responding.
6751 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
6753 Mpi2RaidVolPage1_t volume_pg1
;
6754 Mpi2RaidVolPage0_t volume_pg0
;
6755 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6756 Mpi2ConfigReply_t mpi_reply
;
6761 if (!ioc
->ir_firmware
)
6764 pr_info(MPT3SAS_FMT
"search for raid volumes: start\n",
6767 if (list_empty(&ioc
->raid_device_list
))
6771 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6772 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6773 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6774 MPI2_IOCSTATUS_MASK
;
6775 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6777 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6779 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6780 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6781 sizeof(Mpi2RaidVolPage0_t
)))
6784 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6785 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6786 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6787 _scsih_mark_responding_raid_device(ioc
,
6788 le64_to_cpu(volume_pg1
.WWID
), handle
);
6791 /* refresh the pd_handles */
6792 phys_disk_num
= 0xFF;
6793 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6794 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6795 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6797 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6798 MPI2_IOCSTATUS_MASK
;
6799 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6801 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6802 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6803 set_bit(handle
, ioc
->pd_handles
);
6806 pr_info(MPT3SAS_FMT
"search for responding raid volumes: complete\n",
6811 * _scsih_mark_responding_expander - mark a expander as responding
6812 * @ioc: per adapter object
6813 * @sas_address: sas address
6816 * After host reset, find out whether devices are still responding.
6817 * Used in _scsih_remove_unresponsive_expanders.
6822 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
6825 struct _sas_node
*sas_expander
;
6826 unsigned long flags
;
6829 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6830 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6831 if (sas_expander
->sas_address
!= sas_address
)
6833 sas_expander
->responding
= 1;
6834 if (sas_expander
->handle
== handle
)
6836 pr_info("\texpander(0x%016llx): handle changed" \
6837 " from(0x%04x) to (0x%04x)!!!\n",
6838 (unsigned long long)sas_expander
->sas_address
,
6839 sas_expander
->handle
, handle
);
6840 sas_expander
->handle
= handle
;
6841 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6842 sas_expander
->phy
[i
].handle
= handle
;
6846 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6850 * _scsih_search_responding_expanders -
6851 * @ioc: per adapter object
6853 * After host reset, find out whether devices are still responding.
6859 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
6861 Mpi2ExpanderPage0_t expander_pg0
;
6862 Mpi2ConfigReply_t mpi_reply
;
6867 pr_info(MPT3SAS_FMT
"search for expanders: start\n", ioc
->name
);
6869 if (list_empty(&ioc
->sas_expander_list
))
6873 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6874 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6876 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6877 MPI2_IOCSTATUS_MASK
;
6878 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6881 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6882 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6883 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6885 (unsigned long long)sas_address
);
6886 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6890 pr_info(MPT3SAS_FMT
"search for expanders: complete\n", ioc
->name
);
6894 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6895 * @ioc: per adapter object
6900 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
6902 struct _sas_device
*sas_device
, *sas_device_next
;
6903 struct _sas_node
*sas_expander
, *sas_expander_next
;
6904 struct _raid_device
*raid_device
, *raid_device_next
;
6905 struct list_head tmp_list
;
6906 unsigned long flags
;
6908 pr_info(MPT3SAS_FMT
"removing unresponding devices: start\n",
6911 /* removing unresponding end devices */
6912 pr_info(MPT3SAS_FMT
"removing unresponding devices: end-devices\n",
6914 list_for_each_entry_safe(sas_device
, sas_device_next
,
6915 &ioc
->sas_device_list
, list
) {
6916 if (!sas_device
->responding
)
6917 mpt3sas_device_remove_by_sas_address(ioc
,
6918 sas_device
->sas_address
);
6920 sas_device
->responding
= 0;
6923 /* removing unresponding volumes */
6924 if (ioc
->ir_firmware
) {
6925 pr_info(MPT3SAS_FMT
"removing unresponding devices: volumes\n",
6927 list_for_each_entry_safe(raid_device
, raid_device_next
,
6928 &ioc
->raid_device_list
, list
) {
6929 if (!raid_device
->responding
)
6930 _scsih_sas_volume_delete(ioc
,
6931 raid_device
->handle
);
6933 raid_device
->responding
= 0;
6937 /* removing unresponding expanders */
6938 pr_info(MPT3SAS_FMT
"removing unresponding devices: expanders\n",
6940 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6941 INIT_LIST_HEAD(&tmp_list
);
6942 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
6943 &ioc
->sas_expander_list
, list
) {
6944 if (!sas_expander
->responding
)
6945 list_move_tail(&sas_expander
->list
, &tmp_list
);
6947 sas_expander
->responding
= 0;
6949 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6950 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
6952 list_del(&sas_expander
->list
);
6953 _scsih_expander_node_remove(ioc
, sas_expander
);
6956 pr_info(MPT3SAS_FMT
"removing unresponding devices: complete\n",
6959 /* unblock devices */
6960 _scsih_ublock_io_all_device(ioc
);
6964 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
6965 struct _sas_node
*sas_expander
, u16 handle
)
6967 Mpi2ExpanderPage1_t expander_pg1
;
6968 Mpi2ConfigReply_t mpi_reply
;
6971 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
6972 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
6973 &expander_pg1
, i
, handle
))) {
6974 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
6975 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6979 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
6980 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
6981 expander_pg1
.NegotiatedLinkRate
>> 4);
6986 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6987 * @ioc: per adapter object
6992 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
6994 Mpi2ExpanderPage0_t expander_pg0
;
6995 Mpi2SasDevicePage0_t sas_device_pg0
;
6996 Mpi2RaidVolPage1_t volume_pg1
;
6997 Mpi2RaidVolPage0_t volume_pg0
;
6998 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6999 Mpi2EventIrConfigElement_t element
;
7000 Mpi2ConfigReply_t mpi_reply
;
7003 u16 handle
, parent_handle
;
7005 struct _sas_device
*sas_device
;
7006 struct _sas_node
*expander_device
;
7007 static struct _raid_device
*raid_device
;
7009 unsigned long flags
;
7011 pr_info(MPT3SAS_FMT
"scan devices: start\n", ioc
->name
);
7013 _scsih_sas_host_refresh(ioc
);
7015 pr_info(MPT3SAS_FMT
"\tscan devices: expanders start\n", ioc
->name
);
7019 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7020 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7021 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7022 MPI2_IOCSTATUS_MASK
;
7023 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7024 pr_info(MPT3SAS_FMT
"\tbreak from expander scan: " \
7025 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7026 ioc
->name
, ioc_status
,
7027 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7030 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7031 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7032 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
7033 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7034 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7035 if (expander_device
)
7036 _scsih_refresh_expander_links(ioc
, expander_device
,
7039 pr_info(MPT3SAS_FMT
"\tBEFORE adding expander: " \
7040 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7041 handle
, (unsigned long long)
7042 le64_to_cpu(expander_pg0
.SASAddress
));
7043 _scsih_expander_add(ioc
, handle
);
7044 pr_info(MPT3SAS_FMT
"\tAFTER adding expander: " \
7045 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7046 handle
, (unsigned long long)
7047 le64_to_cpu(expander_pg0
.SASAddress
));
7051 pr_info(MPT3SAS_FMT
"\tscan devices: expanders complete\n",
7054 if (!ioc
->ir_firmware
)
7057 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk start\n", ioc
->name
);
7060 phys_disk_num
= 0xFF;
7061 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7062 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7064 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7065 MPI2_IOCSTATUS_MASK
;
7066 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7067 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan: "\
7068 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7069 ioc
->name
, ioc_status
,
7070 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7073 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7074 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7075 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7076 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
7077 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7080 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7081 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7084 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7085 MPI2_IOCSTATUS_MASK
;
7086 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7087 pr_info(MPT3SAS_FMT
"\tbreak from phys disk scan " \
7088 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7089 ioc
->name
, ioc_status
,
7090 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7093 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7094 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7096 pr_info(MPT3SAS_FMT
"\tBEFORE adding phys disk: " \
7097 " handle (0x%04x), sas_addr(0x%016llx)\n",
7098 ioc
->name
, handle
, (unsigned long long)
7099 le64_to_cpu(sas_device_pg0
.SASAddress
));
7100 mpt3sas_transport_update_links(ioc
, sas_address
,
7101 handle
, sas_device_pg0
.PhyNum
,
7102 MPI2_SAS_NEG_LINK_RATE_1_5
);
7103 set_bit(handle
, ioc
->pd_handles
);
7105 /* This will retry adding the end device.
7106 * _scsih_add_device() will decide on retries and
7107 * return "1" when it should be retried
7109 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7113 pr_info(MPT3SAS_FMT
"\tAFTER adding phys disk: " \
7114 " handle (0x%04x), sas_addr(0x%016llx)\n",
7115 ioc
->name
, handle
, (unsigned long long)
7116 le64_to_cpu(sas_device_pg0
.SASAddress
));
7120 pr_info(MPT3SAS_FMT
"\tscan devices: phys disk complete\n",
7123 pr_info(MPT3SAS_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7127 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7128 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7129 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7130 MPI2_IOCSTATUS_MASK
;
7131 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7132 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7133 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7134 ioc
->name
, ioc_status
,
7135 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7138 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7139 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7140 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7141 le64_to_cpu(volume_pg1
.WWID
));
7142 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7145 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7146 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7147 sizeof(Mpi2RaidVolPage0_t
)))
7149 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7150 MPI2_IOCSTATUS_MASK
;
7151 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7152 pr_info(MPT3SAS_FMT
"\tbreak from volume scan: " \
7153 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7154 ioc
->name
, ioc_status
,
7155 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7158 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7159 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7160 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7161 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7162 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7163 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7165 "\tBEFORE adding volume: handle (0x%04x)\n",
7166 ioc
->name
, volume_pg1
.DevHandle
);
7167 _scsih_sas_volume_add(ioc
, &element
);
7169 "\tAFTER adding volume: handle (0x%04x)\n",
7170 ioc
->name
, volume_pg1
.DevHandle
);
7174 pr_info(MPT3SAS_FMT
"\tscan devices: volumes complete\n",
7179 pr_info(MPT3SAS_FMT
"\tscan devices: end devices start\n",
7184 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7185 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7187 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7188 MPI2_IOCSTATUS_MASK
;
7189 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7190 pr_info(MPT3SAS_FMT
"\tbreak from end device scan:"\
7191 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7192 ioc
->name
, ioc_status
,
7193 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7196 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7197 if (!(_scsih_is_end_device(
7198 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7200 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7201 sas_device
= mpt3sas_scsih_sas_device_find_by_sas_address(ioc
,
7202 le64_to_cpu(sas_device_pg0
.SASAddress
));
7203 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7206 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7207 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7208 pr_info(MPT3SAS_FMT
"\tBEFORE adding end device: " \
7209 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7210 handle
, (unsigned long long)
7211 le64_to_cpu(sas_device_pg0
.SASAddress
));
7212 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7213 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7215 /* This will retry adding the end device.
7216 * _scsih_add_device() will decide on retries and
7217 * return "1" when it should be retried
7219 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7223 pr_info(MPT3SAS_FMT
"\tAFTER adding end device: " \
7224 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7225 handle
, (unsigned long long)
7226 le64_to_cpu(sas_device_pg0
.SASAddress
));
7229 pr_info(MPT3SAS_FMT
"\tscan devices: end devices complete\n",
7232 pr_info(MPT3SAS_FMT
"scan devices: complete\n", ioc
->name
);
7235 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7236 * @ioc: per adapter object
7237 * @reset_phase: phase
7239 * The handler for doing any required cleanup or initialization.
7241 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7242 * MPT3_IOC_DONE_RESET
7247 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
7249 switch (reset_phase
) {
7250 case MPT3_IOC_PRE_RESET
:
7251 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7252 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7254 case MPT3_IOC_AFTER_RESET
:
7255 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7256 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7257 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
7258 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
7259 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7260 complete(&ioc
->scsih_cmds
.done
);
7262 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
7263 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
7264 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7265 complete(&ioc
->tm_cmds
.done
);
7268 _scsih_fw_event_cleanup_queue(ioc
);
7269 _scsih_flush_running_cmds(ioc
);
7271 case MPT3_IOC_DONE_RESET
:
7272 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
7273 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7274 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7275 !ioc
->sas_hba
.num_phys
)) {
7276 _scsih_prep_device_scan(ioc
);
7277 _scsih_search_responding_sas_devices(ioc
);
7278 _scsih_search_responding_raid_devices(ioc
);
7279 _scsih_search_responding_expanders(ioc
);
7280 _scsih_error_recovery_delete_devices(ioc
);
7287 * _mpt3sas_fw_work - delayed task for processing firmware events
7288 * @ioc: per adapter object
7289 * @fw_event: The fw_event_work object
7295 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
7297 /* the queue is being flushed so ignore this event */
7298 if (ioc
->remove_host
||
7299 ioc
->pci_error_recovery
) {
7300 _scsih_fw_event_free(ioc
, fw_event
);
7304 switch (fw_event
->event
) {
7305 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
7306 mpt3sas_process_trigger_data(ioc
,
7307 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
7308 fw_event
->event_data
);
7310 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
7311 while (scsi_host_in_recovery(ioc
->shost
) || ioc
->shost_recovery
)
7313 _scsih_remove_unresponding_sas_devices(ioc
);
7314 _scsih_scan_for_devices_after_reset(ioc
);
7316 case MPT3SAS_PORT_ENABLE_COMPLETE
:
7317 ioc
->start_scan
= 0;
7318 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7319 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
7321 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
7322 "port enable: complete from worker thread\n",
7325 case MPT3SAS_TURN_ON_PFA_LED
:
7326 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7328 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7329 _scsih_sas_topology_change_event(ioc
, fw_event
);
7331 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7332 _scsih_sas_device_status_change_event(ioc
, fw_event
);
7334 case MPI2_EVENT_SAS_DISCOVERY
:
7335 _scsih_sas_discovery_event(ioc
, fw_event
);
7337 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7338 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
7340 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7341 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7344 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7345 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7347 case MPI2_EVENT_IR_VOLUME
:
7348 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7350 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7351 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7353 case MPI2_EVENT_IR_OPERATION_STATUS
:
7354 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7357 _scsih_fw_event_free(ioc
, fw_event
);
7361 * _firmware_event_work
7362 * @ioc: per adapter object
7363 * @work: The fw_event_work object
7366 * wrappers for the work thread handling firmware events
7372 _firmware_event_work(struct work_struct
*work
)
7374 struct fw_event_work
*fw_event
= container_of(work
,
7375 struct fw_event_work
, work
);
7377 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
7381 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7382 * @ioc: per adapter object
7383 * @msix_index: MSIX table index supplied by the OS
7384 * @reply: reply message frame(lower 32bit addr)
7385 * Context: interrupt.
7387 * This function merely adds a new work task into ioc->firmware_event_thread.
7388 * The tasks are worked from _firmware_event_work in user context.
7390 * Return 1 meaning mf should be freed from _base_interrupt
7391 * 0 means the mf is freed from this function.
7394 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
7397 struct fw_event_work
*fw_event
;
7398 Mpi2EventNotificationReply_t
*mpi_reply
;
7402 /* events turned off due to host reset or driver unloading */
7403 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7406 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
7408 if (unlikely(!mpi_reply
)) {
7409 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7410 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7414 event
= le16_to_cpu(mpi_reply
->Event
);
7416 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
7417 mpt3sas_trigger_event(ioc
, event
, 0);
7421 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7423 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7424 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7425 mpi_reply
->EventData
;
7427 if (baen_data
->Primitive
!=
7428 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7431 if (ioc
->broadcast_aen_busy
) {
7432 ioc
->broadcast_aen_pending
++;
7435 ioc
->broadcast_aen_busy
= 1;
7439 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7440 _scsih_check_topo_delete_events(ioc
,
7441 (Mpi2EventDataSasTopologyChangeList_t
*)
7442 mpi_reply
->EventData
);
7444 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7445 _scsih_check_ir_config_unhide_events(ioc
,
7446 (Mpi2EventDataIrConfigChangeList_t
*)
7447 mpi_reply
->EventData
);
7449 case MPI2_EVENT_IR_VOLUME
:
7450 _scsih_check_volume_delete_events(ioc
,
7451 (Mpi2EventDataIrVolume_t
*)
7452 mpi_reply
->EventData
);
7455 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7456 case MPI2_EVENT_IR_OPERATION_STATUS
:
7457 case MPI2_EVENT_SAS_DISCOVERY
:
7458 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7459 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7462 case MPI2_EVENT_TEMP_THRESHOLD
:
7463 _scsih_temp_threshold_events(ioc
,
7464 (Mpi2EventDataTemperature_t
*)
7465 mpi_reply
->EventData
);
7468 default: /* ignore the rest */
7472 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7473 fw_event
= kzalloc(sizeof(*fw_event
) + sz
, GFP_ATOMIC
);
7475 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
7476 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7480 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
7481 fw_event
->ioc
= ioc
;
7482 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7483 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7484 fw_event
->event
= event
;
7485 _scsih_fw_event_add(ioc
, fw_event
);
7489 /* shost template */
7490 static struct scsi_host_template scsih_driver_template
= {
7491 .module
= THIS_MODULE
,
7492 .name
= "Fusion MPT SAS Host",
7493 .proc_name
= MPT3SAS_DRIVER_NAME
,
7494 .queuecommand
= scsih_qcmd
,
7495 .target_alloc
= scsih_target_alloc
,
7496 .slave_alloc
= scsih_slave_alloc
,
7497 .slave_configure
= scsih_slave_configure
,
7498 .target_destroy
= scsih_target_destroy
,
7499 .slave_destroy
= scsih_slave_destroy
,
7500 .scan_finished
= scsih_scan_finished
,
7501 .scan_start
= scsih_scan_start
,
7502 .change_queue_depth
= scsih_change_queue_depth
,
7503 .eh_abort_handler
= scsih_abort
,
7504 .eh_device_reset_handler
= scsih_dev_reset
,
7505 .eh_target_reset_handler
= scsih_target_reset
,
7506 .eh_host_reset_handler
= scsih_host_reset
,
7507 .bios_param
= scsih_bios_param
,
7510 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
7511 .max_sectors
= 32767,
7513 .use_clustering
= ENABLE_CLUSTERING
,
7514 .shost_attrs
= mpt3sas_host_attrs
,
7515 .sdev_attrs
= mpt3sas_dev_attrs
,
7516 .track_queue_depth
= 1,
7520 * _scsih_expander_node_remove - removing expander device from list.
7521 * @ioc: per adapter object
7522 * @sas_expander: the sas_device object
7523 * Context: Calling function should acquire ioc->sas_node_lock.
7525 * Removing object and freeing associated memory from the
7526 * ioc->sas_expander_list.
7531 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
7532 struct _sas_node
*sas_expander
)
7534 struct _sas_port
*mpt3sas_port
, *next
;
7536 /* remove sibling ports attached to this expander */
7537 list_for_each_entry_safe(mpt3sas_port
, next
,
7538 &sas_expander
->sas_port_list
, port_list
) {
7539 if (ioc
->shost_recovery
)
7541 if (mpt3sas_port
->remote_identify
.device_type
==
7543 mpt3sas_device_remove_by_sas_address(ioc
,
7544 mpt3sas_port
->remote_identify
.sas_address
);
7545 else if (mpt3sas_port
->remote_identify
.device_type
==
7546 SAS_EDGE_EXPANDER_DEVICE
||
7547 mpt3sas_port
->remote_identify
.device_type
==
7548 SAS_FANOUT_EXPANDER_DEVICE
)
7549 mpt3sas_expander_remove(ioc
,
7550 mpt3sas_port
->remote_identify
.sas_address
);
7553 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7554 sas_expander
->sas_address_parent
);
7557 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7559 sas_expander
->handle
, (unsigned long long)
7560 sas_expander
->sas_address
);
7562 kfree(sas_expander
->phy
);
7563 kfree(sas_expander
);
7567 * _scsih_ir_shutdown - IR shutdown notification
7568 * @ioc: per adapter object
7570 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7571 * the host system is shutting down.
7576 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
7578 Mpi2RaidActionRequest_t
*mpi_request
;
7579 Mpi2RaidActionReply_t
*mpi_reply
;
7582 /* is IR firmware build loaded ? */
7583 if (!ioc
->ir_firmware
)
7586 /* are there any volumes ? */
7587 if (list_empty(&ioc
->raid_device_list
))
7590 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7592 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7593 pr_err(MPT3SAS_FMT
"%s: scsih_cmd in use\n",
7594 ioc
->name
, __func__
);
7597 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7599 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7601 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
7602 ioc
->name
, __func__
);
7603 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7607 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7608 ioc
->scsih_cmds
.smid
= smid
;
7609 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7611 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7612 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7614 pr_info(MPT3SAS_FMT
"IR shutdown (sending)\n", ioc
->name
);
7615 init_completion(&ioc
->scsih_cmds
.done
);
7616 mpt3sas_base_put_smid_default(ioc
, smid
);
7617 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7619 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7620 pr_err(MPT3SAS_FMT
"%s: timeout\n",
7621 ioc
->name
, __func__
);
7625 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7626 mpi_reply
= ioc
->scsih_cmds
.reply
;
7628 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7629 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7630 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7634 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7635 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7639 * scsih_remove - detach and remove add host
7640 * @pdev: PCI device struct
7642 * Routine called when unloading the driver.
7645 void scsih_remove(struct pci_dev
*pdev
)
7647 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7648 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7649 struct _sas_port
*mpt3sas_port
, *next_port
;
7650 struct _raid_device
*raid_device
, *next
;
7651 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7652 struct workqueue_struct
*wq
;
7653 unsigned long flags
;
7655 ioc
->remove_host
= 1;
7656 _scsih_fw_event_cleanup_queue(ioc
);
7658 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7659 wq
= ioc
->firmware_event_thread
;
7660 ioc
->firmware_event_thread
= NULL
;
7661 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7663 destroy_workqueue(wq
);
7665 /* release all the volumes */
7666 _scsih_ir_shutdown(ioc
);
7667 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7669 if (raid_device
->starget
) {
7670 sas_target_priv_data
=
7671 raid_device
->starget
->hostdata
;
7672 sas_target_priv_data
->deleted
= 1;
7673 scsi_remove_target(&raid_device
->starget
->dev
);
7675 pr_info(MPT3SAS_FMT
"removing handle(0x%04x), wwid(0x%016llx)\n",
7676 ioc
->name
, raid_device
->handle
,
7677 (unsigned long long) raid_device
->wwid
);
7678 _scsih_raid_device_remove(ioc
, raid_device
);
7681 /* free ports attached to the sas_host */
7682 list_for_each_entry_safe(mpt3sas_port
, next_port
,
7683 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7684 if (mpt3sas_port
->remote_identify
.device_type
==
7686 mpt3sas_device_remove_by_sas_address(ioc
,
7687 mpt3sas_port
->remote_identify
.sas_address
);
7688 else if (mpt3sas_port
->remote_identify
.device_type
==
7689 SAS_EDGE_EXPANDER_DEVICE
||
7690 mpt3sas_port
->remote_identify
.device_type
==
7691 SAS_FANOUT_EXPANDER_DEVICE
)
7692 mpt3sas_expander_remove(ioc
,
7693 mpt3sas_port
->remote_identify
.sas_address
);
7696 /* free phys attached to the sas_host */
7697 if (ioc
->sas_hba
.num_phys
) {
7698 kfree(ioc
->sas_hba
.phy
);
7699 ioc
->sas_hba
.phy
= NULL
;
7700 ioc
->sas_hba
.num_phys
= 0;
7703 sas_remove_host(shost
);
7704 scsi_remove_host(shost
);
7705 mpt3sas_base_detach(ioc
);
7706 list_del(&ioc
->list
);
7707 scsi_host_put(shost
);
7711 * scsih_shutdown - routine call during system shutdown
7712 * @pdev: PCI device struct
7717 scsih_shutdown(struct pci_dev
*pdev
)
7719 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7720 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7721 struct workqueue_struct
*wq
;
7722 unsigned long flags
;
7724 ioc
->remove_host
= 1;
7725 _scsih_fw_event_cleanup_queue(ioc
);
7727 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7728 wq
= ioc
->firmware_event_thread
;
7729 ioc
->firmware_event_thread
= NULL
;
7730 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7732 destroy_workqueue(wq
);
7734 _scsih_ir_shutdown(ioc
);
7735 mpt3sas_base_detach(ioc
);
7740 * _scsih_probe_boot_devices - reports 1st device
7741 * @ioc: per adapter object
7743 * If specified in bios page 2, this routine reports the 1st
7744 * device scsi-ml or sas transport for persistent boot device
7745 * purposes. Please refer to function _scsih_determine_boot_device()
7748 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
7752 struct _sas_device
*sas_device
;
7753 struct _raid_device
*raid_device
;
7755 u64 sas_address_parent
;
7757 unsigned long flags
;
7760 /* no Bios, return immediately */
7761 if (!ioc
->bios_pg3
.BiosVersion
)
7766 if (ioc
->req_boot_device
.device
) {
7767 device
= ioc
->req_boot_device
.device
;
7768 is_raid
= ioc
->req_boot_device
.is_raid
;
7769 } else if (ioc
->req_alt_boot_device
.device
) {
7770 device
= ioc
->req_alt_boot_device
.device
;
7771 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7772 } else if (ioc
->current_boot_device
.device
) {
7773 device
= ioc
->current_boot_device
.device
;
7774 is_raid
= ioc
->current_boot_device
.is_raid
;
7781 raid_device
= device
;
7782 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7783 raid_device
->id
, 0);
7785 _scsih_raid_device_remove(ioc
, raid_device
);
7787 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7788 sas_device
= device
;
7789 handle
= sas_device
->handle
;
7790 sas_address_parent
= sas_device
->sas_address_parent
;
7791 sas_address
= sas_device
->sas_address
;
7792 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7793 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7795 if (!mpt3sas_transport_port_add(ioc
, handle
,
7796 sas_address_parent
)) {
7797 _scsih_sas_device_remove(ioc
, sas_device
);
7798 } else if (!sas_device
->starget
) {
7799 if (!ioc
->is_driver_loading
) {
7800 mpt3sas_transport_port_remove(ioc
,
7802 sas_address_parent
);
7803 _scsih_sas_device_remove(ioc
, sas_device
);
7810 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7811 * @ioc: per adapter object
7813 * Called during initial loading of the driver.
7816 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
7818 struct _raid_device
*raid_device
, *raid_next
;
7821 list_for_each_entry_safe(raid_device
, raid_next
,
7822 &ioc
->raid_device_list
, list
) {
7823 if (raid_device
->starget
)
7825 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7826 raid_device
->id
, 0);
7828 _scsih_raid_device_remove(ioc
, raid_device
);
7833 * _scsih_probe_sas - reporting sas devices to sas transport
7834 * @ioc: per adapter object
7836 * Called during initial loading of the driver.
7839 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
7841 struct _sas_device
*sas_device
, *next
;
7842 unsigned long flags
;
7844 /* SAS Device List */
7845 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
7848 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
7849 sas_device
->sas_address_parent
)) {
7850 list_del(&sas_device
->list
);
7853 } else if (!sas_device
->starget
) {
7855 * When asyn scanning is enabled, its not possible to
7856 * remove devices while scanning is turned on due to an
7857 * oops in scsi_sysfs_add_sdev()->add_device()->
7858 * sysfs_addrm_start()
7860 if (!ioc
->is_driver_loading
) {
7861 mpt3sas_transport_port_remove(ioc
,
7862 sas_device
->sas_address
,
7863 sas_device
->sas_address_parent
);
7864 list_del(&sas_device
->list
);
7870 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7871 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7872 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7877 * _scsih_probe_devices - probing for devices
7878 * @ioc: per adapter object
7880 * Called during initial loading of the driver.
7883 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
7885 u16 volume_mapping_flags
;
7887 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
7888 return; /* return when IOC doesn't support initiator mode */
7890 _scsih_probe_boot_devices(ioc
);
7892 if (ioc
->ir_firmware
) {
7893 volume_mapping_flags
=
7894 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
7895 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
7896 if (volume_mapping_flags
==
7897 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
7898 _scsih_probe_raid(ioc
);
7899 _scsih_probe_sas(ioc
);
7901 _scsih_probe_sas(ioc
);
7902 _scsih_probe_raid(ioc
);
7905 _scsih_probe_sas(ioc
);
7909 * scsih_scan_start - scsi lld callback for .scan_start
7910 * @shost: SCSI host pointer
7912 * The shost has the ability to discover targets on its own instead
7913 * of scanning the entire bus. In our implemention, we will kick off
7914 * firmware discovery.
7917 scsih_scan_start(struct Scsi_Host
*shost
)
7919 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7921 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
7922 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
7924 if (disable_discovery
> 0)
7927 ioc
->start_scan
= 1;
7928 rc
= mpt3sas_port_enable(ioc
);
7931 pr_info(MPT3SAS_FMT
"port enable: FAILED\n", ioc
->name
);
7935 * scsih_scan_finished - scsi lld callback for .scan_finished
7936 * @shost: SCSI host pointer
7937 * @time: elapsed time of the scan in jiffies
7939 * This function will be called periodicallyn until it returns 1 with the
7940 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7941 * we wait for firmware discovery to complete, then return 1.
7944 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
7946 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
7948 if (disable_discovery
> 0) {
7949 ioc
->is_driver_loading
= 0;
7950 ioc
->wait_for_discovery_to_complete
= 0;
7954 if (time
>= (300 * HZ
)) {
7955 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
7957 "port enable: FAILED with timeout (timeout=300s)\n",
7959 ioc
->is_driver_loading
= 0;
7963 if (ioc
->start_scan
)
7966 if (ioc
->start_scan_failed
) {
7968 "port enable: FAILED with (ioc_status=0x%08x)\n",
7969 ioc
->name
, ioc
->start_scan_failed
);
7970 ioc
->is_driver_loading
= 0;
7971 ioc
->wait_for_discovery_to_complete
= 0;
7972 ioc
->remove_host
= 1;
7976 pr_info(MPT3SAS_FMT
"port enable: SUCCESS\n", ioc
->name
);
7977 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
7979 if (ioc
->wait_for_discovery_to_complete
) {
7980 ioc
->wait_for_discovery_to_complete
= 0;
7981 _scsih_probe_devices(ioc
);
7983 mpt3sas_base_start_watchdog(ioc
);
7984 ioc
->is_driver_loading
= 0;
7989 * scsih_probe - attach and add scsi host
7990 * @pdev: PCI device struct
7991 * @id: pci device id
7993 * Returns 0 success, anything else error.
7996 scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
7998 struct MPT3SAS_ADAPTER
*ioc
;
7999 struct Scsi_Host
*shost
;
8002 shost
= scsi_host_alloc(&scsih_driver_template
,
8003 sizeof(struct MPT3SAS_ADAPTER
));
8007 /* init local params */
8008 ioc
= shost_priv(shost
);
8009 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
8010 INIT_LIST_HEAD(&ioc
->list
);
8011 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
8013 ioc
->id
= mpt_ids
++;
8014 sprintf(ioc
->name
, "%s%d", MPT3SAS_DRIVER_NAME
, ioc
->id
);
8016 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8017 ioc
->tm_cb_idx
= tm_cb_idx
;
8018 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8019 ioc
->base_cb_idx
= base_cb_idx
;
8020 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8021 ioc
->transport_cb_idx
= transport_cb_idx
;
8022 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8023 ioc
->config_cb_idx
= config_cb_idx
;
8024 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8025 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8026 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8027 ioc
->logging_level
= logging_level
;
8028 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8029 /* misc semaphores and spin locks */
8030 mutex_init(&ioc
->reset_in_progress_mutex
);
8031 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8032 spin_lock_init(&ioc
->scsi_lookup_lock
);
8033 spin_lock_init(&ioc
->sas_device_lock
);
8034 spin_lock_init(&ioc
->sas_node_lock
);
8035 spin_lock_init(&ioc
->fw_event_lock
);
8036 spin_lock_init(&ioc
->raid_device_lock
);
8037 spin_lock_init(&ioc
->diag_trigger_lock
);
8039 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8040 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8041 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8042 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8043 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8044 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8045 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8046 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8047 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8049 /* init shost parameters */
8050 shost
->max_cmd_len
= 32;
8051 shost
->max_lun
= max_lun
;
8052 shost
->transportt
= mpt3sas_transport_template
;
8053 shost
->unique_id
= ioc
->id
;
8055 if (max_sectors
!= 0xFFFF) {
8056 if (max_sectors
< 64) {
8057 shost
->max_sectors
= 64;
8058 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8059 "for max_sectors, range is 64 to 32767. Assigning "
8060 "value of 64.\n", ioc
->name
, max_sectors
);
8061 } else if (max_sectors
> 32767) {
8062 shost
->max_sectors
= 32767;
8063 pr_warn(MPT3SAS_FMT
"Invalid value %d passed " \
8064 "for max_sectors, range is 64 to 32767. Assigning "
8065 "default value of 32767.\n", ioc
->name
,
8068 shost
->max_sectors
= max_sectors
& 0xFFFE;
8070 "The max_sectors value is set to %d\n",
8071 ioc
->name
, shost
->max_sectors
);
8075 /* register EEDP capabilities with SCSI layer */
8077 scsi_host_set_prot(shost
, prot_mask
);
8079 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8080 | SHOST_DIF_TYPE2_PROTECTION
8081 | SHOST_DIF_TYPE3_PROTECTION
);
8083 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8086 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8087 "fw_event%d", ioc
->id
);
8088 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
8089 ioc
->firmware_event_name
, WQ_MEM_RECLAIM
);
8090 if (!ioc
->firmware_event_thread
) {
8091 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8092 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8094 goto out_thread_fail
;
8097 ioc
->is_driver_loading
= 1;
8098 if ((mpt3sas_base_attach(ioc
))) {
8099 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8100 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8102 goto out_attach_fail
;
8104 rv
= scsi_add_host(shost
, &pdev
->dev
);
8106 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
8107 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8108 goto out_add_shost_fail
;
8111 scsi_scan_host(shost
);
8114 mpt3sas_base_detach(ioc
);
8116 destroy_workqueue(ioc
->firmware_event_thread
);
8118 list_del(&ioc
->list
);
8119 scsi_host_put(shost
);
8125 * scsih_suspend - power management suspend main entry point
8126 * @pdev: PCI device struct
8127 * @state: PM state change to (usually PCI_D3)
8129 * Returns 0 success, anything else error.
8132 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8134 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8135 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8136 pci_power_t device_state
;
8138 mpt3sas_base_stop_watchdog(ioc
);
8139 flush_scheduled_work();
8140 scsi_block_requests(shost
);
8141 device_state
= pci_choose_state(pdev
, state
);
8143 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8144 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8146 pci_save_state(pdev
);
8147 mpt3sas_base_free_resources(ioc
);
8148 pci_set_power_state(pdev
, device_state
);
8153 * scsih_resume - power management resume main entry point
8154 * @pdev: PCI device struct
8156 * Returns 0 success, anything else error.
8159 scsih_resume(struct pci_dev
*pdev
)
8161 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8162 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8163 pci_power_t device_state
= pdev
->current_state
;
8167 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8168 ioc
->name
, pdev
, pci_name(pdev
), device_state
);
8170 pci_set_power_state(pdev
, PCI_D0
);
8171 pci_enable_wake(pdev
, PCI_D0
, 0);
8172 pci_restore_state(pdev
);
8174 r
= mpt3sas_base_map_resources(ioc
);
8178 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8179 scsi_unblock_requests(shost
);
8180 mpt3sas_base_start_watchdog(ioc
);
8183 #endif /* CONFIG_PM */
8186 * scsih_pci_error_detected - Called when a PCI error is detected.
8187 * @pdev: PCI device struct
8188 * @state: PCI channel state
8190 * Description: Called when a PCI error is detected.
8193 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8196 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8198 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8199 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8201 pr_info(MPT3SAS_FMT
"PCI error: detected callback, state(%d)!!\n",
8205 case pci_channel_io_normal
:
8206 return PCI_ERS_RESULT_CAN_RECOVER
;
8207 case pci_channel_io_frozen
:
8208 /* Fatal error, prepare for slot reset */
8209 ioc
->pci_error_recovery
= 1;
8210 scsi_block_requests(ioc
->shost
);
8211 mpt3sas_base_stop_watchdog(ioc
);
8212 mpt3sas_base_free_resources(ioc
);
8213 return PCI_ERS_RESULT_NEED_RESET
;
8214 case pci_channel_io_perm_failure
:
8215 /* Permanent error, prepare for device removal */
8216 ioc
->pci_error_recovery
= 1;
8217 mpt3sas_base_stop_watchdog(ioc
);
8218 _scsih_flush_running_cmds(ioc
);
8219 return PCI_ERS_RESULT_DISCONNECT
;
8221 return PCI_ERS_RESULT_NEED_RESET
;
8225 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8226 * @pdev: PCI device struct
8228 * Description: This routine is called by the pci error recovery
8229 * code after the PCI slot has been reset, just before we
8230 * should resume normal operations.
8233 scsih_pci_slot_reset(struct pci_dev
*pdev
)
8235 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8236 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8239 pr_info(MPT3SAS_FMT
"PCI error: slot reset callback!!\n",
8242 ioc
->pci_error_recovery
= 0;
8244 pci_restore_state(pdev
);
8245 rc
= mpt3sas_base_map_resources(ioc
);
8247 return PCI_ERS_RESULT_DISCONNECT
;
8249 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8252 pr_warn(MPT3SAS_FMT
"hard reset: %s\n", ioc
->name
,
8253 (rc
== 0) ? "success" : "failed");
8256 return PCI_ERS_RESULT_RECOVERED
;
8258 return PCI_ERS_RESULT_DISCONNECT
;
8262 * scsih_pci_resume() - resume normal ops after PCI reset
8263 * @pdev: pointer to PCI device
8265 * Called when the error recovery driver tells us that its
8266 * OK to resume normal operation. Use completion to allow
8267 * halted scsi ops to resume.
8270 scsih_pci_resume(struct pci_dev
*pdev
)
8272 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8273 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8275 pr_info(MPT3SAS_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8277 pci_cleanup_aer_uncorrect_error_status(pdev
);
8278 mpt3sas_base_start_watchdog(ioc
);
8279 scsi_unblock_requests(ioc
->shost
);
8283 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8284 * @pdev: pointer to PCI device
8287 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8289 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8290 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
8292 pr_info(MPT3SAS_FMT
"PCI error: mmio enabled callback!!\n",
8295 /* TODO - dump whatever for debugging purposes */
8297 /* Request a slot reset. */
8298 return PCI_ERS_RESULT_NEED_RESET
;
8301 /* raid transport support */
8302 static struct raid_function_template mpt3sas_raid_functions
= {
8303 .cookie
= &scsih_driver_template
,
8304 .is_raid
= scsih_is_raid
,
8305 .get_resync
= scsih_get_resync
,
8306 .get_state
= scsih_get_state
,
8309 static struct pci_error_handlers _scsih_err_handler
= {
8310 .error_detected
= scsih_pci_error_detected
,
8311 .mmio_enabled
= scsih_pci_mmio_enabled
,
8312 .slot_reset
= scsih_pci_slot_reset
,
8313 .resume
= scsih_pci_resume
,
8316 static struct pci_driver scsih_driver
= {
8317 .name
= MPT3SAS_DRIVER_NAME
,
8318 .id_table
= scsih_pci_table
,
8319 .probe
= scsih_probe
,
8320 .remove
= scsih_remove
,
8321 .shutdown
= scsih_shutdown
,
8322 .err_handler
= &_scsih_err_handler
,
8324 .suspend
= scsih_suspend
,
8325 .resume
= scsih_resume
,
8331 * scsih_init - main entry point for this driver.
8333 * Returns 0 success, anything else error.
8342 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
8343 MPT3SAS_DRIVER_VERSION
);
8345 mpt3sas_transport_template
=
8346 sas_attach_transport(&mpt3sas_transport_functions
);
8347 if (!mpt3sas_transport_template
)
8350 /* raid transport support */
8351 mpt3sas_raid_template
= raid_class_attach(&mpt3sas_raid_functions
);
8352 if (!mpt3sas_raid_template
) {
8353 sas_release_transport(mpt3sas_transport_template
);
8357 mpt3sas_base_initialize_callback_handler();
8359 /* queuecommand callback hander */
8360 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
8362 /* task managment callback handler */
8363 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
8365 /* base internal commands callback handler */
8366 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
8367 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
8368 mpt3sas_port_enable_done
);
8370 /* transport internal commands callback handler */
8371 transport_cb_idx
= mpt3sas_base_register_callback_handler(
8372 mpt3sas_transport_done
);
8374 /* scsih internal commands callback handler */
8375 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
8377 /* configuration page API internal commands callback handler */
8378 config_cb_idx
= mpt3sas_base_register_callback_handler(
8379 mpt3sas_config_done
);
8381 /* ctl module callback handler */
8382 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
8384 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
8385 _scsih_tm_tr_complete
);
8387 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
8388 _scsih_tm_volume_tr_complete
);
8390 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
8391 _scsih_sas_control_complete
);
8395 error
= pci_register_driver(&scsih_driver
);
8397 /* raid transport support */
8398 raid_class_release(mpt3sas_raid_template
);
8399 sas_release_transport(mpt3sas_transport_template
);
8406 * _scsih_exit - exit point for this driver (when it is a module).
8408 * Returns 0 success, anything else error.
8413 pr_info("mpt3sas version %s unloading\n",
8414 MPT3SAS_DRIVER_VERSION
);
8418 pci_unregister_driver(&scsih_driver
);
8421 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
8422 mpt3sas_base_release_callback_handler(tm_cb_idx
);
8423 mpt3sas_base_release_callback_handler(base_cb_idx
);
8424 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
8425 mpt3sas_base_release_callback_handler(transport_cb_idx
);
8426 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
8427 mpt3sas_base_release_callback_handler(config_cb_idx
);
8428 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
8430 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
8431 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8432 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8434 /* raid transport support */
8435 raid_class_release(mpt3sas_raid_template
);
8436 sas_release_transport(mpt3sas_transport_template
);
8439 module_init(scsih_init
);
8440 module_exit(scsih_exit
);