2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * (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_PFA_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;
193 char event_data[0] __aligned(4);
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 const struct pci_device_id 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, 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
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 _scsih_adjust_queue_depth(sdev, qdepth);
1110 if (sdev->inquiry_len > 7)
1111 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \
1112 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
1113 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1115 (sdev->inquiry[7] & 2) >> 1);
1117 return sdev->queue_depth;
1121 * _scsih_target_alloc - target add routine
1122 * @starget: scsi target struct
1124 * Returns 0 if ok. Any other return is assumed to be an error and
1125 * the device is ignored.
1128 _scsih_target_alloc(struct scsi_target *starget)
1130 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1131 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1132 struct MPT3SAS_TARGET *sas_target_priv_data;
1133 struct _sas_device *sas_device;
1134 struct _raid_device *raid_device;
1135 unsigned long flags;
1136 struct sas_rphy *rphy;
1138 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1140 if (!sas_target_priv_data)
1143 starget->hostdata = sas_target_priv_data;
1144 sas_target_priv_data->starget = starget;
1145 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1148 if (starget->channel == RAID_CHANNEL) {
1149 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1150 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1153 sas_target_priv_data->handle = raid_device->handle;
1154 sas_target_priv_data->sas_address = raid_device->wwid;
1155 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1156 raid_device->starget = starget;
1158 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1162 /* sas/sata devices */
1163 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1164 rphy = dev_to_rphy(starget->dev.parent);
1165 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1166 rphy->identify.sas_address);
1169 sas_target_priv_data->handle = sas_device->handle;
1170 sas_target_priv_data->sas_address = sas_device->sas_address;
1171 sas_device->starget = starget;
1172 sas_device->id = starget->id;
1173 sas_device->channel = starget->channel;
1174 if (test_bit(sas_device->handle, ioc->pd_handles))
1175 sas_target_priv_data->flags |=
1176 MPT_TARGET_FLAGS_RAID_COMPONENT;
1177 if (sas_device->fast_path)
1178 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1180 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1186 * _scsih_target_destroy - target destroy routine
1187 * @starget: scsi target struct
1192 _scsih_target_destroy(struct scsi_target *starget)
1194 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1195 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1196 struct MPT3SAS_TARGET *sas_target_priv_data;
1197 struct _sas_device *sas_device;
1198 struct _raid_device *raid_device;
1199 unsigned long flags;
1200 struct sas_rphy *rphy;
1202 sas_target_priv_data = starget->hostdata;
1203 if (!sas_target_priv_data)
1206 if (starget->channel == RAID_CHANNEL) {
1207 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1208 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1211 raid_device->starget = NULL;
1212 raid_device->sdev = NULL;
1214 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1218 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1219 rphy = dev_to_rphy(starget->dev.parent);
1220 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1221 rphy->identify.sas_address);
1222 if (sas_device && (sas_device->starget == starget) &&
1223 (sas_device->id == starget->id) &&
1224 (sas_device->channel == starget->channel))
1225 sas_device->starget = NULL;
1227 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1230 kfree(sas_target_priv_data);
1231 starget->hostdata = NULL;
1235 * _scsih_slave_alloc - device add routine
1236 * @sdev: scsi device struct
1238 * Returns 0 if ok. Any other return is assumed to be an error and
1239 * the device is ignored.
1242 _scsih_slave_alloc(struct scsi_device *sdev)
1244 struct Scsi_Host *shost;
1245 struct MPT3SAS_ADAPTER *ioc;
1246 struct MPT3SAS_TARGET *sas_target_priv_data;
1247 struct MPT3SAS_DEVICE *sas_device_priv_data;
1248 struct scsi_target *starget;
1249 struct _raid_device *raid_device;
1250 struct _sas_device *sas_device;
1251 unsigned long flags;
1253 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1255 if (!sas_device_priv_data)
1258 sas_device_priv_data->lun = sdev->lun;
1259 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1261 starget = scsi_target(sdev);
1262 sas_target_priv_data = starget->hostdata;
1263 sas_target_priv_data->num_luns++;
1264 sas_device_priv_data->sas_target = sas_target_priv_data;
1265 sdev->hostdata = sas_device_priv_data;
1266 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1267 sdev->no_uld_attach = 1;
1269 shost = dev_to_shost(&starget->dev);
1270 ioc = shost_priv(shost);
1271 if (starget->channel == RAID_CHANNEL) {
1272 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1273 raid_device = _scsih_raid_device_find_by_id(ioc,
1274 starget->id, starget->channel);
1276 raid_device->sdev = sdev; /* raid is single lun */
1277 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1280 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1281 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1282 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1283 sas_target_priv_data->sas_address);
1284 if (sas_device && (sas_device->starget == NULL)) {
1285 sdev_printk(KERN_INFO, sdev,
1286 "%s : sas_device->starget set to starget @ %d\n",
1287 __func__, __LINE__);
1288 sas_device->starget = starget;
1290 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1297 * _scsih_slave_destroy - device destroy routine
1298 * @sdev: scsi device struct
1303 _scsih_slave_destroy(struct scsi_device *sdev)
1305 struct MPT3SAS_TARGET *sas_target_priv_data;
1306 struct scsi_target *starget;
1307 struct Scsi_Host *shost;
1308 struct MPT3SAS_ADAPTER *ioc;
1309 struct _sas_device *sas_device;
1310 unsigned long flags;
1312 if (!sdev->hostdata)
1315 starget = scsi_target(sdev);
1316 sas_target_priv_data = starget->hostdata;
1317 sas_target_priv_data->num_luns--;
1319 shost = dev_to_shost(&starget->dev);
1320 ioc = shost_priv(shost);
1322 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1323 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1324 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1325 sas_target_priv_data->sas_address);
1326 if (sas_device && !sas_target_priv_data->num_luns)
1327 sas_device->starget = NULL;
1328 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1331 kfree(sdev->hostdata);
1332 sdev->hostdata = NULL;
1336 * _scsih_display_sata_capabilities - sata capabilities
1337 * @ioc: per adapter object
1338 * @handle: device handle
1339 * @sdev: scsi device struct
1342 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1343 u16 handle, struct scsi_device *sdev)
1345 Mpi2ConfigReply_t mpi_reply;
1346 Mpi2SasDevicePage0_t sas_device_pg0;
1351 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1352 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1353 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1354 ioc->name, __FILE__, __LINE__, __func__);
1358 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1359 MPI2_IOCSTATUS_MASK;
1360 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1361 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1362 ioc->name, __FILE__, __LINE__, __func__);
1366 flags = le16_to_cpu(sas_device_pg0.Flags);
1367 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1369 sdev_printk(KERN_INFO, sdev,
1370 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1371 "sw_preserve(%s)\n",
1372 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1373 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1374 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1376 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1377 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1378 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1382 * raid transport support -
1383 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1384 * unloading the driver followed by a load - I beleive that the subroutine
1385 * raid_class_release() is not cleaning up properly.
1389 * _scsih_is_raid - return boolean indicating device is raid volume
1390 * @dev the device struct object
1393 _scsih_is_raid(struct device *dev)
1395 struct scsi_device *sdev = to_scsi_device(dev);
1397 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1401 * _scsih_get_resync - get raid volume resync percent complete
1402 * @dev the device struct object
1405 _scsih_get_resync(struct device *dev)
1407 struct scsi_device *sdev = to_scsi_device(dev);
1408 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1409 static struct _raid_device *raid_device;
1410 unsigned long flags;
1411 Mpi2RaidVolPage0_t vol_pg0;
1412 Mpi2ConfigReply_t mpi_reply;
1413 u32 volume_status_flags;
1414 u8 percent_complete;
1417 percent_complete = 0;
1419 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1420 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1423 handle = raid_device->handle;
1424 percent_complete = raid_device->percent_complete;
1426 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1431 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1432 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1433 sizeof(Mpi2RaidVolPage0_t))) {
1434 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1435 ioc->name, __FILE__, __LINE__, __func__);
1436 percent_complete = 0;
1440 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1441 if (!(volume_status_flags &
1442 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1443 percent_complete = 0;
1446 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1450 * _scsih_get_state - get raid volume level
1451 * @dev the device struct object
1454 _scsih_get_state(struct device *dev)
1456 struct scsi_device *sdev = to_scsi_device(dev);
1457 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1458 static struct _raid_device *raid_device;
1459 unsigned long flags;
1460 Mpi2RaidVolPage0_t vol_pg0;
1461 Mpi2ConfigReply_t mpi_reply;
1463 enum raid_state state = RAID_STATE_UNKNOWN;
1466 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1467 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1470 handle = raid_device->handle;
1471 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1476 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1477 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1478 sizeof(Mpi2RaidVolPage0_t))) {
1479 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1480 ioc->name, __FILE__, __LINE__, __func__);
1484 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1485 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1486 state = RAID_STATE_RESYNCING;
1490 switch (vol_pg0.VolumeState) {
1491 case MPI2_RAID_VOL_STATE_OPTIMAL:
1492 case MPI2_RAID_VOL_STATE_ONLINE:
1493 state = RAID_STATE_ACTIVE;
1495 case MPI2_RAID_VOL_STATE_DEGRADED:
1496 state = RAID_STATE_DEGRADED;
1498 case MPI2_RAID_VOL_STATE_FAILED:
1499 case MPI2_RAID_VOL_STATE_MISSING:
1500 state = RAID_STATE_OFFLINE;
1504 raid_set_state(mpt3sas_raid_template, dev, state);
1508 * _scsih_set_level - set raid level
1509 * @sdev: scsi device struct
1510 * @volume_type: volume type
1513 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1515 enum raid_level level = RAID_LEVEL_UNKNOWN;
1517 switch (volume_type) {
1518 case MPI2_RAID_VOL_TYPE_RAID0:
1519 level = RAID_LEVEL_0;
1521 case MPI2_RAID_VOL_TYPE_RAID10:
1522 level = RAID_LEVEL_10;
1524 case MPI2_RAID_VOL_TYPE_RAID1E:
1525 level = RAID_LEVEL_1E;
1527 case MPI2_RAID_VOL_TYPE_RAID1:
1528 level = RAID_LEVEL_1;
1532 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1537 * _scsih_get_volume_capabilities - volume capabilities
1538 * @ioc: per adapter object
1539 * @sas_device: the raid_device object
1541 * Returns 0 for success, else 1
1544 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1545 struct _raid_device *raid_device)
1547 Mpi2RaidVolPage0_t *vol_pg0;
1548 Mpi2RaidPhysDiskPage0_t pd_pg0;
1549 Mpi2SasDevicePage0_t sas_device_pg0;
1550 Mpi2ConfigReply_t mpi_reply;
1554 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1555 &num_pds)) || !num_pds) {
1556 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1557 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1562 raid_device->num_pds = num_pds;
1563 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1564 sizeof(Mpi2RaidVol0PhysDisk_t));
1565 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1567 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1568 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1573 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1574 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1575 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1576 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1582 raid_device->volume_type = vol_pg0->VolumeType;
1584 /* figure out what the underlying devices are by
1585 * obtaining the device_info bits for the 1st device
1587 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1588 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1589 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1590 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1591 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1592 le16_to_cpu(pd_pg0.DevHandle)))) {
1593 raid_device->device_info =
1594 le32_to_cpu(sas_device_pg0.DeviceInfo);
1605 * _scsih_enable_tlr - setting TLR flags
1606 * @ioc: per adapter object
1607 * @sdev: scsi device struct
1609 * Enabling Transaction Layer Retries for tape devices when
1610 * vpd page 0x90 is present
1614 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1618 if (sdev->type != TYPE_TAPE)
1621 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1624 sas_enable_tlr(sdev);
1625 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1626 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1632 * _scsih_slave_configure - device configure routine.
1633 * @sdev: scsi device struct
1635 * Returns 0 if ok. Any other return is assumed to be an error and
1636 * the device is ignored.
1639 _scsih_slave_configure(struct scsi_device *sdev)
1641 struct Scsi_Host *shost = sdev->host;
1642 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1643 struct MPT3SAS_DEVICE *sas_device_priv_data;
1644 struct MPT3SAS_TARGET *sas_target_priv_data;
1645 struct _sas_device *sas_device;
1646 struct _raid_device *raid_device;
1647 unsigned long flags;
1652 u16 handle, volume_handle = 0;
1653 u64 volume_wwid = 0;
1656 sas_device_priv_data = sdev->hostdata;
1657 sas_device_priv_data->configured_lun = 1;
1658 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1659 sas_target_priv_data = sas_device_priv_data->sas_target;
1660 handle = sas_target_priv_data->handle;
1662 /* raid volume handling */
1663 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1665 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1666 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1667 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1669 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1670 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1671 __LINE__, __func__));
1675 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1676 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1677 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1678 __LINE__, __func__));
1683 /* RAID Queue Depth Support
1684 * IS volume = underlying qdepth of drive type, either
1685 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1686 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1688 if (raid_device->device_info &
1689 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1690 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1693 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1694 if (raid_device->device_info &
1695 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1701 switch (raid_device->volume_type) {
1702 case MPI2_RAID_VOL_TYPE_RAID0:
1705 case MPI2_RAID_VOL_TYPE_RAID1E:
1706 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1707 if (ioc->manu_pg10.OEMIdentifier &&
1708 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1709 MFG10_GF0_R10_DISPLAY) &&
1710 !(raid_device->num_pds % 2))
1715 case MPI2_RAID_VOL_TYPE_RAID1:
1716 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1719 case MPI2_RAID_VOL_TYPE_RAID10:
1720 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1723 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1725 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1730 sdev_printk(KERN_INFO, sdev,
1731 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1732 r_level, raid_device->handle,
1733 (unsigned long long)raid_device->wwid,
1734 raid_device->num_pds, ds);
1737 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1739 /* raid transport support */
1740 _scsih_set_level(sdev, raid_device->volume_type);
1744 /* non-raid handling */
1745 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1746 if (mpt3sas_config_get_volume_handle(ioc, handle,
1748 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1749 "failure at %s:%d/%s()!\n", ioc->name,
1750 __FILE__, __LINE__, __func__));
1753 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1754 volume_handle, &volume_wwid)) {
1755 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1756 "failure at %s:%d/%s()!\n", ioc->name,
1757 __FILE__, __LINE__, __func__));
1762 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1763 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1764 sas_device_priv_data->sas_target->sas_address);
1766 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1767 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1768 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1773 sas_device->volume_handle = volume_handle;
1774 sas_device->volume_wwid = volume_wwid;
1775 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1776 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1780 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1781 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1783 else if (sas_device->device_info &
1784 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1788 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1789 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1790 ds, handle, (unsigned long long)sas_device->sas_address,
1791 sas_device->phy, (unsigned long long)sas_device->device_name);
1792 sdev_printk(KERN_INFO, sdev,
1793 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1794 ds, (unsigned long long)
1795 sas_device->enclosure_logical_id, sas_device->slot);
1797 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1800 _scsih_display_sata_capabilities(ioc, handle, sdev);
1803 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1806 sas_read_port_mode_page(sdev);
1807 _scsih_enable_tlr(ioc, sdev);
1814 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1815 * @sdev: scsi device struct
1816 * @bdev: pointer to block device context
1817 * @capacity: device size (in 512 byte sectors)
1818 * @params: three element array to place output:
1819 * params[0] number of heads (max 255)
1820 * params[1] number of sectors (max 63)
1821 * params[2] number of cylinders
1826 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1827 sector_t capacity, int params[])
1837 dummy = heads * sectors;
1838 cylinders = capacity;
1839 sector_div(cylinders, dummy);
1842 * Handle extended translation size for logical drives
1845 if ((ulong)capacity >= 0x200000) {
1848 dummy = heads * sectors;
1849 cylinders = capacity;
1850 sector_div(cylinders, dummy);
1855 params[1] = sectors;
1856 params[2] = cylinders;
1862 * _scsih_response_code - translation of device response code
1863 * @ioc: per adapter object
1864 * @response_code: response code returned by the device
1869 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1873 switch (response_code) {
1874 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1875 desc = "task management request completed";
1877 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1878 desc = "invalid frame";
1880 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1881 desc = "task management request not supported";
1883 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1884 desc = "task management request failed";
1886 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1887 desc = "task management request succeeded";
1889 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1890 desc = "invalid lun";
1893 desc = "overlapped tag attempted";
1895 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1896 desc = "task queued, however not sent to target";
1902 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1903 ioc->name, response_code, desc);
1907 * _scsih_tm_done - tm completion routine
1908 * @ioc: per adapter object
1909 * @smid: system request message index
1910 * @msix_index: MSIX table index supplied by the OS
1911 * @reply: reply message frame(lower 32bit addr)
1914 * The callback handler when using scsih_issue_tm.
1916 * Return 1 meaning mf should be freed from _base_interrupt
1917 * 0 means the mf is freed from this function.
1920 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1922 MPI2DefaultReply_t *mpi_reply;
1924 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1926 if (ioc->tm_cmds.smid != smid)
1928 mpt3sas_base_flush_reply_queues(ioc);
1929 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1930 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1932 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1933 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1935 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1936 complete(&ioc->tm_cmds.done);
1941 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1942 * @ioc: per adapter object
1943 * @handle: device handle
1945 * During taskmangement request, we need to freeze the device queue.
1948 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1950 struct MPT3SAS_DEVICE *sas_device_priv_data;
1951 struct scsi_device *sdev;
1954 shost_for_each_device(sdev, ioc->shost) {
1957 sas_device_priv_data = sdev->hostdata;
1958 if (!sas_device_priv_data)
1960 if (sas_device_priv_data->sas_target->handle == handle) {
1961 sas_device_priv_data->sas_target->tm_busy = 1;
1963 ioc->ignore_loginfos = 1;
1969 * mpt3sas_scsih_clear_tm_flag - clear 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_clear_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 = 0;
1991 ioc->ignore_loginfos = 0;
1997 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
1998 * @ioc: per adapter struct
1999 * @device_handle: device handle
2000 * @channel: the channel assigned by the OS
2001 * @id: the id assigned by the OS
2003 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2004 * @smid_task: smid assigned to the task
2005 * @timeout: timeout in seconds
2006 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2009 * A generic API for sending task management requests to firmware.
2011 * The callback index is set inside `ioc->tm_cb_idx`.
2013 * Return SUCCESS or FAILED.
2016 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2017 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2018 enum mutex_type m_type)
2020 Mpi2SCSITaskManagementRequest_t *mpi_request;
2021 Mpi2SCSITaskManagementReply_t *mpi_reply;
2024 unsigned long timeleft;
2025 struct scsiio_tracker *scsi_lookup = NULL;
2028 if (m_type == TM_MUTEX_ON)
2029 mutex_lock(&ioc->tm_cmds.mutex);
2030 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2031 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2032 __func__, ioc->name);
2037 if (ioc->shost_recovery || ioc->remove_host ||
2038 ioc->pci_error_recovery) {
2039 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2040 __func__, ioc->name);
2045 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2046 if (ioc_state & MPI2_DOORBELL_USED) {
2047 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2048 "unexpected doorbell active!\n", ioc->name));
2049 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2051 rc = (!rc) ? SUCCESS : FAILED;
2055 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2056 mpt3sas_base_fault_info(ioc, ioc_state &
2057 MPI2_DOORBELL_DATA_MASK);
2058 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2060 rc = (!rc) ? SUCCESS : FAILED;
2064 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2066 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2067 ioc->name, __func__);
2072 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2073 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2075 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2076 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2077 ioc->name, handle, type, smid_task));
2078 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2079 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2080 ioc->tm_cmds.smid = smid;
2081 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2082 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2083 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2084 mpi_request->DevHandle = cpu_to_le16(handle);
2085 mpi_request->TaskType = type;
2086 mpi_request->TaskMID = cpu_to_le16(smid_task);
2087 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2088 mpt3sas_scsih_set_tm_flag(ioc, handle);
2089 init_completion(&ioc->tm_cmds.done);
2090 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2091 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2092 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2093 pr_err(MPT3SAS_FMT "%s: timeout\n",
2094 ioc->name, __func__);
2095 _debug_dump_mf(mpi_request,
2096 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2097 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2098 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2100 rc = (!rc) ? SUCCESS : FAILED;
2101 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2102 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2107 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2108 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2109 mpi_reply = ioc->tm_cmds.reply;
2110 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2111 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2112 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2113 le32_to_cpu(mpi_reply->IOCLogInfo),
2114 le32_to_cpu(mpi_reply->TerminationCount)));
2115 if (ioc->logging_level & MPT_DEBUG_TM) {
2116 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2117 if (mpi_reply->IOCStatus)
2118 _debug_dump_mf(mpi_request,
2119 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2124 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2126 if (scsi_lookup->scmd == NULL)
2131 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2132 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2137 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2138 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2139 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2144 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2152 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2153 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2154 if (m_type == TM_MUTEX_ON)
2155 mutex_unlock(&ioc->tm_cmds.mutex);
2160 if (m_type == TM_MUTEX_ON)
2161 mutex_unlock(&ioc->tm_cmds.mutex);
2166 * _scsih_tm_display_info - displays info about the device
2167 * @ioc: per adapter struct
2168 * @scmd: pointer to scsi command object
2170 * Called by task management callback handlers.
2173 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2175 struct scsi_target *starget = scmd->device->sdev_target;
2176 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2177 struct _sas_device *sas_device = NULL;
2178 unsigned long flags;
2179 char *device_str = NULL;
2183 device_str = "volume";
2185 scsi_print_command(scmd);
2186 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2187 starget_printk(KERN_INFO, starget,
2188 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2189 device_str, priv_target->handle,
2190 device_str, (unsigned long long)priv_target->sas_address);
2192 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2193 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2194 priv_target->sas_address);
2196 if (priv_target->flags &
2197 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2198 starget_printk(KERN_INFO, starget,
2199 "volume handle(0x%04x), "
2200 "volume wwid(0x%016llx)\n",
2201 sas_device->volume_handle,
2202 (unsigned long long)sas_device->volume_wwid);
2204 starget_printk(KERN_INFO, starget,
2205 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2207 (unsigned long long)sas_device->sas_address,
2209 starget_printk(KERN_INFO, starget,
2210 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2211 (unsigned long long)sas_device->enclosure_logical_id,
2214 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2219 * _scsih_abort - eh threads main abort routine
2220 * @scmd: pointer to scsi command object
2222 * Returns SUCCESS if command aborted else FAILED
2225 _scsih_abort(struct scsi_cmnd *scmd)
2227 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2228 struct MPT3SAS_DEVICE *sas_device_priv_data;
2233 sdev_printk(KERN_INFO, scmd->device,
2234 "attempting task abort! scmd(%p)\n", scmd);
2235 _scsih_tm_display_info(ioc, scmd);
2237 sas_device_priv_data = scmd->device->hostdata;
2238 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2239 sdev_printk(KERN_INFO, scmd->device,
2240 "device been deleted! scmd(%p)\n", scmd);
2241 scmd->result = DID_NO_CONNECT << 16;
2242 scmd->scsi_done(scmd);
2247 /* search for the command */
2248 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2250 scmd->result = DID_RESET << 16;
2255 /* for hidden raid components and volumes this is not supported */
2256 if (sas_device_priv_data->sas_target->flags &
2257 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2258 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2259 scmd->result = DID_RESET << 16;
2264 mpt3sas_halt_firmware(ioc);
2266 handle = sas_device_priv_data->sas_target->handle;
2267 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2268 scmd->device->id, scmd->device->lun,
2269 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2272 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2273 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2278 * _scsih_dev_reset - eh threads main device reset routine
2279 * @scmd: pointer to scsi command object
2281 * Returns SUCCESS if command aborted else FAILED
2284 _scsih_dev_reset(struct scsi_cmnd *scmd)
2286 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2287 struct MPT3SAS_DEVICE *sas_device_priv_data;
2288 struct _sas_device *sas_device;
2289 unsigned long flags;
2293 sdev_printk(KERN_INFO, scmd->device,
2294 "attempting device reset! scmd(%p)\n", scmd);
2295 _scsih_tm_display_info(ioc, scmd);
2297 sas_device_priv_data = scmd->device->hostdata;
2298 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2299 sdev_printk(KERN_INFO, scmd->device,
2300 "device been deleted! scmd(%p)\n", scmd);
2301 scmd->result = DID_NO_CONNECT << 16;
2302 scmd->scsi_done(scmd);
2307 /* for hidden raid components obtain the volume_handle */
2309 if (sas_device_priv_data->sas_target->flags &
2310 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2311 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2312 sas_device = _scsih_sas_device_find_by_handle(ioc,
2313 sas_device_priv_data->sas_target->handle);
2315 handle = sas_device->volume_handle;
2316 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2318 handle = sas_device_priv_data->sas_target->handle;
2321 scmd->result = DID_RESET << 16;
2326 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2327 scmd->device->id, scmd->device->lun,
2328 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2331 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2332 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2337 * _scsih_target_reset - eh threads main target reset routine
2338 * @scmd: pointer to scsi command object
2340 * Returns SUCCESS if command aborted else FAILED
2343 _scsih_target_reset(struct scsi_cmnd *scmd)
2345 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2346 struct MPT3SAS_DEVICE *sas_device_priv_data;
2347 struct _sas_device *sas_device;
2348 unsigned long flags;
2351 struct scsi_target *starget = scmd->device->sdev_target;
2353 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2355 _scsih_tm_display_info(ioc, scmd);
2357 sas_device_priv_data = scmd->device->hostdata;
2358 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2359 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2361 scmd->result = DID_NO_CONNECT << 16;
2362 scmd->scsi_done(scmd);
2367 /* for hidden raid components obtain the volume_handle */
2369 if (sas_device_priv_data->sas_target->flags &
2370 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2371 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2372 sas_device = _scsih_sas_device_find_by_handle(ioc,
2373 sas_device_priv_data->sas_target->handle);
2375 handle = sas_device->volume_handle;
2376 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2378 handle = sas_device_priv_data->sas_target->handle;
2381 scmd->result = DID_RESET << 16;
2386 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2387 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2391 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2392 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2398 * _scsih_host_reset - eh threads main host reset routine
2399 * @scmd: pointer to scsi command object
2401 * Returns SUCCESS if command aborted else FAILED
2404 _scsih_host_reset(struct scsi_cmnd *scmd)
2406 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2409 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2411 scsi_print_command(scmd);
2413 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2415 r = (retval < 0) ? FAILED : SUCCESS;
2416 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2417 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2423 * _scsih_fw_event_add - insert and queue up fw_event
2424 * @ioc: per adapter object
2425 * @fw_event: object describing the event
2426 * Context: This function will acquire ioc->fw_event_lock.
2428 * This adds the firmware event object into link list, then queues it up to
2429 * be processed from user context.
2434 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2436 unsigned long flags;
2438 if (ioc->firmware_event_thread == NULL)
2441 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2442 INIT_LIST_HEAD(&fw_event->list);
2443 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2444 INIT_WORK(&fw_event->work, _firmware_event_work);
2445 queue_work(ioc->firmware_event_thread, &fw_event->work);
2446 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2450 * _scsih_fw_event_free - delete fw_event
2451 * @ioc: per adapter object
2452 * @fw_event: object describing the event
2453 * Context: This function will acquire ioc->fw_event_lock.
2455 * This removes firmware event object from link list, frees associated memory.
2460 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2463 unsigned long flags;
2465 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2466 list_del(&fw_event->list);
2468 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2473 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2474 * @ioc: per adapter object
2475 * @event_data: trigger event data
2480 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2481 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2483 struct fw_event_work *fw_event;
2485 if (ioc->is_driver_loading)
2487 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2491 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2492 fw_event->ioc = ioc;
2493 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2494 _scsih_fw_event_add(ioc, fw_event);
2498 * _scsih_error_recovery_delete_devices - remove devices not responding
2499 * @ioc: per adapter object
2504 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2506 struct fw_event_work *fw_event;
2508 if (ioc->is_driver_loading)
2510 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2513 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2514 fw_event->ioc = ioc;
2515 _scsih_fw_event_add(ioc, fw_event);
2519 * mpt3sas_port_enable_complete - port enable completed (fake event)
2520 * @ioc: per adapter object
2525 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2527 struct fw_event_work *fw_event;
2529 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2532 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2533 fw_event->ioc = ioc;
2534 _scsih_fw_event_add(ioc, fw_event);
2538 * _scsih_fw_event_cleanup_queue - cleanup event queue
2539 * @ioc: per adapter object
2541 * Walk the firmware event queue, either killing timers, or waiting
2542 * for outstanding events to complete
2547 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2549 struct fw_event_work *fw_event, *next;
2551 if (list_empty(&ioc->fw_event_list) ||
2552 !ioc->firmware_event_thread || in_interrupt())
2555 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2556 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2557 _scsih_fw_event_free(ioc, fw_event);
2564 * _scsih_ublock_io_all_device - unblock every device
2565 * @ioc: per adapter object
2567 * change the device state from block to running
2570 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2572 struct MPT3SAS_DEVICE *sas_device_priv_data;
2573 struct scsi_device *sdev;
2575 shost_for_each_device(sdev, ioc->shost) {
2576 sas_device_priv_data = sdev->hostdata;
2577 if (!sas_device_priv_data)
2579 if (!sas_device_priv_data->block)
2582 sas_device_priv_data->block = 0;
2583 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2584 "device_running, handle(0x%04x)\n",
2585 sas_device_priv_data->sas_target->handle));
2586 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2592 * _scsih_ublock_io_device - prepare device to be deleted
2593 * @ioc: per adapter object
2594 * @sas_addr: sas address
2596 * unblock then put device in offline state
2599 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2601 struct MPT3SAS_DEVICE *sas_device_priv_data;
2602 struct scsi_device *sdev;
2604 shost_for_each_device(sdev, ioc->shost) {
2605 sas_device_priv_data = sdev->hostdata;
2606 if (!sas_device_priv_data)
2608 if (sas_device_priv_data->sas_target->sas_address
2611 if (sas_device_priv_data->block) {
2612 sas_device_priv_data->block = 0;
2613 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2619 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2620 * @ioc: per adapter object
2621 * @handle: device handle
2623 * During device pull we need to appropiately set the sdev state.
2626 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2628 struct MPT3SAS_DEVICE *sas_device_priv_data;
2629 struct scsi_device *sdev;
2631 shost_for_each_device(sdev, ioc->shost) {
2632 sas_device_priv_data = sdev->hostdata;
2633 if (!sas_device_priv_data)
2635 if (sas_device_priv_data->block)
2637 sas_device_priv_data->block = 1;
2638 scsi_internal_device_block(sdev);
2639 sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n",
2640 sas_device_priv_data->sas_target->handle);
2645 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2646 * @ioc: per adapter object
2647 * @handle: device handle
2649 * During device pull we need to appropiately set the sdev state.
2652 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2654 struct MPT3SAS_DEVICE *sas_device_priv_data;
2655 struct scsi_device *sdev;
2657 shost_for_each_device(sdev, ioc->shost) {
2658 sas_device_priv_data = sdev->hostdata;
2659 if (!sas_device_priv_data)
2661 if (sas_device_priv_data->sas_target->handle != handle)
2663 if (sas_device_priv_data->block)
2665 sas_device_priv_data->block = 1;
2666 scsi_internal_device_block(sdev);
2667 sdev_printk(KERN_INFO, sdev,
2668 "device_blocked, handle(0x%04x)\n", handle);
2673 * _scsih_block_io_to_children_attached_to_ex
2674 * @ioc: per adapter object
2675 * @sas_expander: the sas_device object
2677 * This routine set sdev state to SDEV_BLOCK for all devices
2678 * attached to this expander. This function called when expander is
2682 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2683 struct _sas_node *sas_expander)
2685 struct _sas_port *mpt3sas_port;
2686 struct _sas_device *sas_device;
2687 struct _sas_node *expander_sibling;
2688 unsigned long flags;
2693 list_for_each_entry(mpt3sas_port,
2694 &sas_expander->sas_port_list, port_list) {
2695 if (mpt3sas_port->remote_identify.device_type ==
2697 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2699 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2700 mpt3sas_port->remote_identify.sas_address);
2702 set_bit(sas_device->handle,
2703 ioc->blocking_handles);
2704 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2708 list_for_each_entry(mpt3sas_port,
2709 &sas_expander->sas_port_list, port_list) {
2711 if (mpt3sas_port->remote_identify.device_type ==
2712 SAS_EDGE_EXPANDER_DEVICE ||
2713 mpt3sas_port->remote_identify.device_type ==
2714 SAS_FANOUT_EXPANDER_DEVICE) {
2716 mpt3sas_scsih_expander_find_by_sas_address(
2717 ioc, mpt3sas_port->remote_identify.sas_address);
2718 _scsih_block_io_to_children_attached_to_ex(ioc,
2725 * _scsih_block_io_to_children_attached_directly
2726 * @ioc: per adapter object
2727 * @event_data: topology change event data
2729 * This routine set sdev state to SDEV_BLOCK for all devices
2730 * direct attached during device pull.
2733 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2734 Mpi2EventDataSasTopologyChangeList_t *event_data)
2740 for (i = 0; i < event_data->NumEntries; i++) {
2741 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2744 reason_code = event_data->PHY[i].PhyStatus &
2745 MPI2_EVENT_SAS_TOPO_RC_MASK;
2746 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2747 _scsih_block_io_device(ioc, handle);
2752 * _scsih_tm_tr_send - send task management request
2753 * @ioc: per adapter object
2754 * @handle: device handle
2755 * Context: interrupt time.
2757 * This code is to initiate the device removal handshake protocol
2758 * with controller firmware. This function will issue target reset
2759 * using high priority request queue. It will send a sas iounit
2760 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2762 * This is designed to send muliple task management request at the same
2763 * time to the fifo. If the fifo is full, we will append the request,
2764 * and process it in a future completion.
2767 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2769 Mpi2SCSITaskManagementRequest_t *mpi_request;
2771 struct _sas_device *sas_device;
2772 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2773 u64 sas_address = 0;
2774 unsigned long flags;
2775 struct _tr_list *delayed_tr;
2778 if (ioc->remove_host) {
2779 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2780 "%s: host has been removed: handle(0x%04x)\n",
2781 __func__, ioc->name, handle));
2783 } else if (ioc->pci_error_recovery) {
2784 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2785 "%s: host in pci error recovery: handle(0x%04x)\n",
2786 __func__, ioc->name,
2790 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2791 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2792 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2793 "%s: host is not operational: handle(0x%04x)\n",
2794 __func__, ioc->name,
2799 /* if PD, then return */
2800 if (test_bit(handle, ioc->pd_handles))
2803 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2804 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2805 if (sas_device && sas_device->starget &&
2806 sas_device->starget->hostdata) {
2807 sas_target_priv_data = sas_device->starget->hostdata;
2808 sas_target_priv_data->deleted = 1;
2809 sas_address = sas_device->sas_address;
2811 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2813 if (sas_target_priv_data) {
2814 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2815 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2817 (unsigned long long)sas_address));
2818 _scsih_ublock_io_device(ioc, sas_address);
2819 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2822 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2824 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2827 INIT_LIST_HEAD(&delayed_tr->list);
2828 delayed_tr->handle = handle;
2829 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2830 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2831 "DELAYED:tr:handle(0x%04x), (open)\n",
2832 ioc->name, handle));
2836 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2837 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2838 ioc->name, handle, smid,
2839 ioc->tm_tr_cb_idx));
2840 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2841 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2842 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2843 mpi_request->DevHandle = cpu_to_le16(handle);
2844 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2845 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2846 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2850 * _scsih_tm_tr_complete -
2851 * @ioc: per adapter object
2852 * @smid: system request message index
2853 * @msix_index: MSIX table index supplied by the OS
2854 * @reply: reply message frame(lower 32bit addr)
2855 * Context: interrupt time.
2857 * This is the target reset completion routine.
2858 * This code is part of the code to initiate the device removal
2859 * handshake protocol with controller firmware.
2860 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2862 * Return 1 meaning mf should be freed from _base_interrupt
2863 * 0 means the mf is freed from this function.
2866 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2870 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2871 Mpi2SCSITaskManagementReply_t *mpi_reply =
2872 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2873 Mpi2SasIoUnitControlRequest_t *mpi_request;
2877 if (ioc->remove_host) {
2878 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2879 "%s: host has been removed\n", __func__, ioc->name));
2881 } else if (ioc->pci_error_recovery) {
2882 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2883 "%s: host in pci error recovery\n", __func__,
2887 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2888 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2889 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2890 "%s: host is not operational\n", __func__, ioc->name));
2893 if (unlikely(!mpi_reply)) {
2894 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2895 ioc->name, __FILE__, __LINE__, __func__);
2898 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2899 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2900 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2901 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2902 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2904 le16_to_cpu(mpi_reply->DevHandle), smid));
2908 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2909 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2910 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2911 "loginfo(0x%08x), completed(%d)\n", ioc->name,
2912 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
2913 le32_to_cpu(mpi_reply->IOCLogInfo),
2914 le32_to_cpu(mpi_reply->TerminationCount)));
2916 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2917 if (!smid_sas_ctrl) {
2918 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2919 ioc->name, __func__);
2923 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2924 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2925 ioc->name, handle, smid_sas_ctrl,
2926 ioc->tm_sas_control_cb_idx));
2927 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2928 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2929 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2930 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2931 mpi_request->DevHandle = mpi_request_tm->DevHandle;
2932 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
2934 return _scsih_check_for_pending_tm(ioc, smid);
2939 * _scsih_sas_control_complete - completion routine
2940 * @ioc: per adapter object
2941 * @smid: system request message index
2942 * @msix_index: MSIX table index supplied by the OS
2943 * @reply: reply message frame(lower 32bit addr)
2944 * Context: interrupt time.
2946 * This is the sas iounit control completion routine.
2947 * This code is part of the code to initiate the device removal
2948 * handshake protocol with controller firmware.
2950 * Return 1 meaning mf should be freed from _base_interrupt
2951 * 0 means the mf is freed from this function.
2954 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
2955 u8 msix_index, u32 reply)
2957 Mpi2SasIoUnitControlReply_t *mpi_reply =
2958 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2960 if (likely(mpi_reply)) {
2961 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2962 "sc_complete:handle(0x%04x), (open) "
2963 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2964 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2965 le16_to_cpu(mpi_reply->IOCStatus),
2966 le32_to_cpu(mpi_reply->IOCLogInfo)));
2968 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2969 ioc->name, __FILE__, __LINE__, __func__);
2975 * _scsih_tm_tr_volume_send - send target reset request for volumes
2976 * @ioc: per adapter object
2977 * @handle: device handle
2978 * Context: interrupt time.
2980 * This is designed to send muliple task management request at the same
2981 * time to the fifo. If the fifo is full, we will append the request,
2982 * and process it in a future completion.
2985 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2987 Mpi2SCSITaskManagementRequest_t *mpi_request;
2989 struct _tr_list *delayed_tr;
2991 if (ioc->shost_recovery || ioc->remove_host ||
2992 ioc->pci_error_recovery) {
2993 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2994 "%s: host reset in progress!\n",
2995 __func__, ioc->name));
2999 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3001 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3004 INIT_LIST_HEAD(&delayed_tr->list);
3005 delayed_tr->handle = handle;
3006 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3007 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3008 "DELAYED:tr:handle(0x%04x), (open)\n",
3009 ioc->name, handle));
3013 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3014 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3015 ioc->name, handle, smid,
3016 ioc->tm_tr_volume_cb_idx));
3017 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3018 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3019 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3020 mpi_request->DevHandle = cpu_to_le16(handle);
3021 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3022 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3026 * _scsih_tm_volume_tr_complete - target reset completion
3027 * @ioc: per adapter object
3028 * @smid: system request message index
3029 * @msix_index: MSIX table index supplied by the OS
3030 * @reply: reply message frame(lower 32bit addr)
3031 * Context: interrupt time.
3033 * Return 1 meaning mf should be freed from _base_interrupt
3034 * 0 means the mf is freed from this function.
3037 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3038 u8 msix_index, u32 reply)
3041 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3042 Mpi2SCSITaskManagementReply_t *mpi_reply =
3043 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3045 if (ioc->shost_recovery || ioc->remove_host ||
3046 ioc->pci_error_recovery) {
3047 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3048 "%s: host reset in progress!\n",
3049 __func__, ioc->name));
3052 if (unlikely(!mpi_reply)) {
3053 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3054 ioc->name, __FILE__, __LINE__, __func__);
3058 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3059 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3060 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3061 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3062 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3064 le16_to_cpu(mpi_reply->DevHandle), smid));
3068 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3069 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3070 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3071 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3072 le32_to_cpu(mpi_reply->IOCLogInfo),
3073 le32_to_cpu(mpi_reply->TerminationCount)));
3075 return _scsih_check_for_pending_tm(ioc, smid);
3080 * _scsih_check_for_pending_tm - check for pending task management
3081 * @ioc: per adapter object
3082 * @smid: system request message index
3084 * This will check delayed target reset list, and feed the
3087 * Return 1 meaning mf should be freed from _base_interrupt
3088 * 0 means the mf is freed from this function.
3091 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3093 struct _tr_list *delayed_tr;
3095 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3096 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3097 struct _tr_list, list);
3098 mpt3sas_base_free_smid(ioc, smid);
3099 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3100 list_del(&delayed_tr->list);
3105 if (!list_empty(&ioc->delayed_tr_list)) {
3106 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3107 struct _tr_list, list);
3108 mpt3sas_base_free_smid(ioc, smid);
3109 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3110 list_del(&delayed_tr->list);
3119 * _scsih_check_topo_delete_events - sanity check on topo events
3120 * @ioc: per adapter object
3121 * @event_data: the event data payload
3123 * This routine added to better handle cable breaker.
3125 * This handles the case where driver receives multiple expander
3126 * add and delete events in a single shot. When there is a delete event
3127 * the routine will void any pending add events waiting in the event queue.
3132 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3133 Mpi2EventDataSasTopologyChangeList_t *event_data)
3135 struct fw_event_work *fw_event;
3136 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3137 u16 expander_handle;
3138 struct _sas_node *sas_expander;
3139 unsigned long flags;
3143 for (i = 0 ; i < event_data->NumEntries; i++) {
3144 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3147 reason_code = event_data->PHY[i].PhyStatus &
3148 MPI2_EVENT_SAS_TOPO_RC_MASK;
3149 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3150 _scsih_tm_tr_send(ioc, handle);
3153 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3154 if (expander_handle < ioc->sas_hba.num_phys) {
3155 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3158 if (event_data->ExpStatus ==
3159 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3160 /* put expander attached devices into blocking state */
3161 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3162 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3164 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3165 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3167 handle = find_first_bit(ioc->blocking_handles,
3168 ioc->facts.MaxDevHandle);
3169 if (handle < ioc->facts.MaxDevHandle)
3170 _scsih_block_io_device(ioc, handle);
3171 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3172 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3173 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3175 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3178 /* mark ignore flag for pending events */
3179 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3180 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3181 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3184 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3185 fw_event->event_data;
3186 if (local_event_data->ExpStatus ==
3187 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3188 local_event_data->ExpStatus ==
3189 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3190 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3192 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3193 "setting ignoring flag\n", ioc->name));
3194 fw_event->ignore = 1;
3198 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3202 * _scsih_set_volume_delete_flag - setting volume delete flag
3203 * @ioc: per adapter object
3204 * @handle: device handle
3206 * This returns nothing.
3209 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3211 struct _raid_device *raid_device;
3212 struct MPT3SAS_TARGET *sas_target_priv_data;
3213 unsigned long flags;
3215 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3216 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3217 if (raid_device && raid_device->starget &&
3218 raid_device->starget->hostdata) {
3219 sas_target_priv_data =
3220 raid_device->starget->hostdata;
3221 sas_target_priv_data->deleted = 1;
3222 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3223 "setting delete flag: handle(0x%04x), "
3224 "wwid(0x%016llx)\n", ioc->name, handle,
3225 (unsigned long long) raid_device->wwid));
3227 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3231 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3232 * @handle: input handle
3233 * @a: handle for volume a
3234 * @b: handle for volume b
3236 * IR firmware only supports two raid volumes. The purpose of this
3237 * routine is to set the volume handle in either a or b. When the given
3238 * input handle is non-zero, or when a and b have not been set before.
3241 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3243 if (!handle || handle == *a || handle == *b)
3252 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3253 * @ioc: per adapter object
3254 * @event_data: the event data payload
3255 * Context: interrupt time.
3257 * This routine will send target reset to volume, followed by target
3258 * resets to the PDs. This is called when a PD has been removed, or
3259 * volume has been deleted or removed. When the target reset is sent
3260 * to volume, the PD target resets need to be queued to start upon
3261 * completion of the volume target reset.
3266 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3267 Mpi2EventDataIrConfigChangeList_t *event_data)
3269 Mpi2EventIrConfigElement_t *element;
3271 u16 handle, volume_handle, a, b;
3272 struct _tr_list *delayed_tr;
3277 /* Volume Resets for Deleted or Removed */
3278 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3279 for (i = 0; i < event_data->NumElements; i++, element++) {
3280 if (le32_to_cpu(event_data->Flags) &
3281 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3283 if (element->ReasonCode ==
3284 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3285 element->ReasonCode ==
3286 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3287 volume_handle = le16_to_cpu(element->VolDevHandle);
3288 _scsih_set_volume_delete_flag(ioc, volume_handle);
3289 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3293 /* Volume Resets for UNHIDE events */
3294 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3295 for (i = 0; i < event_data->NumElements; i++, element++) {
3296 if (le32_to_cpu(event_data->Flags) &
3297 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3299 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3300 volume_handle = le16_to_cpu(element->VolDevHandle);
3301 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3306 _scsih_tm_tr_volume_send(ioc, a);
3308 _scsih_tm_tr_volume_send(ioc, b);
3310 /* PD target resets */
3311 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3312 for (i = 0; i < event_data->NumElements; i++, element++) {
3313 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3315 handle = le16_to_cpu(element->PhysDiskDevHandle);
3316 volume_handle = le16_to_cpu(element->VolDevHandle);
3317 clear_bit(handle, ioc->pd_handles);
3319 _scsih_tm_tr_send(ioc, handle);
3320 else if (volume_handle == a || volume_handle == b) {
3321 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3322 BUG_ON(!delayed_tr);
3323 INIT_LIST_HEAD(&delayed_tr->list);
3324 delayed_tr->handle = handle;
3325 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3326 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3327 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3330 _scsih_tm_tr_send(ioc, handle);
3336 * _scsih_check_volume_delete_events - set delete flag for volumes
3337 * @ioc: per adapter object
3338 * @event_data: the event data payload
3339 * Context: interrupt time.
3341 * This will handle the case when the cable connected to entire volume is
3342 * pulled. We will take care of setting the deleted flag so normal IO will
3348 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3349 Mpi2EventDataIrVolume_t *event_data)
3353 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3355 state = le32_to_cpu(event_data->NewValue);
3356 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3357 MPI2_RAID_VOL_STATE_FAILED)
3358 _scsih_set_volume_delete_flag(ioc,
3359 le16_to_cpu(event_data->VolDevHandle));
3363 * _scsih_flush_running_cmds - completing outstanding commands.
3364 * @ioc: per adapter object
3366 * The flushing out of all pending scmd commands following host reset,
3367 * where all IO is dropped to the floor.
3372 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3374 struct scsi_cmnd *scmd;
3378 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3379 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3383 mpt3sas_base_free_smid(ioc, smid);
3384 scsi_dma_unmap(scmd);
3385 if (ioc->pci_error_recovery)
3386 scmd->result = DID_NO_CONNECT << 16;
3388 scmd->result = DID_RESET << 16;
3389 scmd->scsi_done(scmd);
3391 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3396 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3397 * @ioc: per adapter object
3398 * @scmd: pointer to scsi command object
3399 * @mpi_request: pointer to the SCSI_IO reqest message frame
3401 * Supporting protection 1 and 3.
3406 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3407 Mpi2SCSIIORequest_t *mpi_request)
3410 unsigned char prot_op = scsi_get_prot_op(scmd);
3411 unsigned char prot_type = scsi_get_prot_type(scmd);
3412 Mpi25SCSIIORequest_t *mpi_request_3v =
3413 (Mpi25SCSIIORequest_t *)mpi_request;
3415 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3418 if (prot_op == SCSI_PROT_READ_STRIP)
3419 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3420 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3421 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3425 switch (prot_type) {
3426 case SCSI_PROT_DIF_TYPE1:
3427 case SCSI_PROT_DIF_TYPE2:
3430 * enable ref/guard checking
3431 * auto increment ref tag
3433 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3434 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3435 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3436 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3437 cpu_to_be32(scsi_get_lba(scmd));
3440 case SCSI_PROT_DIF_TYPE3:
3443 * enable guard checking
3445 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3450 mpi_request_3v->EEDPBlockSize =
3451 cpu_to_le16(scmd->device->sector_size);
3452 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3456 * _scsih_eedp_error_handling - return sense code for EEDP errors
3457 * @scmd: pointer to scsi command object
3458 * @ioc_status: ioc status
3463 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3467 switch (ioc_status) {
3468 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3471 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3474 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3481 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3483 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3484 SAM_STAT_CHECK_CONDITION;
3489 * _scsih_qcmd - main scsi request entry point
3490 * @scmd: pointer to scsi command object
3491 * @done: function pointer to be invoked on completion
3493 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3495 * Returns 0 on success. If there's a failure, return either:
3496 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3497 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3500 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3502 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3503 struct MPT3SAS_DEVICE *sas_device_priv_data;
3504 struct MPT3SAS_TARGET *sas_target_priv_data;
3505 Mpi2SCSIIORequest_t *mpi_request;
3510 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3511 if (ioc->logging_level & MPT_DEBUG_SCSI)
3512 scsi_print_command(scmd);
3515 sas_device_priv_data = scmd->device->hostdata;
3516 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3517 scmd->result = DID_NO_CONNECT << 16;
3518 scmd->scsi_done(scmd);
3522 if (ioc->pci_error_recovery || ioc->remove_host) {
3523 scmd->result = DID_NO_CONNECT << 16;
3524 scmd->scsi_done(scmd);
3528 sas_target_priv_data = sas_device_priv_data->sas_target;
3530 /* invalid device handle */
3531 handle = sas_target_priv_data->handle;
3532 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3533 scmd->result = DID_NO_CONNECT << 16;
3534 scmd->scsi_done(scmd);
3539 /* host recovery or link resets sent via IOCTLs */
3540 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3541 return SCSI_MLQUEUE_HOST_BUSY;
3543 /* device has been deleted */
3544 else if (sas_target_priv_data->deleted) {
3545 scmd->result = DID_NO_CONNECT << 16;
3546 scmd->scsi_done(scmd);
3548 /* device busy with task managment */
3549 } else if (sas_target_priv_data->tm_busy ||
3550 sas_device_priv_data->block)
3551 return SCSI_MLQUEUE_DEVICE_BUSY;
3553 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3554 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3555 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3556 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3558 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3561 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3563 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3564 scmd->cmd_len != 32)
3565 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3567 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3569 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3570 ioc->name, __func__);
3573 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3574 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3575 _scsih_setup_eedp(ioc, scmd, mpi_request);
3577 if (scmd->cmd_len == 32)
3578 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3579 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3580 if (sas_device_priv_data->sas_target->flags &
3581 MPT_TARGET_FLAGS_RAID_COMPONENT)
3582 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3584 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3585 mpi_request->DevHandle = cpu_to_le16(handle);
3586 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3587 mpi_request->Control = cpu_to_le32(mpi_control);
3588 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3589 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3590 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3591 mpi_request->SenseBufferLowAddress =
3592 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3593 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3594 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3596 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3598 if (mpi_request->DataLength) {
3599 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3600 mpt3sas_base_free_smid(ioc, smid);
3604 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3606 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3607 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3608 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3609 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3610 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3612 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3614 mpt3sas_base_put_smid_default(ioc, smid);
3618 return SCSI_MLQUEUE_HOST_BUSY;
3622 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3623 * @sense_buffer: sense data returned by target
3624 * @data: normalized skey/asc/ascq
3629 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3631 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3632 /* descriptor format */
3633 data->skey = sense_buffer[1] & 0x0F;
3634 data->asc = sense_buffer[2];
3635 data->ascq = sense_buffer[3];
3638 data->skey = sense_buffer[2] & 0x0F;
3639 data->asc = sense_buffer[12];
3640 data->ascq = sense_buffer[13];
3644 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3646 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3647 * @ioc: per adapter object
3648 * @scmd: pointer to scsi command object
3649 * @mpi_reply: reply mf payload returned from firmware
3651 * scsi_status - SCSI Status code returned from target device
3652 * scsi_state - state info associated with SCSI_IO determined by ioc
3653 * ioc_status - ioc supplied status info
3658 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3659 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3663 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3664 MPI2_IOCSTATUS_MASK;
3665 u8 scsi_state = mpi_reply->SCSIState;
3666 u8 scsi_status = mpi_reply->SCSIStatus;
3667 char *desc_ioc_state = NULL;
3668 char *desc_scsi_status = NULL;
3669 char *desc_scsi_state = ioc->tmp_string;
3670 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3671 struct _sas_device *sas_device = NULL;
3672 unsigned long flags;
3673 struct scsi_target *starget = scmd->device->sdev_target;
3674 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3675 char *device_str = NULL;
3679 device_str = "volume";
3681 if (log_info == 0x31170000)
3684 switch (ioc_status) {
3685 case MPI2_IOCSTATUS_SUCCESS:
3686 desc_ioc_state = "success";
3688 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3689 desc_ioc_state = "invalid function";
3691 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3692 desc_ioc_state = "scsi recovered error";
3694 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3695 desc_ioc_state = "scsi invalid dev handle";
3697 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3698 desc_ioc_state = "scsi device not there";
3700 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3701 desc_ioc_state = "scsi data overrun";
3703 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3704 desc_ioc_state = "scsi data underrun";
3706 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3707 desc_ioc_state = "scsi io data error";
3709 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3710 desc_ioc_state = "scsi protocol error";
3712 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3713 desc_ioc_state = "scsi task terminated";
3715 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3716 desc_ioc_state = "scsi residual mismatch";
3718 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3719 desc_ioc_state = "scsi task mgmt failed";
3721 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3722 desc_ioc_state = "scsi ioc terminated";
3724 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3725 desc_ioc_state = "scsi ext terminated";
3727 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3728 desc_ioc_state = "eedp guard error";
3730 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3731 desc_ioc_state = "eedp ref tag error";
3733 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3734 desc_ioc_state = "eedp app tag error";
3737 desc_ioc_state = "unknown";
3741 switch (scsi_status) {
3742 case MPI2_SCSI_STATUS_GOOD:
3743 desc_scsi_status = "good";
3745 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3746 desc_scsi_status = "check condition";
3748 case MPI2_SCSI_STATUS_CONDITION_MET:
3749 desc_scsi_status = "condition met";
3751 case MPI2_SCSI_STATUS_BUSY:
3752 desc_scsi_status = "busy";
3754 case MPI2_SCSI_STATUS_INTERMEDIATE:
3755 desc_scsi_status = "intermediate";
3757 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3758 desc_scsi_status = "intermediate condmet";
3760 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3761 desc_scsi_status = "reservation conflict";
3763 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3764 desc_scsi_status = "command terminated";
3766 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3767 desc_scsi_status = "task set full";
3769 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3770 desc_scsi_status = "aca active";
3772 case MPI2_SCSI_STATUS_TASK_ABORTED:
3773 desc_scsi_status = "task aborted";
3776 desc_scsi_status = "unknown";
3780 desc_scsi_state[0] = '\0';
3782 desc_scsi_state = " ";
3783 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3784 strcat(desc_scsi_state, "response info ");
3785 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3786 strcat(desc_scsi_state, "state terminated ");
3787 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3788 strcat(desc_scsi_state, "no status ");
3789 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3790 strcat(desc_scsi_state, "autosense failed ");
3791 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3792 strcat(desc_scsi_state, "autosense valid ");
3794 scsi_print_command(scmd);
3796 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3797 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3798 device_str, (unsigned long long)priv_target->sas_address);
3800 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3801 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3802 priv_target->sas_address);
3805 "\tsas_address(0x%016llx), phy(%d)\n",
3806 ioc->name, (unsigned long long)
3807 sas_device->sas_address, sas_device->phy);
3809 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3810 ioc->name, (unsigned long long)
3811 sas_device->enclosure_logical_id, sas_device->slot);
3813 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3817 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3818 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3819 desc_ioc_state, ioc_status, smid);
3821 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3822 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3823 scsi_get_resid(scmd));
3825 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3826 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3827 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3829 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3830 ioc->name, desc_scsi_status,
3831 scsi_status, desc_scsi_state, scsi_state);
3833 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3834 struct sense_info data;
3835 _scsih_normalize_sense(scmd->sense_buffer, &data);
3837 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3838 ioc->name, data.skey,
3839 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3842 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3843 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3844 response_bytes = (u8 *)&response_info;
3845 _scsih_response_code(ioc, response_bytes[0]);
3851 * _scsih_turn_on_pfa_led - illuminate PFA LED
3852 * @ioc: per adapter object
3853 * @handle: device handle
3859 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3861 Mpi2SepReply_t mpi_reply;
3862 Mpi2SepRequest_t mpi_request;
3863 struct _sas_device *sas_device;
3865 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3869 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3870 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3871 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3872 mpi_request.SlotStatus =
3873 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3874 mpi_request.DevHandle = cpu_to_le16(handle);
3875 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3876 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3877 &mpi_request)) != 0) {
3878 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3879 __FILE__, __LINE__, __func__);
3882 sas_device->pfa_led_on = 1;
3884 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3885 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3886 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3887 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3888 le32_to_cpu(mpi_reply.IOCLogInfo)));
3893 * _scsih_turn_off_pfa_led - turn off Fault LED
3894 * @ioc: per adapter object
3895 * @sas_device: sas device whose PFA LED has to turned off
3901 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
3902 struct _sas_device *sas_device)
3904 Mpi2SepReply_t mpi_reply;
3905 Mpi2SepRequest_t mpi_request;
3907 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3908 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3909 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3910 mpi_request.SlotStatus = 0;
3911 mpi_request.Slot = cpu_to_le16(sas_device->slot);
3912 mpi_request.DevHandle = 0;
3913 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
3914 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
3915 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3916 &mpi_request)) != 0) {
3917 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3918 __FILE__, __LINE__, __func__);
3922 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3923 dewtprintk(ioc, printk(MPT3SAS_FMT
3924 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3925 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3926 le32_to_cpu(mpi_reply.IOCLogInfo)));
3931 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
3932 * @ioc: per adapter object
3933 * @handle: device handle
3934 * Context: interrupt.
3939 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3941 struct fw_event_work *fw_event;
3943 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
3946 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
3947 fw_event->device_handle = handle;
3948 fw_event->ioc = ioc;
3949 _scsih_fw_event_add(ioc, fw_event);
3953 * _scsih_smart_predicted_fault - process smart errors
3954 * @ioc: per adapter object
3955 * @handle: device handle
3956 * Context: interrupt.
3961 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3963 struct scsi_target *starget;
3964 struct MPT3SAS_TARGET *sas_target_priv_data;
3965 Mpi2EventNotificationReply_t *event_reply;
3966 Mpi2EventDataSasDeviceStatusChange_t *event_data;
3967 struct _sas_device *sas_device;
3969 unsigned long flags;
3971 /* only handle non-raid devices */
3972 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3973 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3975 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3978 starget = sas_device->starget;
3979 sas_target_priv_data = starget->hostdata;
3981 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
3982 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
3983 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3986 starget_printk(KERN_WARNING, starget, "predicted fault\n");
3987 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3989 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
3990 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
3992 /* insert into event log */
3993 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
3994 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
3995 event_reply = kzalloc(sz, GFP_KERNEL);
3997 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
3998 ioc->name, __FILE__, __LINE__, __func__);
4002 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4003 event_reply->Event =
4004 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4005 event_reply->MsgLength = sz/4;
4006 event_reply->EventDataLength =
4007 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4008 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4009 event_reply->EventData;
4010 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4011 event_data->ASC = 0x5D;
4012 event_data->DevHandle = cpu_to_le16(handle);
4013 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4014 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4019 * _scsih_io_done - scsi request callback
4020 * @ioc: per adapter object
4021 * @smid: system request message index
4022 * @msix_index: MSIX table index supplied by the OS
4023 * @reply: reply message frame(lower 32bit addr)
4025 * Callback handler when using _scsih_qcmd.
4027 * Return 1 meaning mf should be freed from _base_interrupt
4028 * 0 means the mf is freed from this function.
4031 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4033 Mpi2SCSIIORequest_t *mpi_request;
4034 Mpi2SCSIIOReply_t *mpi_reply;
4035 struct scsi_cmnd *scmd;
4041 struct MPT3SAS_DEVICE *sas_device_priv_data;
4042 u32 response_code = 0;
4044 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4045 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4049 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4051 if (mpi_reply == NULL) {
4052 scmd->result = DID_OK << 16;
4056 sas_device_priv_data = scmd->device->hostdata;
4057 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4058 sas_device_priv_data->sas_target->deleted) {
4059 scmd->result = DID_NO_CONNECT << 16;
4062 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4064 /* turning off TLR */
4065 scsi_state = mpi_reply->SCSIState;
4066 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4068 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4069 if (!sas_device_priv_data->tlr_snoop_check) {
4070 sas_device_priv_data->tlr_snoop_check++;
4071 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4072 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4073 sas_device_priv_data->flags &=
4077 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4078 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4079 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4080 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4083 ioc_status &= MPI2_IOCSTATUS_MASK;
4084 scsi_status = mpi_reply->SCSIStatus;
4086 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4087 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4088 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4089 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4090 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4093 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4094 struct sense_info data;
4095 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4097 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4098 le32_to_cpu(mpi_reply->SenseCount));
4099 memcpy(scmd->sense_buffer, sense_data, sz);
4100 _scsih_normalize_sense(scmd->sense_buffer, &data);
4101 /* failure prediction threshold exceeded */
4102 if (data.asc == 0x5D)
4103 _scsih_smart_predicted_fault(ioc,
4104 le16_to_cpu(mpi_reply->DevHandle));
4105 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4108 switch (ioc_status) {
4109 case MPI2_IOCSTATUS_BUSY:
4110 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4111 scmd->result = SAM_STAT_BUSY;
4114 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4115 scmd->result = DID_NO_CONNECT << 16;
4118 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4119 if (sas_device_priv_data->block) {
4120 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4123 if (log_info == 0x31110630) {
4124 if (scmd->retries > 2) {
4125 scmd->result = DID_NO_CONNECT << 16;
4126 scsi_device_set_state(scmd->device,
4129 scmd->result = DID_SOFT_ERROR << 16;
4130 scmd->device->expecting_cc_ua = 1;
4134 scmd->result = DID_SOFT_ERROR << 16;
4136 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4137 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4138 scmd->result = DID_RESET << 16;
4141 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4142 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4143 scmd->result = DID_SOFT_ERROR << 16;
4145 scmd->result = (DID_OK << 16) | scsi_status;
4148 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4149 scmd->result = (DID_OK << 16) | scsi_status;
4151 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4154 if (xfer_cnt < scmd->underflow) {
4155 if (scsi_status == SAM_STAT_BUSY)
4156 scmd->result = SAM_STAT_BUSY;
4158 scmd->result = DID_SOFT_ERROR << 16;
4159 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4160 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4161 scmd->result = DID_SOFT_ERROR << 16;
4162 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4163 scmd->result = DID_RESET << 16;
4164 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4165 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4166 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4167 scmd->result = (DRIVER_SENSE << 24) |
4168 SAM_STAT_CHECK_CONDITION;
4169 scmd->sense_buffer[0] = 0x70;
4170 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4171 scmd->sense_buffer[12] = 0x20;
4172 scmd->sense_buffer[13] = 0;
4176 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4177 scsi_set_resid(scmd, 0);
4178 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4179 case MPI2_IOCSTATUS_SUCCESS:
4180 scmd->result = (DID_OK << 16) | scsi_status;
4181 if (response_code ==
4182 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4183 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4184 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4185 scmd->result = DID_SOFT_ERROR << 16;
4186 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4187 scmd->result = DID_RESET << 16;
4190 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4191 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4192 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4193 _scsih_eedp_error_handling(scmd, ioc_status);
4196 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4197 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4198 case MPI2_IOCSTATUS_INVALID_SGL:
4199 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4200 case MPI2_IOCSTATUS_INVALID_FIELD:
4201 case MPI2_IOCSTATUS_INVALID_STATE:
4202 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4203 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4205 scmd->result = DID_SOFT_ERROR << 16;
4210 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4211 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4212 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4217 scsi_dma_unmap(scmd);
4219 scmd->scsi_done(scmd);
4224 * _scsih_sas_host_refresh - refreshing sas host object contents
4225 * @ioc: per adapter object
4228 * During port enable, fw will send topology events for every device. Its
4229 * possible that the handles may change from the previous setting, so this
4230 * code keeping handles updating if changed.
4235 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4240 Mpi2ConfigReply_t mpi_reply;
4241 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4242 u16 attached_handle;
4245 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4246 "updating handles for sas_host(0x%016llx)\n",
4247 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4249 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4250 * sizeof(Mpi2SasIOUnit0PhyData_t));
4251 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4252 if (!sas_iounit_pg0) {
4253 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4254 ioc->name, __FILE__, __LINE__, __func__);
4258 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4259 sas_iounit_pg0, sz)) != 0)
4261 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4262 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4264 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4265 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4267 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4268 PhyData[0].ControllerDevHandle);
4269 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4270 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4272 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4273 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4274 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4275 attached_handle, i, link_rate);
4278 kfree(sas_iounit_pg0);
4282 * _scsih_sas_host_add - create sas host object
4283 * @ioc: per adapter object
4285 * Creating host side data object, stored in ioc->sas_hba
4290 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4293 Mpi2ConfigReply_t mpi_reply;
4294 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4295 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4296 Mpi2SasPhyPage0_t phy_pg0;
4297 Mpi2SasDevicePage0_t sas_device_pg0;
4298 Mpi2SasEnclosurePage0_t enclosure_pg0;
4301 u8 device_missing_delay;
4303 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4304 if (!ioc->sas_hba.num_phys) {
4305 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4306 ioc->name, __FILE__, __LINE__, __func__);
4310 /* sas_iounit page 0 */
4311 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4312 sizeof(Mpi2SasIOUnit0PhyData_t));
4313 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4314 if (!sas_iounit_pg0) {
4315 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4316 ioc->name, __FILE__, __LINE__, __func__);
4319 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4320 sas_iounit_pg0, sz))) {
4321 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4322 ioc->name, __FILE__, __LINE__, __func__);
4325 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4326 MPI2_IOCSTATUS_MASK;
4327 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4328 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4329 ioc->name, __FILE__, __LINE__, __func__);
4333 /* sas_iounit page 1 */
4334 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4335 sizeof(Mpi2SasIOUnit1PhyData_t));
4336 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4337 if (!sas_iounit_pg1) {
4338 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4339 ioc->name, __FILE__, __LINE__, __func__);
4342 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4343 sas_iounit_pg1, sz))) {
4344 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4345 ioc->name, __FILE__, __LINE__, __func__);
4348 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4349 MPI2_IOCSTATUS_MASK;
4350 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4351 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4352 ioc->name, __FILE__, __LINE__, __func__);
4356 ioc->io_missing_delay =
4357 sas_iounit_pg1->IODeviceMissingDelay;
4358 device_missing_delay =
4359 sas_iounit_pg1->ReportDeviceMissingDelay;
4360 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4361 ioc->device_missing_delay = (device_missing_delay &
4362 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4364 ioc->device_missing_delay = device_missing_delay &
4365 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4367 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4368 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4369 sizeof(struct _sas_phy), GFP_KERNEL);
4370 if (!ioc->sas_hba.phy) {
4371 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4372 ioc->name, __FILE__, __LINE__, __func__);
4375 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4376 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4378 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4379 ioc->name, __FILE__, __LINE__, __func__);
4382 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4383 MPI2_IOCSTATUS_MASK;
4384 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4385 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4386 ioc->name, __FILE__, __LINE__, __func__);
4391 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4392 PhyData[0].ControllerDevHandle);
4393 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4394 ioc->sas_hba.phy[i].phy_id = i;
4395 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4396 phy_pg0, ioc->sas_hba.parent_dev);
4398 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4400 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4401 ioc->name, __FILE__, __LINE__, __func__);
4404 ioc->sas_hba.enclosure_handle =
4405 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4406 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4408 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4409 ioc->name, ioc->sas_hba.handle,
4410 (unsigned long long) ioc->sas_hba.sas_address,
4411 ioc->sas_hba.num_phys) ;
4413 if (ioc->sas_hba.enclosure_handle) {
4414 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4415 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4416 ioc->sas_hba.enclosure_handle)))
4417 ioc->sas_hba.enclosure_logical_id =
4418 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4422 kfree(sas_iounit_pg1);
4423 kfree(sas_iounit_pg0);
4427 * _scsih_expander_add - creating expander object
4428 * @ioc: per adapter object
4429 * @handle: expander handle
4431 * Creating expander object, stored in ioc->sas_expander_list.
4433 * Return 0 for success, else error.
4436 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4438 struct _sas_node *sas_expander;
4439 Mpi2ConfigReply_t mpi_reply;
4440 Mpi2ExpanderPage0_t expander_pg0;
4441 Mpi2ExpanderPage1_t expander_pg1;
4442 Mpi2SasEnclosurePage0_t enclosure_pg0;
4445 u64 sas_address, sas_address_parent = 0;
4447 unsigned long flags;
4448 struct _sas_port *mpt3sas_port = NULL;
4455 if (ioc->shost_recovery || ioc->pci_error_recovery)
4458 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4459 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4460 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4461 ioc->name, __FILE__, __LINE__, __func__);
4465 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4466 MPI2_IOCSTATUS_MASK;
4467 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4468 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4469 ioc->name, __FILE__, __LINE__, __func__);
4473 /* handle out of order topology events */
4474 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4475 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4477 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4478 ioc->name, __FILE__, __LINE__, __func__);
4481 if (sas_address_parent != ioc->sas_hba.sas_address) {
4482 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4483 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4484 sas_address_parent);
4485 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4486 if (!sas_expander) {
4487 rc = _scsih_expander_add(ioc, parent_handle);
4493 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4494 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4495 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4497 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4502 sas_expander = kzalloc(sizeof(struct _sas_node),
4504 if (!sas_expander) {
4505 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4506 ioc->name, __FILE__, __LINE__, __func__);
4510 sas_expander->handle = handle;
4511 sas_expander->num_phys = expander_pg0.NumPhys;
4512 sas_expander->sas_address_parent = sas_address_parent;
4513 sas_expander->sas_address = sas_address;
4515 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4516 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4517 handle, parent_handle, (unsigned long long)
4518 sas_expander->sas_address, sas_expander->num_phys);
4520 if (!sas_expander->num_phys)
4522 sas_expander->phy = kcalloc(sas_expander->num_phys,
4523 sizeof(struct _sas_phy), GFP_KERNEL);
4524 if (!sas_expander->phy) {
4525 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4526 ioc->name, __FILE__, __LINE__, __func__);
4531 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4532 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4533 sas_address_parent);
4534 if (!mpt3sas_port) {
4535 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4536 ioc->name, __FILE__, __LINE__, __func__);
4540 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4542 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4543 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4544 &expander_pg1, i, handle))) {
4545 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4546 ioc->name, __FILE__, __LINE__, __func__);
4550 sas_expander->phy[i].handle = handle;
4551 sas_expander->phy[i].phy_id = i;
4553 if ((mpt3sas_transport_add_expander_phy(ioc,
4554 &sas_expander->phy[i], expander_pg1,
4555 sas_expander->parent_dev))) {
4556 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4557 ioc->name, __FILE__, __LINE__, __func__);
4563 if (sas_expander->enclosure_handle) {
4564 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4565 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4566 sas_expander->enclosure_handle)))
4567 sas_expander->enclosure_logical_id =
4568 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4571 _scsih_expander_node_add(ioc, sas_expander);
4577 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4578 sas_address_parent);
4579 kfree(sas_expander);
4584 * mpt3sas_expander_remove - removing expander object
4585 * @ioc: per adapter object
4586 * @sas_address: expander sas_address
4591 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4593 struct _sas_node *sas_expander;
4594 unsigned long flags;
4596 if (ioc->shost_recovery)
4599 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4600 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4603 list_del(&sas_expander->list);
4604 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4606 _scsih_expander_node_remove(ioc, sas_expander);
4610 * _scsih_done - internal SCSI_IO callback handler.
4611 * @ioc: per adapter object
4612 * @smid: system request message index
4613 * @msix_index: MSIX table index supplied by the OS
4614 * @reply: reply message frame(lower 32bit addr)
4616 * Callback handler when sending internal generated SCSI_IO.
4617 * The callback index passed is `ioc->scsih_cb_idx`
4619 * Return 1 meaning mf should be freed from _base_interrupt
4620 * 0 means the mf is freed from this function.
4623 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4625 MPI2DefaultReply_t *mpi_reply;
4627 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4628 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4630 if (ioc->scsih_cmds.smid != smid)
4632 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4634 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4635 mpi_reply->MsgLength*4);
4636 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4638 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4639 complete(&ioc->scsih_cmds.done);
4646 #define MPT3_MAX_LUNS (255)
4650 * _scsih_check_access_status - check access flags
4651 * @ioc: per adapter object
4652 * @sas_address: sas address
4653 * @handle: sas device handle
4654 * @access_flags: errors returned during discovery of the device
4656 * Return 0 for success, else failure
4659 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4660 u16 handle, u8 access_status)
4665 switch (access_status) {
4666 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4667 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4670 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4671 desc = "sata capability failed";
4673 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4674 desc = "sata affiliation conflict";
4676 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4677 desc = "route not addressable";
4679 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4680 desc = "smp error not addressable";
4682 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4683 desc = "device blocked";
4685 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4686 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4687 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4688 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4689 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4690 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4691 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4692 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4693 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4694 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4695 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4696 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4697 desc = "sata initialization failed";
4708 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4709 ioc->name, desc, (unsigned long long)sas_address, handle);
4714 * _scsih_check_device - checking device responsiveness
4715 * @ioc: per adapter object
4716 * @parent_sas_address: sas address of parent expander or sas host
4717 * @handle: attached device handle
4718 * @phy_numberv: phy number
4719 * @link_rate: new link rate
4724 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4725 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4727 Mpi2ConfigReply_t mpi_reply;
4728 Mpi2SasDevicePage0_t sas_device_pg0;
4729 struct _sas_device *sas_device;
4731 unsigned long flags;
4733 struct scsi_target *starget;
4734 struct MPT3SAS_TARGET *sas_target_priv_data;
4738 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4739 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4742 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4743 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4746 /* wide port handling ~ we need only handle device once for the phy that
4747 * is matched in sas device page zero
4749 if (phy_number != sas_device_pg0.PhyNum)
4752 /* check if this is end device */
4753 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4754 if (!(_scsih_is_end_device(device_info)))
4757 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4758 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4759 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4763 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4767 if (unlikely(sas_device->handle != handle)) {
4768 starget = sas_device->starget;
4769 sas_target_priv_data = starget->hostdata;
4770 starget_printk(KERN_INFO, starget,
4771 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4772 sas_device->handle, handle);
4773 sas_target_priv_data->handle = handle;
4774 sas_device->handle = handle;
4777 /* check if device is present */
4778 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4779 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4781 "device is not present handle(0x%04x), flags!!!\n",
4783 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4787 /* check if there were any issues with discovery */
4788 if (_scsih_check_access_status(ioc, sas_address, handle,
4789 sas_device_pg0.AccessStatus)) {
4790 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4794 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4795 _scsih_ublock_io_device(ioc, sas_address);
4800 * _scsih_add_device - creating sas device object
4801 * @ioc: per adapter object
4802 * @handle: sas device handle
4803 * @phy_num: phy number end device attached to
4804 * @is_pd: is this hidden raid component
4806 * Creating end device object, stored in ioc->sas_device_list.
4808 * Returns 0 for success, non-zero for failure.
4811 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4814 Mpi2ConfigReply_t mpi_reply;
4815 Mpi2SasDevicePage0_t sas_device_pg0;
4816 Mpi2SasEnclosurePage0_t enclosure_pg0;
4817 struct _sas_device *sas_device;
4821 unsigned long flags;
4823 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4824 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4825 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4826 ioc->name, __FILE__, __LINE__, __func__);
4830 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4831 MPI2_IOCSTATUS_MASK;
4832 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4833 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4834 ioc->name, __FILE__, __LINE__, __func__);
4838 /* check if this is end device */
4839 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4840 if (!(_scsih_is_end_device(device_info)))
4842 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4844 /* check if device is present */
4845 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4846 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4847 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4852 /* check if there were any issues with discovery */
4853 if (_scsih_check_access_status(ioc, sas_address, handle,
4854 sas_device_pg0.AccessStatus))
4857 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4858 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4860 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4865 sas_device = kzalloc(sizeof(struct _sas_device),
4868 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4869 ioc->name, __FILE__, __LINE__, __func__);
4873 sas_device->handle = handle;
4874 if (_scsih_get_sas_address(ioc,
4875 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4876 &sas_device->sas_address_parent) != 0)
4877 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4878 ioc->name, __FILE__, __LINE__, __func__);
4879 sas_device->enclosure_handle =
4880 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4882 le16_to_cpu(sas_device_pg0.Slot);
4883 sas_device->device_info = device_info;
4884 sas_device->sas_address = sas_address;
4885 sas_device->phy = sas_device_pg0.PhyNum;
4886 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
4887 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
4889 /* get enclosure_logical_id */
4890 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
4891 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4892 sas_device->enclosure_handle)))
4893 sas_device->enclosure_logical_id =
4894 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4896 /* get device name */
4897 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
4899 if (ioc->wait_for_discovery_to_complete)
4900 _scsih_sas_device_init_add(ioc, sas_device);
4902 _scsih_sas_device_add(ioc, sas_device);
4908 * _scsih_remove_device - removing sas device object
4909 * @ioc: per adapter object
4910 * @sas_device_delete: the sas_device object
4915 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
4916 struct _sas_device *sas_device)
4918 struct MPT3SAS_TARGET *sas_target_priv_data;
4920 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
4921 (sas_device->pfa_led_on)) {
4922 _scsih_turn_off_pfa_led(ioc, sas_device);
4923 sas_device->pfa_led_on = 0;
4925 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4926 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4927 ioc->name, __func__,
4928 sas_device->handle, (unsigned long long)
4929 sas_device->sas_address));
4931 if (sas_device->starget && sas_device->starget->hostdata) {
4932 sas_target_priv_data = sas_device->starget->hostdata;
4933 sas_target_priv_data->deleted = 1;
4934 _scsih_ublock_io_device(ioc, sas_device->sas_address);
4935 sas_target_priv_data->handle =
4936 MPT3SAS_INVALID_DEVICE_HANDLE;
4938 mpt3sas_transport_port_remove(ioc,
4939 sas_device->sas_address,
4940 sas_device->sas_address_parent);
4943 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4944 ioc->name, sas_device->handle,
4945 (unsigned long long) sas_device->sas_address);
4947 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4948 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4949 ioc->name, __func__,
4950 sas_device->handle, (unsigned long long)
4951 sas_device->sas_address));
4956 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4958 * _scsih_sas_topology_change_event_debug - debug for topology event
4959 * @ioc: per adapter object
4960 * @event_data: event data payload
4964 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
4965 Mpi2EventDataSasTopologyChangeList_t *event_data)
4971 char *status_str = NULL;
4972 u8 link_rate, prev_link_rate;
4974 switch (event_data->ExpStatus) {
4975 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
4978 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
4979 status_str = "remove";
4981 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
4983 status_str = "responding";
4985 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
4986 status_str = "remove delay";
4989 status_str = "unknown status";
4992 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
4993 ioc->name, status_str);
4994 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
4995 "start_phy(%02d), count(%d)\n",
4996 le16_to_cpu(event_data->ExpanderDevHandle),
4997 le16_to_cpu(event_data->EnclosureHandle),
4998 event_data->StartPhyNum, event_data->NumEntries);
4999 for (i = 0; i < event_data->NumEntries; i++) {
5000 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5003 phy_number = event_data->StartPhyNum + i;
5004 reason_code = event_data->PHY[i].PhyStatus &
5005 MPI2_EVENT_SAS_TOPO_RC_MASK;
5006 switch (reason_code) {
5007 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5008 status_str = "target add";
5010 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5011 status_str = "target remove";
5013 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5014 status_str = "delay target remove";
5016 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5017 status_str = "link rate change";
5019 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5020 status_str = "target responding";
5023 status_str = "unknown";
5026 link_rate = event_data->PHY[i].LinkRate >> 4;
5027 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5028 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5029 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5030 handle, status_str, link_rate, prev_link_rate);
5037 * _scsih_sas_topology_change_event - handle topology changes
5038 * @ioc: per adapter object
5039 * @fw_event: The fw_event_work object
5044 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5045 struct fw_event_work *fw_event)
5048 u16 parent_handle, handle;
5050 u8 phy_number, max_phys;
5051 struct _sas_node *sas_expander;
5053 unsigned long flags;
5054 u8 link_rate, prev_link_rate;
5055 Mpi2EventDataSasTopologyChangeList_t *event_data =
5056 (Mpi2EventDataSasTopologyChangeList_t *)
5057 fw_event->event_data;
5059 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5060 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5061 _scsih_sas_topology_change_event_debug(ioc, event_data);
5064 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5067 if (!ioc->sas_hba.num_phys)
5068 _scsih_sas_host_add(ioc);
5070 _scsih_sas_host_refresh(ioc);
5072 if (fw_event->ignore) {
5073 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5074 "ignoring expander event\n", ioc->name));
5078 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5080 /* handle expander add */
5081 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5082 if (_scsih_expander_add(ioc, parent_handle) != 0)
5085 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5086 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5089 sas_address = sas_expander->sas_address;
5090 max_phys = sas_expander->num_phys;
5091 } else if (parent_handle < ioc->sas_hba.num_phys) {
5092 sas_address = ioc->sas_hba.sas_address;
5093 max_phys = ioc->sas_hba.num_phys;
5095 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5098 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5100 /* handle siblings events */
5101 for (i = 0; i < event_data->NumEntries; i++) {
5102 if (fw_event->ignore) {
5103 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5104 "ignoring expander event\n", ioc->name));
5107 if (ioc->remove_host || ioc->pci_error_recovery)
5109 phy_number = event_data->StartPhyNum + i;
5110 if (phy_number >= max_phys)
5112 reason_code = event_data->PHY[i].PhyStatus &
5113 MPI2_EVENT_SAS_TOPO_RC_MASK;
5114 if ((event_data->PHY[i].PhyStatus &
5115 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5116 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5118 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5121 link_rate = event_data->PHY[i].LinkRate >> 4;
5122 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5123 switch (reason_code) {
5124 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5126 if (ioc->shost_recovery)
5129 if (link_rate == prev_link_rate)
5132 mpt3sas_transport_update_links(ioc, sas_address,
5133 handle, phy_number, link_rate);
5135 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5138 _scsih_check_device(ioc, sas_address, handle,
5139 phy_number, link_rate);
5142 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5144 if (ioc->shost_recovery)
5147 mpt3sas_transport_update_links(ioc, sas_address,
5148 handle, phy_number, link_rate);
5150 _scsih_add_device(ioc, handle, phy_number, 0);
5153 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5155 _scsih_device_remove_by_handle(ioc, handle);
5160 /* handle expander removal */
5161 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5163 mpt3sas_expander_remove(ioc, sas_address);
5168 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5170 * _scsih_sas_device_status_change_event_debug - debug for device event
5171 * @event_data: event data payload
5177 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5178 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5180 char *reason_str = NULL;
5182 switch (event_data->ReasonCode) {
5183 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5184 reason_str = "smart data";
5186 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5187 reason_str = "unsupported device discovered";
5189 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5190 reason_str = "internal device reset";
5192 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5193 reason_str = "internal task abort";
5195 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5196 reason_str = "internal task abort set";
5198 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5199 reason_str = "internal clear task set";
5201 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5202 reason_str = "internal query task";
5204 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5205 reason_str = "sata init failure";
5207 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5208 reason_str = "internal device reset complete";
5210 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5211 reason_str = "internal task abort complete";
5213 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5214 reason_str = "internal async notification";
5216 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5217 reason_str = "expander reduced functionality";
5219 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5220 reason_str = "expander reduced functionality complete";
5223 reason_str = "unknown reason";
5226 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5227 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5228 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5229 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5230 le16_to_cpu(event_data->TaskTag));
5231 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5232 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5233 event_data->ASC, event_data->ASCQ);
5239 * _scsih_sas_device_status_change_event - handle device status change
5240 * @ioc: per adapter object
5241 * @fw_event: The fw_event_work object
5247 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5248 struct fw_event_work *fw_event)
5250 struct MPT3SAS_TARGET *target_priv_data;
5251 struct _sas_device *sas_device;
5253 unsigned long flags;
5254 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5255 (Mpi2EventDataSasDeviceStatusChange_t *)
5256 fw_event->event_data;
5258 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5259 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5260 _scsih_sas_device_status_change_event_debug(ioc,
5264 /* In MPI Revision K (0xC), the internal device reset complete was
5265 * implemented, so avoid setting tm_busy flag for older firmware.
5267 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5270 if (event_data->ReasonCode !=
5271 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5272 event_data->ReasonCode !=
5273 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5276 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5277 sas_address = le64_to_cpu(event_data->SASAddress);
5278 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5281 if (!sas_device || !sas_device->starget) {
5282 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5286 target_priv_data = sas_device->starget->hostdata;
5287 if (!target_priv_data) {
5288 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5292 if (event_data->ReasonCode ==
5293 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5294 target_priv_data->tm_busy = 1;
5296 target_priv_data->tm_busy = 0;
5297 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5300 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5302 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5304 * @ioc: per adapter object
5305 * @event_data: event data payload
5311 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5312 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5314 char *reason_str = NULL;
5316 switch (event_data->ReasonCode) {
5317 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5318 reason_str = "enclosure add";
5320 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5321 reason_str = "enclosure remove";
5324 reason_str = "unknown reason";
5328 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5329 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5330 " number slots(%d)\n", ioc->name, reason_str,
5331 le16_to_cpu(event_data->EnclosureHandle),
5332 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5333 le16_to_cpu(event_data->StartSlot));
5338 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5339 * @ioc: per adapter object
5340 * @fw_event: The fw_event_work object
5346 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5347 struct fw_event_work *fw_event)
5349 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5350 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5351 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5352 (Mpi2EventDataSasEnclDevStatusChange_t *)
5353 fw_event->event_data);
5358 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5359 * @ioc: per adapter object
5360 * @fw_event: The fw_event_work object
5366 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5367 struct fw_event_work *fw_event)
5369 struct scsi_cmnd *scmd;
5370 struct scsi_device *sdev;
5373 struct MPT3SAS_DEVICE *sas_device_priv_data;
5374 u32 termination_count;
5376 Mpi2SCSITaskManagementReply_t *mpi_reply;
5377 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5378 (Mpi2EventDataSasBroadcastPrimitive_t *)
5379 fw_event->event_data;
5381 unsigned long flags;
5384 u8 task_abort_retries;
5386 mutex_lock(&ioc->tm_cmds.mutex);
5388 "%s: enter: phy number(%d), width(%d)\n",
5389 ioc->name, __func__, event_data->PhyNum,
5390 event_data->PortWidth);
5392 _scsih_block_io_all_device(ioc);
5394 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5395 mpi_reply = ioc->tm_cmds.reply;
5396 broadcast_aen_retry:
5398 /* sanity checks for retrying this loop */
5399 if (max_retries++ == 5) {
5400 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5401 ioc->name, __func__));
5403 } else if (max_retries > 1)
5404 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5405 ioc->name, __func__, max_retries - 1));
5407 termination_count = 0;
5409 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5410 if (ioc->shost_recovery)
5412 scmd = _scsih_scsi_lookup_get(ioc, smid);
5415 sdev = scmd->device;
5416 sas_device_priv_data = sdev->hostdata;
5417 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5419 /* skip hidden raid components */
5420 if (sas_device_priv_data->sas_target->flags &
5421 MPT_TARGET_FLAGS_RAID_COMPONENT)
5424 if (sas_device_priv_data->sas_target->flags &
5425 MPT_TARGET_FLAGS_VOLUME)
5428 handle = sas_device_priv_data->sas_target->handle;
5429 lun = sas_device_priv_data->lun;
5432 if (ioc->shost_recovery)
5435 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5436 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5437 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5440 sdev_printk(KERN_WARNING, sdev,
5441 "mpt3sas_scsih_issue_tm: FAILED when sending "
5442 "QUERY_TASK: scmd(%p)\n", scmd);
5443 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5444 goto broadcast_aen_retry;
5446 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5447 & MPI2_IOCSTATUS_MASK;
5448 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5449 sdev_printk(KERN_WARNING, sdev,
5450 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5452 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5453 goto broadcast_aen_retry;
5456 /* see if IO is still owned by IOC and target */
5457 if (mpi_reply->ResponseCode ==
5458 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5459 mpi_reply->ResponseCode ==
5460 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5461 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5464 task_abort_retries = 0;
5466 if (task_abort_retries++ == 60) {
5467 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5468 "%s: ABORT_TASK: giving up\n", ioc->name,
5470 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5471 goto broadcast_aen_retry;
5474 if (ioc->shost_recovery)
5477 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5478 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5481 sdev_printk(KERN_WARNING, sdev,
5482 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5483 "scmd(%p)\n", scmd);
5487 if (task_abort_retries > 1)
5488 sdev_printk(KERN_WARNING, sdev,
5489 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5491 task_abort_retries - 1, scmd);
5493 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5494 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5497 if (ioc->broadcast_aen_pending) {
5498 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5499 "%s: loop back due to pending AEN\n",
5500 ioc->name, __func__));
5501 ioc->broadcast_aen_pending = 0;
5502 goto broadcast_aen_retry;
5506 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5509 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5510 "%s - exit, query_count = %d termination_count = %d\n",
5511 ioc->name, __func__, query_count, termination_count));
5513 ioc->broadcast_aen_busy = 0;
5514 if (!ioc->shost_recovery)
5515 _scsih_ublock_io_all_device(ioc);
5516 mutex_unlock(&ioc->tm_cmds.mutex);
5520 * _scsih_sas_discovery_event - handle discovery events
5521 * @ioc: per adapter object
5522 * @fw_event: The fw_event_work object
5528 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5529 struct fw_event_work *fw_event)
5531 Mpi2EventDataSasDiscovery_t *event_data =
5532 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5534 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5535 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5536 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5537 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5539 if (event_data->DiscoveryStatus)
5540 pr_info("discovery_status(0x%08x)",
5541 le32_to_cpu(event_data->DiscoveryStatus));
5546 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5547 !ioc->sas_hba.num_phys) {
5548 if (disable_discovery > 0 && ioc->shost_recovery) {
5549 /* Wait for the reset to complete */
5550 while (ioc->shost_recovery)
5553 _scsih_sas_host_add(ioc);
5558 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5559 * @ioc: per adapter object
5560 * @handle: device handle for physical disk
5561 * @phys_disk_num: physical disk number
5563 * Return 0 for success, else failure.
5566 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5568 Mpi2RaidActionRequest_t *mpi_request;
5569 Mpi2RaidActionReply_t *mpi_reply;
5577 mutex_lock(&ioc->scsih_cmds.mutex);
5579 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5580 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5581 ioc->name, __func__);
5585 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5587 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5589 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5590 ioc->name, __func__);
5591 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5596 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5597 ioc->scsih_cmds.smid = smid;
5598 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5600 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5601 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5602 mpi_request->PhysDiskNum = phys_disk_num;
5604 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5605 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5606 handle, phys_disk_num));
5608 init_completion(&ioc->scsih_cmds.done);
5609 mpt3sas_base_put_smid_default(ioc, smid);
5610 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5612 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5613 pr_err(MPT3SAS_FMT "%s: timeout\n",
5614 ioc->name, __func__);
5615 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5621 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5623 mpi_reply = ioc->scsih_cmds.reply;
5624 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5625 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5626 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5629 ioc_status &= MPI2_IOCSTATUS_MASK;
5630 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5631 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5632 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5633 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5637 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5638 "IR RAID_ACTION: completed successfully\n",
5643 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5644 mutex_unlock(&ioc->scsih_cmds.mutex);
5647 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5653 * _scsih_reprobe_lun - reprobing lun
5654 * @sdev: scsi device struct
5655 * @no_uld_attach: sdev->no_uld_attach flag setting
5659 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5662 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5663 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5664 sdev->no_uld_attach ? "hidding" : "exposing");
5665 rc = scsi_device_reprobe(sdev);
5669 * _scsih_sas_volume_add - add new volume
5670 * @ioc: per adapter object
5671 * @element: IR config element data
5677 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5678 Mpi2EventIrConfigElement_t *element)
5680 struct _raid_device *raid_device;
5681 unsigned long flags;
5683 u16 handle = le16_to_cpu(element->VolDevHandle);
5686 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5689 "failure at %s:%d/%s()!\n", ioc->name,
5690 __FILE__, __LINE__, __func__);
5694 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5695 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5696 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5701 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5704 "failure at %s:%d/%s()!\n", ioc->name,
5705 __FILE__, __LINE__, __func__);
5709 raid_device->id = ioc->sas_id++;
5710 raid_device->channel = RAID_CHANNEL;
5711 raid_device->handle = handle;
5712 raid_device->wwid = wwid;
5713 _scsih_raid_device_add(ioc, raid_device);
5714 if (!ioc->wait_for_discovery_to_complete) {
5715 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5716 raid_device->id, 0);
5718 _scsih_raid_device_remove(ioc, raid_device);
5720 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5721 _scsih_determine_boot_device(ioc, raid_device, 1);
5722 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5727 * _scsih_sas_volume_delete - delete volume
5728 * @ioc: per adapter object
5729 * @handle: volume device handle
5735 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5737 struct _raid_device *raid_device;
5738 unsigned long flags;
5739 struct MPT3SAS_TARGET *sas_target_priv_data;
5740 struct scsi_target *starget = NULL;
5742 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5743 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5745 if (raid_device->starget) {
5746 starget = raid_device->starget;
5747 sas_target_priv_data = starget->hostdata;
5748 sas_target_priv_data->deleted = 1;
5750 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5751 ioc->name, raid_device->handle,
5752 (unsigned long long) raid_device->wwid);
5753 list_del(&raid_device->list);
5756 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5758 scsi_remove_target(&starget->dev);
5762 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5763 * @ioc: per adapter object
5764 * @element: IR config element data
5770 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5771 Mpi2EventIrConfigElement_t *element)
5773 struct _sas_device *sas_device;
5774 struct scsi_target *starget = NULL;
5775 struct MPT3SAS_TARGET *sas_target_priv_data;
5776 unsigned long flags;
5777 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5779 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5780 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5782 sas_device->volume_handle = 0;
5783 sas_device->volume_wwid = 0;
5784 clear_bit(handle, ioc->pd_handles);
5785 if (sas_device->starget && sas_device->starget->hostdata) {
5786 starget = sas_device->starget;
5787 sas_target_priv_data = starget->hostdata;
5788 sas_target_priv_data->flags &=
5789 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5792 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5796 /* exposing raid component */
5798 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5802 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5803 * @ioc: per adapter object
5804 * @element: IR config element data
5810 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5811 Mpi2EventIrConfigElement_t *element)
5813 struct _sas_device *sas_device;
5814 struct scsi_target *starget = NULL;
5815 struct MPT3SAS_TARGET *sas_target_priv_data;
5816 unsigned long flags;
5817 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5818 u16 volume_handle = 0;
5819 u64 volume_wwid = 0;
5821 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
5823 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
5826 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5827 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5829 set_bit(handle, ioc->pd_handles);
5830 if (sas_device->starget && sas_device->starget->hostdata) {
5831 starget = sas_device->starget;
5832 sas_target_priv_data = starget->hostdata;
5833 sas_target_priv_data->flags |=
5834 MPT_TARGET_FLAGS_RAID_COMPONENT;
5835 sas_device->volume_handle = volume_handle;
5836 sas_device->volume_wwid = volume_wwid;
5839 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5843 /* hiding raid component */
5844 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5846 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
5850 * _scsih_sas_pd_delete - delete pd component
5851 * @ioc: per adapter object
5852 * @element: IR config element data
5858 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
5859 Mpi2EventIrConfigElement_t *element)
5861 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5863 _scsih_device_remove_by_handle(ioc, handle);
5867 * _scsih_sas_pd_add - remove pd component
5868 * @ioc: per adapter object
5869 * @element: IR config element data
5875 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
5876 Mpi2EventIrConfigElement_t *element)
5878 struct _sas_device *sas_device;
5879 unsigned long flags;
5880 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5881 Mpi2ConfigReply_t mpi_reply;
5882 Mpi2SasDevicePage0_t sas_device_pg0;
5887 set_bit(handle, ioc->pd_handles);
5889 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5890 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5891 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5893 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5897 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5898 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5899 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5900 ioc->name, __FILE__, __LINE__, __func__);
5904 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5905 MPI2_IOCSTATUS_MASK;
5906 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5907 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5908 ioc->name, __FILE__, __LINE__, __func__);
5912 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5913 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5914 mpt3sas_transport_update_links(ioc, sas_address, handle,
5915 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5917 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5918 _scsih_add_device(ioc, handle, 0, 1);
5921 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5923 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5924 * @ioc: per adapter object
5925 * @event_data: event data payload
5931 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5932 Mpi2EventDataIrConfigChangeList_t *event_data)
5934 Mpi2EventIrConfigElement_t *element;
5937 char *reason_str = NULL, *element_str = NULL;
5939 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5941 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
5942 ioc->name, (le32_to_cpu(event_data->Flags) &
5943 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5944 "foreign" : "native", event_data->NumElements);
5945 for (i = 0; i < event_data->NumElements; i++, element++) {
5946 switch (element->ReasonCode) {
5947 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5950 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5951 reason_str = "remove";
5953 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5954 reason_str = "no change";
5956 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5957 reason_str = "hide";
5959 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5960 reason_str = "unhide";
5962 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5963 reason_str = "volume_created";
5965 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
5966 reason_str = "volume_deleted";
5968 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
5969 reason_str = "pd_created";
5971 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
5972 reason_str = "pd_deleted";
5975 reason_str = "unknown reason";
5978 element_type = le16_to_cpu(element->ElementFlags) &
5979 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
5980 switch (element_type) {
5981 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
5982 element_str = "volume";
5984 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
5985 element_str = "phys disk";
5987 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
5988 element_str = "hot spare";
5991 element_str = "unknown element";
5994 pr_info("\t(%s:%s), vol handle(0x%04x), " \
5995 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
5996 reason_str, le16_to_cpu(element->VolDevHandle),
5997 le16_to_cpu(element->PhysDiskDevHandle),
5998 element->PhysDiskNum);
6004 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6005 * @ioc: per adapter object
6006 * @fw_event: The fw_event_work object
6012 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6013 struct fw_event_work *fw_event)
6015 Mpi2EventIrConfigElement_t *element;
6018 Mpi2EventDataIrConfigChangeList_t *event_data =
6019 (Mpi2EventDataIrConfigChangeList_t *)
6020 fw_event->event_data;
6022 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6023 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6024 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6028 foreign_config = (le32_to_cpu(event_data->Flags) &
6029 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6031 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6032 if (ioc->shost_recovery) {
6034 for (i = 0; i < event_data->NumElements; i++, element++) {
6035 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6036 _scsih_ir_fastpath(ioc,
6037 le16_to_cpu(element->PhysDiskDevHandle),
6038 element->PhysDiskNum);
6042 for (i = 0; i < event_data->NumElements; i++, element++) {
6044 switch (element->ReasonCode) {
6045 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6046 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6047 if (!foreign_config)
6048 _scsih_sas_volume_add(ioc, element);
6050 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6051 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6052 if (!foreign_config)
6053 _scsih_sas_volume_delete(ioc,
6054 le16_to_cpu(element->VolDevHandle));
6056 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6057 _scsih_sas_pd_hide(ioc, element);
6059 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6060 _scsih_sas_pd_expose(ioc, element);
6062 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6063 _scsih_sas_pd_add(ioc, element);
6065 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6066 _scsih_sas_pd_delete(ioc, element);
6073 * _scsih_sas_ir_volume_event - IR volume event
6074 * @ioc: per adapter object
6075 * @fw_event: The fw_event_work object
6081 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6082 struct fw_event_work *fw_event)
6085 unsigned long flags;
6086 struct _raid_device *raid_device;
6090 Mpi2EventDataIrVolume_t *event_data =
6091 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6093 if (ioc->shost_recovery)
6096 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6099 handle = le16_to_cpu(event_data->VolDevHandle);
6100 state = le32_to_cpu(event_data->NewValue);
6101 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6102 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6103 ioc->name, __func__, handle,
6104 le32_to_cpu(event_data->PreviousValue), state));
6106 case MPI2_RAID_VOL_STATE_MISSING:
6107 case MPI2_RAID_VOL_STATE_FAILED:
6108 _scsih_sas_volume_delete(ioc, handle);
6111 case MPI2_RAID_VOL_STATE_ONLINE:
6112 case MPI2_RAID_VOL_STATE_DEGRADED:
6113 case MPI2_RAID_VOL_STATE_OPTIMAL:
6115 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6116 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6117 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6122 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6125 "failure at %s:%d/%s()!\n", ioc->name,
6126 __FILE__, __LINE__, __func__);
6130 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6133 "failure at %s:%d/%s()!\n", ioc->name,
6134 __FILE__, __LINE__, __func__);
6138 raid_device->id = ioc->sas_id++;
6139 raid_device->channel = RAID_CHANNEL;
6140 raid_device->handle = handle;
6141 raid_device->wwid = wwid;
6142 _scsih_raid_device_add(ioc, raid_device);
6143 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6144 raid_device->id, 0);
6146 _scsih_raid_device_remove(ioc, raid_device);
6149 case MPI2_RAID_VOL_STATE_INITIALIZING:
6156 * _scsih_sas_ir_physical_disk_event - PD event
6157 * @ioc: per adapter object
6158 * @fw_event: The fw_event_work object
6164 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6165 struct fw_event_work *fw_event)
6167 u16 handle, parent_handle;
6169 struct _sas_device *sas_device;
6170 unsigned long flags;
6171 Mpi2ConfigReply_t mpi_reply;
6172 Mpi2SasDevicePage0_t sas_device_pg0;
6174 Mpi2EventDataIrPhysicalDisk_t *event_data =
6175 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6178 if (ioc->shost_recovery)
6181 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6184 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6185 state = le32_to_cpu(event_data->NewValue);
6187 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6188 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6189 ioc->name, __func__, handle,
6190 le32_to_cpu(event_data->PreviousValue), state));
6192 case MPI2_RAID_PD_STATE_ONLINE:
6193 case MPI2_RAID_PD_STATE_DEGRADED:
6194 case MPI2_RAID_PD_STATE_REBUILDING:
6195 case MPI2_RAID_PD_STATE_OPTIMAL:
6196 case MPI2_RAID_PD_STATE_HOT_SPARE:
6198 set_bit(handle, ioc->pd_handles);
6199 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6200 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6201 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6206 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6207 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6209 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6210 ioc->name, __FILE__, __LINE__, __func__);
6214 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6215 MPI2_IOCSTATUS_MASK;
6216 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6217 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6218 ioc->name, __FILE__, __LINE__, __func__);
6222 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6223 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6224 mpt3sas_transport_update_links(ioc, sas_address, handle,
6225 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6227 _scsih_add_device(ioc, handle, 0, 1);
6231 case MPI2_RAID_PD_STATE_OFFLINE:
6232 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6233 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6239 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6241 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6242 * @ioc: per adapter object
6243 * @event_data: event data payload
6249 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6250 Mpi2EventDataIrOperationStatus_t *event_data)
6252 char *reason_str = NULL;
6254 switch (event_data->RAIDOperation) {
6255 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6256 reason_str = "resync";
6258 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6259 reason_str = "online capacity expansion";
6261 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6262 reason_str = "consistency check";
6264 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6265 reason_str = "background init";
6267 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6268 reason_str = "make data consistent";
6275 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6276 "\thandle(0x%04x), percent complete(%d)\n",
6277 ioc->name, reason_str,
6278 le16_to_cpu(event_data->VolDevHandle),
6279 event_data->PercentComplete);
6284 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6285 * @ioc: per adapter object
6286 * @fw_event: The fw_event_work object
6292 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6293 struct fw_event_work *fw_event)
6295 Mpi2EventDataIrOperationStatus_t *event_data =
6296 (Mpi2EventDataIrOperationStatus_t *)
6297 fw_event->event_data;
6298 static struct _raid_device *raid_device;
6299 unsigned long flags;
6302 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6303 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6304 _scsih_sas_ir_operation_status_event_debug(ioc,
6308 /* code added for raid transport support */
6309 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6311 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6312 handle = le16_to_cpu(event_data->VolDevHandle);
6313 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6315 raid_device->percent_complete =
6316 event_data->PercentComplete;
6317 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6322 * _scsih_prep_device_scan - initialize parameters prior to device scan
6323 * @ioc: per adapter object
6325 * Set the deleted flag prior to device scan. If the device is found during
6326 * the scan, then we clear the deleted flag.
6329 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6331 struct MPT3SAS_DEVICE *sas_device_priv_data;
6332 struct scsi_device *sdev;
6334 shost_for_each_device(sdev, ioc->shost) {
6335 sas_device_priv_data = sdev->hostdata;
6336 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6337 sas_device_priv_data->sas_target->deleted = 1;
6342 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6343 * @ioc: per adapter object
6344 * @sas_address: sas address
6345 * @slot: enclosure slot id
6346 * @handle: device handle
6348 * After host reset, find out whether devices are still responding.
6349 * Used in _scsih_remove_unresponsive_sas_devices.
6354 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6355 u16 slot, u16 handle)
6357 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6358 struct scsi_target *starget;
6359 struct _sas_device *sas_device;
6360 unsigned long flags;
6362 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6363 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6364 if (sas_device->sas_address == sas_address &&
6365 sas_device->slot == slot) {
6366 sas_device->responding = 1;
6367 starget = sas_device->starget;
6368 if (starget && starget->hostdata) {
6369 sas_target_priv_data = starget->hostdata;
6370 sas_target_priv_data->tm_busy = 0;
6371 sas_target_priv_data->deleted = 0;
6373 sas_target_priv_data = NULL;
6375 starget_printk(KERN_INFO, starget,
6376 "handle(0x%04x), sas_addr(0x%016llx), "
6377 "enclosure logical id(0x%016llx), "
6378 "slot(%d)\n", handle,
6379 (unsigned long long)sas_device->sas_address,
6380 (unsigned long long)
6381 sas_device->enclosure_logical_id,
6383 if (sas_device->handle == handle)
6385 pr_info("\thandle changed from(0x%04x)!!!\n",
6386 sas_device->handle);
6387 sas_device->handle = handle;
6388 if (sas_target_priv_data)
6389 sas_target_priv_data->handle = handle;
6394 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6398 * _scsih_search_responding_sas_devices -
6399 * @ioc: per adapter object
6401 * After host reset, find out whether devices are still responding.
6407 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6409 Mpi2SasDevicePage0_t sas_device_pg0;
6410 Mpi2ConfigReply_t mpi_reply;
6415 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6417 if (list_empty(&ioc->sas_device_list))
6421 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6422 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6424 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6425 MPI2_IOCSTATUS_MASK;
6426 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6428 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6429 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6430 if (!(_scsih_is_end_device(device_info)))
6432 _scsih_mark_responding_sas_device(ioc,
6433 le64_to_cpu(sas_device_pg0.SASAddress),
6434 le16_to_cpu(sas_device_pg0.Slot), handle);
6438 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6443 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6444 * @ioc: per adapter object
6445 * @wwid: world wide identifier for raid volume
6446 * @handle: device handle
6448 * After host reset, find out whether devices are still responding.
6449 * Used in _scsih_remove_unresponsive_raid_devices.
6454 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6457 struct MPT3SAS_TARGET *sas_target_priv_data;
6458 struct scsi_target *starget;
6459 struct _raid_device *raid_device;
6460 unsigned long flags;
6462 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6463 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6464 if (raid_device->wwid == wwid && raid_device->starget) {
6465 starget = raid_device->starget;
6466 if (starget && starget->hostdata) {
6467 sas_target_priv_data = starget->hostdata;
6468 sas_target_priv_data->deleted = 0;
6470 sas_target_priv_data = NULL;
6471 raid_device->responding = 1;
6472 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6473 starget_printk(KERN_INFO, raid_device->starget,
6474 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6475 (unsigned long long)raid_device->wwid);
6476 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6477 if (raid_device->handle == handle) {
6478 spin_unlock_irqrestore(&ioc->raid_device_lock,
6482 pr_info("\thandle changed from(0x%04x)!!!\n",
6483 raid_device->handle);
6484 raid_device->handle = handle;
6485 if (sas_target_priv_data)
6486 sas_target_priv_data->handle = handle;
6487 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6491 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6495 * _scsih_search_responding_raid_devices -
6496 * @ioc: per adapter object
6498 * After host reset, find out whether devices are still responding.
6504 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6506 Mpi2RaidVolPage1_t volume_pg1;
6507 Mpi2RaidVolPage0_t volume_pg0;
6508 Mpi2RaidPhysDiskPage0_t pd_pg0;
6509 Mpi2ConfigReply_t mpi_reply;
6514 if (!ioc->ir_firmware)
6517 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6520 if (list_empty(&ioc->raid_device_list))
6524 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6525 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6526 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6527 MPI2_IOCSTATUS_MASK;
6528 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6530 handle = le16_to_cpu(volume_pg1.DevHandle);
6532 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6533 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6534 sizeof(Mpi2RaidVolPage0_t)))
6537 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6538 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6539 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6540 _scsih_mark_responding_raid_device(ioc,
6541 le64_to_cpu(volume_pg1.WWID), handle);
6544 /* refresh the pd_handles */
6545 phys_disk_num = 0xFF;
6546 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6547 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6548 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6550 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6551 MPI2_IOCSTATUS_MASK;
6552 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6554 phys_disk_num = pd_pg0.PhysDiskNum;
6555 handle = le16_to_cpu(pd_pg0.DevHandle);
6556 set_bit(handle, ioc->pd_handles);
6559 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6564 * _scsih_mark_responding_expander - mark a expander as responding
6565 * @ioc: per adapter object
6566 * @sas_address: sas address
6569 * After host reset, find out whether devices are still responding.
6570 * Used in _scsih_remove_unresponsive_expanders.
6575 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6578 struct _sas_node *sas_expander;
6579 unsigned long flags;
6582 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6583 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6584 if (sas_expander->sas_address != sas_address)
6586 sas_expander->responding = 1;
6587 if (sas_expander->handle == handle)
6589 pr_info("\texpander(0x%016llx): handle changed" \
6590 " from(0x%04x) to (0x%04x)!!!\n",
6591 (unsigned long long)sas_expander->sas_address,
6592 sas_expander->handle, handle);
6593 sas_expander->handle = handle;
6594 for (i = 0 ; i < sas_expander->num_phys ; i++)
6595 sas_expander->phy[i].handle = handle;
6599 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6603 * _scsih_search_responding_expanders -
6604 * @ioc: per adapter object
6606 * After host reset, find out whether devices are still responding.
6612 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6614 Mpi2ExpanderPage0_t expander_pg0;
6615 Mpi2ConfigReply_t mpi_reply;
6620 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6622 if (list_empty(&ioc->sas_expander_list))
6626 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6627 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6629 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6630 MPI2_IOCSTATUS_MASK;
6631 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6634 handle = le16_to_cpu(expander_pg0.DevHandle);
6635 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6636 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6638 (unsigned long long)sas_address);
6639 _scsih_mark_responding_expander(ioc, sas_address, handle);
6643 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6647 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6648 * @ioc: per adapter object
6653 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6655 struct _sas_device *sas_device, *sas_device_next;
6656 struct _sas_node *sas_expander, *sas_expander_next;
6657 struct _raid_device *raid_device, *raid_device_next;
6658 struct list_head tmp_list;
6659 unsigned long flags;
6661 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6664 /* removing unresponding end devices */
6665 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6667 list_for_each_entry_safe(sas_device, sas_device_next,
6668 &ioc->sas_device_list, list) {
6669 if (!sas_device->responding)
6670 mpt3sas_device_remove_by_sas_address(ioc,
6671 sas_device->sas_address);
6673 sas_device->responding = 0;
6676 /* removing unresponding volumes */
6677 if (ioc->ir_firmware) {
6678 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6680 list_for_each_entry_safe(raid_device, raid_device_next,
6681 &ioc->raid_device_list, list) {
6682 if (!raid_device->responding)
6683 _scsih_sas_volume_delete(ioc,
6684 raid_device->handle);
6686 raid_device->responding = 0;
6690 /* removing unresponding expanders */
6691 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6693 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6694 INIT_LIST_HEAD(&tmp_list);
6695 list_for_each_entry_safe(sas_expander, sas_expander_next,
6696 &ioc->sas_expander_list, list) {
6697 if (!sas_expander->responding)
6698 list_move_tail(&sas_expander->list, &tmp_list);
6700 sas_expander->responding = 0;
6702 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6703 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6705 list_del(&sas_expander->list);
6706 _scsih_expander_node_remove(ioc, sas_expander);
6709 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6712 /* unblock devices */
6713 _scsih_ublock_io_all_device(ioc);
6717 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6718 struct _sas_node *sas_expander, u16 handle)
6720 Mpi2ExpanderPage1_t expander_pg1;
6721 Mpi2ConfigReply_t mpi_reply;
6724 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6725 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6726 &expander_pg1, i, handle))) {
6727 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6728 ioc->name, __FILE__, __LINE__, __func__);
6732 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6733 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6734 expander_pg1.NegotiatedLinkRate >> 4);
6739 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6740 * @ioc: per adapter object
6745 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6747 Mpi2ExpanderPage0_t expander_pg0;
6748 Mpi2SasDevicePage0_t sas_device_pg0;
6749 Mpi2RaidVolPage1_t volume_pg1;
6750 Mpi2RaidVolPage0_t volume_pg0;
6751 Mpi2RaidPhysDiskPage0_t pd_pg0;
6752 Mpi2EventIrConfigElement_t element;
6753 Mpi2ConfigReply_t mpi_reply;
6756 u16 handle, parent_handle;
6758 struct _sas_device *sas_device;
6759 struct _sas_node *expander_device;
6760 static struct _raid_device *raid_device;
6762 unsigned long flags;
6764 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6766 _scsih_sas_host_refresh(ioc);
6768 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6772 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6773 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6774 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6775 MPI2_IOCSTATUS_MASK;
6776 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6777 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6778 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6779 ioc->name, ioc_status,
6780 le32_to_cpu(mpi_reply.IOCLogInfo));
6783 handle = le16_to_cpu(expander_pg0.DevHandle);
6784 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6785 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6786 ioc, le64_to_cpu(expander_pg0.SASAddress));
6787 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6788 if (expander_device)
6789 _scsih_refresh_expander_links(ioc, expander_device,
6792 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6793 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6794 handle, (unsigned long long)
6795 le64_to_cpu(expander_pg0.SASAddress));
6796 _scsih_expander_add(ioc, handle);
6797 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6798 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6799 handle, (unsigned long long)
6800 le64_to_cpu(expander_pg0.SASAddress));
6804 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6807 if (!ioc->ir_firmware)
6810 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6813 phys_disk_num = 0xFF;
6814 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6815 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
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 phys_disk_num = pd_pg0.PhysDiskNum;
6827 handle = le16_to_cpu(pd_pg0.DevHandle);
6828 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6829 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6830 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6833 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6834 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6837 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6838 MPI2_IOCSTATUS_MASK;
6839 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6840 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
6841 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6842 ioc->name, ioc_status,
6843 le32_to_cpu(mpi_reply.IOCLogInfo));
6846 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6847 if (!_scsih_get_sas_address(ioc, parent_handle,
6849 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
6850 " handle (0x%04x), sas_addr(0x%016llx)\n",
6851 ioc->name, handle, (unsigned long long)
6852 le64_to_cpu(sas_device_pg0.SASAddress));
6853 mpt3sas_transport_update_links(ioc, sas_address,
6854 handle, sas_device_pg0.PhyNum,
6855 MPI2_SAS_NEG_LINK_RATE_1_5);
6856 set_bit(handle, ioc->pd_handles);
6858 /* This will retry adding the end device.
6859 * _scsih_add_device() will decide on retries and
6860 * return "1" when it should be retried
6862 while (_scsih_add_device(ioc, handle, retry_count++,
6866 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
6867 " handle (0x%04x), sas_addr(0x%016llx)\n",
6868 ioc->name, handle, (unsigned long long)
6869 le64_to_cpu(sas_device_pg0.SASAddress));
6873 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
6876 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
6880 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6881 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
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 handle = le16_to_cpu(volume_pg1.DevHandle);
6892 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6893 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6894 le64_to_cpu(volume_pg1.WWID));
6895 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6898 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6899 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6900 sizeof(Mpi2RaidVolPage0_t)))
6902 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6903 MPI2_IOCSTATUS_MASK;
6904 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6905 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6906 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6907 ioc->name, ioc_status,
6908 le32_to_cpu(mpi_reply.IOCLogInfo));
6911 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6912 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6913 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6914 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6915 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6916 element.VolDevHandle = volume_pg1.DevHandle;
6918 "\tBEFORE adding volume: handle (0x%04x)\n",
6919 ioc->name, volume_pg1.DevHandle);
6920 _scsih_sas_volume_add(ioc, &element);
6922 "\tAFTER adding volume: handle (0x%04x)\n",
6923 ioc->name, volume_pg1.DevHandle);
6927 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
6932 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
6937 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6938 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6940 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6941 MPI2_IOCSTATUS_MASK;
6942 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6943 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
6944 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6945 ioc->name, ioc_status,
6946 le32_to_cpu(mpi_reply.IOCLogInfo));
6949 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6950 if (!(_scsih_is_end_device(
6951 le32_to_cpu(sas_device_pg0.DeviceInfo))))
6953 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6954 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
6955 le64_to_cpu(sas_device_pg0.SASAddress));
6956 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6959 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6960 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
6961 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
6962 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6963 handle, (unsigned long long)
6964 le64_to_cpu(sas_device_pg0.SASAddress));
6965 mpt3sas_transport_update_links(ioc, sas_address, handle,
6966 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6968 /* This will retry adding the end device.
6969 * _scsih_add_device() will decide on retries and
6970 * return "1" when it should be retried
6972 while (_scsih_add_device(ioc, handle, retry_count++,
6976 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
6977 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6978 handle, (unsigned long long)
6979 le64_to_cpu(sas_device_pg0.SASAddress));
6982 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
6985 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
6988 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
6989 * @ioc: per adapter object
6990 * @reset_phase: phase
6992 * The handler for doing any required cleanup or initialization.
6994 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
6995 * MPT3_IOC_DONE_RESET
7000 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7002 switch (reset_phase) {
7003 case MPT3_IOC_PRE_RESET:
7004 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7005 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7007 case MPT3_IOC_AFTER_RESET:
7008 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7009 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7010 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7011 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7012 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7013 complete(&ioc->scsih_cmds.done);
7015 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7016 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7017 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7018 complete(&ioc->tm_cmds.done);
7021 _scsih_fw_event_cleanup_queue(ioc);
7022 _scsih_flush_running_cmds(ioc);
7024 case MPT3_IOC_DONE_RESET:
7025 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7026 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7027 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7028 !ioc->sas_hba.num_phys)) {
7029 _scsih_prep_device_scan(ioc);
7030 _scsih_search_responding_sas_devices(ioc);
7031 _scsih_search_responding_raid_devices(ioc);
7032 _scsih_search_responding_expanders(ioc);
7033 _scsih_error_recovery_delete_devices(ioc);
7040 * _mpt3sas_fw_work - delayed task for processing firmware events
7041 * @ioc: per adapter object
7042 * @fw_event: The fw_event_work object
7048 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7050 /* the queue is being flushed so ignore this event */
7051 if (ioc->remove_host ||
7052 ioc->pci_error_recovery) {
7053 _scsih_fw_event_free(ioc, fw_event);
7057 switch (fw_event->event) {
7058 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7059 mpt3sas_process_trigger_data(ioc,
7060 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7061 fw_event->event_data);
7063 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7064 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7066 _scsih_remove_unresponding_sas_devices(ioc);
7067 _scsih_scan_for_devices_after_reset(ioc);
7069 case MPT3SAS_PORT_ENABLE_COMPLETE:
7070 ioc->start_scan = 0;
7071 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7072 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7074 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7075 "port enable: complete from worker thread\n",
7078 case MPT3SAS_TURN_ON_PFA_LED:
7079 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7081 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7082 _scsih_sas_topology_change_event(ioc, fw_event);
7084 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7085 _scsih_sas_device_status_change_event(ioc, fw_event);
7087 case MPI2_EVENT_SAS_DISCOVERY:
7088 _scsih_sas_discovery_event(ioc, fw_event);
7090 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7091 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7093 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7094 _scsih_sas_enclosure_dev_status_change_event(ioc,
7097 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7098 _scsih_sas_ir_config_change_event(ioc, fw_event);
7100 case MPI2_EVENT_IR_VOLUME:
7101 _scsih_sas_ir_volume_event(ioc, fw_event);
7103 case MPI2_EVENT_IR_PHYSICAL_DISK:
7104 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7106 case MPI2_EVENT_IR_OPERATION_STATUS:
7107 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7110 _scsih_fw_event_free(ioc, fw_event);
7114 * _firmware_event_work
7115 * @ioc: per adapter object
7116 * @work: The fw_event_work object
7119 * wrappers for the work thread handling firmware events
7125 _firmware_event_work(struct work_struct *work)
7127 struct fw_event_work *fw_event = container_of(work,
7128 struct fw_event_work, work);
7130 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7134 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7135 * @ioc: per adapter object
7136 * @msix_index: MSIX table index supplied by the OS
7137 * @reply: reply message frame(lower 32bit addr)
7138 * Context: interrupt.
7140 * This function merely adds a new work task into ioc->firmware_event_thread.
7141 * The tasks are worked from _firmware_event_work in user context.
7143 * Return 1 meaning mf should be freed from _base_interrupt
7144 * 0 means the mf is freed from this function.
7147 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7150 struct fw_event_work *fw_event;
7151 Mpi2EventNotificationReply_t *mpi_reply;
7155 /* events turned off due to host reset or driver unloading */
7156 if (ioc->remove_host || ioc->pci_error_recovery)
7159 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7161 if (unlikely(!mpi_reply)) {
7162 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7163 ioc->name, __FILE__, __LINE__, __func__);
7167 event = le16_to_cpu(mpi_reply->Event);
7169 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7170 mpt3sas_trigger_event(ioc, event, 0);
7174 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7176 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7177 (Mpi2EventDataSasBroadcastPrimitive_t *)
7178 mpi_reply->EventData;
7180 if (baen_data->Primitive !=
7181 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7184 if (ioc->broadcast_aen_busy) {
7185 ioc->broadcast_aen_pending++;
7188 ioc->broadcast_aen_busy = 1;
7192 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7193 _scsih_check_topo_delete_events(ioc,
7194 (Mpi2EventDataSasTopologyChangeList_t *)
7195 mpi_reply->EventData);
7197 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7198 _scsih_check_ir_config_unhide_events(ioc,
7199 (Mpi2EventDataIrConfigChangeList_t *)
7200 mpi_reply->EventData);
7202 case MPI2_EVENT_IR_VOLUME:
7203 _scsih_check_volume_delete_events(ioc,
7204 (Mpi2EventDataIrVolume_t *)
7205 mpi_reply->EventData);
7208 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7209 case MPI2_EVENT_IR_OPERATION_STATUS:
7210 case MPI2_EVENT_SAS_DISCOVERY:
7211 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7212 case MPI2_EVENT_IR_PHYSICAL_DISK:
7215 default: /* ignore the rest */
7219 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7220 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7222 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7223 ioc->name, __FILE__, __LINE__, __func__);
7227 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7228 fw_event->ioc = ioc;
7229 fw_event->VF_ID = mpi_reply->VF_ID;
7230 fw_event->VP_ID = mpi_reply->VP_ID;
7231 fw_event->event = event;
7232 _scsih_fw_event_add(ioc, fw_event);
7236 /* shost template */
7237 static struct scsi_host_template scsih_driver_template = {
7238 .module = THIS_MODULE,
7239 .name = "Fusion MPT SAS Host",
7240 .proc_name = MPT3SAS_DRIVER_NAME,
7241 .queuecommand = _scsih_qcmd,
7242 .target_alloc = _scsih_target_alloc,
7243 .slave_alloc = _scsih_slave_alloc,
7244 .slave_configure = _scsih_slave_configure,
7245 .target_destroy = _scsih_target_destroy,
7246 .slave_destroy = _scsih_slave_destroy,
7247 .scan_finished = _scsih_scan_finished,
7248 .scan_start = _scsih_scan_start,
7249 .change_queue_depth = _scsih_change_queue_depth,
7250 .change_queue_type = scsi_change_queue_type,
7251 .eh_abort_handler = _scsih_abort,
7252 .eh_device_reset_handler = _scsih_dev_reset,
7253 .eh_target_reset_handler = _scsih_target_reset,
7254 .eh_host_reset_handler = _scsih_host_reset,
7255 .bios_param = _scsih_bios_param,
7258 .sg_tablesize = MPT3SAS_SG_DEPTH,
7259 .max_sectors = 32767,
7261 .use_clustering = ENABLE_CLUSTERING,
7262 .shost_attrs = mpt3sas_host_attrs,
7263 .sdev_attrs = mpt3sas_dev_attrs,
7264 .track_queue_depth = 1,
7268 * _scsih_expander_node_remove - removing expander device from list.
7269 * @ioc: per adapter object
7270 * @sas_expander: the sas_device object
7271 * Context: Calling function should acquire ioc->sas_node_lock.
7273 * Removing object and freeing associated memory from the
7274 * ioc->sas_expander_list.
7279 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7280 struct _sas_node *sas_expander)
7282 struct _sas_port *mpt3sas_port, *next;
7284 /* remove sibling ports attached to this expander */
7285 list_for_each_entry_safe(mpt3sas_port, next,
7286 &sas_expander->sas_port_list, port_list) {
7287 if (ioc->shost_recovery)
7289 if (mpt3sas_port->remote_identify.device_type ==
7291 mpt3sas_device_remove_by_sas_address(ioc,
7292 mpt3sas_port->remote_identify.sas_address);
7293 else if (mpt3sas_port->remote_identify.device_type ==
7294 SAS_EDGE_EXPANDER_DEVICE ||
7295 mpt3sas_port->remote_identify.device_type ==
7296 SAS_FANOUT_EXPANDER_DEVICE)
7297 mpt3sas_expander_remove(ioc,
7298 mpt3sas_port->remote_identify.sas_address);
7301 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7302 sas_expander->sas_address_parent);
7305 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7307 sas_expander->handle, (unsigned long long)
7308 sas_expander->sas_address);
7310 kfree(sas_expander->phy);
7311 kfree(sas_expander);
7315 * _scsih_ir_shutdown - IR shutdown notification
7316 * @ioc: per adapter object
7318 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7319 * the host system is shutting down.
7324 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7326 Mpi2RaidActionRequest_t *mpi_request;
7327 Mpi2RaidActionReply_t *mpi_reply;
7330 /* is IR firmware build loaded ? */
7331 if (!ioc->ir_firmware)
7334 /* are there any volumes ? */
7335 if (list_empty(&ioc->raid_device_list))
7338 mutex_lock(&ioc->scsih_cmds.mutex);
7340 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7341 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7342 ioc->name, __func__);
7345 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7347 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7349 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7350 ioc->name, __func__);
7351 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7355 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7356 ioc->scsih_cmds.smid = smid;
7357 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7359 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7360 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7362 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7363 init_completion(&ioc->scsih_cmds.done);
7364 mpt3sas_base_put_smid_default(ioc, smid);
7365 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7367 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7368 pr_err(MPT3SAS_FMT "%s: timeout\n",
7369 ioc->name, __func__);
7373 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7374 mpi_reply = ioc->scsih_cmds.reply;
7376 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7377 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7378 le32_to_cpu(mpi_reply->IOCLogInfo));
7382 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7383 mutex_unlock(&ioc->scsih_cmds.mutex);
7387 * _scsih_remove - detach and remove add host
7388 * @pdev: PCI device struct
7390 * Routine called when unloading the driver.
7393 static void _scsih_remove(struct pci_dev *pdev)
7395 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7396 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7397 struct _sas_port *mpt3sas_port, *next_port;
7398 struct _raid_device *raid_device, *next;
7399 struct MPT3SAS_TARGET *sas_target_priv_data;
7400 struct workqueue_struct *wq;
7401 unsigned long flags;
7403 ioc->remove_host = 1;
7404 _scsih_fw_event_cleanup_queue(ioc);
7406 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7407 wq = ioc->firmware_event_thread;
7408 ioc->firmware_event_thread = NULL;
7409 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7411 destroy_workqueue(wq);
7413 /* release all the volumes */
7414 _scsih_ir_shutdown(ioc);
7415 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7417 if (raid_device->starget) {
7418 sas_target_priv_data =
7419 raid_device->starget->hostdata;
7420 sas_target_priv_data->deleted = 1;
7421 scsi_remove_target(&raid_device->starget->dev);
7423 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7424 ioc->name, raid_device->handle,
7425 (unsigned long long) raid_device->wwid);
7426 _scsih_raid_device_remove(ioc, raid_device);
7429 /* free ports attached to the sas_host */
7430 list_for_each_entry_safe(mpt3sas_port, next_port,
7431 &ioc->sas_hba.sas_port_list, port_list) {
7432 if (mpt3sas_port->remote_identify.device_type ==
7434 mpt3sas_device_remove_by_sas_address(ioc,
7435 mpt3sas_port->remote_identify.sas_address);
7436 else if (mpt3sas_port->remote_identify.device_type ==
7437 SAS_EDGE_EXPANDER_DEVICE ||
7438 mpt3sas_port->remote_identify.device_type ==
7439 SAS_FANOUT_EXPANDER_DEVICE)
7440 mpt3sas_expander_remove(ioc,
7441 mpt3sas_port->remote_identify.sas_address);
7444 /* free phys attached to the sas_host */
7445 if (ioc->sas_hba.num_phys) {
7446 kfree(ioc->sas_hba.phy);
7447 ioc->sas_hba.phy = NULL;
7448 ioc->sas_hba.num_phys = 0;
7451 sas_remove_host(shost);
7452 scsi_remove_host(shost);
7453 mpt3sas_base_detach(ioc);
7454 list_del(&ioc->list);
7455 scsi_host_put(shost);
7459 * _scsih_shutdown - routine call during system shutdown
7460 * @pdev: PCI device struct
7465 _scsih_shutdown(struct pci_dev *pdev)
7467 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7468 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7469 struct workqueue_struct *wq;
7470 unsigned long flags;
7472 ioc->remove_host = 1;
7473 _scsih_fw_event_cleanup_queue(ioc);
7475 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7476 wq = ioc->firmware_event_thread;
7477 ioc->firmware_event_thread = NULL;
7478 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7480 destroy_workqueue(wq);
7482 _scsih_ir_shutdown(ioc);
7483 mpt3sas_base_detach(ioc);
7488 * _scsih_probe_boot_devices - reports 1st device
7489 * @ioc: per adapter object
7491 * If specified in bios page 2, this routine reports the 1st
7492 * device scsi-ml or sas transport for persistent boot device
7493 * purposes. Please refer to function _scsih_determine_boot_device()
7496 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7500 struct _sas_device *sas_device;
7501 struct _raid_device *raid_device;
7503 u64 sas_address_parent;
7505 unsigned long flags;
7508 /* no Bios, return immediately */
7509 if (!ioc->bios_pg3.BiosVersion)
7514 if (ioc->req_boot_device.device) {
7515 device = ioc->req_boot_device.device;
7516 is_raid = ioc->req_boot_device.is_raid;
7517 } else if (ioc->req_alt_boot_device.device) {
7518 device = ioc->req_alt_boot_device.device;
7519 is_raid = ioc->req_alt_boot_device.is_raid;
7520 } else if (ioc->current_boot_device.device) {
7521 device = ioc->current_boot_device.device;
7522 is_raid = ioc->current_boot_device.is_raid;
7529 raid_device = device;
7530 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7531 raid_device->id, 0);
7533 _scsih_raid_device_remove(ioc, raid_device);
7535 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7536 sas_device = device;
7537 handle = sas_device->handle;
7538 sas_address_parent = sas_device->sas_address_parent;
7539 sas_address = sas_device->sas_address;
7540 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7541 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7543 if (!mpt3sas_transport_port_add(ioc, handle,
7544 sas_address_parent)) {
7545 _scsih_sas_device_remove(ioc, sas_device);
7546 } else if (!sas_device->starget) {
7547 if (!ioc->is_driver_loading) {
7548 mpt3sas_transport_port_remove(ioc,
7550 sas_address_parent);
7551 _scsih_sas_device_remove(ioc, sas_device);
7558 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7559 * @ioc: per adapter object
7561 * Called during initial loading of the driver.
7564 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7566 struct _raid_device *raid_device, *raid_next;
7569 list_for_each_entry_safe(raid_device, raid_next,
7570 &ioc->raid_device_list, list) {
7571 if (raid_device->starget)
7573 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7574 raid_device->id, 0);
7576 _scsih_raid_device_remove(ioc, raid_device);
7581 * _scsih_probe_sas - reporting sas devices to sas transport
7582 * @ioc: per adapter object
7584 * Called during initial loading of the driver.
7587 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7589 struct _sas_device *sas_device, *next;
7590 unsigned long flags;
7592 /* SAS Device List */
7593 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7596 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7597 sas_device->sas_address_parent)) {
7598 list_del(&sas_device->list);
7601 } else if (!sas_device->starget) {
7603 * When asyn scanning is enabled, its not possible to
7604 * remove devices while scanning is turned on due to an
7605 * oops in scsi_sysfs_add_sdev()->add_device()->
7606 * sysfs_addrm_start()
7608 if (!ioc->is_driver_loading) {
7609 mpt3sas_transport_port_remove(ioc,
7610 sas_device->sas_address,
7611 sas_device->sas_address_parent);
7612 list_del(&sas_device->list);
7618 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7619 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7620 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7625 * _scsih_probe_devices - probing for devices
7626 * @ioc: per adapter object
7628 * Called during initial loading of the driver.
7631 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7633 u16 volume_mapping_flags;
7635 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7636 return; /* return when IOC doesn't support initiator mode */
7638 _scsih_probe_boot_devices(ioc);
7640 if (ioc->ir_firmware) {
7641 volume_mapping_flags =
7642 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7643 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7644 if (volume_mapping_flags ==
7645 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7646 _scsih_probe_raid(ioc);
7647 _scsih_probe_sas(ioc);
7649 _scsih_probe_sas(ioc);
7650 _scsih_probe_raid(ioc);
7653 _scsih_probe_sas(ioc);
7657 * _scsih_scan_start - scsi lld callback for .scan_start
7658 * @shost: SCSI host pointer
7660 * The shost has the ability to discover targets on its own instead
7661 * of scanning the entire bus. In our implemention, we will kick off
7662 * firmware discovery.
7665 _scsih_scan_start(struct Scsi_Host *shost)
7667 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7669 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7670 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7672 if (disable_discovery > 0)
7675 ioc->start_scan = 1;
7676 rc = mpt3sas_port_enable(ioc);
7679 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7683 * _scsih_scan_finished - scsi lld callback for .scan_finished
7684 * @shost: SCSI host pointer
7685 * @time: elapsed time of the scan in jiffies
7687 * This function will be called periodicallyn until it returns 1 with the
7688 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7689 * we wait for firmware discovery to complete, then return 1.
7692 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7694 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7696 if (disable_discovery > 0) {
7697 ioc->is_driver_loading = 0;
7698 ioc->wait_for_discovery_to_complete = 0;
7702 if (time >= (300 * HZ)) {
7703 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7705 "port enable: FAILED with timeout (timeout=300s)\n",
7707 ioc->is_driver_loading = 0;
7711 if (ioc->start_scan)
7714 if (ioc->start_scan_failed) {
7716 "port enable: FAILED with (ioc_status=0x%08x)\n",
7717 ioc->name, ioc->start_scan_failed);
7718 ioc->is_driver_loading = 0;
7719 ioc->wait_for_discovery_to_complete = 0;
7720 ioc->remove_host = 1;
7724 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7725 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7727 if (ioc->wait_for_discovery_to_complete) {
7728 ioc->wait_for_discovery_to_complete = 0;
7729 _scsih_probe_devices(ioc);
7731 mpt3sas_base_start_watchdog(ioc);
7732 ioc->is_driver_loading = 0;
7737 * _scsih_probe - attach and add scsi host
7738 * @pdev: PCI device struct
7739 * @id: pci device id
7741 * Returns 0 success, anything else error.
7744 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7746 struct MPT3SAS_ADAPTER *ioc;
7747 struct Scsi_Host *shost;
7750 shost = scsi_host_alloc(&scsih_driver_template,
7751 sizeof(struct MPT3SAS_ADAPTER));
7755 /* init local params */
7756 ioc = shost_priv(shost);
7757 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7758 INIT_LIST_HEAD(&ioc->list);
7759 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7761 ioc->id = mpt_ids++;
7762 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
7764 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7765 ioc->tm_cb_idx = tm_cb_idx;
7766 ioc->ctl_cb_idx = ctl_cb_idx;
7767 ioc->base_cb_idx = base_cb_idx;
7768 ioc->port_enable_cb_idx = port_enable_cb_idx;
7769 ioc->transport_cb_idx = transport_cb_idx;
7770 ioc->scsih_cb_idx = scsih_cb_idx;
7771 ioc->config_cb_idx = config_cb_idx;
7772 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7773 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7774 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7775 ioc->logging_level = logging_level;
7776 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7777 /* misc semaphores and spin locks */
7778 mutex_init(&ioc->reset_in_progress_mutex);
7779 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7780 spin_lock_init(&ioc->scsi_lookup_lock);
7781 spin_lock_init(&ioc->sas_device_lock);
7782 spin_lock_init(&ioc->sas_node_lock);
7783 spin_lock_init(&ioc->fw_event_lock);
7784 spin_lock_init(&ioc->raid_device_lock);
7785 spin_lock_init(&ioc->diag_trigger_lock);
7787 INIT_LIST_HEAD(&ioc->sas_device_list);
7788 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7789 INIT_LIST_HEAD(&ioc->sas_expander_list);
7790 INIT_LIST_HEAD(&ioc->fw_event_list);
7791 INIT_LIST_HEAD(&ioc->raid_device_list);
7792 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7793 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7794 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7795 INIT_LIST_HEAD(&ioc->reply_queue_list);
7797 /* init shost parameters */
7798 shost->max_cmd_len = 32;
7799 shost->max_lun = max_lun;
7800 shost->transportt = mpt3sas_transport_template;
7801 shost->unique_id = ioc->id;
7803 if (max_sectors != 0xFFFF) {
7804 if (max_sectors < 64) {
7805 shost->max_sectors = 64;
7806 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7807 "for max_sectors, range is 64 to 32767. Assigning "
7808 "value of 64.\n", ioc->name, max_sectors);
7809 } else if (max_sectors > 32767) {
7810 shost->max_sectors = 32767;
7811 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7812 "for max_sectors, range is 64 to 32767. Assigning "
7813 "default value of 32767.\n", ioc->name,
7816 shost->max_sectors = max_sectors & 0xFFFE;
7818 "The max_sectors value is set to %d\n",
7819 ioc->name, shost->max_sectors);
7823 /* register EEDP capabilities with SCSI layer */
7825 scsi_host_set_prot(shost, prot_mask);
7827 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7828 | SHOST_DIF_TYPE2_PROTECTION
7829 | SHOST_DIF_TYPE3_PROTECTION);
7831 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7834 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7835 "fw_event%d", ioc->id);
7836 ioc->firmware_event_thread = create_singlethread_workqueue(
7837 ioc->firmware_event_name);
7838 if (!ioc->firmware_event_thread) {
7839 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7840 ioc->name, __FILE__, __LINE__, __func__);
7842 goto out_thread_fail;
7845 ioc->is_driver_loading = 1;
7846 if ((mpt3sas_base_attach(ioc))) {
7847 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7848 ioc->name, __FILE__, __LINE__, __func__);
7850 goto out_attach_fail;
7852 rv = scsi_add_host(shost, &pdev->dev);
7854 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7855 ioc->name, __FILE__, __LINE__, __func__);
7856 goto out_add_shost_fail;
7859 scsi_scan_host(shost);
7862 mpt3sas_base_detach(ioc);
7864 destroy_workqueue(ioc->firmware_event_thread);
7866 list_del(&ioc->list);
7867 scsi_host_put(shost);
7873 * _scsih_suspend - power management suspend main entry point
7874 * @pdev: PCI device struct
7875 * @state: PM state change to (usually PCI_D3)
7877 * Returns 0 success, anything else error.
7880 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7882 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7883 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7884 pci_power_t device_state;
7886 mpt3sas_base_stop_watchdog(ioc);
7887 flush_scheduled_work();
7888 scsi_block_requests(shost);
7889 device_state = pci_choose_state(pdev, state);
7891 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7892 ioc->name, pdev, pci_name(pdev), device_state);
7894 pci_save_state(pdev);
7895 mpt3sas_base_free_resources(ioc);
7896 pci_set_power_state(pdev, device_state);
7901 * _scsih_resume - power management resume main entry point
7902 * @pdev: PCI device struct
7904 * Returns 0 success, anything else error.
7907 _scsih_resume(struct pci_dev *pdev)
7909 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7910 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7911 pci_power_t device_state = pdev->current_state;
7915 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7916 ioc->name, pdev, pci_name(pdev), device_state);
7918 pci_set_power_state(pdev, PCI_D0);
7919 pci_enable_wake(pdev, PCI_D0, 0);
7920 pci_restore_state(pdev);
7922 r = mpt3sas_base_map_resources(ioc);
7926 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7927 scsi_unblock_requests(shost);
7928 mpt3sas_base_start_watchdog(ioc);
7931 #endif /* CONFIG_PM */
7934 * _scsih_pci_error_detected - Called when a PCI error is detected.
7935 * @pdev: PCI device struct
7936 * @state: PCI channel state
7938 * Description: Called when a PCI error is detected.
7941 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7943 static pci_ers_result_t
7944 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7946 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7947 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7949 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
7953 case pci_channel_io_normal:
7954 return PCI_ERS_RESULT_CAN_RECOVER;
7955 case pci_channel_io_frozen:
7956 /* Fatal error, prepare for slot reset */
7957 ioc->pci_error_recovery = 1;
7958 scsi_block_requests(ioc->shost);
7959 mpt3sas_base_stop_watchdog(ioc);
7960 mpt3sas_base_free_resources(ioc);
7961 return PCI_ERS_RESULT_NEED_RESET;
7962 case pci_channel_io_perm_failure:
7963 /* Permanent error, prepare for device removal */
7964 ioc->pci_error_recovery = 1;
7965 mpt3sas_base_stop_watchdog(ioc);
7966 _scsih_flush_running_cmds(ioc);
7967 return PCI_ERS_RESULT_DISCONNECT;
7969 return PCI_ERS_RESULT_NEED_RESET;
7973 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7974 * @pdev: PCI device struct
7976 * Description: This routine is called by the pci error recovery
7977 * code after the PCI slot has been reset, just before we
7978 * should resume normal operations.
7980 static pci_ers_result_t
7981 _scsih_pci_slot_reset(struct pci_dev *pdev)
7983 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7984 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7987 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
7990 ioc->pci_error_recovery = 0;
7992 pci_restore_state(pdev);
7993 rc = mpt3sas_base_map_resources(ioc);
7995 return PCI_ERS_RESULT_DISCONNECT;
7997 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8000 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8001 (rc == 0) ? "success" : "failed");
8004 return PCI_ERS_RESULT_RECOVERED;
8006 return PCI_ERS_RESULT_DISCONNECT;
8010 * _scsih_pci_resume() - resume normal ops after PCI reset
8011 * @pdev: pointer to PCI device
8013 * Called when the error recovery driver tells us that its
8014 * OK to resume normal operation. Use completion to allow
8015 * halted scsi ops to resume.
8018 _scsih_pci_resume(struct pci_dev *pdev)
8020 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8021 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8023 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8025 pci_cleanup_aer_uncorrect_error_status(pdev);
8026 mpt3sas_base_start_watchdog(ioc);
8027 scsi_unblock_requests(ioc->shost);
8031 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8032 * @pdev: pointer to PCI device
8034 static pci_ers_result_t
8035 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8037 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8038 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8040 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8043 /* TODO - dump whatever for debugging purposes */
8045 /* Request a slot reset. */
8046 return PCI_ERS_RESULT_NEED_RESET;
8049 /* raid transport support */
8050 static struct raid_function_template mpt3sas_raid_functions = {
8051 .cookie = &scsih_driver_template,
8052 .is_raid = _scsih_is_raid,
8053 .get_resync = _scsih_get_resync,
8054 .get_state = _scsih_get_state,
8057 static struct pci_error_handlers _scsih_err_handler = {
8058 .error_detected = _scsih_pci_error_detected,
8059 .mmio_enabled = _scsih_pci_mmio_enabled,
8060 .slot_reset = _scsih_pci_slot_reset,
8061 .resume = _scsih_pci_resume,
8064 static struct pci_driver scsih_driver = {
8065 .name = MPT3SAS_DRIVER_NAME,
8066 .id_table = scsih_pci_table,
8067 .probe = _scsih_probe,
8068 .remove = _scsih_remove,
8069 .shutdown = _scsih_shutdown,
8070 .err_handler = &_scsih_err_handler,
8072 .suspend = _scsih_suspend,
8073 .resume = _scsih_resume,
8079 * _scsih_init - main entry point for this driver.
8081 * Returns 0 success, anything else error.
8090 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8091 MPT3SAS_DRIVER_VERSION);
8093 mpt3sas_transport_template =
8094 sas_attach_transport(&mpt3sas_transport_functions);
8095 if (!mpt3sas_transport_template)
8098 /* raid transport support */
8099 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8100 if (!mpt3sas_raid_template) {
8101 sas_release_transport(mpt3sas_transport_template);
8105 mpt3sas_base_initialize_callback_handler();
8107 /* queuecommand callback hander */
8108 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8110 /* task managment callback handler */
8111 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8113 /* base internal commands callback handler */
8114 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8115 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8116 mpt3sas_port_enable_done);
8118 /* transport internal commands callback handler */
8119 transport_cb_idx = mpt3sas_base_register_callback_handler(
8120 mpt3sas_transport_done);
8122 /* scsih internal commands callback handler */
8123 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8125 /* configuration page API internal commands callback handler */
8126 config_cb_idx = mpt3sas_base_register_callback_handler(
8127 mpt3sas_config_done);
8129 /* ctl module callback handler */
8130 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8132 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8133 _scsih_tm_tr_complete);
8135 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8136 _scsih_tm_volume_tr_complete);
8138 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8139 _scsih_sas_control_complete);
8143 error = pci_register_driver(&scsih_driver);
8145 /* raid transport support */
8146 raid_class_release(mpt3sas_raid_template);
8147 sas_release_transport(mpt3sas_transport_template);
8154 * _scsih_exit - exit point for this driver (when it is a module).
8156 * Returns 0 success, anything else error.
8161 pr_info("mpt3sas version %s unloading\n",
8162 MPT3SAS_DRIVER_VERSION);
8166 pci_unregister_driver(&scsih_driver);
8169 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8170 mpt3sas_base_release_callback_handler(tm_cb_idx);
8171 mpt3sas_base_release_callback_handler(base_cb_idx);
8172 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8173 mpt3sas_base_release_callback_handler(transport_cb_idx);
8174 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8175 mpt3sas_base_release_callback_handler(config_cb_idx);
8176 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8178 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8179 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8180 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8182 /* raid transport support */
8183 raid_class_release(mpt3sas_raid_template);
8184 sas_release_transport(mpt3sas_transport_template);
8187 module_init(_scsih_init);
8188 module_exit(_scsih_exit);