2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2013 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
57 #include "mpt3sas_base.h"
59 MODULE_AUTHOR(MPT3SAS_AUTHOR);
60 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
64 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
67 struct _sas_node *sas_expander);
68 static void _firmware_event_work(struct work_struct *work);
70 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
71 struct _sas_device *sas_device);
72 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
73 u8 retry_count, u8 is_pd);
75 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
77 static void _scsih_scan_start(struct Scsi_Host *shost);
78 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
80 /* global parameters */
81 LIST_HEAD(mpt3sas_ioc_list);
83 /* local parameters */
84 static u8 scsi_io_cb_idx = -1;
85 static u8 tm_cb_idx = -1;
86 static u8 ctl_cb_idx = -1;
87 static u8 base_cb_idx = -1;
88 static u8 port_enable_cb_idx = -1;
89 static u8 transport_cb_idx = -1;
90 static u8 scsih_cb_idx = -1;
91 static u8 config_cb_idx = -1;
94 static u8 tm_tr_cb_idx = -1 ;
95 static u8 tm_tr_volume_cb_idx = -1 ;
96 static u8 tm_sas_control_cb_idx = -1;
98 /* command line options */
99 static u32 logging_level;
100 MODULE_PARM_DESC(logging_level,
101 " bits for enabling additional logging info (default=0)");
104 static ushort max_sectors = 0xFFFF;
105 module_param(max_sectors, ushort, 0);
106 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
109 static int missing_delay[2] = {-1, -1};
110 module_param_array(missing_delay, int, NULL, 0);
111 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
113 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
114 #define MPT3SAS_MAX_LUN (16895)
115 static u64 max_lun = MPT3SAS_MAX_LUN;
116 module_param(max_lun, ullong, 0);
117 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
122 /* diag_buffer_enable is bitwise
124 * bit 1 set = SNAPSHOT
125 * bit 2 set = EXTENDED
127 * Either bit can be set, or both
129 static int diag_buffer_enable = -1;
130 module_param(diag_buffer_enable, int, 0);
131 MODULE_PARM_DESC(diag_buffer_enable,
132 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
133 static int disable_discovery = -1;
134 module_param(disable_discovery, int, 0);
135 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
138 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
139 static int prot_mask = -1;
140 module_param(prot_mask, int, 0);
141 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
144 /* raid transport support */
146 static struct raid_template *mpt3sas_raid_template;
150 * struct sense_info - common structure for obtaining sense keys
152 * @asc: additional sense code
153 * @ascq: additional sense code qualifier
161 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
162 #define MPT3SAS_TURN_ON_FAULT_LED (0xFFFC)
163 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
164 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
165 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
167 * struct fw_event_work - firmware event struct
168 * @list: link list framework
169 * @work: work object (ioc->fault_reset_work_q)
170 * @cancel_pending_work: flag set during reset handling
171 * @ioc: per adapter object
172 * @device_handle: device handle
173 * @VF_ID: virtual function id
174 * @VP_ID: virtual port id
175 * @ignore: flag meaning this event has been marked to ignore
176 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
177 * @event_data: reply event data payload follows
179 * This object stored on ioc->fw_event_list.
181 struct fw_event_work {
182 struct list_head list;
183 struct work_struct work;
184 u8 cancel_pending_work;
185 struct delayed_work delayed_work;
187 struct MPT3SAS_ADAPTER *ioc;
196 /* raid transport support */
197 static struct raid_template *mpt3sas_raid_template;
200 * struct _scsi_io_transfer - scsi io transfer
201 * @handle: sas device handle (assigned by firmware)
202 * @is_raid: flag set for hidden raid components
203 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
204 * @data_length: data transfer length
205 * @data_dma: dma pointer to data
208 * @cdb_length: cdb length
210 * @timeout: timeout for this command
211 * @VF_ID: virtual function id
212 * @VP_ID: virtual port id
213 * @valid_reply: flag set for reply message
214 * @sense_length: sense length
215 * @ioc_status: ioc status
216 * @scsi_state: scsi state
217 * @scsi_status: scsi staus
218 * @log_info: log information
219 * @transfer_length: data length transfer when there is a reply message
221 * Used for sending internal scsi commands to devices within this module.
222 * Refer to _scsi_send_scsi_io().
224 struct _scsi_io_transfer {
227 enum dma_data_direction dir;
230 u8 sense[SCSI_SENSE_BUFFERSIZE];
238 /* the following bits are only valid when 'valid_reply = 1' */
248 * The pci device ids are defined in mpi/mpi2_cnfg.h.
250 static DEFINE_PCI_DEVICE_TABLE(scsih_pci_table) = {
251 /* Fury ~ 3004 and 3008 */
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
253 PCI_ANY_ID, PCI_ANY_ID },
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
255 PCI_ANY_ID, PCI_ANY_ID },
257 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
258 PCI_ANY_ID, PCI_ANY_ID },
259 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
260 PCI_ANY_ID, PCI_ANY_ID },
261 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
262 PCI_ANY_ID, PCI_ANY_ID },
263 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
264 PCI_ANY_ID, PCI_ANY_ID },
265 {0} /* Terminating entry */
267 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
270 * _scsih_set_debug_level - global setting of ioc->logging_level.
272 * Note: The logging levels are defined in mpt3sas_debug.h.
275 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
277 int ret = param_set_int(val, kp);
278 struct MPT3SAS_ADAPTER *ioc;
283 pr_info("setting logging_level(0x%08x)\n", logging_level);
284 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
285 ioc->logging_level = logging_level;
288 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
289 &logging_level, 0644);
292 * _scsih_srch_boot_sas_address - search based on sas_address
293 * @sas_address: sas address
294 * @boot_device: boot device object from bios page 2
296 * Returns 1 when there's a match, 0 means no match.
299 _scsih_srch_boot_sas_address(u64 sas_address,
300 Mpi2BootDeviceSasWwid_t *boot_device)
302 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
306 * _scsih_srch_boot_device_name - search based on device name
307 * @device_name: device name specified in INDENTIFY fram
308 * @boot_device: boot device object from bios page 2
310 * Returns 1 when there's a match, 0 means no match.
313 _scsih_srch_boot_device_name(u64 device_name,
314 Mpi2BootDeviceDeviceName_t *boot_device)
316 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
320 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
321 * @enclosure_logical_id: enclosure logical id
322 * @slot_number: slot number
323 * @boot_device: boot device object from bios page 2
325 * Returns 1 when there's a match, 0 means no match.
328 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
329 Mpi2BootDeviceEnclosureSlot_t *boot_device)
331 return (enclosure_logical_id == le64_to_cpu(boot_device->
332 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
333 SlotNumber)) ? 1 : 0;
337 * _scsih_is_boot_device - search for matching boot device.
338 * @sas_address: sas address
339 * @device_name: device name specified in INDENTIFY fram
340 * @enclosure_logical_id: enclosure logical id
341 * @slot_number: slot number
342 * @form: specifies boot device form
343 * @boot_device: boot device object from bios page 2
345 * Returns 1 when there's a match, 0 means no match.
348 _scsih_is_boot_device(u64 sas_address, u64 device_name,
349 u64 enclosure_logical_id, u16 slot, u8 form,
350 Mpi2BiosPage2BootDevice_t *boot_device)
355 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
358 rc = _scsih_srch_boot_sas_address(
359 sas_address, &boot_device->SasWwid);
361 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
362 if (!enclosure_logical_id)
364 rc = _scsih_srch_boot_encl_slot(
365 enclosure_logical_id,
366 slot, &boot_device->EnclosureSlot);
368 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
371 rc = _scsih_srch_boot_device_name(
372 device_name, &boot_device->DeviceName);
374 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
382 * _scsih_get_sas_address - set the sas_address for given device handle
383 * @handle: device handle
384 * @sas_address: sas address
386 * Returns 0 success, non-zero when failure
389 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
392 Mpi2SasDevicePage0_t sas_device_pg0;
393 Mpi2ConfigReply_t mpi_reply;
398 if (handle <= ioc->sas_hba.num_phys) {
399 *sas_address = ioc->sas_hba.sas_address;
403 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
404 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
405 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
406 __FILE__, __LINE__, __func__);
410 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
411 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
412 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
416 /* we hit this becuase the given parent handle doesn't exist */
417 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
420 /* else error case */
422 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
423 ioc->name, handle, ioc_status,
424 __FILE__, __LINE__, __func__);
429 * _scsih_determine_boot_device - determine boot device.
430 * @ioc: per adapter object
431 * @device: either sas_device or raid_device object
432 * @is_raid: [flag] 1 = raid object, 0 = sas object
434 * Determines whether this device should be first reported device to
435 * to scsi-ml or sas transport, this purpose is for persistent boot device.
436 * There are primary, alternate, and current entries in bios page 2. The order
437 * priority is primary, alternate, then current. This routine saves
438 * the corresponding device object and is_raid flag in the ioc object.
439 * The saved data to be used later in _scsih_probe_boot_devices().
442 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
443 void *device, u8 is_raid)
445 struct _sas_device *sas_device;
446 struct _raid_device *raid_device;
449 u64 enclosure_logical_id;
452 /* only process this function when driver loads */
453 if (!ioc->is_driver_loading)
456 /* no Bios, return immediately */
457 if (!ioc->bios_pg3.BiosVersion)
462 sas_address = sas_device->sas_address;
463 device_name = sas_device->device_name;
464 enclosure_logical_id = sas_device->enclosure_logical_id;
465 slot = sas_device->slot;
467 raid_device = device;
468 sas_address = raid_device->wwid;
470 enclosure_logical_id = 0;
474 if (!ioc->req_boot_device.device) {
475 if (_scsih_is_boot_device(sas_address, device_name,
476 enclosure_logical_id, slot,
477 (ioc->bios_pg2.ReqBootDeviceForm &
478 MPI2_BIOSPAGE2_FORM_MASK),
479 &ioc->bios_pg2.RequestedBootDevice)) {
480 dinitprintk(ioc, pr_info(MPT3SAS_FMT
481 "%s: req_boot_device(0x%016llx)\n",
483 (unsigned long long)sas_address));
484 ioc->req_boot_device.device = device;
485 ioc->req_boot_device.is_raid = is_raid;
489 if (!ioc->req_alt_boot_device.device) {
490 if (_scsih_is_boot_device(sas_address, device_name,
491 enclosure_logical_id, slot,
492 (ioc->bios_pg2.ReqAltBootDeviceForm &
493 MPI2_BIOSPAGE2_FORM_MASK),
494 &ioc->bios_pg2.RequestedAltBootDevice)) {
495 dinitprintk(ioc, pr_info(MPT3SAS_FMT
496 "%s: req_alt_boot_device(0x%016llx)\n",
498 (unsigned long long)sas_address));
499 ioc->req_alt_boot_device.device = device;
500 ioc->req_alt_boot_device.is_raid = is_raid;
504 if (!ioc->current_boot_device.device) {
505 if (_scsih_is_boot_device(sas_address, device_name,
506 enclosure_logical_id, slot,
507 (ioc->bios_pg2.CurrentBootDeviceForm &
508 MPI2_BIOSPAGE2_FORM_MASK),
509 &ioc->bios_pg2.CurrentBootDevice)) {
510 dinitprintk(ioc, pr_info(MPT3SAS_FMT
511 "%s: current_boot_device(0x%016llx)\n",
513 (unsigned long long)sas_address));
514 ioc->current_boot_device.device = device;
515 ioc->current_boot_device.is_raid = is_raid;
521 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
522 * @ioc: per adapter object
523 * @sas_address: sas address
524 * Context: Calling function should acquire ioc->sas_device_lock
526 * This searches for sas_device based on sas_address, then return sas_device
530 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
533 struct _sas_device *sas_device;
535 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
536 if (sas_device->sas_address == sas_address)
539 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
540 if (sas_device->sas_address == sas_address)
547 * _scsih_sas_device_find_by_handle - sas device search
548 * @ioc: per adapter object
549 * @handle: sas device handle (assigned by firmware)
550 * Context: Calling function should acquire ioc->sas_device_lock
552 * This searches for sas_device based on sas_address, then return sas_device
555 static struct _sas_device *
556 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
558 struct _sas_device *sas_device;
560 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
561 if (sas_device->handle == handle)
564 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
565 if (sas_device->handle == handle)
572 * _scsih_sas_device_remove - remove sas_device from list.
573 * @ioc: per adapter object
574 * @sas_device: the sas_device object
575 * Context: This function will acquire ioc->sas_device_lock.
577 * Removing object and freeing associated memory from the ioc->sas_device_list.
580 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
581 struct _sas_device *sas_device)
588 spin_lock_irqsave(&ioc->sas_device_lock, flags);
589 list_del(&sas_device->list);
591 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
595 * _scsih_device_remove_by_handle - removing device object by handle
596 * @ioc: per adapter object
597 * @handle: device handle
602 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
604 struct _sas_device *sas_device;
607 if (ioc->shost_recovery)
610 spin_lock_irqsave(&ioc->sas_device_lock, flags);
611 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
613 list_del(&sas_device->list);
614 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
616 _scsih_remove_device(ioc, sas_device);
620 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
621 * @ioc: per adapter object
622 * @sas_address: device sas_address
627 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
630 struct _sas_device *sas_device;
633 if (ioc->shost_recovery)
636 spin_lock_irqsave(&ioc->sas_device_lock, flags);
637 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
640 list_del(&sas_device->list);
641 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
643 _scsih_remove_device(ioc, sas_device);
647 * _scsih_sas_device_add - insert sas_device to the list.
648 * @ioc: per adapter object
649 * @sas_device: the sas_device object
650 * Context: This function will acquire ioc->sas_device_lock.
652 * Adding new object to the ioc->sas_device_list.
655 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
656 struct _sas_device *sas_device)
660 dewtprintk(ioc, pr_info(MPT3SAS_FMT
661 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
662 ioc->name, __func__, sas_device->handle,
663 (unsigned long long)sas_device->sas_address));
665 spin_lock_irqsave(&ioc->sas_device_lock, flags);
666 list_add_tail(&sas_device->list, &ioc->sas_device_list);
667 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
669 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
670 sas_device->sas_address_parent)) {
671 _scsih_sas_device_remove(ioc, sas_device);
672 } else if (!sas_device->starget) {
674 * When asyn scanning is enabled, its not possible to remove
675 * devices while scanning is turned on due to an oops in
676 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
678 if (!ioc->is_driver_loading) {
679 mpt3sas_transport_port_remove(ioc,
680 sas_device->sas_address,
681 sas_device->sas_address_parent);
682 _scsih_sas_device_remove(ioc, sas_device);
688 * _scsih_sas_device_init_add - insert sas_device to the list.
689 * @ioc: per adapter object
690 * @sas_device: the sas_device object
691 * Context: This function will acquire ioc->sas_device_lock.
693 * Adding new object at driver load time to the ioc->sas_device_init_list.
696 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
697 struct _sas_device *sas_device)
701 dewtprintk(ioc, pr_info(MPT3SAS_FMT
702 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
703 __func__, sas_device->handle,
704 (unsigned long long)sas_device->sas_address));
706 spin_lock_irqsave(&ioc->sas_device_lock, flags);
707 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
708 _scsih_determine_boot_device(ioc, sas_device, 0);
709 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
713 * _scsih_raid_device_find_by_id - raid device search
714 * @ioc: per adapter object
715 * @id: sas device target id
716 * @channel: sas device channel
717 * Context: Calling function should acquire ioc->raid_device_lock
719 * This searches for raid_device based on target id, then return raid_device
722 static struct _raid_device *
723 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
725 struct _raid_device *raid_device, *r;
728 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
729 if (raid_device->id == id && raid_device->channel == channel) {
740 * _scsih_raid_device_find_by_handle - raid device search
741 * @ioc: per adapter object
742 * @handle: sas device handle (assigned by firmware)
743 * Context: Calling function should acquire ioc->raid_device_lock
745 * This searches for raid_device based on handle, then return raid_device
748 static struct _raid_device *
749 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
751 struct _raid_device *raid_device, *r;
754 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
755 if (raid_device->handle != handle)
766 * _scsih_raid_device_find_by_wwid - raid device search
767 * @ioc: per adapter object
768 * @handle: sas device handle (assigned by firmware)
769 * Context: Calling function should acquire ioc->raid_device_lock
771 * This searches for raid_device based on wwid, then return raid_device
774 static struct _raid_device *
775 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
777 struct _raid_device *raid_device, *r;
780 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
781 if (raid_device->wwid != wwid)
792 * _scsih_raid_device_add - add raid_device object
793 * @ioc: per adapter object
794 * @raid_device: raid_device object
796 * This is added to the raid_device_list link list.
799 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
800 struct _raid_device *raid_device)
804 dewtprintk(ioc, pr_info(MPT3SAS_FMT
805 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
806 raid_device->handle, (unsigned long long)raid_device->wwid));
808 spin_lock_irqsave(&ioc->raid_device_lock, flags);
809 list_add_tail(&raid_device->list, &ioc->raid_device_list);
810 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
814 * _scsih_raid_device_remove - delete raid_device object
815 * @ioc: per adapter object
816 * @raid_device: raid_device object
820 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
821 struct _raid_device *raid_device)
825 spin_lock_irqsave(&ioc->raid_device_lock, flags);
826 list_del(&raid_device->list);
828 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
832 * mpt3sas_scsih_expander_find_by_handle - expander device search
833 * @ioc: per adapter object
834 * @handle: expander handle (assigned by firmware)
835 * Context: Calling function should acquire ioc->sas_device_lock
837 * This searches for expander device based on handle, then returns the
841 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
843 struct _sas_node *sas_expander, *r;
846 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
847 if (sas_expander->handle != handle)
857 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
858 * @ioc: per adapter object
859 * @sas_address: sas address
860 * Context: Calling function should acquire ioc->sas_node_lock.
862 * This searches for expander device based on sas_address, then returns the
866 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
869 struct _sas_node *sas_expander, *r;
872 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
873 if (sas_expander->sas_address != sas_address)
883 * _scsih_expander_node_add - insert expander device to the list.
884 * @ioc: per adapter object
885 * @sas_expander: the sas_device object
886 * Context: This function will acquire ioc->sas_node_lock.
888 * Adding new object to the ioc->sas_expander_list.
893 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
894 struct _sas_node *sas_expander)
898 spin_lock_irqsave(&ioc->sas_node_lock, flags);
899 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
900 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
904 * _scsih_is_end_device - determines if device is an end device
905 * @device_info: bitfield providing information about the device.
908 * Returns 1 if end device.
911 _scsih_is_end_device(u32 device_info)
913 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
914 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
915 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
916 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
923 * _scsih_scsi_lookup_get - returns scmd entry
924 * @ioc: per adapter object
925 * @smid: system request message index
927 * Returns the smid stored scmd pointer.
929 static struct scsi_cmnd *
930 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
932 return ioc->scsi_lookup[smid - 1].scmd;
936 * _scsih_scsi_lookup_get_clear - returns scmd entry
937 * @ioc: per adapter object
938 * @smid: system request message index
940 * Returns the smid stored scmd pointer.
941 * Then will derefrence the stored scmd pointer.
943 static inline struct scsi_cmnd *
944 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
947 struct scsi_cmnd *scmd;
949 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
950 scmd = ioc->scsi_lookup[smid - 1].scmd;
951 ioc->scsi_lookup[smid - 1].scmd = NULL;
952 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
958 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
959 * @ioc: per adapter object
960 * @smid: system request message index
961 * @scmd: pointer to scsi command object
962 * Context: This function will acquire ioc->scsi_lookup_lock.
964 * This will search for a scmd pointer in the scsi_lookup array,
965 * returning the revelent smid. A returned value of zero means invalid.
968 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
975 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
977 for (i = 0; i < ioc->scsiio_depth; i++) {
978 if (ioc->scsi_lookup[i].scmd == scmd) {
979 smid = ioc->scsi_lookup[i].smid;
984 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
989 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
990 * @ioc: per adapter object
993 * Context: This function will acquire ioc->scsi_lookup_lock.
995 * This will search for a matching channel:id in the scsi_lookup array,
996 * returning 1 if found.
999 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1003 unsigned long flags;
1006 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1008 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1009 if (ioc->scsi_lookup[i].scmd &&
1010 (ioc->scsi_lookup[i].scmd->device->id == id &&
1011 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1017 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1022 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1023 * @ioc: per adapter object
1027 * Context: This function will acquire ioc->scsi_lookup_lock.
1029 * This will search for a matching channel:id:lun in the scsi_lookup array,
1030 * returning 1 if found.
1033 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1034 unsigned int lun, int channel)
1037 unsigned long flags;
1040 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1042 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1043 if (ioc->scsi_lookup[i].scmd &&
1044 (ioc->scsi_lookup[i].scmd->device->id == id &&
1045 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1046 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1052 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1058 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1060 struct Scsi_Host *shost = sdev->host;
1062 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1063 struct MPT3SAS_DEVICE *sas_device_priv_data;
1064 struct MPT3SAS_TARGET *sas_target_priv_data;
1065 struct _sas_device *sas_device;
1066 unsigned long flags;
1068 max_depth = shost->can_queue;
1070 /* limit max device queue for SATA to 32 */
1071 sas_device_priv_data = sdev->hostdata;
1072 if (!sas_device_priv_data)
1074 sas_target_priv_data = sas_device_priv_data->sas_target;
1075 if (!sas_target_priv_data)
1077 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1079 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1080 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1081 sas_device_priv_data->sas_target->sas_address);
1082 if (sas_device && sas_device->device_info &
1083 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1084 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1085 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1089 if (!sdev->tagged_supported)
1091 if (qdepth > max_depth)
1093 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1097 * _scsih_change_queue_depth - setting device queue depth
1098 * @sdev: scsi device struct
1099 * @qdepth: requested queue depth
1100 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1101 * (see include/scsi/scsi_host.h for definition)
1103 * Returns queue depth.
1106 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1108 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1109 _scsih_adjust_queue_depth(sdev, qdepth);
1110 else if (reason == SCSI_QDEPTH_QFULL)
1111 scsi_track_queue_full(sdev, qdepth);
1115 if (sdev->inquiry_len > 7)
1116 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \
1117 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1118 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1119 sdev->ordered_tags, sdev->scsi_level,
1120 (sdev->inquiry[7] & 2) >> 1);
1122 return sdev->queue_depth;
1126 * _scsih_change_queue_type - changing device queue tag type
1127 * @sdev: scsi device struct
1128 * @tag_type: requested tag type
1130 * Returns queue tag type.
1133 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1135 if (sdev->tagged_supported) {
1136 scsi_set_tag_type(sdev, tag_type);
1138 scsi_activate_tcq(sdev, sdev->queue_depth);
1140 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1149 * _scsih_target_alloc - target add routine
1150 * @starget: scsi target struct
1152 * Returns 0 if ok. Any other return is assumed to be an error and
1153 * the device is ignored.
1156 _scsih_target_alloc(struct scsi_target *starget)
1158 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1159 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1160 struct MPT3SAS_TARGET *sas_target_priv_data;
1161 struct _sas_device *sas_device;
1162 struct _raid_device *raid_device;
1163 unsigned long flags;
1164 struct sas_rphy *rphy;
1166 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1168 if (!sas_target_priv_data)
1171 starget->hostdata = sas_target_priv_data;
1172 sas_target_priv_data->starget = starget;
1173 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1176 if (starget->channel == RAID_CHANNEL) {
1177 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1178 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1181 sas_target_priv_data->handle = raid_device->handle;
1182 sas_target_priv_data->sas_address = raid_device->wwid;
1183 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1184 raid_device->starget = starget;
1186 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1190 /* sas/sata devices */
1191 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1192 rphy = dev_to_rphy(starget->dev.parent);
1193 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1194 rphy->identify.sas_address);
1197 sas_target_priv_data->handle = sas_device->handle;
1198 sas_target_priv_data->sas_address = sas_device->sas_address;
1199 sas_device->starget = starget;
1200 sas_device->id = starget->id;
1201 sas_device->channel = starget->channel;
1202 if (test_bit(sas_device->handle, ioc->pd_handles))
1203 sas_target_priv_data->flags |=
1204 MPT_TARGET_FLAGS_RAID_COMPONENT;
1205 if (sas_device->fast_path)
1206 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1208 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1214 * _scsih_target_destroy - target destroy routine
1215 * @starget: scsi target struct
1220 _scsih_target_destroy(struct scsi_target *starget)
1222 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1223 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1224 struct MPT3SAS_TARGET *sas_target_priv_data;
1225 struct _sas_device *sas_device;
1226 struct _raid_device *raid_device;
1227 unsigned long flags;
1228 struct sas_rphy *rphy;
1230 sas_target_priv_data = starget->hostdata;
1231 if (!sas_target_priv_data)
1234 if (starget->channel == RAID_CHANNEL) {
1235 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1236 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1239 raid_device->starget = NULL;
1240 raid_device->sdev = NULL;
1242 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1246 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1247 rphy = dev_to_rphy(starget->dev.parent);
1248 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1249 rphy->identify.sas_address);
1250 if (sas_device && (sas_device->starget == starget) &&
1251 (sas_device->id == starget->id) &&
1252 (sas_device->channel == starget->channel))
1253 sas_device->starget = NULL;
1255 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1258 kfree(sas_target_priv_data);
1259 starget->hostdata = NULL;
1263 * _scsih_slave_alloc - device add routine
1264 * @sdev: scsi device struct
1266 * Returns 0 if ok. Any other return is assumed to be an error and
1267 * the device is ignored.
1270 _scsih_slave_alloc(struct scsi_device *sdev)
1272 struct Scsi_Host *shost;
1273 struct MPT3SAS_ADAPTER *ioc;
1274 struct MPT3SAS_TARGET *sas_target_priv_data;
1275 struct MPT3SAS_DEVICE *sas_device_priv_data;
1276 struct scsi_target *starget;
1277 struct _raid_device *raid_device;
1278 struct _sas_device *sas_device;
1279 unsigned long flags;
1281 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1283 if (!sas_device_priv_data)
1286 sas_device_priv_data->lun = sdev->lun;
1287 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1289 starget = scsi_target(sdev);
1290 sas_target_priv_data = starget->hostdata;
1291 sas_target_priv_data->num_luns++;
1292 sas_device_priv_data->sas_target = sas_target_priv_data;
1293 sdev->hostdata = sas_device_priv_data;
1294 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1295 sdev->no_uld_attach = 1;
1297 shost = dev_to_shost(&starget->dev);
1298 ioc = shost_priv(shost);
1299 if (starget->channel == RAID_CHANNEL) {
1300 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1301 raid_device = _scsih_raid_device_find_by_id(ioc,
1302 starget->id, starget->channel);
1304 raid_device->sdev = sdev; /* raid is single lun */
1305 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1308 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1309 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1310 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1311 sas_target_priv_data->sas_address);
1312 if (sas_device && (sas_device->starget == NULL)) {
1313 sdev_printk(KERN_INFO, sdev,
1314 "%s : sas_device->starget set to starget @ %d\n",
1315 __func__, __LINE__);
1316 sas_device->starget = starget;
1318 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1325 * _scsih_slave_destroy - device destroy routine
1326 * @sdev: scsi device struct
1331 _scsih_slave_destroy(struct scsi_device *sdev)
1333 struct MPT3SAS_TARGET *sas_target_priv_data;
1334 struct scsi_target *starget;
1335 struct Scsi_Host *shost;
1336 struct MPT3SAS_ADAPTER *ioc;
1337 struct _sas_device *sas_device;
1338 unsigned long flags;
1340 if (!sdev->hostdata)
1343 starget = scsi_target(sdev);
1344 sas_target_priv_data = starget->hostdata;
1345 sas_target_priv_data->num_luns--;
1347 shost = dev_to_shost(&starget->dev);
1348 ioc = shost_priv(shost);
1350 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1351 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1352 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1353 sas_target_priv_data->sas_address);
1354 if (sas_device && !sas_target_priv_data->num_luns)
1355 sas_device->starget = NULL;
1356 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1359 kfree(sdev->hostdata);
1360 sdev->hostdata = NULL;
1364 * _scsih_display_sata_capabilities - sata capabilities
1365 * @ioc: per adapter object
1366 * @handle: device handle
1367 * @sdev: scsi device struct
1370 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1371 u16 handle, struct scsi_device *sdev)
1373 Mpi2ConfigReply_t mpi_reply;
1374 Mpi2SasDevicePage0_t sas_device_pg0;
1379 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1380 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1381 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1382 ioc->name, __FILE__, __LINE__, __func__);
1386 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1387 MPI2_IOCSTATUS_MASK;
1388 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1389 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1390 ioc->name, __FILE__, __LINE__, __func__);
1394 flags = le16_to_cpu(sas_device_pg0.Flags);
1395 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1397 sdev_printk(KERN_INFO, sdev,
1398 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1399 "sw_preserve(%s)\n",
1400 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1401 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1402 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1404 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1405 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1406 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1410 * raid transport support -
1411 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1412 * unloading the driver followed by a load - I beleive that the subroutine
1413 * raid_class_release() is not cleaning up properly.
1417 * _scsih_is_raid - return boolean indicating device is raid volume
1418 * @dev the device struct object
1421 _scsih_is_raid(struct device *dev)
1423 struct scsi_device *sdev = to_scsi_device(dev);
1425 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1429 * _scsih_get_resync - get raid volume resync percent complete
1430 * @dev the device struct object
1433 _scsih_get_resync(struct device *dev)
1435 struct scsi_device *sdev = to_scsi_device(dev);
1436 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1437 static struct _raid_device *raid_device;
1438 unsigned long flags;
1439 Mpi2RaidVolPage0_t vol_pg0;
1440 Mpi2ConfigReply_t mpi_reply;
1441 u32 volume_status_flags;
1442 u8 percent_complete;
1445 percent_complete = 0;
1447 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1448 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1451 handle = raid_device->handle;
1452 percent_complete = raid_device->percent_complete;
1454 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1459 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1460 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1461 sizeof(Mpi2RaidVolPage0_t))) {
1462 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1463 ioc->name, __FILE__, __LINE__, __func__);
1464 percent_complete = 0;
1468 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1469 if (!(volume_status_flags &
1470 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1471 percent_complete = 0;
1474 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1478 * _scsih_get_state - get raid volume level
1479 * @dev the device struct object
1482 _scsih_get_state(struct device *dev)
1484 struct scsi_device *sdev = to_scsi_device(dev);
1485 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1486 static struct _raid_device *raid_device;
1487 unsigned long flags;
1488 Mpi2RaidVolPage0_t vol_pg0;
1489 Mpi2ConfigReply_t mpi_reply;
1491 enum raid_state state = RAID_STATE_UNKNOWN;
1494 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1495 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1498 handle = raid_device->handle;
1499 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1504 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1505 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1506 sizeof(Mpi2RaidVolPage0_t))) {
1507 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1508 ioc->name, __FILE__, __LINE__, __func__);
1512 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1513 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1514 state = RAID_STATE_RESYNCING;
1518 switch (vol_pg0.VolumeState) {
1519 case MPI2_RAID_VOL_STATE_OPTIMAL:
1520 case MPI2_RAID_VOL_STATE_ONLINE:
1521 state = RAID_STATE_ACTIVE;
1523 case MPI2_RAID_VOL_STATE_DEGRADED:
1524 state = RAID_STATE_DEGRADED;
1526 case MPI2_RAID_VOL_STATE_FAILED:
1527 case MPI2_RAID_VOL_STATE_MISSING:
1528 state = RAID_STATE_OFFLINE;
1532 raid_set_state(mpt3sas_raid_template, dev, state);
1536 * _scsih_set_level - set raid level
1537 * @sdev: scsi device struct
1538 * @volume_type: volume type
1541 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1543 enum raid_level level = RAID_LEVEL_UNKNOWN;
1545 switch (volume_type) {
1546 case MPI2_RAID_VOL_TYPE_RAID0:
1547 level = RAID_LEVEL_0;
1549 case MPI2_RAID_VOL_TYPE_RAID10:
1550 level = RAID_LEVEL_10;
1552 case MPI2_RAID_VOL_TYPE_RAID1E:
1553 level = RAID_LEVEL_1E;
1555 case MPI2_RAID_VOL_TYPE_RAID1:
1556 level = RAID_LEVEL_1;
1560 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1565 * _scsih_get_volume_capabilities - volume capabilities
1566 * @ioc: per adapter object
1567 * @sas_device: the raid_device object
1569 * Returns 0 for success, else 1
1572 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1573 struct _raid_device *raid_device)
1575 Mpi2RaidVolPage0_t *vol_pg0;
1576 Mpi2RaidPhysDiskPage0_t pd_pg0;
1577 Mpi2SasDevicePage0_t sas_device_pg0;
1578 Mpi2ConfigReply_t mpi_reply;
1582 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1583 &num_pds)) || !num_pds) {
1584 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1585 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1590 raid_device->num_pds = num_pds;
1591 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1592 sizeof(Mpi2RaidVol0PhysDisk_t));
1593 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1595 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1596 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1601 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1602 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1603 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1604 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1610 raid_device->volume_type = vol_pg0->VolumeType;
1612 /* figure out what the underlying devices are by
1613 * obtaining the device_info bits for the 1st device
1615 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1616 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1617 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1618 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1619 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1620 le16_to_cpu(pd_pg0.DevHandle)))) {
1621 raid_device->device_info =
1622 le32_to_cpu(sas_device_pg0.DeviceInfo);
1633 * _scsih_enable_tlr - setting TLR flags
1634 * @ioc: per adapter object
1635 * @sdev: scsi device struct
1637 * Enabling Transaction Layer Retries for tape devices when
1638 * vpd page 0x90 is present
1642 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1646 if (sdev->type != TYPE_TAPE)
1649 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1652 sas_enable_tlr(sdev);
1653 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1654 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1660 * _scsih_slave_configure - device configure routine.
1661 * @sdev: scsi device struct
1663 * Returns 0 if ok. Any other return is assumed to be an error and
1664 * the device is ignored.
1667 _scsih_slave_configure(struct scsi_device *sdev)
1669 struct Scsi_Host *shost = sdev->host;
1670 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1671 struct MPT3SAS_DEVICE *sas_device_priv_data;
1672 struct MPT3SAS_TARGET *sas_target_priv_data;
1673 struct _sas_device *sas_device;
1674 struct _raid_device *raid_device;
1675 unsigned long flags;
1680 u16 handle, volume_handle = 0;
1681 u64 volume_wwid = 0;
1684 sas_device_priv_data = sdev->hostdata;
1685 sas_device_priv_data->configured_lun = 1;
1686 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1687 sas_target_priv_data = sas_device_priv_data->sas_target;
1688 handle = sas_target_priv_data->handle;
1690 /* raid volume handling */
1691 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1693 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1694 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1695 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1697 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1698 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1699 __LINE__, __func__));
1703 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1704 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1705 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1706 __LINE__, __func__));
1711 /* RAID Queue Depth Support
1712 * IS volume = underlying qdepth of drive type, either
1713 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1714 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1716 if (raid_device->device_info &
1717 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1718 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1721 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1722 if (raid_device->device_info &
1723 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1729 switch (raid_device->volume_type) {
1730 case MPI2_RAID_VOL_TYPE_RAID0:
1733 case MPI2_RAID_VOL_TYPE_RAID1E:
1734 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1735 if (ioc->manu_pg10.OEMIdentifier &&
1736 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1737 MFG10_GF0_R10_DISPLAY) &&
1738 !(raid_device->num_pds % 2))
1743 case MPI2_RAID_VOL_TYPE_RAID1:
1744 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1747 case MPI2_RAID_VOL_TYPE_RAID10:
1748 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1751 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1753 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1758 sdev_printk(KERN_INFO, sdev,
1759 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1760 r_level, raid_device->handle,
1761 (unsigned long long)raid_device->wwid,
1762 raid_device->num_pds, ds);
1765 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1767 /* raid transport support */
1768 _scsih_set_level(sdev, raid_device->volume_type);
1772 /* non-raid handling */
1773 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1774 if (mpt3sas_config_get_volume_handle(ioc, handle,
1776 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1777 "failure at %s:%d/%s()!\n", ioc->name,
1778 __FILE__, __LINE__, __func__));
1781 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1782 volume_handle, &volume_wwid)) {
1783 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1784 "failure at %s:%d/%s()!\n", ioc->name,
1785 __FILE__, __LINE__, __func__));
1790 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1791 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1792 sas_device_priv_data->sas_target->sas_address);
1794 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1795 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1796 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1801 sas_device->volume_handle = volume_handle;
1802 sas_device->volume_wwid = volume_wwid;
1803 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1804 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1808 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1809 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1811 else if (sas_device->device_info &
1812 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1816 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1817 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1818 ds, handle, (unsigned long long)sas_device->sas_address,
1819 sas_device->phy, (unsigned long long)sas_device->device_name);
1820 sdev_printk(KERN_INFO, sdev,
1821 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1822 ds, (unsigned long long)
1823 sas_device->enclosure_logical_id, sas_device->slot);
1825 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1828 _scsih_display_sata_capabilities(ioc, handle, sdev);
1831 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1834 sas_read_port_mode_page(sdev);
1835 _scsih_enable_tlr(ioc, sdev);
1842 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1843 * @sdev: scsi device struct
1844 * @bdev: pointer to block device context
1845 * @capacity: device size (in 512 byte sectors)
1846 * @params: three element array to place output:
1847 * params[0] number of heads (max 255)
1848 * params[1] number of sectors (max 63)
1849 * params[2] number of cylinders
1854 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1855 sector_t capacity, int params[])
1865 dummy = heads * sectors;
1866 cylinders = capacity;
1867 sector_div(cylinders, dummy);
1870 * Handle extended translation size for logical drives
1873 if ((ulong)capacity >= 0x200000) {
1876 dummy = heads * sectors;
1877 cylinders = capacity;
1878 sector_div(cylinders, dummy);
1883 params[1] = sectors;
1884 params[2] = cylinders;
1890 * _scsih_response_code - translation of device response code
1891 * @ioc: per adapter object
1892 * @response_code: response code returned by the device
1897 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1901 switch (response_code) {
1902 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1903 desc = "task management request completed";
1905 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1906 desc = "invalid frame";
1908 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1909 desc = "task management request not supported";
1911 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1912 desc = "task management request failed";
1914 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1915 desc = "task management request succeeded";
1917 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1918 desc = "invalid lun";
1921 desc = "overlapped tag attempted";
1923 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1924 desc = "task queued, however not sent to target";
1930 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1931 ioc->name, response_code, desc);
1935 * _scsih_tm_done - tm completion routine
1936 * @ioc: per adapter object
1937 * @smid: system request message index
1938 * @msix_index: MSIX table index supplied by the OS
1939 * @reply: reply message frame(lower 32bit addr)
1942 * The callback handler when using scsih_issue_tm.
1944 * Return 1 meaning mf should be freed from _base_interrupt
1945 * 0 means the mf is freed from this function.
1948 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1950 MPI2DefaultReply_t *mpi_reply;
1952 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1954 if (ioc->tm_cmds.smid != smid)
1956 mpt3sas_base_flush_reply_queues(ioc);
1957 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1958 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1960 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1961 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1963 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1964 complete(&ioc->tm_cmds.done);
1969 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1970 * @ioc: per adapter object
1971 * @handle: device handle
1973 * During taskmangement request, we need to freeze the device queue.
1976 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1978 struct MPT3SAS_DEVICE *sas_device_priv_data;
1979 struct scsi_device *sdev;
1982 shost_for_each_device(sdev, ioc->shost) {
1985 sas_device_priv_data = sdev->hostdata;
1986 if (!sas_device_priv_data)
1988 if (sas_device_priv_data->sas_target->handle == handle) {
1989 sas_device_priv_data->sas_target->tm_busy = 1;
1991 ioc->ignore_loginfos = 1;
1997 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1998 * @ioc: per adapter object
1999 * @handle: device handle
2001 * During taskmangement request, we need to freeze the device queue.
2004 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2006 struct MPT3SAS_DEVICE *sas_device_priv_data;
2007 struct scsi_device *sdev;
2010 shost_for_each_device(sdev, ioc->shost) {
2013 sas_device_priv_data = sdev->hostdata;
2014 if (!sas_device_priv_data)
2016 if (sas_device_priv_data->sas_target->handle == handle) {
2017 sas_device_priv_data->sas_target->tm_busy = 0;
2019 ioc->ignore_loginfos = 0;
2025 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2026 * @ioc: per adapter struct
2027 * @device_handle: device handle
2028 * @channel: the channel assigned by the OS
2029 * @id: the id assigned by the OS
2031 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2032 * @smid_task: smid assigned to the task
2033 * @timeout: timeout in seconds
2034 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2037 * A generic API for sending task management requests to firmware.
2039 * The callback index is set inside `ioc->tm_cb_idx`.
2041 * Return SUCCESS or FAILED.
2044 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2045 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2046 enum mutex_type m_type)
2048 Mpi2SCSITaskManagementRequest_t *mpi_request;
2049 Mpi2SCSITaskManagementReply_t *mpi_reply;
2052 unsigned long timeleft;
2053 struct scsiio_tracker *scsi_lookup = NULL;
2056 if (m_type == TM_MUTEX_ON)
2057 mutex_lock(&ioc->tm_cmds.mutex);
2058 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2059 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2060 __func__, ioc->name);
2065 if (ioc->shost_recovery || ioc->remove_host ||
2066 ioc->pci_error_recovery) {
2067 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2068 __func__, ioc->name);
2073 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2074 if (ioc_state & MPI2_DOORBELL_USED) {
2075 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2076 "unexpected doorbell active!\n", ioc->name));
2077 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2079 rc = (!rc) ? SUCCESS : FAILED;
2083 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2084 mpt3sas_base_fault_info(ioc, ioc_state &
2085 MPI2_DOORBELL_DATA_MASK);
2086 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2088 rc = (!rc) ? SUCCESS : FAILED;
2092 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2094 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2095 ioc->name, __func__);
2100 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2101 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2103 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2104 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2105 ioc->name, handle, type, smid_task));
2106 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2107 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2108 ioc->tm_cmds.smid = smid;
2109 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2110 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2111 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2112 mpi_request->DevHandle = cpu_to_le16(handle);
2113 mpi_request->TaskType = type;
2114 mpi_request->TaskMID = cpu_to_le16(smid_task);
2115 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2116 mpt3sas_scsih_set_tm_flag(ioc, handle);
2117 init_completion(&ioc->tm_cmds.done);
2118 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2119 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2120 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2121 pr_err(MPT3SAS_FMT "%s: timeout\n",
2122 ioc->name, __func__);
2123 _debug_dump_mf(mpi_request,
2124 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2125 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2126 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2128 rc = (!rc) ? SUCCESS : FAILED;
2129 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2130 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2135 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2136 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2137 mpi_reply = ioc->tm_cmds.reply;
2138 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2139 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2140 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2141 le32_to_cpu(mpi_reply->IOCLogInfo),
2142 le32_to_cpu(mpi_reply->TerminationCount)));
2143 if (ioc->logging_level & MPT_DEBUG_TM) {
2144 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2145 if (mpi_reply->IOCStatus)
2146 _debug_dump_mf(mpi_request,
2147 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2152 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2154 if (scsi_lookup->scmd == NULL)
2159 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2160 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2165 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2166 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2167 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2172 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2180 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2181 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2182 if (m_type == TM_MUTEX_ON)
2183 mutex_unlock(&ioc->tm_cmds.mutex);
2188 if (m_type == TM_MUTEX_ON)
2189 mutex_unlock(&ioc->tm_cmds.mutex);
2194 * _scsih_tm_display_info - displays info about the device
2195 * @ioc: per adapter struct
2196 * @scmd: pointer to scsi command object
2198 * Called by task management callback handlers.
2201 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2203 struct scsi_target *starget = scmd->device->sdev_target;
2204 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2205 struct _sas_device *sas_device = NULL;
2206 unsigned long flags;
2207 char *device_str = NULL;
2211 device_str = "volume";
2213 scsi_print_command(scmd);
2214 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2215 starget_printk(KERN_INFO, starget,
2216 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2217 device_str, priv_target->handle,
2218 device_str, (unsigned long long)priv_target->sas_address);
2220 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2221 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2222 priv_target->sas_address);
2224 if (priv_target->flags &
2225 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2226 starget_printk(KERN_INFO, starget,
2227 "volume handle(0x%04x), "
2228 "volume wwid(0x%016llx)\n",
2229 sas_device->volume_handle,
2230 (unsigned long long)sas_device->volume_wwid);
2232 starget_printk(KERN_INFO, starget,
2233 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2235 (unsigned long long)sas_device->sas_address,
2237 starget_printk(KERN_INFO, starget,
2238 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2239 (unsigned long long)sas_device->enclosure_logical_id,
2242 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2247 * _scsih_abort - eh threads main abort routine
2248 * @scmd: pointer to scsi command object
2250 * Returns SUCCESS if command aborted else FAILED
2253 _scsih_abort(struct scsi_cmnd *scmd)
2255 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2256 struct MPT3SAS_DEVICE *sas_device_priv_data;
2261 sdev_printk(KERN_INFO, scmd->device,
2262 "attempting task abort! scmd(%p)\n", scmd);
2263 _scsih_tm_display_info(ioc, scmd);
2265 sas_device_priv_data = scmd->device->hostdata;
2266 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2267 sdev_printk(KERN_INFO, scmd->device,
2268 "device been deleted! scmd(%p)\n", scmd);
2269 scmd->result = DID_NO_CONNECT << 16;
2270 scmd->scsi_done(scmd);
2275 /* search for the command */
2276 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2278 scmd->result = DID_RESET << 16;
2283 /* for hidden raid components and volumes this is not supported */
2284 if (sas_device_priv_data->sas_target->flags &
2285 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2286 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2287 scmd->result = DID_RESET << 16;
2292 mpt3sas_halt_firmware(ioc);
2294 handle = sas_device_priv_data->sas_target->handle;
2295 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2296 scmd->device->id, scmd->device->lun,
2297 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2300 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2301 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2306 * _scsih_dev_reset - eh threads main device reset routine
2307 * @scmd: pointer to scsi command object
2309 * Returns SUCCESS if command aborted else FAILED
2312 _scsih_dev_reset(struct scsi_cmnd *scmd)
2314 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2315 struct MPT3SAS_DEVICE *sas_device_priv_data;
2316 struct _sas_device *sas_device;
2317 unsigned long flags;
2321 sdev_printk(KERN_INFO, scmd->device,
2322 "attempting device reset! scmd(%p)\n", scmd);
2323 _scsih_tm_display_info(ioc, scmd);
2325 sas_device_priv_data = scmd->device->hostdata;
2326 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2327 sdev_printk(KERN_INFO, scmd->device,
2328 "device been deleted! scmd(%p)\n", scmd);
2329 scmd->result = DID_NO_CONNECT << 16;
2330 scmd->scsi_done(scmd);
2335 /* for hidden raid components obtain the volume_handle */
2337 if (sas_device_priv_data->sas_target->flags &
2338 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2339 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2340 sas_device = _scsih_sas_device_find_by_handle(ioc,
2341 sas_device_priv_data->sas_target->handle);
2343 handle = sas_device->volume_handle;
2344 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2346 handle = sas_device_priv_data->sas_target->handle;
2349 scmd->result = DID_RESET << 16;
2354 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2355 scmd->device->id, scmd->device->lun,
2356 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2359 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2360 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2365 * _scsih_target_reset - eh threads main target reset routine
2366 * @scmd: pointer to scsi command object
2368 * Returns SUCCESS if command aborted else FAILED
2371 _scsih_target_reset(struct scsi_cmnd *scmd)
2373 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2374 struct MPT3SAS_DEVICE *sas_device_priv_data;
2375 struct _sas_device *sas_device;
2376 unsigned long flags;
2379 struct scsi_target *starget = scmd->device->sdev_target;
2381 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2383 _scsih_tm_display_info(ioc, scmd);
2385 sas_device_priv_data = scmd->device->hostdata;
2386 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2387 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2389 scmd->result = DID_NO_CONNECT << 16;
2390 scmd->scsi_done(scmd);
2395 /* for hidden raid components obtain the volume_handle */
2397 if (sas_device_priv_data->sas_target->flags &
2398 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2399 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2400 sas_device = _scsih_sas_device_find_by_handle(ioc,
2401 sas_device_priv_data->sas_target->handle);
2403 handle = sas_device->volume_handle;
2404 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2406 handle = sas_device_priv_data->sas_target->handle;
2409 scmd->result = DID_RESET << 16;
2414 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2415 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2419 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2420 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2426 * _scsih_host_reset - eh threads main host reset routine
2427 * @scmd: pointer to scsi command object
2429 * Returns SUCCESS if command aborted else FAILED
2432 _scsih_host_reset(struct scsi_cmnd *scmd)
2434 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2437 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2439 scsi_print_command(scmd);
2441 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2443 r = (retval < 0) ? FAILED : SUCCESS;
2444 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2445 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2451 * _scsih_fw_event_add - insert and queue up fw_event
2452 * @ioc: per adapter object
2453 * @fw_event: object describing the event
2454 * Context: This function will acquire ioc->fw_event_lock.
2456 * This adds the firmware event object into link list, then queues it up to
2457 * be processed from user context.
2462 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2464 unsigned long flags;
2466 if (ioc->firmware_event_thread == NULL)
2469 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2470 INIT_LIST_HEAD(&fw_event->list);
2471 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2472 INIT_WORK(&fw_event->work, _firmware_event_work);
2473 queue_work(ioc->firmware_event_thread, &fw_event->work);
2474 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2478 * _scsih_fw_event_free - delete fw_event
2479 * @ioc: per adapter object
2480 * @fw_event: object describing the event
2481 * Context: This function will acquire ioc->fw_event_lock.
2483 * This removes firmware event object from link list, frees associated memory.
2488 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2491 unsigned long flags;
2493 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2494 list_del(&fw_event->list);
2495 kfree(fw_event->event_data);
2497 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2502 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2503 * @ioc: per adapter object
2504 * @event_data: trigger event data
2509 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2510 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2512 struct fw_event_work *fw_event;
2514 if (ioc->is_driver_loading)
2516 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2519 fw_event->event_data = kzalloc(sizeof(*event_data), GFP_ATOMIC);
2520 if (!fw_event->event_data)
2522 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2523 fw_event->ioc = ioc;
2524 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2525 _scsih_fw_event_add(ioc, fw_event);
2529 * _scsih_error_recovery_delete_devices - remove devices not responding
2530 * @ioc: per adapter object
2535 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2537 struct fw_event_work *fw_event;
2539 if (ioc->is_driver_loading)
2541 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2544 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2545 fw_event->ioc = ioc;
2546 _scsih_fw_event_add(ioc, fw_event);
2550 * mpt3sas_port_enable_complete - port enable completed (fake event)
2551 * @ioc: per adapter object
2556 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2558 struct fw_event_work *fw_event;
2560 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2563 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2564 fw_event->ioc = ioc;
2565 _scsih_fw_event_add(ioc, fw_event);
2569 * _scsih_fw_event_cleanup_queue - cleanup event queue
2570 * @ioc: per adapter object
2572 * Walk the firmware event queue, either killing timers, or waiting
2573 * for outstanding events to complete
2578 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2580 struct fw_event_work *fw_event, *next;
2582 if (list_empty(&ioc->fw_event_list) ||
2583 !ioc->firmware_event_thread || in_interrupt())
2586 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2587 if (cancel_delayed_work(&fw_event->delayed_work)) {
2588 _scsih_fw_event_free(ioc, fw_event);
2591 fw_event->cancel_pending_work = 1;
2596 * _scsih_ublock_io_all_device - unblock every device
2597 * @ioc: per adapter object
2599 * change the device state from block to running
2602 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2604 struct MPT3SAS_DEVICE *sas_device_priv_data;
2605 struct scsi_device *sdev;
2607 shost_for_each_device(sdev, ioc->shost) {
2608 sas_device_priv_data = sdev->hostdata;
2609 if (!sas_device_priv_data)
2611 if (!sas_device_priv_data->block)
2614 sas_device_priv_data->block = 0;
2615 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2616 "device_running, handle(0x%04x)\n",
2617 sas_device_priv_data->sas_target->handle));
2618 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2624 * _scsih_ublock_io_device - prepare device to be deleted
2625 * @ioc: per adapter object
2626 * @sas_addr: sas address
2628 * unblock then put device in offline state
2631 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2633 struct MPT3SAS_DEVICE *sas_device_priv_data;
2634 struct scsi_device *sdev;
2636 shost_for_each_device(sdev, ioc->shost) {
2637 sas_device_priv_data = sdev->hostdata;
2638 if (!sas_device_priv_data)
2640 if (sas_device_priv_data->sas_target->sas_address
2643 if (sas_device_priv_data->block) {
2644 sas_device_priv_data->block = 0;
2645 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2651 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2652 * @ioc: per adapter object
2653 * @handle: device handle
2655 * During device pull we need to appropiately set the sdev state.
2658 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2660 struct MPT3SAS_DEVICE *sas_device_priv_data;
2661 struct scsi_device *sdev;
2663 shost_for_each_device(sdev, ioc->shost) {
2664 sas_device_priv_data = sdev->hostdata;
2665 if (!sas_device_priv_data)
2667 if (sas_device_priv_data->block)
2669 sas_device_priv_data->block = 1;
2670 scsi_internal_device_block(sdev);
2671 sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n",
2672 sas_device_priv_data->sas_target->handle);
2677 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2678 * @ioc: per adapter object
2679 * @handle: device handle
2681 * During device pull we need to appropiately set the sdev state.
2684 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2686 struct MPT3SAS_DEVICE *sas_device_priv_data;
2687 struct scsi_device *sdev;
2689 shost_for_each_device(sdev, ioc->shost) {
2690 sas_device_priv_data = sdev->hostdata;
2691 if (!sas_device_priv_data)
2693 if (sas_device_priv_data->sas_target->handle != handle)
2695 if (sas_device_priv_data->block)
2697 sas_device_priv_data->block = 1;
2698 scsi_internal_device_block(sdev);
2699 sdev_printk(KERN_INFO, sdev,
2700 "device_blocked, handle(0x%04x)\n", handle);
2705 * _scsih_block_io_to_children_attached_to_ex
2706 * @ioc: per adapter object
2707 * @sas_expander: the sas_device object
2709 * This routine set sdev state to SDEV_BLOCK for all devices
2710 * attached to this expander. This function called when expander is
2714 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2715 struct _sas_node *sas_expander)
2717 struct _sas_port *mpt3sas_port;
2718 struct _sas_device *sas_device;
2719 struct _sas_node *expander_sibling;
2720 unsigned long flags;
2725 list_for_each_entry(mpt3sas_port,
2726 &sas_expander->sas_port_list, port_list) {
2727 if (mpt3sas_port->remote_identify.device_type ==
2729 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2731 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2732 mpt3sas_port->remote_identify.sas_address);
2734 set_bit(sas_device->handle,
2735 ioc->blocking_handles);
2736 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2740 list_for_each_entry(mpt3sas_port,
2741 &sas_expander->sas_port_list, port_list) {
2743 if (mpt3sas_port->remote_identify.device_type ==
2744 SAS_EDGE_EXPANDER_DEVICE ||
2745 mpt3sas_port->remote_identify.device_type ==
2746 SAS_FANOUT_EXPANDER_DEVICE) {
2748 mpt3sas_scsih_expander_find_by_sas_address(
2749 ioc, mpt3sas_port->remote_identify.sas_address);
2750 _scsih_block_io_to_children_attached_to_ex(ioc,
2757 * _scsih_block_io_to_children_attached_directly
2758 * @ioc: per adapter object
2759 * @event_data: topology change event data
2761 * This routine set sdev state to SDEV_BLOCK for all devices
2762 * direct attached during device pull.
2765 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2766 Mpi2EventDataSasTopologyChangeList_t *event_data)
2772 for (i = 0; i < event_data->NumEntries; i++) {
2773 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2776 reason_code = event_data->PHY[i].PhyStatus &
2777 MPI2_EVENT_SAS_TOPO_RC_MASK;
2778 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2779 _scsih_block_io_device(ioc, handle);
2784 * _scsih_tm_tr_send - send task management request
2785 * @ioc: per adapter object
2786 * @handle: device handle
2787 * Context: interrupt time.
2789 * This code is to initiate the device removal handshake protocol
2790 * with controller firmware. This function will issue target reset
2791 * using high priority request queue. It will send a sas iounit
2792 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2794 * This is designed to send muliple task management request at the same
2795 * time to the fifo. If the fifo is full, we will append the request,
2796 * and process it in a future completion.
2799 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2801 Mpi2SCSITaskManagementRequest_t *mpi_request;
2803 struct _sas_device *sas_device;
2804 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2805 u64 sas_address = 0;
2806 unsigned long flags;
2807 struct _tr_list *delayed_tr;
2810 if (ioc->remove_host) {
2811 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2812 "%s: host has been removed: handle(0x%04x)\n",
2813 __func__, ioc->name, handle));
2815 } else if (ioc->pci_error_recovery) {
2816 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2817 "%s: host in pci error recovery: handle(0x%04x)\n",
2818 __func__, ioc->name,
2822 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2823 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2824 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2825 "%s: host is not operational: handle(0x%04x)\n",
2826 __func__, ioc->name,
2831 /* if PD, then return */
2832 if (test_bit(handle, ioc->pd_handles))
2835 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2836 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2837 if (sas_device && sas_device->starget &&
2838 sas_device->starget->hostdata) {
2839 sas_target_priv_data = sas_device->starget->hostdata;
2840 sas_target_priv_data->deleted = 1;
2841 sas_address = sas_device->sas_address;
2843 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2845 if (sas_target_priv_data) {
2846 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2847 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2849 (unsigned long long)sas_address));
2850 _scsih_ublock_io_device(ioc, sas_address);
2851 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2854 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2856 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2859 INIT_LIST_HEAD(&delayed_tr->list);
2860 delayed_tr->handle = handle;
2861 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2862 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2863 "DELAYED:tr:handle(0x%04x), (open)\n",
2864 ioc->name, handle));
2868 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2869 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2870 ioc->name, handle, smid,
2871 ioc->tm_tr_cb_idx));
2872 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2873 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2874 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2875 mpi_request->DevHandle = cpu_to_le16(handle);
2876 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2877 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2878 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2882 * _scsih_tm_tr_complete -
2883 * @ioc: per adapter object
2884 * @smid: system request message index
2885 * @msix_index: MSIX table index supplied by the OS
2886 * @reply: reply message frame(lower 32bit addr)
2887 * Context: interrupt time.
2889 * This is the target reset completion routine.
2890 * This code is part of the code to initiate the device removal
2891 * handshake protocol with controller firmware.
2892 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2894 * Return 1 meaning mf should be freed from _base_interrupt
2895 * 0 means the mf is freed from this function.
2898 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2902 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2903 Mpi2SCSITaskManagementReply_t *mpi_reply =
2904 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2905 Mpi2SasIoUnitControlRequest_t *mpi_request;
2909 if (ioc->remove_host) {
2910 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2911 "%s: host has been removed\n", __func__, ioc->name));
2913 } else if (ioc->pci_error_recovery) {
2914 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2915 "%s: host in pci error recovery\n", __func__,
2919 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2920 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2921 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2922 "%s: host is not operational\n", __func__, ioc->name));
2925 if (unlikely(!mpi_reply)) {
2926 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2927 ioc->name, __FILE__, __LINE__, __func__);
2930 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2931 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2932 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2933 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2934 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2936 le16_to_cpu(mpi_reply->DevHandle), smid));
2940 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2941 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2942 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2943 "loginfo(0x%08x), completed(%d)\n", ioc->name,
2944 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
2945 le32_to_cpu(mpi_reply->IOCLogInfo),
2946 le32_to_cpu(mpi_reply->TerminationCount)));
2948 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2949 if (!smid_sas_ctrl) {
2950 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2951 ioc->name, __func__);
2955 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2956 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2957 ioc->name, handle, smid_sas_ctrl,
2958 ioc->tm_sas_control_cb_idx));
2959 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2960 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2961 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2962 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2963 mpi_request->DevHandle = mpi_request_tm->DevHandle;
2964 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
2966 return _scsih_check_for_pending_tm(ioc, smid);
2971 * _scsih_sas_control_complete - completion routine
2972 * @ioc: per adapter object
2973 * @smid: system request message index
2974 * @msix_index: MSIX table index supplied by the OS
2975 * @reply: reply message frame(lower 32bit addr)
2976 * Context: interrupt time.
2978 * This is the sas iounit control completion routine.
2979 * This code is part of the code to initiate the device removal
2980 * handshake protocol with controller firmware.
2982 * Return 1 meaning mf should be freed from _base_interrupt
2983 * 0 means the mf is freed from this function.
2986 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
2987 u8 msix_index, u32 reply)
2989 Mpi2SasIoUnitControlReply_t *mpi_reply =
2990 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2992 if (likely(mpi_reply)) {
2993 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2994 "sc_complete:handle(0x%04x), (open) "
2995 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2996 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2997 le16_to_cpu(mpi_reply->IOCStatus),
2998 le32_to_cpu(mpi_reply->IOCLogInfo)));
3000 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3001 ioc->name, __FILE__, __LINE__, __func__);
3007 * _scsih_tm_tr_volume_send - send target reset request for volumes
3008 * @ioc: per adapter object
3009 * @handle: device handle
3010 * Context: interrupt time.
3012 * This is designed to send muliple task management request at the same
3013 * time to the fifo. If the fifo is full, we will append the request,
3014 * and process it in a future completion.
3017 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3019 Mpi2SCSITaskManagementRequest_t *mpi_request;
3021 struct _tr_list *delayed_tr;
3023 if (ioc->shost_recovery || ioc->remove_host ||
3024 ioc->pci_error_recovery) {
3025 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3026 "%s: host reset in progress!\n",
3027 __func__, ioc->name));
3031 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3033 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3036 INIT_LIST_HEAD(&delayed_tr->list);
3037 delayed_tr->handle = handle;
3038 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3039 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3040 "DELAYED:tr:handle(0x%04x), (open)\n",
3041 ioc->name, handle));
3045 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3046 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3047 ioc->name, handle, smid,
3048 ioc->tm_tr_volume_cb_idx));
3049 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3050 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3051 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3052 mpi_request->DevHandle = cpu_to_le16(handle);
3053 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3054 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3058 * _scsih_tm_volume_tr_complete - target reset completion
3059 * @ioc: per adapter object
3060 * @smid: system request message index
3061 * @msix_index: MSIX table index supplied by the OS
3062 * @reply: reply message frame(lower 32bit addr)
3063 * Context: interrupt time.
3065 * Return 1 meaning mf should be freed from _base_interrupt
3066 * 0 means the mf is freed from this function.
3069 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3070 u8 msix_index, u32 reply)
3073 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3074 Mpi2SCSITaskManagementReply_t *mpi_reply =
3075 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3077 if (ioc->shost_recovery || ioc->remove_host ||
3078 ioc->pci_error_recovery) {
3079 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3080 "%s: host reset in progress!\n",
3081 __func__, ioc->name));
3084 if (unlikely(!mpi_reply)) {
3085 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3086 ioc->name, __FILE__, __LINE__, __func__);
3090 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3091 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3092 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3093 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3094 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3096 le16_to_cpu(mpi_reply->DevHandle), smid));
3100 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3101 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3102 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3103 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3104 le32_to_cpu(mpi_reply->IOCLogInfo),
3105 le32_to_cpu(mpi_reply->TerminationCount)));
3107 return _scsih_check_for_pending_tm(ioc, smid);
3112 * _scsih_check_for_pending_tm - check for pending task management
3113 * @ioc: per adapter object
3114 * @smid: system request message index
3116 * This will check delayed target reset list, and feed the
3119 * Return 1 meaning mf should be freed from _base_interrupt
3120 * 0 means the mf is freed from this function.
3123 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3125 struct _tr_list *delayed_tr;
3127 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3128 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3129 struct _tr_list, list);
3130 mpt3sas_base_free_smid(ioc, smid);
3131 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3132 list_del(&delayed_tr->list);
3137 if (!list_empty(&ioc->delayed_tr_list)) {
3138 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3139 struct _tr_list, list);
3140 mpt3sas_base_free_smid(ioc, smid);
3141 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3142 list_del(&delayed_tr->list);
3151 * _scsih_check_topo_delete_events - sanity check on topo events
3152 * @ioc: per adapter object
3153 * @event_data: the event data payload
3155 * This routine added to better handle cable breaker.
3157 * This handles the case where driver receives multiple expander
3158 * add and delete events in a single shot. When there is a delete event
3159 * the routine will void any pending add events waiting in the event queue.
3164 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3165 Mpi2EventDataSasTopologyChangeList_t *event_data)
3167 struct fw_event_work *fw_event;
3168 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3169 u16 expander_handle;
3170 struct _sas_node *sas_expander;
3171 unsigned long flags;
3175 for (i = 0 ; i < event_data->NumEntries; i++) {
3176 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3179 reason_code = event_data->PHY[i].PhyStatus &
3180 MPI2_EVENT_SAS_TOPO_RC_MASK;
3181 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3182 _scsih_tm_tr_send(ioc, handle);
3185 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3186 if (expander_handle < ioc->sas_hba.num_phys) {
3187 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3190 if (event_data->ExpStatus ==
3191 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3192 /* put expander attached devices into blocking state */
3193 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3194 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3196 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3197 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3199 handle = find_first_bit(ioc->blocking_handles,
3200 ioc->facts.MaxDevHandle);
3201 if (handle < ioc->facts.MaxDevHandle)
3202 _scsih_block_io_device(ioc, handle);
3203 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3204 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3205 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3207 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3210 /* mark ignore flag for pending events */
3211 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3212 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3213 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3216 local_event_data = fw_event->event_data;
3217 if (local_event_data->ExpStatus ==
3218 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3219 local_event_data->ExpStatus ==
3220 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3221 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3223 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3224 "setting ignoring flag\n", ioc->name));
3225 fw_event->ignore = 1;
3229 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3233 * _scsih_set_volume_delete_flag - setting volume delete flag
3234 * @ioc: per adapter object
3235 * @handle: device handle
3237 * This returns nothing.
3240 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3242 struct _raid_device *raid_device;
3243 struct MPT3SAS_TARGET *sas_target_priv_data;
3244 unsigned long flags;
3246 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3247 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3248 if (raid_device && raid_device->starget &&
3249 raid_device->starget->hostdata) {
3250 sas_target_priv_data =
3251 raid_device->starget->hostdata;
3252 sas_target_priv_data->deleted = 1;
3253 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3254 "setting delete flag: handle(0x%04x), "
3255 "wwid(0x%016llx)\n", ioc->name, handle,
3256 (unsigned long long) raid_device->wwid));
3258 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3262 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3263 * @handle: input handle
3264 * @a: handle for volume a
3265 * @b: handle for volume b
3267 * IR firmware only supports two raid volumes. The purpose of this
3268 * routine is to set the volume handle in either a or b. When the given
3269 * input handle is non-zero, or when a and b have not been set before.
3272 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3274 if (!handle || handle == *a || handle == *b)
3283 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3284 * @ioc: per adapter object
3285 * @event_data: the event data payload
3286 * Context: interrupt time.
3288 * This routine will send target reset to volume, followed by target
3289 * resets to the PDs. This is called when a PD has been removed, or
3290 * volume has been deleted or removed. When the target reset is sent
3291 * to volume, the PD target resets need to be queued to start upon
3292 * completion of the volume target reset.
3297 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3298 Mpi2EventDataIrConfigChangeList_t *event_data)
3300 Mpi2EventIrConfigElement_t *element;
3302 u16 handle, volume_handle, a, b;
3303 struct _tr_list *delayed_tr;
3308 /* Volume Resets for Deleted or Removed */
3309 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3310 for (i = 0; i < event_data->NumElements; i++, element++) {
3311 if (le32_to_cpu(event_data->Flags) &
3312 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3314 if (element->ReasonCode ==
3315 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3316 element->ReasonCode ==
3317 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3318 volume_handle = le16_to_cpu(element->VolDevHandle);
3319 _scsih_set_volume_delete_flag(ioc, volume_handle);
3320 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3324 /* Volume Resets for UNHIDE events */
3325 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3326 for (i = 0; i < event_data->NumElements; i++, element++) {
3327 if (le32_to_cpu(event_data->Flags) &
3328 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3330 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3331 volume_handle = le16_to_cpu(element->VolDevHandle);
3332 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3337 _scsih_tm_tr_volume_send(ioc, a);
3339 _scsih_tm_tr_volume_send(ioc, b);
3341 /* PD target resets */
3342 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3343 for (i = 0; i < event_data->NumElements; i++, element++) {
3344 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3346 handle = le16_to_cpu(element->PhysDiskDevHandle);
3347 volume_handle = le16_to_cpu(element->VolDevHandle);
3348 clear_bit(handle, ioc->pd_handles);
3350 _scsih_tm_tr_send(ioc, handle);
3351 else if (volume_handle == a || volume_handle == b) {
3352 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3353 BUG_ON(!delayed_tr);
3354 INIT_LIST_HEAD(&delayed_tr->list);
3355 delayed_tr->handle = handle;
3356 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3357 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3358 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3361 _scsih_tm_tr_send(ioc, handle);
3367 * _scsih_check_volume_delete_events - set delete flag for volumes
3368 * @ioc: per adapter object
3369 * @event_data: the event data payload
3370 * Context: interrupt time.
3372 * This will handle the case when the cable connected to entire volume is
3373 * pulled. We will take care of setting the deleted flag so normal IO will
3379 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3380 Mpi2EventDataIrVolume_t *event_data)
3384 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3386 state = le32_to_cpu(event_data->NewValue);
3387 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3388 MPI2_RAID_VOL_STATE_FAILED)
3389 _scsih_set_volume_delete_flag(ioc,
3390 le16_to_cpu(event_data->VolDevHandle));
3394 * _scsih_flush_running_cmds - completing outstanding commands.
3395 * @ioc: per adapter object
3397 * The flushing out of all pending scmd commands following host reset,
3398 * where all IO is dropped to the floor.
3403 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3405 struct scsi_cmnd *scmd;
3409 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3410 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3414 mpt3sas_base_free_smid(ioc, smid);
3415 scsi_dma_unmap(scmd);
3416 if (ioc->pci_error_recovery)
3417 scmd->result = DID_NO_CONNECT << 16;
3419 scmd->result = DID_RESET << 16;
3420 scmd->scsi_done(scmd);
3422 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3427 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3428 * @ioc: per adapter object
3429 * @scmd: pointer to scsi command object
3430 * @mpi_request: pointer to the SCSI_IO reqest message frame
3432 * Supporting protection 1 and 3.
3437 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3438 Mpi2SCSIIORequest_t *mpi_request)
3441 unsigned char prot_op = scsi_get_prot_op(scmd);
3442 unsigned char prot_type = scsi_get_prot_type(scmd);
3443 Mpi25SCSIIORequest_t *mpi_request_3v =
3444 (Mpi25SCSIIORequest_t *)mpi_request;
3446 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3449 if (prot_op == SCSI_PROT_READ_STRIP)
3450 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3451 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3452 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3456 switch (prot_type) {
3457 case SCSI_PROT_DIF_TYPE1:
3458 case SCSI_PROT_DIF_TYPE2:
3461 * enable ref/guard checking
3462 * auto increment ref tag
3464 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3465 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3466 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3467 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3468 cpu_to_be32(scsi_get_lba(scmd));
3471 case SCSI_PROT_DIF_TYPE3:
3474 * enable guard checking
3476 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3481 mpi_request_3v->EEDPBlockSize =
3482 cpu_to_le16(scmd->device->sector_size);
3483 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3487 * _scsih_eedp_error_handling - return sense code for EEDP errors
3488 * @scmd: pointer to scsi command object
3489 * @ioc_status: ioc status
3494 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3498 switch (ioc_status) {
3499 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3502 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3505 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3512 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3514 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3515 SAM_STAT_CHECK_CONDITION;
3520 * _scsih_qcmd - main scsi request entry point
3521 * @scmd: pointer to scsi command object
3522 * @done: function pointer to be invoked on completion
3524 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3526 * Returns 0 on success. If there's a failure, return either:
3527 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3528 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3531 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3533 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3534 struct MPT3SAS_DEVICE *sas_device_priv_data;
3535 struct MPT3SAS_TARGET *sas_target_priv_data;
3536 Mpi2SCSIIORequest_t *mpi_request;
3541 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3542 if (ioc->logging_level & MPT_DEBUG_SCSI)
3543 scsi_print_command(scmd);
3546 sas_device_priv_data = scmd->device->hostdata;
3547 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3548 scmd->result = DID_NO_CONNECT << 16;
3549 scmd->scsi_done(scmd);
3553 if (ioc->pci_error_recovery || ioc->remove_host) {
3554 scmd->result = DID_NO_CONNECT << 16;
3555 scmd->scsi_done(scmd);
3559 sas_target_priv_data = sas_device_priv_data->sas_target;
3561 /* invalid device handle */
3562 handle = sas_target_priv_data->handle;
3563 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3564 scmd->result = DID_NO_CONNECT << 16;
3565 scmd->scsi_done(scmd);
3570 /* host recovery or link resets sent via IOCTLs */
3571 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3572 return SCSI_MLQUEUE_HOST_BUSY;
3574 /* device has been deleted */
3575 else if (sas_target_priv_data->deleted) {
3576 scmd->result = DID_NO_CONNECT << 16;
3577 scmd->scsi_done(scmd);
3579 /* device busy with task managment */
3580 } else if (sas_target_priv_data->tm_busy ||
3581 sas_device_priv_data->block)
3582 return SCSI_MLQUEUE_DEVICE_BUSY;
3584 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3585 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3586 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3587 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3589 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3592 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3593 if (scmd->device->tagged_supported) {
3594 if (scmd->device->ordered_tags)
3595 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3597 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3599 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3601 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3603 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3604 scmd->cmd_len != 32)
3605 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3607 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3609 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3610 ioc->name, __func__);
3613 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3614 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3615 _scsih_setup_eedp(ioc, scmd, mpi_request);
3617 if (scmd->cmd_len == 32)
3618 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3619 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3620 if (sas_device_priv_data->sas_target->flags &
3621 MPT_TARGET_FLAGS_RAID_COMPONENT)
3622 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3624 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3625 mpi_request->DevHandle = cpu_to_le16(handle);
3626 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3627 mpi_request->Control = cpu_to_le32(mpi_control);
3628 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3629 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3630 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3631 mpi_request->SenseBufferLowAddress =
3632 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3633 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3634 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3636 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3638 if (mpi_request->DataLength) {
3639 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3640 mpt3sas_base_free_smid(ioc, smid);
3644 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3646 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3647 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3648 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3649 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3650 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3652 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3654 mpt3sas_base_put_smid_default(ioc, smid);
3658 return SCSI_MLQUEUE_HOST_BUSY;
3662 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3663 * @sense_buffer: sense data returned by target
3664 * @data: normalized skey/asc/ascq
3669 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3671 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3672 /* descriptor format */
3673 data->skey = sense_buffer[1] & 0x0F;
3674 data->asc = sense_buffer[2];
3675 data->ascq = sense_buffer[3];
3678 data->skey = sense_buffer[2] & 0x0F;
3679 data->asc = sense_buffer[12];
3680 data->ascq = sense_buffer[13];
3684 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3686 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3687 * @ioc: per adapter object
3688 * @scmd: pointer to scsi command object
3689 * @mpi_reply: reply mf payload returned from firmware
3691 * scsi_status - SCSI Status code returned from target device
3692 * scsi_state - state info associated with SCSI_IO determined by ioc
3693 * ioc_status - ioc supplied status info
3698 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3699 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3703 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3704 MPI2_IOCSTATUS_MASK;
3705 u8 scsi_state = mpi_reply->SCSIState;
3706 u8 scsi_status = mpi_reply->SCSIStatus;
3707 char *desc_ioc_state = NULL;
3708 char *desc_scsi_status = NULL;
3709 char *desc_scsi_state = ioc->tmp_string;
3710 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3711 struct _sas_device *sas_device = NULL;
3712 unsigned long flags;
3713 struct scsi_target *starget = scmd->device->sdev_target;
3714 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3715 char *device_str = NULL;
3719 device_str = "volume";
3721 if (log_info == 0x31170000)
3724 switch (ioc_status) {
3725 case MPI2_IOCSTATUS_SUCCESS:
3726 desc_ioc_state = "success";
3728 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3729 desc_ioc_state = "invalid function";
3731 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3732 desc_ioc_state = "scsi recovered error";
3734 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3735 desc_ioc_state = "scsi invalid dev handle";
3737 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3738 desc_ioc_state = "scsi device not there";
3740 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3741 desc_ioc_state = "scsi data overrun";
3743 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3744 desc_ioc_state = "scsi data underrun";
3746 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3747 desc_ioc_state = "scsi io data error";
3749 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3750 desc_ioc_state = "scsi protocol error";
3752 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3753 desc_ioc_state = "scsi task terminated";
3755 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3756 desc_ioc_state = "scsi residual mismatch";
3758 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3759 desc_ioc_state = "scsi task mgmt failed";
3761 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3762 desc_ioc_state = "scsi ioc terminated";
3764 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3765 desc_ioc_state = "scsi ext terminated";
3767 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3768 desc_ioc_state = "eedp guard error";
3770 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3771 desc_ioc_state = "eedp ref tag error";
3773 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3774 desc_ioc_state = "eedp app tag error";
3777 desc_ioc_state = "unknown";
3781 switch (scsi_status) {
3782 case MPI2_SCSI_STATUS_GOOD:
3783 desc_scsi_status = "good";
3785 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3786 desc_scsi_status = "check condition";
3788 case MPI2_SCSI_STATUS_CONDITION_MET:
3789 desc_scsi_status = "condition met";
3791 case MPI2_SCSI_STATUS_BUSY:
3792 desc_scsi_status = "busy";
3794 case MPI2_SCSI_STATUS_INTERMEDIATE:
3795 desc_scsi_status = "intermediate";
3797 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3798 desc_scsi_status = "intermediate condmet";
3800 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3801 desc_scsi_status = "reservation conflict";
3803 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3804 desc_scsi_status = "command terminated";
3806 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3807 desc_scsi_status = "task set full";
3809 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3810 desc_scsi_status = "aca active";
3812 case MPI2_SCSI_STATUS_TASK_ABORTED:
3813 desc_scsi_status = "task aborted";
3816 desc_scsi_status = "unknown";
3820 desc_scsi_state[0] = '\0';
3822 desc_scsi_state = " ";
3823 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3824 strcat(desc_scsi_state, "response info ");
3825 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3826 strcat(desc_scsi_state, "state terminated ");
3827 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3828 strcat(desc_scsi_state, "no status ");
3829 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3830 strcat(desc_scsi_state, "autosense failed ");
3831 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3832 strcat(desc_scsi_state, "autosense valid ");
3834 scsi_print_command(scmd);
3836 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3837 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3838 device_str, (unsigned long long)priv_target->sas_address);
3840 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3841 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3842 priv_target->sas_address);
3845 "\tsas_address(0x%016llx), phy(%d)\n",
3846 ioc->name, (unsigned long long)
3847 sas_device->sas_address, sas_device->phy);
3849 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3850 ioc->name, (unsigned long long)
3851 sas_device->enclosure_logical_id, sas_device->slot);
3853 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3857 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3858 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3859 desc_ioc_state, ioc_status, smid);
3861 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3862 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3863 scsi_get_resid(scmd));
3865 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3866 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3867 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3869 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3870 ioc->name, desc_scsi_status,
3871 scsi_status, desc_scsi_state, scsi_state);
3873 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3874 struct sense_info data;
3875 _scsih_normalize_sense(scmd->sense_buffer, &data);
3877 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3878 ioc->name, data.skey,
3879 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3882 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3883 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3884 response_bytes = (u8 *)&response_info;
3885 _scsih_response_code(ioc, response_bytes[0]);
3891 * _scsih_turn_on_fault_led - illuminate Fault LED
3892 * @ioc: per adapter object
3893 * @handle: device handle
3899 _scsih_turn_on_fault_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3901 Mpi2SepReply_t mpi_reply;
3902 Mpi2SepRequest_t mpi_request;
3904 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3905 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3906 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3907 mpi_request.SlotStatus =
3908 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3909 mpi_request.DevHandle = cpu_to_le16(handle);
3910 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3911 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3912 &mpi_request)) != 0) {
3913 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3914 __FILE__, __LINE__, __func__);
3918 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3919 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3920 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3921 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3922 le32_to_cpu(mpi_reply.IOCLogInfo)));
3928 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
3929 * @ioc: per adapter object
3930 * @handle: device handle
3931 * Context: interrupt.
3936 _scsih_send_event_to_turn_on_fault_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3938 struct fw_event_work *fw_event;
3940 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
3943 fw_event->event = MPT3SAS_TURN_ON_FAULT_LED;
3944 fw_event->device_handle = handle;
3945 fw_event->ioc = ioc;
3946 _scsih_fw_event_add(ioc, fw_event);
3950 * _scsih_smart_predicted_fault - process smart errors
3951 * @ioc: per adapter object
3952 * @handle: device handle
3953 * Context: interrupt.
3958 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3960 struct scsi_target *starget;
3961 struct MPT3SAS_TARGET *sas_target_priv_data;
3962 Mpi2EventNotificationReply_t *event_reply;
3963 Mpi2EventDataSasDeviceStatusChange_t *event_data;
3964 struct _sas_device *sas_device;
3966 unsigned long flags;
3968 /* only handle non-raid devices */
3969 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3970 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3972 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3975 starget = sas_device->starget;
3976 sas_target_priv_data = starget->hostdata;
3978 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
3979 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
3980 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3983 starget_printk(KERN_WARNING, starget, "predicted fault\n");
3984 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3986 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
3987 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
3989 /* insert into event log */
3990 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
3991 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
3992 event_reply = kzalloc(sz, GFP_KERNEL);
3994 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
3995 ioc->name, __FILE__, __LINE__, __func__);
3999 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4000 event_reply->Event =
4001 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4002 event_reply->MsgLength = sz/4;
4003 event_reply->EventDataLength =
4004 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4005 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4006 event_reply->EventData;
4007 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4008 event_data->ASC = 0x5D;
4009 event_data->DevHandle = cpu_to_le16(handle);
4010 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4011 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4016 * _scsih_io_done - scsi request callback
4017 * @ioc: per adapter object
4018 * @smid: system request message index
4019 * @msix_index: MSIX table index supplied by the OS
4020 * @reply: reply message frame(lower 32bit addr)
4022 * Callback handler when using _scsih_qcmd.
4024 * Return 1 meaning mf should be freed from _base_interrupt
4025 * 0 means the mf is freed from this function.
4028 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4030 Mpi2SCSIIORequest_t *mpi_request;
4031 Mpi2SCSIIOReply_t *mpi_reply;
4032 struct scsi_cmnd *scmd;
4038 struct MPT3SAS_DEVICE *sas_device_priv_data;
4039 u32 response_code = 0;
4041 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4042 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4046 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4048 if (mpi_reply == NULL) {
4049 scmd->result = DID_OK << 16;
4053 sas_device_priv_data = scmd->device->hostdata;
4054 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4055 sas_device_priv_data->sas_target->deleted) {
4056 scmd->result = DID_NO_CONNECT << 16;
4059 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4061 /* turning off TLR */
4062 scsi_state = mpi_reply->SCSIState;
4063 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4065 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4066 if (!sas_device_priv_data->tlr_snoop_check) {
4067 sas_device_priv_data->tlr_snoop_check++;
4068 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4069 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4070 sas_device_priv_data->flags &=
4074 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4075 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4076 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4077 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4080 ioc_status &= MPI2_IOCSTATUS_MASK;
4081 scsi_status = mpi_reply->SCSIStatus;
4083 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4084 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4085 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4086 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4087 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4090 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4091 struct sense_info data;
4092 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4094 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4095 le32_to_cpu(mpi_reply->SenseCount));
4096 memcpy(scmd->sense_buffer, sense_data, sz);
4097 _scsih_normalize_sense(scmd->sense_buffer, &data);
4098 /* failure prediction threshold exceeded */
4099 if (data.asc == 0x5D)
4100 _scsih_smart_predicted_fault(ioc,
4101 le16_to_cpu(mpi_reply->DevHandle));
4102 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4105 switch (ioc_status) {
4106 case MPI2_IOCSTATUS_BUSY:
4107 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4108 scmd->result = SAM_STAT_BUSY;
4111 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4112 scmd->result = DID_NO_CONNECT << 16;
4115 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4116 if (sas_device_priv_data->block) {
4117 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4120 if (log_info == 0x31110630) {
4121 if (scmd->retries > 2) {
4122 scmd->result = DID_NO_CONNECT << 16;
4123 scsi_device_set_state(scmd->device,
4126 scmd->result = DID_SOFT_ERROR << 16;
4127 scmd->device->expecting_cc_ua = 1;
4131 scmd->result = DID_SOFT_ERROR << 16;
4133 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4134 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4135 scmd->result = DID_RESET << 16;
4138 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4139 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4140 scmd->result = DID_SOFT_ERROR << 16;
4142 scmd->result = (DID_OK << 16) | scsi_status;
4145 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4146 scmd->result = (DID_OK << 16) | scsi_status;
4148 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4151 if (xfer_cnt < scmd->underflow) {
4152 if (scsi_status == SAM_STAT_BUSY)
4153 scmd->result = SAM_STAT_BUSY;
4155 scmd->result = DID_SOFT_ERROR << 16;
4156 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4157 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4158 scmd->result = DID_SOFT_ERROR << 16;
4159 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4160 scmd->result = DID_RESET << 16;
4161 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4162 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4163 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4164 scmd->result = (DRIVER_SENSE << 24) |
4165 SAM_STAT_CHECK_CONDITION;
4166 scmd->sense_buffer[0] = 0x70;
4167 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4168 scmd->sense_buffer[12] = 0x20;
4169 scmd->sense_buffer[13] = 0;
4173 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4174 scsi_set_resid(scmd, 0);
4175 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4176 case MPI2_IOCSTATUS_SUCCESS:
4177 scmd->result = (DID_OK << 16) | scsi_status;
4178 if (response_code ==
4179 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4180 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4181 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4182 scmd->result = DID_SOFT_ERROR << 16;
4183 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4184 scmd->result = DID_RESET << 16;
4187 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4188 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4189 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4190 _scsih_eedp_error_handling(scmd, ioc_status);
4193 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4194 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4195 case MPI2_IOCSTATUS_INVALID_SGL:
4196 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4197 case MPI2_IOCSTATUS_INVALID_FIELD:
4198 case MPI2_IOCSTATUS_INVALID_STATE:
4199 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4200 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4202 scmd->result = DID_SOFT_ERROR << 16;
4207 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4208 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4209 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4214 scsi_dma_unmap(scmd);
4216 scmd->scsi_done(scmd);
4221 * _scsih_sas_host_refresh - refreshing sas host object contents
4222 * @ioc: per adapter object
4225 * During port enable, fw will send topology events for every device. Its
4226 * possible that the handles may change from the previous setting, so this
4227 * code keeping handles updating if changed.
4232 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4237 Mpi2ConfigReply_t mpi_reply;
4238 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4239 u16 attached_handle;
4242 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4243 "updating handles for sas_host(0x%016llx)\n",
4244 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4246 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4247 * sizeof(Mpi2SasIOUnit0PhyData_t));
4248 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4249 if (!sas_iounit_pg0) {
4250 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4251 ioc->name, __FILE__, __LINE__, __func__);
4255 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4256 sas_iounit_pg0, sz)) != 0)
4258 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4259 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4261 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4262 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4264 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4265 PhyData[0].ControllerDevHandle);
4266 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4267 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4269 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4270 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4271 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4272 attached_handle, i, link_rate);
4275 kfree(sas_iounit_pg0);
4279 * _scsih_sas_host_add - create sas host object
4280 * @ioc: per adapter object
4282 * Creating host side data object, stored in ioc->sas_hba
4287 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4290 Mpi2ConfigReply_t mpi_reply;
4291 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4292 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4293 Mpi2SasPhyPage0_t phy_pg0;
4294 Mpi2SasDevicePage0_t sas_device_pg0;
4295 Mpi2SasEnclosurePage0_t enclosure_pg0;
4298 u8 device_missing_delay;
4300 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4301 if (!ioc->sas_hba.num_phys) {
4302 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4303 ioc->name, __FILE__, __LINE__, __func__);
4307 /* sas_iounit page 0 */
4308 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4309 sizeof(Mpi2SasIOUnit0PhyData_t));
4310 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4311 if (!sas_iounit_pg0) {
4312 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4313 ioc->name, __FILE__, __LINE__, __func__);
4316 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4317 sas_iounit_pg0, sz))) {
4318 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4319 ioc->name, __FILE__, __LINE__, __func__);
4322 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4323 MPI2_IOCSTATUS_MASK;
4324 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4325 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4326 ioc->name, __FILE__, __LINE__, __func__);
4330 /* sas_iounit page 1 */
4331 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4332 sizeof(Mpi2SasIOUnit1PhyData_t));
4333 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4334 if (!sas_iounit_pg1) {
4335 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4336 ioc->name, __FILE__, __LINE__, __func__);
4339 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4340 sas_iounit_pg1, sz))) {
4341 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4342 ioc->name, __FILE__, __LINE__, __func__);
4345 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4346 MPI2_IOCSTATUS_MASK;
4347 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4348 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4349 ioc->name, __FILE__, __LINE__, __func__);
4353 ioc->io_missing_delay =
4354 sas_iounit_pg1->IODeviceMissingDelay;
4355 device_missing_delay =
4356 sas_iounit_pg1->ReportDeviceMissingDelay;
4357 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4358 ioc->device_missing_delay = (device_missing_delay &
4359 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4361 ioc->device_missing_delay = device_missing_delay &
4362 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4364 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4365 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4366 sizeof(struct _sas_phy), GFP_KERNEL);
4367 if (!ioc->sas_hba.phy) {
4368 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4369 ioc->name, __FILE__, __LINE__, __func__);
4372 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4373 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4375 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4376 ioc->name, __FILE__, __LINE__, __func__);
4379 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4380 MPI2_IOCSTATUS_MASK;
4381 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4382 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4383 ioc->name, __FILE__, __LINE__, __func__);
4388 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4389 PhyData[0].ControllerDevHandle);
4390 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4391 ioc->sas_hba.phy[i].phy_id = i;
4392 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4393 phy_pg0, ioc->sas_hba.parent_dev);
4395 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4396 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4397 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4398 ioc->name, __FILE__, __LINE__, __func__);
4401 ioc->sas_hba.enclosure_handle =
4402 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4403 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4405 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4406 ioc->name, ioc->sas_hba.handle,
4407 (unsigned long long) ioc->sas_hba.sas_address,
4408 ioc->sas_hba.num_phys) ;
4410 if (ioc->sas_hba.enclosure_handle) {
4411 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4412 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4413 ioc->sas_hba.enclosure_handle)))
4414 ioc->sas_hba.enclosure_logical_id =
4415 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4419 kfree(sas_iounit_pg1);
4420 kfree(sas_iounit_pg0);
4424 * _scsih_expander_add - creating expander object
4425 * @ioc: per adapter object
4426 * @handle: expander handle
4428 * Creating expander object, stored in ioc->sas_expander_list.
4430 * Return 0 for success, else error.
4433 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4435 struct _sas_node *sas_expander;
4436 Mpi2ConfigReply_t mpi_reply;
4437 Mpi2ExpanderPage0_t expander_pg0;
4438 Mpi2ExpanderPage1_t expander_pg1;
4439 Mpi2SasEnclosurePage0_t enclosure_pg0;
4442 u64 sas_address, sas_address_parent = 0;
4444 unsigned long flags;
4445 struct _sas_port *mpt3sas_port = NULL;
4452 if (ioc->shost_recovery || ioc->pci_error_recovery)
4455 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4456 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4457 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4458 ioc->name, __FILE__, __LINE__, __func__);
4462 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4463 MPI2_IOCSTATUS_MASK;
4464 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4465 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4466 ioc->name, __FILE__, __LINE__, __func__);
4470 /* handle out of order topology events */
4471 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4472 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4474 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4475 ioc->name, __FILE__, __LINE__, __func__);
4478 if (sas_address_parent != ioc->sas_hba.sas_address) {
4479 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4480 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4481 sas_address_parent);
4482 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4483 if (!sas_expander) {
4484 rc = _scsih_expander_add(ioc, parent_handle);
4490 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4491 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4492 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4494 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4499 sas_expander = kzalloc(sizeof(struct _sas_node),
4501 if (!sas_expander) {
4502 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4503 ioc->name, __FILE__, __LINE__, __func__);
4507 sas_expander->handle = handle;
4508 sas_expander->num_phys = expander_pg0.NumPhys;
4509 sas_expander->sas_address_parent = sas_address_parent;
4510 sas_expander->sas_address = sas_address;
4512 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4513 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4514 handle, parent_handle, (unsigned long long)
4515 sas_expander->sas_address, sas_expander->num_phys);
4517 if (!sas_expander->num_phys)
4519 sas_expander->phy = kcalloc(sas_expander->num_phys,
4520 sizeof(struct _sas_phy), GFP_KERNEL);
4521 if (!sas_expander->phy) {
4522 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4523 ioc->name, __FILE__, __LINE__, __func__);
4528 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4529 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4530 sas_address_parent);
4531 if (!mpt3sas_port) {
4532 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4533 ioc->name, __FILE__, __LINE__, __func__);
4537 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4539 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4540 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4541 &expander_pg1, i, handle))) {
4542 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4543 ioc->name, __FILE__, __LINE__, __func__);
4547 sas_expander->phy[i].handle = handle;
4548 sas_expander->phy[i].phy_id = i;
4550 if ((mpt3sas_transport_add_expander_phy(ioc,
4551 &sas_expander->phy[i], expander_pg1,
4552 sas_expander->parent_dev))) {
4553 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4554 ioc->name, __FILE__, __LINE__, __func__);
4560 if (sas_expander->enclosure_handle) {
4561 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4562 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4563 sas_expander->enclosure_handle)))
4564 sas_expander->enclosure_logical_id =
4565 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4568 _scsih_expander_node_add(ioc, sas_expander);
4574 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4575 sas_address_parent);
4576 kfree(sas_expander);
4581 * mpt3sas_expander_remove - removing expander object
4582 * @ioc: per adapter object
4583 * @sas_address: expander sas_address
4588 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4590 struct _sas_node *sas_expander;
4591 unsigned long flags;
4593 if (ioc->shost_recovery)
4596 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4597 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4600 list_del(&sas_expander->list);
4601 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4603 _scsih_expander_node_remove(ioc, sas_expander);
4607 * _scsih_done - internal SCSI_IO callback handler.
4608 * @ioc: per adapter object
4609 * @smid: system request message index
4610 * @msix_index: MSIX table index supplied by the OS
4611 * @reply: reply message frame(lower 32bit addr)
4613 * Callback handler when sending internal generated SCSI_IO.
4614 * The callback index passed is `ioc->scsih_cb_idx`
4616 * Return 1 meaning mf should be freed from _base_interrupt
4617 * 0 means the mf is freed from this function.
4620 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4622 MPI2DefaultReply_t *mpi_reply;
4624 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4625 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4627 if (ioc->scsih_cmds.smid != smid)
4629 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4631 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4632 mpi_reply->MsgLength*4);
4633 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4635 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4636 complete(&ioc->scsih_cmds.done);
4643 #define MPT3_MAX_LUNS (255)
4647 * _scsih_check_access_status - check access flags
4648 * @ioc: per adapter object
4649 * @sas_address: sas address
4650 * @handle: sas device handle
4651 * @access_flags: errors returned during discovery of the device
4653 * Return 0 for success, else failure
4656 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4657 u16 handle, u8 access_status)
4662 switch (access_status) {
4663 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4664 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4667 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4668 desc = "sata capability failed";
4670 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4671 desc = "sata affiliation conflict";
4673 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4674 desc = "route not addressable";
4676 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4677 desc = "smp error not addressable";
4679 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4680 desc = "device blocked";
4682 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4683 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4684 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4685 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4686 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4687 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4688 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4689 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4690 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4691 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4692 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4693 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4694 desc = "sata initialization failed";
4705 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4706 ioc->name, desc, (unsigned long long)sas_address, handle);
4711 * _scsih_check_device - checking device responsiveness
4712 * @ioc: per adapter object
4713 * @parent_sas_address: sas address of parent expander or sas host
4714 * @handle: attached device handle
4715 * @phy_numberv: phy number
4716 * @link_rate: new link rate
4721 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4722 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4724 Mpi2ConfigReply_t mpi_reply;
4725 Mpi2SasDevicePage0_t sas_device_pg0;
4726 struct _sas_device *sas_device;
4728 unsigned long flags;
4730 struct scsi_target *starget;
4731 struct MPT3SAS_TARGET *sas_target_priv_data;
4735 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4736 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4739 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4740 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4743 /* wide port handling ~ we need only handle device once for the phy that
4744 * is matched in sas device page zero
4746 if (phy_number != sas_device_pg0.PhyNum)
4749 /* check if this is end device */
4750 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4751 if (!(_scsih_is_end_device(device_info)))
4754 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4755 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4756 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4760 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4764 if (unlikely(sas_device->handle != handle)) {
4765 starget = sas_device->starget;
4766 sas_target_priv_data = starget->hostdata;
4767 starget_printk(KERN_INFO, starget,
4768 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4769 sas_device->handle, handle);
4770 sas_target_priv_data->handle = handle;
4771 sas_device->handle = handle;
4774 /* check if device is present */
4775 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4776 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4778 "device is not present handle(0x%04x), flags!!!\n",
4780 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4784 /* check if there were any issues with discovery */
4785 if (_scsih_check_access_status(ioc, sas_address, handle,
4786 sas_device_pg0.AccessStatus)) {
4787 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4791 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4792 _scsih_ublock_io_device(ioc, sas_address);
4797 * _scsih_add_device - creating sas device object
4798 * @ioc: per adapter object
4799 * @handle: sas device handle
4800 * @phy_num: phy number end device attached to
4801 * @is_pd: is this hidden raid component
4803 * Creating end device object, stored in ioc->sas_device_list.
4805 * Returns 0 for success, non-zero for failure.
4808 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4811 Mpi2ConfigReply_t mpi_reply;
4812 Mpi2SasDevicePage0_t sas_device_pg0;
4813 Mpi2SasEnclosurePage0_t enclosure_pg0;
4814 struct _sas_device *sas_device;
4818 unsigned long flags;
4820 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4821 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4822 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4823 ioc->name, __FILE__, __LINE__, __func__);
4827 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4828 MPI2_IOCSTATUS_MASK;
4829 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4830 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4831 ioc->name, __FILE__, __LINE__, __func__);
4835 /* check if this is end device */
4836 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4837 if (!(_scsih_is_end_device(device_info)))
4839 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4841 /* check if device is present */
4842 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4843 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4844 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4849 /* check if there were any issues with discovery */
4850 if (_scsih_check_access_status(ioc, sas_address, handle,
4851 sas_device_pg0.AccessStatus))
4854 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4855 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4857 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4862 sas_device = kzalloc(sizeof(struct _sas_device),
4865 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4866 ioc->name, __FILE__, __LINE__, __func__);
4870 sas_device->handle = handle;
4871 if (_scsih_get_sas_address(ioc,
4872 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4873 &sas_device->sas_address_parent) != 0)
4874 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4875 ioc->name, __FILE__, __LINE__, __func__);
4876 sas_device->enclosure_handle =
4877 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4879 le16_to_cpu(sas_device_pg0.Slot);
4880 sas_device->device_info = device_info;
4881 sas_device->sas_address = sas_address;
4882 sas_device->phy = sas_device_pg0.PhyNum;
4883 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
4884 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
4886 /* get enclosure_logical_id */
4887 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
4888 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4889 sas_device->enclosure_handle)))
4890 sas_device->enclosure_logical_id =
4891 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4893 /* get device name */
4894 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
4896 if (ioc->wait_for_discovery_to_complete)
4897 _scsih_sas_device_init_add(ioc, sas_device);
4899 _scsih_sas_device_add(ioc, sas_device);
4905 * _scsih_remove_device - removing sas device object
4906 * @ioc: per adapter object
4907 * @sas_device_delete: the sas_device object
4912 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
4913 struct _sas_device *sas_device)
4915 struct MPT3SAS_TARGET *sas_target_priv_data;
4918 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4919 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4920 ioc->name, __func__,
4921 sas_device->handle, (unsigned long long)
4922 sas_device->sas_address));
4924 if (sas_device->starget && sas_device->starget->hostdata) {
4925 sas_target_priv_data = sas_device->starget->hostdata;
4926 sas_target_priv_data->deleted = 1;
4927 _scsih_ublock_io_device(ioc, sas_device->sas_address);
4928 sas_target_priv_data->handle =
4929 MPT3SAS_INVALID_DEVICE_HANDLE;
4931 mpt3sas_transport_port_remove(ioc,
4932 sas_device->sas_address,
4933 sas_device->sas_address_parent);
4936 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4937 ioc->name, sas_device->handle,
4938 (unsigned long long) sas_device->sas_address);
4940 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4941 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4942 ioc->name, __func__,
4943 sas_device->handle, (unsigned long long)
4944 sas_device->sas_address));
4949 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4951 * _scsih_sas_topology_change_event_debug - debug for topology event
4952 * @ioc: per adapter object
4953 * @event_data: event data payload
4957 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
4958 Mpi2EventDataSasTopologyChangeList_t *event_data)
4964 char *status_str = NULL;
4965 u8 link_rate, prev_link_rate;
4967 switch (event_data->ExpStatus) {
4968 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
4971 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
4972 status_str = "remove";
4974 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
4976 status_str = "responding";
4978 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
4979 status_str = "remove delay";
4982 status_str = "unknown status";
4985 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
4986 ioc->name, status_str);
4987 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
4988 "start_phy(%02d), count(%d)\n",
4989 le16_to_cpu(event_data->ExpanderDevHandle),
4990 le16_to_cpu(event_data->EnclosureHandle),
4991 event_data->StartPhyNum, event_data->NumEntries);
4992 for (i = 0; i < event_data->NumEntries; i++) {
4993 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4996 phy_number = event_data->StartPhyNum + i;
4997 reason_code = event_data->PHY[i].PhyStatus &
4998 MPI2_EVENT_SAS_TOPO_RC_MASK;
4999 switch (reason_code) {
5000 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5001 status_str = "target add";
5003 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5004 status_str = "target remove";
5006 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5007 status_str = "delay target remove";
5009 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5010 status_str = "link rate change";
5012 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5013 status_str = "target responding";
5016 status_str = "unknown";
5019 link_rate = event_data->PHY[i].LinkRate >> 4;
5020 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5021 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5022 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5023 handle, status_str, link_rate, prev_link_rate);
5030 * _scsih_sas_topology_change_event - handle topology changes
5031 * @ioc: per adapter object
5032 * @fw_event: The fw_event_work object
5037 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5038 struct fw_event_work *fw_event)
5041 u16 parent_handle, handle;
5043 u8 phy_number, max_phys;
5044 struct _sas_node *sas_expander;
5046 unsigned long flags;
5047 u8 link_rate, prev_link_rate;
5048 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5050 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5051 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5052 _scsih_sas_topology_change_event_debug(ioc, event_data);
5055 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5058 if (!ioc->sas_hba.num_phys)
5059 _scsih_sas_host_add(ioc);
5061 _scsih_sas_host_refresh(ioc);
5063 if (fw_event->ignore) {
5064 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5065 "ignoring expander event\n", ioc->name));
5069 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5071 /* handle expander add */
5072 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5073 if (_scsih_expander_add(ioc, parent_handle) != 0)
5076 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5077 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5080 sas_address = sas_expander->sas_address;
5081 max_phys = sas_expander->num_phys;
5082 } else if (parent_handle < ioc->sas_hba.num_phys) {
5083 sas_address = ioc->sas_hba.sas_address;
5084 max_phys = ioc->sas_hba.num_phys;
5086 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5089 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5091 /* handle siblings events */
5092 for (i = 0; i < event_data->NumEntries; i++) {
5093 if (fw_event->ignore) {
5094 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5095 "ignoring expander event\n", ioc->name));
5098 if (ioc->remove_host || ioc->pci_error_recovery)
5100 phy_number = event_data->StartPhyNum + i;
5101 if (phy_number >= max_phys)
5103 reason_code = event_data->PHY[i].PhyStatus &
5104 MPI2_EVENT_SAS_TOPO_RC_MASK;
5105 if ((event_data->PHY[i].PhyStatus &
5106 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5107 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5109 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5112 link_rate = event_data->PHY[i].LinkRate >> 4;
5113 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5114 switch (reason_code) {
5115 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5117 if (ioc->shost_recovery)
5120 if (link_rate == prev_link_rate)
5123 mpt3sas_transport_update_links(ioc, sas_address,
5124 handle, phy_number, link_rate);
5126 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5129 _scsih_check_device(ioc, sas_address, handle,
5130 phy_number, link_rate);
5133 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5135 if (ioc->shost_recovery)
5138 mpt3sas_transport_update_links(ioc, sas_address,
5139 handle, phy_number, link_rate);
5141 _scsih_add_device(ioc, handle, phy_number, 0);
5144 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5146 _scsih_device_remove_by_handle(ioc, handle);
5151 /* handle expander removal */
5152 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5154 mpt3sas_expander_remove(ioc, sas_address);
5159 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5161 * _scsih_sas_device_status_change_event_debug - debug for device event
5162 * @event_data: event data payload
5168 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5169 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5171 char *reason_str = NULL;
5173 switch (event_data->ReasonCode) {
5174 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5175 reason_str = "smart data";
5177 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5178 reason_str = "unsupported device discovered";
5180 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5181 reason_str = "internal device reset";
5183 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5184 reason_str = "internal task abort";
5186 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5187 reason_str = "internal task abort set";
5189 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5190 reason_str = "internal clear task set";
5192 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5193 reason_str = "internal query task";
5195 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5196 reason_str = "sata init failure";
5198 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5199 reason_str = "internal device reset complete";
5201 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5202 reason_str = "internal task abort complete";
5204 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5205 reason_str = "internal async notification";
5207 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5208 reason_str = "expander reduced functionality";
5210 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5211 reason_str = "expander reduced functionality complete";
5214 reason_str = "unknown reason";
5217 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5218 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5219 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5220 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5221 le16_to_cpu(event_data->TaskTag));
5222 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5223 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5224 event_data->ASC, event_data->ASCQ);
5230 * _scsih_sas_device_status_change_event - handle device status change
5231 * @ioc: per adapter object
5232 * @fw_event: The fw_event_work object
5238 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5239 struct fw_event_work *fw_event)
5241 struct MPT3SAS_TARGET *target_priv_data;
5242 struct _sas_device *sas_device;
5244 unsigned long flags;
5245 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5246 fw_event->event_data;
5248 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5249 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5250 _scsih_sas_device_status_change_event_debug(ioc,
5254 /* In MPI Revision K (0xC), the internal device reset complete was
5255 * implemented, so avoid setting tm_busy flag for older firmware.
5257 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5260 if (event_data->ReasonCode !=
5261 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5262 event_data->ReasonCode !=
5263 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5266 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5267 sas_address = le64_to_cpu(event_data->SASAddress);
5268 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5271 if (!sas_device || !sas_device->starget) {
5272 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5276 target_priv_data = sas_device->starget->hostdata;
5277 if (!target_priv_data) {
5278 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5282 if (event_data->ReasonCode ==
5283 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5284 target_priv_data->tm_busy = 1;
5286 target_priv_data->tm_busy = 0;
5287 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5290 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5292 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5294 * @ioc: per adapter object
5295 * @event_data: event data payload
5301 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5302 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5304 char *reason_str = NULL;
5306 switch (event_data->ReasonCode) {
5307 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5308 reason_str = "enclosure add";
5310 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5311 reason_str = "enclosure remove";
5314 reason_str = "unknown reason";
5318 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5319 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5320 " number slots(%d)\n", ioc->name, reason_str,
5321 le16_to_cpu(event_data->EnclosureHandle),
5322 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5323 le16_to_cpu(event_data->StartSlot));
5328 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5329 * @ioc: per adapter object
5330 * @fw_event: The fw_event_work object
5336 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5337 struct fw_event_work *fw_event)
5339 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5340 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5341 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5342 fw_event->event_data);
5347 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5348 * @ioc: per adapter object
5349 * @fw_event: The fw_event_work object
5355 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5356 struct fw_event_work *fw_event)
5358 struct scsi_cmnd *scmd;
5359 struct scsi_device *sdev;
5362 struct MPT3SAS_DEVICE *sas_device_priv_data;
5363 u32 termination_count;
5365 Mpi2SCSITaskManagementReply_t *mpi_reply;
5366 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5368 unsigned long flags;
5371 u8 task_abort_retries;
5373 mutex_lock(&ioc->tm_cmds.mutex);
5375 "%s: enter: phy number(%d), width(%d)\n",
5376 ioc->name, __func__, event_data->PhyNum,
5377 event_data->PortWidth);
5379 _scsih_block_io_all_device(ioc);
5381 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5382 mpi_reply = ioc->tm_cmds.reply;
5383 broadcast_aen_retry:
5385 /* sanity checks for retrying this loop */
5386 if (max_retries++ == 5) {
5387 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5388 ioc->name, __func__));
5390 } else if (max_retries > 1)
5391 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5392 ioc->name, __func__, max_retries - 1));
5394 termination_count = 0;
5396 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5397 if (ioc->shost_recovery)
5399 scmd = _scsih_scsi_lookup_get(ioc, smid);
5402 sdev = scmd->device;
5403 sas_device_priv_data = sdev->hostdata;
5404 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5406 /* skip hidden raid components */
5407 if (sas_device_priv_data->sas_target->flags &
5408 MPT_TARGET_FLAGS_RAID_COMPONENT)
5411 if (sas_device_priv_data->sas_target->flags &
5412 MPT_TARGET_FLAGS_VOLUME)
5415 handle = sas_device_priv_data->sas_target->handle;
5416 lun = sas_device_priv_data->lun;
5419 if (ioc->shost_recovery)
5422 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5423 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5424 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5427 sdev_printk(KERN_WARNING, sdev,
5428 "mpt3sas_scsih_issue_tm: FAILED when sending "
5429 "QUERY_TASK: scmd(%p)\n", scmd);
5430 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5431 goto broadcast_aen_retry;
5433 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5434 & MPI2_IOCSTATUS_MASK;
5435 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5436 sdev_printk(KERN_WARNING, sdev,
5437 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5439 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5440 goto broadcast_aen_retry;
5443 /* see if IO is still owned by IOC and target */
5444 if (mpi_reply->ResponseCode ==
5445 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5446 mpi_reply->ResponseCode ==
5447 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5448 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5451 task_abort_retries = 0;
5453 if (task_abort_retries++ == 60) {
5454 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5455 "%s: ABORT_TASK: giving up\n", ioc->name,
5457 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5458 goto broadcast_aen_retry;
5461 if (ioc->shost_recovery)
5464 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5465 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5468 sdev_printk(KERN_WARNING, sdev,
5469 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5470 "scmd(%p)\n", scmd);
5474 if (task_abort_retries > 1)
5475 sdev_printk(KERN_WARNING, sdev,
5476 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5478 task_abort_retries - 1, scmd);
5480 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5481 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5484 if (ioc->broadcast_aen_pending) {
5485 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5486 "%s: loop back due to pending AEN\n",
5487 ioc->name, __func__));
5488 ioc->broadcast_aen_pending = 0;
5489 goto broadcast_aen_retry;
5493 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5496 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5497 "%s - exit, query_count = %d termination_count = %d\n",
5498 ioc->name, __func__, query_count, termination_count));
5500 ioc->broadcast_aen_busy = 0;
5501 if (!ioc->shost_recovery)
5502 _scsih_ublock_io_all_device(ioc);
5503 mutex_unlock(&ioc->tm_cmds.mutex);
5507 * _scsih_sas_discovery_event - handle discovery events
5508 * @ioc: per adapter object
5509 * @fw_event: The fw_event_work object
5515 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5516 struct fw_event_work *fw_event)
5518 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5520 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5521 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5522 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5523 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5525 if (event_data->DiscoveryStatus)
5526 pr_info("discovery_status(0x%08x)",
5527 le32_to_cpu(event_data->DiscoveryStatus));
5532 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5533 !ioc->sas_hba.num_phys) {
5534 if (disable_discovery > 0 && ioc->shost_recovery) {
5535 /* Wait for the reset to complete */
5536 while (ioc->shost_recovery)
5539 _scsih_sas_host_add(ioc);
5544 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5545 * @ioc: per adapter object
5546 * @handle: device handle for physical disk
5547 * @phys_disk_num: physical disk number
5549 * Return 0 for success, else failure.
5552 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5554 Mpi2RaidActionRequest_t *mpi_request;
5555 Mpi2RaidActionReply_t *mpi_reply;
5563 mutex_lock(&ioc->scsih_cmds.mutex);
5565 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5566 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5567 ioc->name, __func__);
5571 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5573 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5575 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5576 ioc->name, __func__);
5577 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5582 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5583 ioc->scsih_cmds.smid = smid;
5584 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5586 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5587 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5588 mpi_request->PhysDiskNum = phys_disk_num;
5590 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5591 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5592 handle, phys_disk_num));
5594 init_completion(&ioc->scsih_cmds.done);
5595 mpt3sas_base_put_smid_default(ioc, smid);
5596 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5598 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5599 pr_err(MPT3SAS_FMT "%s: timeout\n",
5600 ioc->name, __func__);
5601 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5607 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5609 mpi_reply = ioc->scsih_cmds.reply;
5610 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5611 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5612 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5615 ioc_status &= MPI2_IOCSTATUS_MASK;
5616 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5617 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5618 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5619 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5623 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5624 "IR RAID_ACTION: completed successfully\n",
5629 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5630 mutex_unlock(&ioc->scsih_cmds.mutex);
5633 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5639 * _scsih_reprobe_lun - reprobing lun
5640 * @sdev: scsi device struct
5641 * @no_uld_attach: sdev->no_uld_attach flag setting
5645 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5648 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5649 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5650 sdev->no_uld_attach ? "hidding" : "exposing");
5651 rc = scsi_device_reprobe(sdev);
5655 * _scsih_sas_volume_add - add new volume
5656 * @ioc: per adapter object
5657 * @element: IR config element data
5663 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5664 Mpi2EventIrConfigElement_t *element)
5666 struct _raid_device *raid_device;
5667 unsigned long flags;
5669 u16 handle = le16_to_cpu(element->VolDevHandle);
5672 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5675 "failure at %s:%d/%s()!\n", ioc->name,
5676 __FILE__, __LINE__, __func__);
5680 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5681 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5682 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5687 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5690 "failure at %s:%d/%s()!\n", ioc->name,
5691 __FILE__, __LINE__, __func__);
5695 raid_device->id = ioc->sas_id++;
5696 raid_device->channel = RAID_CHANNEL;
5697 raid_device->handle = handle;
5698 raid_device->wwid = wwid;
5699 _scsih_raid_device_add(ioc, raid_device);
5700 if (!ioc->wait_for_discovery_to_complete) {
5701 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5702 raid_device->id, 0);
5704 _scsih_raid_device_remove(ioc, raid_device);
5706 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5707 _scsih_determine_boot_device(ioc, raid_device, 1);
5708 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5713 * _scsih_sas_volume_delete - delete volume
5714 * @ioc: per adapter object
5715 * @handle: volume device handle
5721 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5723 struct _raid_device *raid_device;
5724 unsigned long flags;
5725 struct MPT3SAS_TARGET *sas_target_priv_data;
5726 struct scsi_target *starget = NULL;
5728 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5729 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5731 if (raid_device->starget) {
5732 starget = raid_device->starget;
5733 sas_target_priv_data = starget->hostdata;
5734 sas_target_priv_data->deleted = 1;
5736 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5737 ioc->name, raid_device->handle,
5738 (unsigned long long) raid_device->wwid);
5739 list_del(&raid_device->list);
5742 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5744 scsi_remove_target(&starget->dev);
5748 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5749 * @ioc: per adapter object
5750 * @element: IR config element data
5756 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5757 Mpi2EventIrConfigElement_t *element)
5759 struct _sas_device *sas_device;
5760 struct scsi_target *starget = NULL;
5761 struct MPT3SAS_TARGET *sas_target_priv_data;
5762 unsigned long flags;
5763 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5765 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5766 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5768 sas_device->volume_handle = 0;
5769 sas_device->volume_wwid = 0;
5770 clear_bit(handle, ioc->pd_handles);
5771 if (sas_device->starget && sas_device->starget->hostdata) {
5772 starget = sas_device->starget;
5773 sas_target_priv_data = starget->hostdata;
5774 sas_target_priv_data->flags &=
5775 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5778 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5782 /* exposing raid component */
5784 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5788 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5789 * @ioc: per adapter object
5790 * @element: IR config element data
5796 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5797 Mpi2EventIrConfigElement_t *element)
5799 struct _sas_device *sas_device;
5800 struct scsi_target *starget = NULL;
5801 struct MPT3SAS_TARGET *sas_target_priv_data;
5802 unsigned long flags;
5803 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5804 u16 volume_handle = 0;
5805 u64 volume_wwid = 0;
5807 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
5809 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
5812 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5813 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5815 set_bit(handle, ioc->pd_handles);
5816 if (sas_device->starget && sas_device->starget->hostdata) {
5817 starget = sas_device->starget;
5818 sas_target_priv_data = starget->hostdata;
5819 sas_target_priv_data->flags |=
5820 MPT_TARGET_FLAGS_RAID_COMPONENT;
5821 sas_device->volume_handle = volume_handle;
5822 sas_device->volume_wwid = volume_wwid;
5825 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5829 /* hiding raid component */
5830 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5832 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
5836 * _scsih_sas_pd_delete - delete pd component
5837 * @ioc: per adapter object
5838 * @element: IR config element data
5844 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
5845 Mpi2EventIrConfigElement_t *element)
5847 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5849 _scsih_device_remove_by_handle(ioc, handle);
5853 * _scsih_sas_pd_add - remove pd component
5854 * @ioc: per adapter object
5855 * @element: IR config element data
5861 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
5862 Mpi2EventIrConfigElement_t *element)
5864 struct _sas_device *sas_device;
5865 unsigned long flags;
5866 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5867 Mpi2ConfigReply_t mpi_reply;
5868 Mpi2SasDevicePage0_t sas_device_pg0;
5873 set_bit(handle, ioc->pd_handles);
5875 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5876 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5877 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5879 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5883 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5884 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5885 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5886 ioc->name, __FILE__, __LINE__, __func__);
5890 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5891 MPI2_IOCSTATUS_MASK;
5892 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5893 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5894 ioc->name, __FILE__, __LINE__, __func__);
5898 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5899 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5900 mpt3sas_transport_update_links(ioc, sas_address, handle,
5901 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5903 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5904 _scsih_add_device(ioc, handle, 0, 1);
5907 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5909 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5910 * @ioc: per adapter object
5911 * @event_data: event data payload
5917 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5918 Mpi2EventDataIrConfigChangeList_t *event_data)
5920 Mpi2EventIrConfigElement_t *element;
5923 char *reason_str = NULL, *element_str = NULL;
5925 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5927 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
5928 ioc->name, (le32_to_cpu(event_data->Flags) &
5929 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5930 "foreign" : "native", event_data->NumElements);
5931 for (i = 0; i < event_data->NumElements; i++, element++) {
5932 switch (element->ReasonCode) {
5933 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5936 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5937 reason_str = "remove";
5939 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5940 reason_str = "no change";
5942 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5943 reason_str = "hide";
5945 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5946 reason_str = "unhide";
5948 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5949 reason_str = "volume_created";
5951 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
5952 reason_str = "volume_deleted";
5954 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
5955 reason_str = "pd_created";
5957 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
5958 reason_str = "pd_deleted";
5961 reason_str = "unknown reason";
5964 element_type = le16_to_cpu(element->ElementFlags) &
5965 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
5966 switch (element_type) {
5967 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
5968 element_str = "volume";
5970 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
5971 element_str = "phys disk";
5973 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
5974 element_str = "hot spare";
5977 element_str = "unknown element";
5980 pr_info("\t(%s:%s), vol handle(0x%04x), " \
5981 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
5982 reason_str, le16_to_cpu(element->VolDevHandle),
5983 le16_to_cpu(element->PhysDiskDevHandle),
5984 element->PhysDiskNum);
5990 * _scsih_sas_ir_config_change_event - handle ir configuration change events
5991 * @ioc: per adapter object
5992 * @fw_event: The fw_event_work object
5998 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
5999 struct fw_event_work *fw_event)
6001 Mpi2EventIrConfigElement_t *element;
6004 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
6006 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6007 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6008 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6012 foreign_config = (le32_to_cpu(event_data->Flags) &
6013 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6015 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6016 if (ioc->shost_recovery) {
6018 for (i = 0; i < event_data->NumElements; i++, element++) {
6019 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6020 _scsih_ir_fastpath(ioc,
6021 le16_to_cpu(element->PhysDiskDevHandle),
6022 element->PhysDiskNum);
6026 for (i = 0; i < event_data->NumElements; i++, element++) {
6028 switch (element->ReasonCode) {
6029 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6030 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6031 if (!foreign_config)
6032 _scsih_sas_volume_add(ioc, element);
6034 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6035 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6036 if (!foreign_config)
6037 _scsih_sas_volume_delete(ioc,
6038 le16_to_cpu(element->VolDevHandle));
6040 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6041 _scsih_sas_pd_hide(ioc, element);
6043 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6044 _scsih_sas_pd_expose(ioc, element);
6046 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6047 _scsih_sas_pd_add(ioc, element);
6049 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6050 _scsih_sas_pd_delete(ioc, element);
6057 * _scsih_sas_ir_volume_event - IR volume event
6058 * @ioc: per adapter object
6059 * @fw_event: The fw_event_work object
6065 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6066 struct fw_event_work *fw_event)
6069 unsigned long flags;
6070 struct _raid_device *raid_device;
6074 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6076 if (ioc->shost_recovery)
6079 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6082 handle = le16_to_cpu(event_data->VolDevHandle);
6083 state = le32_to_cpu(event_data->NewValue);
6084 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6085 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6086 ioc->name, __func__, handle,
6087 le32_to_cpu(event_data->PreviousValue), state));
6089 case MPI2_RAID_VOL_STATE_MISSING:
6090 case MPI2_RAID_VOL_STATE_FAILED:
6091 _scsih_sas_volume_delete(ioc, handle);
6094 case MPI2_RAID_VOL_STATE_ONLINE:
6095 case MPI2_RAID_VOL_STATE_DEGRADED:
6096 case MPI2_RAID_VOL_STATE_OPTIMAL:
6098 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6099 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6100 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6105 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6108 "failure at %s:%d/%s()!\n", ioc->name,
6109 __FILE__, __LINE__, __func__);
6113 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6116 "failure at %s:%d/%s()!\n", ioc->name,
6117 __FILE__, __LINE__, __func__);
6121 raid_device->id = ioc->sas_id++;
6122 raid_device->channel = RAID_CHANNEL;
6123 raid_device->handle = handle;
6124 raid_device->wwid = wwid;
6125 _scsih_raid_device_add(ioc, raid_device);
6126 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6127 raid_device->id, 0);
6129 _scsih_raid_device_remove(ioc, raid_device);
6132 case MPI2_RAID_VOL_STATE_INITIALIZING:
6139 * _scsih_sas_ir_physical_disk_event - PD event
6140 * @ioc: per adapter object
6141 * @fw_event: The fw_event_work object
6147 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6148 struct fw_event_work *fw_event)
6150 u16 handle, parent_handle;
6152 struct _sas_device *sas_device;
6153 unsigned long flags;
6154 Mpi2ConfigReply_t mpi_reply;
6155 Mpi2SasDevicePage0_t sas_device_pg0;
6157 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6160 if (ioc->shost_recovery)
6163 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6166 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6167 state = le32_to_cpu(event_data->NewValue);
6169 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6170 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6171 ioc->name, __func__, handle,
6172 le32_to_cpu(event_data->PreviousValue), state));
6174 case MPI2_RAID_PD_STATE_ONLINE:
6175 case MPI2_RAID_PD_STATE_DEGRADED:
6176 case MPI2_RAID_PD_STATE_REBUILDING:
6177 case MPI2_RAID_PD_STATE_OPTIMAL:
6178 case MPI2_RAID_PD_STATE_HOT_SPARE:
6180 set_bit(handle, ioc->pd_handles);
6181 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6182 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6183 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6188 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6189 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6191 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6192 ioc->name, __FILE__, __LINE__, __func__);
6196 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6197 MPI2_IOCSTATUS_MASK;
6198 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6199 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6200 ioc->name, __FILE__, __LINE__, __func__);
6204 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6205 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6206 mpt3sas_transport_update_links(ioc, sas_address, handle,
6207 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6209 _scsih_add_device(ioc, handle, 0, 1);
6213 case MPI2_RAID_PD_STATE_OFFLINE:
6214 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6215 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6221 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6223 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6224 * @ioc: per adapter object
6225 * @event_data: event data payload
6231 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6232 Mpi2EventDataIrOperationStatus_t *event_data)
6234 char *reason_str = NULL;
6236 switch (event_data->RAIDOperation) {
6237 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6238 reason_str = "resync";
6240 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6241 reason_str = "online capacity expansion";
6243 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6244 reason_str = "consistency check";
6246 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6247 reason_str = "background init";
6249 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6250 reason_str = "make data consistent";
6257 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6258 "\thandle(0x%04x), percent complete(%d)\n",
6259 ioc->name, reason_str,
6260 le16_to_cpu(event_data->VolDevHandle),
6261 event_data->PercentComplete);
6266 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6267 * @ioc: per adapter object
6268 * @fw_event: The fw_event_work object
6274 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6275 struct fw_event_work *fw_event)
6277 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6278 static struct _raid_device *raid_device;
6279 unsigned long flags;
6282 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6283 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6284 _scsih_sas_ir_operation_status_event_debug(ioc,
6288 /* code added for raid transport support */
6289 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6291 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6292 handle = le16_to_cpu(event_data->VolDevHandle);
6293 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6295 raid_device->percent_complete =
6296 event_data->PercentComplete;
6297 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6302 * _scsih_prep_device_scan - initialize parameters prior to device scan
6303 * @ioc: per adapter object
6305 * Set the deleted flag prior to device scan. If the device is found during
6306 * the scan, then we clear the deleted flag.
6309 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6311 struct MPT3SAS_DEVICE *sas_device_priv_data;
6312 struct scsi_device *sdev;
6314 shost_for_each_device(sdev, ioc->shost) {
6315 sas_device_priv_data = sdev->hostdata;
6316 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6317 sas_device_priv_data->sas_target->deleted = 1;
6322 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6323 * @ioc: per adapter object
6324 * @sas_address: sas address
6325 * @slot: enclosure slot id
6326 * @handle: device handle
6328 * After host reset, find out whether devices are still responding.
6329 * Used in _scsih_remove_unresponsive_sas_devices.
6334 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6335 u16 slot, u16 handle)
6337 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6338 struct scsi_target *starget;
6339 struct _sas_device *sas_device;
6340 unsigned long flags;
6342 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6343 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6344 if (sas_device->sas_address == sas_address &&
6345 sas_device->slot == slot) {
6346 sas_device->responding = 1;
6347 starget = sas_device->starget;
6348 if (starget && starget->hostdata) {
6349 sas_target_priv_data = starget->hostdata;
6350 sas_target_priv_data->tm_busy = 0;
6351 sas_target_priv_data->deleted = 0;
6353 sas_target_priv_data = NULL;
6355 starget_printk(KERN_INFO, starget,
6356 "handle(0x%04x), sas_addr(0x%016llx), "
6357 "enclosure logical id(0x%016llx), "
6358 "slot(%d)\n", handle,
6359 (unsigned long long)sas_device->sas_address,
6360 (unsigned long long)
6361 sas_device->enclosure_logical_id,
6363 if (sas_device->handle == handle)
6365 pr_info("\thandle changed from(0x%04x)!!!\n",
6366 sas_device->handle);
6367 sas_device->handle = handle;
6368 if (sas_target_priv_data)
6369 sas_target_priv_data->handle = handle;
6374 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6378 * _scsih_search_responding_sas_devices -
6379 * @ioc: per adapter object
6381 * After host reset, find out whether devices are still responding.
6387 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6389 Mpi2SasDevicePage0_t sas_device_pg0;
6390 Mpi2ConfigReply_t mpi_reply;
6395 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6397 if (list_empty(&ioc->sas_device_list))
6401 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6402 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6404 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6405 MPI2_IOCSTATUS_MASK;
6406 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6408 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6409 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6410 if (!(_scsih_is_end_device(device_info)))
6412 _scsih_mark_responding_sas_device(ioc,
6413 le64_to_cpu(sas_device_pg0.SASAddress),
6414 le16_to_cpu(sas_device_pg0.Slot), handle);
6418 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6423 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6424 * @ioc: per adapter object
6425 * @wwid: world wide identifier for raid volume
6426 * @handle: device handle
6428 * After host reset, find out whether devices are still responding.
6429 * Used in _scsih_remove_unresponsive_raid_devices.
6434 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6437 struct MPT3SAS_TARGET *sas_target_priv_data;
6438 struct scsi_target *starget;
6439 struct _raid_device *raid_device;
6440 unsigned long flags;
6442 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6443 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6444 if (raid_device->wwid == wwid && raid_device->starget) {
6445 starget = raid_device->starget;
6446 if (starget && starget->hostdata) {
6447 sas_target_priv_data = starget->hostdata;
6448 sas_target_priv_data->deleted = 0;
6450 sas_target_priv_data = NULL;
6451 raid_device->responding = 1;
6452 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6453 starget_printk(KERN_INFO, raid_device->starget,
6454 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6455 (unsigned long long)raid_device->wwid);
6456 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6457 if (raid_device->handle == handle) {
6458 spin_unlock_irqrestore(&ioc->raid_device_lock,
6462 pr_info("\thandle changed from(0x%04x)!!!\n",
6463 raid_device->handle);
6464 raid_device->handle = handle;
6465 if (sas_target_priv_data)
6466 sas_target_priv_data->handle = handle;
6467 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6471 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6475 * _scsih_search_responding_raid_devices -
6476 * @ioc: per adapter object
6478 * After host reset, find out whether devices are still responding.
6484 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6486 Mpi2RaidVolPage1_t volume_pg1;
6487 Mpi2RaidVolPage0_t volume_pg0;
6488 Mpi2RaidPhysDiskPage0_t pd_pg0;
6489 Mpi2ConfigReply_t mpi_reply;
6494 if (!ioc->ir_firmware)
6497 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6500 if (list_empty(&ioc->raid_device_list))
6504 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6505 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6506 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6507 MPI2_IOCSTATUS_MASK;
6508 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6510 handle = le16_to_cpu(volume_pg1.DevHandle);
6512 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6513 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6514 sizeof(Mpi2RaidVolPage0_t)))
6517 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6518 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6519 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6520 _scsih_mark_responding_raid_device(ioc,
6521 le64_to_cpu(volume_pg1.WWID), handle);
6524 /* refresh the pd_handles */
6525 phys_disk_num = 0xFF;
6526 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6527 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6528 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6530 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6531 MPI2_IOCSTATUS_MASK;
6532 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6534 phys_disk_num = pd_pg0.PhysDiskNum;
6535 handle = le16_to_cpu(pd_pg0.DevHandle);
6536 set_bit(handle, ioc->pd_handles);
6539 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6544 * _scsih_mark_responding_expander - mark a expander as responding
6545 * @ioc: per adapter object
6546 * @sas_address: sas address
6549 * After host reset, find out whether devices are still responding.
6550 * Used in _scsih_remove_unresponsive_expanders.
6555 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6558 struct _sas_node *sas_expander;
6559 unsigned long flags;
6562 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6563 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6564 if (sas_expander->sas_address != sas_address)
6566 sas_expander->responding = 1;
6567 if (sas_expander->handle == handle)
6569 pr_info("\texpander(0x%016llx): handle changed" \
6570 " from(0x%04x) to (0x%04x)!!!\n",
6571 (unsigned long long)sas_expander->sas_address,
6572 sas_expander->handle, handle);
6573 sas_expander->handle = handle;
6574 for (i = 0 ; i < sas_expander->num_phys ; i++)
6575 sas_expander->phy[i].handle = handle;
6579 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6583 * _scsih_search_responding_expanders -
6584 * @ioc: per adapter object
6586 * After host reset, find out whether devices are still responding.
6592 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6594 Mpi2ExpanderPage0_t expander_pg0;
6595 Mpi2ConfigReply_t mpi_reply;
6600 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6602 if (list_empty(&ioc->sas_expander_list))
6606 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6607 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6609 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6610 MPI2_IOCSTATUS_MASK;
6611 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6614 handle = le16_to_cpu(expander_pg0.DevHandle);
6615 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6616 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6618 (unsigned long long)sas_address);
6619 _scsih_mark_responding_expander(ioc, sas_address, handle);
6623 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6627 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6628 * @ioc: per adapter object
6633 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6635 struct _sas_device *sas_device, *sas_device_next;
6636 struct _sas_node *sas_expander, *sas_expander_next;
6637 struct _raid_device *raid_device, *raid_device_next;
6638 struct list_head tmp_list;
6639 unsigned long flags;
6641 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6644 /* removing unresponding end devices */
6645 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6647 list_for_each_entry_safe(sas_device, sas_device_next,
6648 &ioc->sas_device_list, list) {
6649 if (!sas_device->responding)
6650 mpt3sas_device_remove_by_sas_address(ioc,
6651 sas_device->sas_address);
6653 sas_device->responding = 0;
6656 /* removing unresponding volumes */
6657 if (ioc->ir_firmware) {
6658 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6660 list_for_each_entry_safe(raid_device, raid_device_next,
6661 &ioc->raid_device_list, list) {
6662 if (!raid_device->responding)
6663 _scsih_sas_volume_delete(ioc,
6664 raid_device->handle);
6666 raid_device->responding = 0;
6670 /* removing unresponding expanders */
6671 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6673 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6674 INIT_LIST_HEAD(&tmp_list);
6675 list_for_each_entry_safe(sas_expander, sas_expander_next,
6676 &ioc->sas_expander_list, list) {
6677 if (!sas_expander->responding)
6678 list_move_tail(&sas_expander->list, &tmp_list);
6680 sas_expander->responding = 0;
6682 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6683 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6685 list_del(&sas_expander->list);
6686 _scsih_expander_node_remove(ioc, sas_expander);
6689 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6692 /* unblock devices */
6693 _scsih_ublock_io_all_device(ioc);
6697 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6698 struct _sas_node *sas_expander, u16 handle)
6700 Mpi2ExpanderPage1_t expander_pg1;
6701 Mpi2ConfigReply_t mpi_reply;
6704 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6705 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6706 &expander_pg1, i, handle))) {
6707 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6708 ioc->name, __FILE__, __LINE__, __func__);
6712 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6713 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6714 expander_pg1.NegotiatedLinkRate >> 4);
6719 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6720 * @ioc: per adapter object
6725 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6727 Mpi2ExpanderPage0_t expander_pg0;
6728 Mpi2SasDevicePage0_t sas_device_pg0;
6729 Mpi2RaidVolPage1_t volume_pg1;
6730 Mpi2RaidVolPage0_t volume_pg0;
6731 Mpi2RaidPhysDiskPage0_t pd_pg0;
6732 Mpi2EventIrConfigElement_t element;
6733 Mpi2ConfigReply_t mpi_reply;
6736 u16 handle, parent_handle;
6738 struct _sas_device *sas_device;
6739 struct _sas_node *expander_device;
6740 static struct _raid_device *raid_device;
6742 unsigned long flags;
6744 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6746 _scsih_sas_host_refresh(ioc);
6748 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6752 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6753 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6755 MPI2_IOCSTATUS_MASK;
6756 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6757 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6758 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6759 ioc->name, ioc_status,
6760 le32_to_cpu(mpi_reply.IOCLogInfo));
6763 handle = le16_to_cpu(expander_pg0.DevHandle);
6764 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6765 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6766 ioc, le64_to_cpu(expander_pg0.SASAddress));
6767 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6768 if (expander_device)
6769 _scsih_refresh_expander_links(ioc, expander_device,
6772 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6773 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6774 handle, (unsigned long long)
6775 le64_to_cpu(expander_pg0.SASAddress));
6776 _scsih_expander_add(ioc, handle);
6777 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6778 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6779 handle, (unsigned long long)
6780 le64_to_cpu(expander_pg0.SASAddress));
6784 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6787 if (!ioc->ir_firmware)
6790 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6793 phys_disk_num = 0xFF;
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) {
6800 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
6801 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6802 ioc->name, ioc_status,
6803 le32_to_cpu(mpi_reply.IOCLogInfo));
6806 phys_disk_num = pd_pg0.PhysDiskNum;
6807 handle = le16_to_cpu(pd_pg0.DevHandle);
6808 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6809 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6810 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6813 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6814 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6817 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6818 MPI2_IOCSTATUS_MASK;
6819 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6820 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
6821 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6822 ioc->name, ioc_status,
6823 le32_to_cpu(mpi_reply.IOCLogInfo));
6826 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6827 if (!_scsih_get_sas_address(ioc, parent_handle,
6829 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
6830 " handle (0x%04x), sas_addr(0x%016llx)\n",
6831 ioc->name, handle, (unsigned long long)
6832 le64_to_cpu(sas_device_pg0.SASAddress));
6833 mpt3sas_transport_update_links(ioc, sas_address,
6834 handle, sas_device_pg0.PhyNum,
6835 MPI2_SAS_NEG_LINK_RATE_1_5);
6836 set_bit(handle, ioc->pd_handles);
6838 /* This will retry adding the end device.
6839 * _scsih_add_device() will decide on retries and
6840 * return "1" when it should be retried
6842 while (_scsih_add_device(ioc, handle, retry_count++,
6846 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
6847 " handle (0x%04x), sas_addr(0x%016llx)\n",
6848 ioc->name, handle, (unsigned long long)
6849 le64_to_cpu(sas_device_pg0.SASAddress));
6853 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
6856 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
6860 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6861 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6862 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6863 MPI2_IOCSTATUS_MASK;
6864 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6865 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6866 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6867 ioc->name, ioc_status,
6868 le32_to_cpu(mpi_reply.IOCLogInfo));
6871 handle = le16_to_cpu(volume_pg1.DevHandle);
6872 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6873 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6874 le64_to_cpu(volume_pg1.WWID));
6875 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6878 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6879 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6880 sizeof(Mpi2RaidVolPage0_t)))
6882 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6883 MPI2_IOCSTATUS_MASK;
6884 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6885 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6886 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6887 ioc->name, ioc_status,
6888 le32_to_cpu(mpi_reply.IOCLogInfo));
6891 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6892 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6893 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6894 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6895 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6896 element.VolDevHandle = volume_pg1.DevHandle;
6898 "\tBEFORE adding volume: handle (0x%04x)\n",
6899 ioc->name, volume_pg1.DevHandle);
6900 _scsih_sas_volume_add(ioc, &element);
6902 "\tAFTER adding volume: handle (0x%04x)\n",
6903 ioc->name, volume_pg1.DevHandle);
6907 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
6912 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
6917 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6918 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6920 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6921 MPI2_IOCSTATUS_MASK;
6922 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6923 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
6924 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6925 ioc->name, ioc_status,
6926 le32_to_cpu(mpi_reply.IOCLogInfo));
6929 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6930 if (!(_scsih_is_end_device(
6931 le32_to_cpu(sas_device_pg0.DeviceInfo))))
6933 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6934 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
6935 le64_to_cpu(sas_device_pg0.SASAddress));
6936 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6939 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6940 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
6941 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
6942 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6943 handle, (unsigned long long)
6944 le64_to_cpu(sas_device_pg0.SASAddress));
6945 mpt3sas_transport_update_links(ioc, sas_address, handle,
6946 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6948 /* This will retry adding the end device.
6949 * _scsih_add_device() will decide on retries and
6950 * return "1" when it should be retried
6952 while (_scsih_add_device(ioc, handle, retry_count++,
6956 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
6957 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6958 handle, (unsigned long long)
6959 le64_to_cpu(sas_device_pg0.SASAddress));
6962 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
6965 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
6968 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
6969 * @ioc: per adapter object
6970 * @reset_phase: phase
6972 * The handler for doing any required cleanup or initialization.
6974 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
6975 * MPT3_IOC_DONE_RESET
6980 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
6982 switch (reset_phase) {
6983 case MPT3_IOC_PRE_RESET:
6984 dtmprintk(ioc, pr_info(MPT3SAS_FMT
6985 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
6987 case MPT3_IOC_AFTER_RESET:
6988 dtmprintk(ioc, pr_info(MPT3SAS_FMT
6989 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
6990 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
6991 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
6992 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
6993 complete(&ioc->scsih_cmds.done);
6995 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
6996 ioc->tm_cmds.status |= MPT3_CMD_RESET;
6997 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
6998 complete(&ioc->tm_cmds.done);
7001 _scsih_fw_event_cleanup_queue(ioc);
7002 _scsih_flush_running_cmds(ioc);
7004 case MPT3_IOC_DONE_RESET:
7005 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7006 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7007 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7008 !ioc->sas_hba.num_phys)) {
7009 _scsih_prep_device_scan(ioc);
7010 _scsih_search_responding_sas_devices(ioc);
7011 _scsih_search_responding_raid_devices(ioc);
7012 _scsih_search_responding_expanders(ioc);
7013 _scsih_error_recovery_delete_devices(ioc);
7020 * _mpt3sas_fw_work - delayed task for processing firmware events
7021 * @ioc: per adapter object
7022 * @fw_event: The fw_event_work object
7028 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7030 /* the queue is being flushed so ignore this event */
7031 if (ioc->remove_host || fw_event->cancel_pending_work ||
7032 ioc->pci_error_recovery) {
7033 _scsih_fw_event_free(ioc, fw_event);
7037 switch (fw_event->event) {
7038 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7039 mpt3sas_process_trigger_data(ioc, fw_event->event_data);
7041 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7042 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7044 _scsih_remove_unresponding_sas_devices(ioc);
7045 _scsih_scan_for_devices_after_reset(ioc);
7047 case MPT3SAS_PORT_ENABLE_COMPLETE:
7048 ioc->start_scan = 0;
7049 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7050 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7052 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7053 "port enable: complete from worker thread\n",
7056 case MPT3SAS_TURN_ON_FAULT_LED:
7057 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7059 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7060 _scsih_sas_topology_change_event(ioc, fw_event);
7062 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7063 _scsih_sas_device_status_change_event(ioc, fw_event);
7065 case MPI2_EVENT_SAS_DISCOVERY:
7066 _scsih_sas_discovery_event(ioc, fw_event);
7068 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7069 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7071 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7072 _scsih_sas_enclosure_dev_status_change_event(ioc,
7075 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7076 _scsih_sas_ir_config_change_event(ioc, fw_event);
7078 case MPI2_EVENT_IR_VOLUME:
7079 _scsih_sas_ir_volume_event(ioc, fw_event);
7081 case MPI2_EVENT_IR_PHYSICAL_DISK:
7082 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7084 case MPI2_EVENT_IR_OPERATION_STATUS:
7085 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7088 _scsih_fw_event_free(ioc, fw_event);
7092 * _firmware_event_work
7093 * @ioc: per adapter object
7094 * @work: The fw_event_work object
7097 * wrappers for the work thread handling firmware events
7103 _firmware_event_work(struct work_struct *work)
7105 struct fw_event_work *fw_event = container_of(work,
7106 struct fw_event_work, work);
7108 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7112 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7113 * @ioc: per adapter object
7114 * @msix_index: MSIX table index supplied by the OS
7115 * @reply: reply message frame(lower 32bit addr)
7116 * Context: interrupt.
7118 * This function merely adds a new work task into ioc->firmware_event_thread.
7119 * The tasks are worked from _firmware_event_work in user context.
7121 * Return 1 meaning mf should be freed from _base_interrupt
7122 * 0 means the mf is freed from this function.
7125 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7128 struct fw_event_work *fw_event;
7129 Mpi2EventNotificationReply_t *mpi_reply;
7133 /* events turned off due to host reset or driver unloading */
7134 if (ioc->remove_host || ioc->pci_error_recovery)
7137 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7139 if (unlikely(!mpi_reply)) {
7140 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7141 ioc->name, __FILE__, __LINE__, __func__);
7145 event = le16_to_cpu(mpi_reply->Event);
7147 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7148 mpt3sas_trigger_event(ioc, event, 0);
7152 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7154 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7155 (Mpi2EventDataSasBroadcastPrimitive_t *)
7156 mpi_reply->EventData;
7158 if (baen_data->Primitive !=
7159 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7162 if (ioc->broadcast_aen_busy) {
7163 ioc->broadcast_aen_pending++;
7166 ioc->broadcast_aen_busy = 1;
7170 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7171 _scsih_check_topo_delete_events(ioc,
7172 (Mpi2EventDataSasTopologyChangeList_t *)
7173 mpi_reply->EventData);
7175 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7176 _scsih_check_ir_config_unhide_events(ioc,
7177 (Mpi2EventDataIrConfigChangeList_t *)
7178 mpi_reply->EventData);
7180 case MPI2_EVENT_IR_VOLUME:
7181 _scsih_check_volume_delete_events(ioc,
7182 (Mpi2EventDataIrVolume_t *)
7183 mpi_reply->EventData);
7186 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7187 case MPI2_EVENT_IR_OPERATION_STATUS:
7188 case MPI2_EVENT_SAS_DISCOVERY:
7189 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7190 case MPI2_EVENT_IR_PHYSICAL_DISK:
7193 default: /* ignore the rest */
7197 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7199 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7200 ioc->name, __FILE__, __LINE__, __func__);
7203 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7204 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
7205 if (!fw_event->event_data) {
7206 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7207 ioc->name, __FILE__, __LINE__, __func__);
7212 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7213 fw_event->ioc = ioc;
7214 fw_event->VF_ID = mpi_reply->VF_ID;
7215 fw_event->VP_ID = mpi_reply->VP_ID;
7216 fw_event->event = event;
7217 _scsih_fw_event_add(ioc, fw_event);
7221 /* shost template */
7222 static struct scsi_host_template scsih_driver_template = {
7223 .module = THIS_MODULE,
7224 .name = "Fusion MPT SAS Host",
7225 .proc_name = MPT3SAS_DRIVER_NAME,
7226 .queuecommand = _scsih_qcmd,
7227 .target_alloc = _scsih_target_alloc,
7228 .slave_alloc = _scsih_slave_alloc,
7229 .slave_configure = _scsih_slave_configure,
7230 .target_destroy = _scsih_target_destroy,
7231 .slave_destroy = _scsih_slave_destroy,
7232 .scan_finished = _scsih_scan_finished,
7233 .scan_start = _scsih_scan_start,
7234 .change_queue_depth = _scsih_change_queue_depth,
7235 .change_queue_type = _scsih_change_queue_type,
7236 .eh_abort_handler = _scsih_abort,
7237 .eh_device_reset_handler = _scsih_dev_reset,
7238 .eh_target_reset_handler = _scsih_target_reset,
7239 .eh_host_reset_handler = _scsih_host_reset,
7240 .bios_param = _scsih_bios_param,
7243 .sg_tablesize = MPT3SAS_SG_DEPTH,
7244 .max_sectors = 32767,
7246 .use_clustering = ENABLE_CLUSTERING,
7247 .shost_attrs = mpt3sas_host_attrs,
7248 .sdev_attrs = mpt3sas_dev_attrs,
7252 * _scsih_expander_node_remove - removing expander device from list.
7253 * @ioc: per adapter object
7254 * @sas_expander: the sas_device object
7255 * Context: Calling function should acquire ioc->sas_node_lock.
7257 * Removing object and freeing associated memory from the
7258 * ioc->sas_expander_list.
7263 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7264 struct _sas_node *sas_expander)
7266 struct _sas_port *mpt3sas_port, *next;
7268 /* remove sibling ports attached to this expander */
7269 list_for_each_entry_safe(mpt3sas_port, next,
7270 &sas_expander->sas_port_list, port_list) {
7271 if (ioc->shost_recovery)
7273 if (mpt3sas_port->remote_identify.device_type ==
7275 mpt3sas_device_remove_by_sas_address(ioc,
7276 mpt3sas_port->remote_identify.sas_address);
7277 else if (mpt3sas_port->remote_identify.device_type ==
7278 SAS_EDGE_EXPANDER_DEVICE ||
7279 mpt3sas_port->remote_identify.device_type ==
7280 SAS_FANOUT_EXPANDER_DEVICE)
7281 mpt3sas_expander_remove(ioc,
7282 mpt3sas_port->remote_identify.sas_address);
7285 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7286 sas_expander->sas_address_parent);
7289 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7291 sas_expander->handle, (unsigned long long)
7292 sas_expander->sas_address);
7294 kfree(sas_expander->phy);
7295 kfree(sas_expander);
7299 * _scsih_ir_shutdown - IR shutdown notification
7300 * @ioc: per adapter object
7302 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7303 * the host system is shutting down.
7308 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7310 Mpi2RaidActionRequest_t *mpi_request;
7311 Mpi2RaidActionReply_t *mpi_reply;
7314 /* is IR firmware build loaded ? */
7315 if (!ioc->ir_firmware)
7318 /* are there any volumes ? */
7319 if (list_empty(&ioc->raid_device_list))
7322 mutex_lock(&ioc->scsih_cmds.mutex);
7324 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7325 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7326 ioc->name, __func__);
7329 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7331 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7333 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7334 ioc->name, __func__);
7335 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7339 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7340 ioc->scsih_cmds.smid = smid;
7341 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7343 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7344 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7346 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7347 init_completion(&ioc->scsih_cmds.done);
7348 mpt3sas_base_put_smid_default(ioc, smid);
7349 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7351 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7352 pr_err(MPT3SAS_FMT "%s: timeout\n",
7353 ioc->name, __func__);
7357 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7358 mpi_reply = ioc->scsih_cmds.reply;
7360 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7361 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7362 le32_to_cpu(mpi_reply->IOCLogInfo));
7366 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7367 mutex_unlock(&ioc->scsih_cmds.mutex);
7371 * _scsih_remove - detach and remove add host
7372 * @pdev: PCI device struct
7374 * Routine called when unloading the driver.
7377 static void _scsih_remove(struct pci_dev *pdev)
7379 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7380 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7381 struct _sas_port *mpt3sas_port, *next_port;
7382 struct _raid_device *raid_device, *next;
7383 struct MPT3SAS_TARGET *sas_target_priv_data;
7384 struct workqueue_struct *wq;
7385 unsigned long flags;
7387 ioc->remove_host = 1;
7388 _scsih_fw_event_cleanup_queue(ioc);
7390 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7391 wq = ioc->firmware_event_thread;
7392 ioc->firmware_event_thread = NULL;
7393 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7395 destroy_workqueue(wq);
7397 /* release all the volumes */
7398 _scsih_ir_shutdown(ioc);
7399 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7401 if (raid_device->starget) {
7402 sas_target_priv_data =
7403 raid_device->starget->hostdata;
7404 sas_target_priv_data->deleted = 1;
7405 scsi_remove_target(&raid_device->starget->dev);
7407 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7408 ioc->name, raid_device->handle,
7409 (unsigned long long) raid_device->wwid);
7410 _scsih_raid_device_remove(ioc, raid_device);
7413 /* free ports attached to the sas_host */
7414 list_for_each_entry_safe(mpt3sas_port, next_port,
7415 &ioc->sas_hba.sas_port_list, port_list) {
7416 if (mpt3sas_port->remote_identify.device_type ==
7418 mpt3sas_device_remove_by_sas_address(ioc,
7419 mpt3sas_port->remote_identify.sas_address);
7420 else if (mpt3sas_port->remote_identify.device_type ==
7421 SAS_EDGE_EXPANDER_DEVICE ||
7422 mpt3sas_port->remote_identify.device_type ==
7423 SAS_FANOUT_EXPANDER_DEVICE)
7424 mpt3sas_expander_remove(ioc,
7425 mpt3sas_port->remote_identify.sas_address);
7428 /* free phys attached to the sas_host */
7429 if (ioc->sas_hba.num_phys) {
7430 kfree(ioc->sas_hba.phy);
7431 ioc->sas_hba.phy = NULL;
7432 ioc->sas_hba.num_phys = 0;
7435 sas_remove_host(shost);
7436 mpt3sas_base_detach(ioc);
7437 list_del(&ioc->list);
7438 scsi_remove_host(shost);
7439 scsi_host_put(shost);
7443 * _scsih_shutdown - routine call during system shutdown
7444 * @pdev: PCI device struct
7449 _scsih_shutdown(struct pci_dev *pdev)
7451 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7452 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7453 struct workqueue_struct *wq;
7454 unsigned long flags;
7456 ioc->remove_host = 1;
7457 _scsih_fw_event_cleanup_queue(ioc);
7459 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7460 wq = ioc->firmware_event_thread;
7461 ioc->firmware_event_thread = NULL;
7462 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7464 destroy_workqueue(wq);
7466 _scsih_ir_shutdown(ioc);
7467 mpt3sas_base_detach(ioc);
7472 * _scsih_probe_boot_devices - reports 1st device
7473 * @ioc: per adapter object
7475 * If specified in bios page 2, this routine reports the 1st
7476 * device scsi-ml or sas transport for persistent boot device
7477 * purposes. Please refer to function _scsih_determine_boot_device()
7480 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7484 struct _sas_device *sas_device;
7485 struct _raid_device *raid_device;
7487 u64 sas_address_parent;
7489 unsigned long flags;
7492 /* no Bios, return immediately */
7493 if (!ioc->bios_pg3.BiosVersion)
7498 if (ioc->req_boot_device.device) {
7499 device = ioc->req_boot_device.device;
7500 is_raid = ioc->req_boot_device.is_raid;
7501 } else if (ioc->req_alt_boot_device.device) {
7502 device = ioc->req_alt_boot_device.device;
7503 is_raid = ioc->req_alt_boot_device.is_raid;
7504 } else if (ioc->current_boot_device.device) {
7505 device = ioc->current_boot_device.device;
7506 is_raid = ioc->current_boot_device.is_raid;
7513 raid_device = device;
7514 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7515 raid_device->id, 0);
7517 _scsih_raid_device_remove(ioc, raid_device);
7519 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7520 sas_device = device;
7521 handle = sas_device->handle;
7522 sas_address_parent = sas_device->sas_address_parent;
7523 sas_address = sas_device->sas_address;
7524 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7525 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7527 if (!mpt3sas_transport_port_add(ioc, handle,
7528 sas_address_parent)) {
7529 _scsih_sas_device_remove(ioc, sas_device);
7530 } else if (!sas_device->starget) {
7531 if (!ioc->is_driver_loading) {
7532 mpt3sas_transport_port_remove(ioc,
7534 sas_address_parent);
7535 _scsih_sas_device_remove(ioc, sas_device);
7542 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7543 * @ioc: per adapter object
7545 * Called during initial loading of the driver.
7548 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7550 struct _raid_device *raid_device, *raid_next;
7553 list_for_each_entry_safe(raid_device, raid_next,
7554 &ioc->raid_device_list, list) {
7555 if (raid_device->starget)
7557 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7558 raid_device->id, 0);
7560 _scsih_raid_device_remove(ioc, raid_device);
7565 * _scsih_probe_sas - reporting sas devices to sas transport
7566 * @ioc: per adapter object
7568 * Called during initial loading of the driver.
7571 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7573 struct _sas_device *sas_device, *next;
7574 unsigned long flags;
7576 /* SAS Device List */
7577 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7580 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7581 sas_device->sas_address_parent)) {
7582 list_del(&sas_device->list);
7585 } else if (!sas_device->starget) {
7587 * When asyn scanning is enabled, its not possible to
7588 * remove devices while scanning is turned on due to an
7589 * oops in scsi_sysfs_add_sdev()->add_device()->
7590 * sysfs_addrm_start()
7592 if (!ioc->is_driver_loading) {
7593 mpt3sas_transport_port_remove(ioc,
7594 sas_device->sas_address,
7595 sas_device->sas_address_parent);
7596 list_del(&sas_device->list);
7602 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7603 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7604 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7609 * _scsih_probe_devices - probing for devices
7610 * @ioc: per adapter object
7612 * Called during initial loading of the driver.
7615 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7617 u16 volume_mapping_flags;
7619 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7620 return; /* return when IOC doesn't support initiator mode */
7622 _scsih_probe_boot_devices(ioc);
7624 if (ioc->ir_firmware) {
7625 volume_mapping_flags =
7626 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7627 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7628 if (volume_mapping_flags ==
7629 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7630 _scsih_probe_raid(ioc);
7631 _scsih_probe_sas(ioc);
7633 _scsih_probe_sas(ioc);
7634 _scsih_probe_raid(ioc);
7637 _scsih_probe_sas(ioc);
7641 * _scsih_scan_start - scsi lld callback for .scan_start
7642 * @shost: SCSI host pointer
7644 * The shost has the ability to discover targets on its own instead
7645 * of scanning the entire bus. In our implemention, we will kick off
7646 * firmware discovery.
7649 _scsih_scan_start(struct Scsi_Host *shost)
7651 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7653 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7654 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7656 if (disable_discovery > 0)
7659 ioc->start_scan = 1;
7660 rc = mpt3sas_port_enable(ioc);
7663 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7667 * _scsih_scan_finished - scsi lld callback for .scan_finished
7668 * @shost: SCSI host pointer
7669 * @time: elapsed time of the scan in jiffies
7671 * This function will be called periodicallyn until it returns 1 with the
7672 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7673 * we wait for firmware discovery to complete, then return 1.
7676 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7678 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7680 if (disable_discovery > 0) {
7681 ioc->is_driver_loading = 0;
7682 ioc->wait_for_discovery_to_complete = 0;
7686 if (time >= (300 * HZ)) {
7687 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7689 "port enable: FAILED with timeout (timeout=300s)\n",
7691 ioc->is_driver_loading = 0;
7695 if (ioc->start_scan)
7698 if (ioc->start_scan_failed) {
7700 "port enable: FAILED with (ioc_status=0x%08x)\n",
7701 ioc->name, ioc->start_scan_failed);
7702 ioc->is_driver_loading = 0;
7703 ioc->wait_for_discovery_to_complete = 0;
7704 ioc->remove_host = 1;
7708 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7709 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7711 if (ioc->wait_for_discovery_to_complete) {
7712 ioc->wait_for_discovery_to_complete = 0;
7713 _scsih_probe_devices(ioc);
7715 mpt3sas_base_start_watchdog(ioc);
7716 ioc->is_driver_loading = 0;
7721 * _scsih_probe - attach and add scsi host
7722 * @pdev: PCI device struct
7723 * @id: pci device id
7725 * Returns 0 success, anything else error.
7728 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7730 struct MPT3SAS_ADAPTER *ioc;
7731 struct Scsi_Host *shost;
7733 shost = scsi_host_alloc(&scsih_driver_template,
7734 sizeof(struct MPT3SAS_ADAPTER));
7738 /* init local params */
7739 ioc = shost_priv(shost);
7740 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7741 INIT_LIST_HEAD(&ioc->list);
7742 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7744 ioc->id = mpt_ids++;
7745 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
7747 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7748 ioc->tm_cb_idx = tm_cb_idx;
7749 ioc->ctl_cb_idx = ctl_cb_idx;
7750 ioc->base_cb_idx = base_cb_idx;
7751 ioc->port_enable_cb_idx = port_enable_cb_idx;
7752 ioc->transport_cb_idx = transport_cb_idx;
7753 ioc->scsih_cb_idx = scsih_cb_idx;
7754 ioc->config_cb_idx = config_cb_idx;
7755 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7756 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7757 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7758 ioc->logging_level = logging_level;
7759 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7760 /* misc semaphores and spin locks */
7761 mutex_init(&ioc->reset_in_progress_mutex);
7762 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7763 spin_lock_init(&ioc->scsi_lookup_lock);
7764 spin_lock_init(&ioc->sas_device_lock);
7765 spin_lock_init(&ioc->sas_node_lock);
7766 spin_lock_init(&ioc->fw_event_lock);
7767 spin_lock_init(&ioc->raid_device_lock);
7768 spin_lock_init(&ioc->diag_trigger_lock);
7770 INIT_LIST_HEAD(&ioc->sas_device_list);
7771 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7772 INIT_LIST_HEAD(&ioc->sas_expander_list);
7773 INIT_LIST_HEAD(&ioc->fw_event_list);
7774 INIT_LIST_HEAD(&ioc->raid_device_list);
7775 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7776 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7777 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7778 INIT_LIST_HEAD(&ioc->reply_queue_list);
7780 /* init shost parameters */
7781 shost->max_cmd_len = 32;
7782 shost->max_lun = max_lun;
7783 shost->transportt = mpt3sas_transport_template;
7784 shost->unique_id = ioc->id;
7786 if (max_sectors != 0xFFFF) {
7787 if (max_sectors < 64) {
7788 shost->max_sectors = 64;
7789 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7790 "for max_sectors, range is 64 to 32767. Assigning "
7791 "value of 64.\n", ioc->name, max_sectors);
7792 } else if (max_sectors > 32767) {
7793 shost->max_sectors = 32767;
7794 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7795 "for max_sectors, range is 64 to 32767. Assigning "
7796 "default value of 32767.\n", ioc->name,
7799 shost->max_sectors = max_sectors & 0xFFFE;
7801 "The max_sectors value is set to %d\n",
7802 ioc->name, shost->max_sectors);
7806 if ((scsi_add_host(shost, &pdev->dev))) {
7807 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7808 ioc->name, __FILE__, __LINE__, __func__);
7809 list_del(&ioc->list);
7810 goto out_add_shost_fail;
7813 /* register EEDP capabilities with SCSI layer */
7815 scsi_host_set_prot(shost, prot_mask);
7817 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7818 | SHOST_DIF_TYPE2_PROTECTION
7819 | SHOST_DIF_TYPE3_PROTECTION);
7821 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7824 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7825 "fw_event%d", ioc->id);
7826 ioc->firmware_event_thread = create_singlethread_workqueue(
7827 ioc->firmware_event_name);
7828 if (!ioc->firmware_event_thread) {
7829 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7830 ioc->name, __FILE__, __LINE__, __func__);
7831 goto out_thread_fail;
7834 ioc->is_driver_loading = 1;
7835 if ((mpt3sas_base_attach(ioc))) {
7836 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7837 ioc->name, __FILE__, __LINE__, __func__);
7838 goto out_attach_fail;
7840 scsi_scan_host(shost);
7844 destroy_workqueue(ioc->firmware_event_thread);
7846 list_del(&ioc->list);
7847 scsi_remove_host(shost);
7849 scsi_host_put(shost);
7855 * _scsih_suspend - power management suspend main entry point
7856 * @pdev: PCI device struct
7857 * @state: PM state change to (usually PCI_D3)
7859 * Returns 0 success, anything else error.
7862 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7864 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7865 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7866 pci_power_t device_state;
7868 mpt3sas_base_stop_watchdog(ioc);
7869 flush_scheduled_work();
7870 scsi_block_requests(shost);
7871 device_state = pci_choose_state(pdev, state);
7873 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7874 ioc->name, pdev, pci_name(pdev), device_state);
7876 pci_save_state(pdev);
7877 mpt3sas_base_free_resources(ioc);
7878 pci_set_power_state(pdev, device_state);
7883 * _scsih_resume - power management resume main entry point
7884 * @pdev: PCI device struct
7886 * Returns 0 success, anything else error.
7889 _scsih_resume(struct pci_dev *pdev)
7891 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7892 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7893 pci_power_t device_state = pdev->current_state;
7897 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7898 ioc->name, pdev, pci_name(pdev), device_state);
7900 pci_set_power_state(pdev, PCI_D0);
7901 pci_enable_wake(pdev, PCI_D0, 0);
7902 pci_restore_state(pdev);
7904 r = mpt3sas_base_map_resources(ioc);
7908 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7909 scsi_unblock_requests(shost);
7910 mpt3sas_base_start_watchdog(ioc);
7913 #endif /* CONFIG_PM */
7916 * _scsih_pci_error_detected - Called when a PCI error is detected.
7917 * @pdev: PCI device struct
7918 * @state: PCI channel state
7920 * Description: Called when a PCI error is detected.
7923 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7925 static pci_ers_result_t
7926 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7928 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7929 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7931 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
7935 case pci_channel_io_normal:
7936 return PCI_ERS_RESULT_CAN_RECOVER;
7937 case pci_channel_io_frozen:
7938 /* Fatal error, prepare for slot reset */
7939 ioc->pci_error_recovery = 1;
7940 scsi_block_requests(ioc->shost);
7941 mpt3sas_base_stop_watchdog(ioc);
7942 mpt3sas_base_free_resources(ioc);
7943 return PCI_ERS_RESULT_NEED_RESET;
7944 case pci_channel_io_perm_failure:
7945 /* Permanent error, prepare for device removal */
7946 ioc->pci_error_recovery = 1;
7947 mpt3sas_base_stop_watchdog(ioc);
7948 _scsih_flush_running_cmds(ioc);
7949 return PCI_ERS_RESULT_DISCONNECT;
7951 return PCI_ERS_RESULT_NEED_RESET;
7955 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7956 * @pdev: PCI device struct
7958 * Description: This routine is called by the pci error recovery
7959 * code after the PCI slot has been reset, just before we
7960 * should resume normal operations.
7962 static pci_ers_result_t
7963 _scsih_pci_slot_reset(struct pci_dev *pdev)
7965 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7966 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7969 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
7972 ioc->pci_error_recovery = 0;
7974 pci_restore_state(pdev);
7975 rc = mpt3sas_base_map_resources(ioc);
7977 return PCI_ERS_RESULT_DISCONNECT;
7979 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
7982 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
7983 (rc == 0) ? "success" : "failed");
7986 return PCI_ERS_RESULT_RECOVERED;
7988 return PCI_ERS_RESULT_DISCONNECT;
7992 * _scsih_pci_resume() - resume normal ops after PCI reset
7993 * @pdev: pointer to PCI device
7995 * Called when the error recovery driver tells us that its
7996 * OK to resume normal operation. Use completion to allow
7997 * halted scsi ops to resume.
8000 _scsih_pci_resume(struct pci_dev *pdev)
8002 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8003 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8005 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8007 pci_cleanup_aer_uncorrect_error_status(pdev);
8008 mpt3sas_base_start_watchdog(ioc);
8009 scsi_unblock_requests(ioc->shost);
8013 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8014 * @pdev: pointer to PCI device
8016 static pci_ers_result_t
8017 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8019 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8020 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8022 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8025 /* TODO - dump whatever for debugging purposes */
8027 /* Request a slot reset. */
8028 return PCI_ERS_RESULT_NEED_RESET;
8031 /* raid transport support */
8032 static struct raid_function_template mpt3sas_raid_functions = {
8033 .cookie = &scsih_driver_template,
8034 .is_raid = _scsih_is_raid,
8035 .get_resync = _scsih_get_resync,
8036 .get_state = _scsih_get_state,
8039 static struct pci_error_handlers _scsih_err_handler = {
8040 .error_detected = _scsih_pci_error_detected,
8041 .mmio_enabled = _scsih_pci_mmio_enabled,
8042 .slot_reset = _scsih_pci_slot_reset,
8043 .resume = _scsih_pci_resume,
8046 static struct pci_driver scsih_driver = {
8047 .name = MPT3SAS_DRIVER_NAME,
8048 .id_table = scsih_pci_table,
8049 .probe = _scsih_probe,
8050 .remove = _scsih_remove,
8051 .shutdown = _scsih_shutdown,
8052 .err_handler = &_scsih_err_handler,
8054 .suspend = _scsih_suspend,
8055 .resume = _scsih_resume,
8061 * _scsih_init - main entry point for this driver.
8063 * Returns 0 success, anything else error.
8072 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8073 MPT3SAS_DRIVER_VERSION);
8075 mpt3sas_transport_template =
8076 sas_attach_transport(&mpt3sas_transport_functions);
8077 if (!mpt3sas_transport_template)
8080 /* raid transport support */
8081 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8082 if (!mpt3sas_raid_template) {
8083 sas_release_transport(mpt3sas_transport_template);
8087 mpt3sas_base_initialize_callback_handler();
8089 /* queuecommand callback hander */
8090 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8092 /* task managment callback handler */
8093 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8095 /* base internal commands callback handler */
8096 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8097 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8098 mpt3sas_port_enable_done);
8100 /* transport internal commands callback handler */
8101 transport_cb_idx = mpt3sas_base_register_callback_handler(
8102 mpt3sas_transport_done);
8104 /* scsih internal commands callback handler */
8105 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8107 /* configuration page API internal commands callback handler */
8108 config_cb_idx = mpt3sas_base_register_callback_handler(
8109 mpt3sas_config_done);
8111 /* ctl module callback handler */
8112 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8114 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8115 _scsih_tm_tr_complete);
8117 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8118 _scsih_tm_volume_tr_complete);
8120 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8121 _scsih_sas_control_complete);
8125 error = pci_register_driver(&scsih_driver);
8127 /* raid transport support */
8128 raid_class_release(mpt3sas_raid_template);
8129 sas_release_transport(mpt3sas_transport_template);
8136 * _scsih_exit - exit point for this driver (when it is a module).
8138 * Returns 0 success, anything else error.
8143 pr_info("mpt3sas version %s unloading\n",
8144 MPT3SAS_DRIVER_VERSION);
8148 pci_unregister_driver(&scsih_driver);
8151 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8152 mpt3sas_base_release_callback_handler(tm_cb_idx);
8153 mpt3sas_base_release_callback_handler(base_cb_idx);
8154 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8155 mpt3sas_base_release_callback_handler(transport_cb_idx);
8156 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8157 mpt3sas_base_release_callback_handler(config_cb_idx);
8158 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8160 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8161 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8162 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8164 /* raid transport support */
8165 raid_class_release(mpt3sas_raid_template);
8166 sas_release_transport(mpt3sas_transport_template);
8169 module_init(_scsih_init);
8170 module_exit(_scsih_exit);