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_change_queue_depth(sdev, qdepth);
1097 * _scsih_change_queue_depth - setting device queue depth
1098 * @sdev: scsi device struct
1099 * @qdepth: requested queue depth
1101 * Returns queue depth.
1104 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1106 _scsih_adjust_queue_depth(sdev, qdepth);
1108 if (sdev->inquiry_len > 7)
1109 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \
1110 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
1111 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1113 (sdev->inquiry[7] & 2) >> 1);
1115 return sdev->queue_depth;
1119 * _scsih_target_alloc - target add routine
1120 * @starget: scsi target struct
1122 * Returns 0 if ok. Any other return is assumed to be an error and
1123 * the device is ignored.
1126 _scsih_target_alloc(struct scsi_target *starget)
1128 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1129 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1130 struct MPT3SAS_TARGET *sas_target_priv_data;
1131 struct _sas_device *sas_device;
1132 struct _raid_device *raid_device;
1133 unsigned long flags;
1134 struct sas_rphy *rphy;
1136 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1138 if (!sas_target_priv_data)
1141 starget->hostdata = sas_target_priv_data;
1142 sas_target_priv_data->starget = starget;
1143 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1146 if (starget->channel == RAID_CHANNEL) {
1147 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1148 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1151 sas_target_priv_data->handle = raid_device->handle;
1152 sas_target_priv_data->sas_address = raid_device->wwid;
1153 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1154 raid_device->starget = starget;
1156 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1160 /* sas/sata devices */
1161 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1162 rphy = dev_to_rphy(starget->dev.parent);
1163 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1164 rphy->identify.sas_address);
1167 sas_target_priv_data->handle = sas_device->handle;
1168 sas_target_priv_data->sas_address = sas_device->sas_address;
1169 sas_device->starget = starget;
1170 sas_device->id = starget->id;
1171 sas_device->channel = starget->channel;
1172 if (test_bit(sas_device->handle, ioc->pd_handles))
1173 sas_target_priv_data->flags |=
1174 MPT_TARGET_FLAGS_RAID_COMPONENT;
1175 if (sas_device->fast_path)
1176 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1178 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1184 * _scsih_target_destroy - target destroy routine
1185 * @starget: scsi target struct
1190 _scsih_target_destroy(struct scsi_target *starget)
1192 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1193 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1194 struct MPT3SAS_TARGET *sas_target_priv_data;
1195 struct _sas_device *sas_device;
1196 struct _raid_device *raid_device;
1197 unsigned long flags;
1198 struct sas_rphy *rphy;
1200 sas_target_priv_data = starget->hostdata;
1201 if (!sas_target_priv_data)
1204 if (starget->channel == RAID_CHANNEL) {
1205 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1206 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1209 raid_device->starget = NULL;
1210 raid_device->sdev = NULL;
1212 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1216 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1217 rphy = dev_to_rphy(starget->dev.parent);
1218 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1219 rphy->identify.sas_address);
1220 if (sas_device && (sas_device->starget == starget) &&
1221 (sas_device->id == starget->id) &&
1222 (sas_device->channel == starget->channel))
1223 sas_device->starget = NULL;
1225 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1228 kfree(sas_target_priv_data);
1229 starget->hostdata = NULL;
1233 * _scsih_slave_alloc - device add routine
1234 * @sdev: scsi device struct
1236 * Returns 0 if ok. Any other return is assumed to be an error and
1237 * the device is ignored.
1240 _scsih_slave_alloc(struct scsi_device *sdev)
1242 struct Scsi_Host *shost;
1243 struct MPT3SAS_ADAPTER *ioc;
1244 struct MPT3SAS_TARGET *sas_target_priv_data;
1245 struct MPT3SAS_DEVICE *sas_device_priv_data;
1246 struct scsi_target *starget;
1247 struct _raid_device *raid_device;
1248 struct _sas_device *sas_device;
1249 unsigned long flags;
1251 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1253 if (!sas_device_priv_data)
1256 sas_device_priv_data->lun = sdev->lun;
1257 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1259 starget = scsi_target(sdev);
1260 sas_target_priv_data = starget->hostdata;
1261 sas_target_priv_data->num_luns++;
1262 sas_device_priv_data->sas_target = sas_target_priv_data;
1263 sdev->hostdata = sas_device_priv_data;
1264 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1265 sdev->no_uld_attach = 1;
1267 shost = dev_to_shost(&starget->dev);
1268 ioc = shost_priv(shost);
1269 if (starget->channel == RAID_CHANNEL) {
1270 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1271 raid_device = _scsih_raid_device_find_by_id(ioc,
1272 starget->id, starget->channel);
1274 raid_device->sdev = sdev; /* raid is single lun */
1275 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1278 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1279 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1280 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1281 sas_target_priv_data->sas_address);
1282 if (sas_device && (sas_device->starget == NULL)) {
1283 sdev_printk(KERN_INFO, sdev,
1284 "%s : sas_device->starget set to starget @ %d\n",
1285 __func__, __LINE__);
1286 sas_device->starget = starget;
1288 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1295 * _scsih_slave_destroy - device destroy routine
1296 * @sdev: scsi device struct
1301 _scsih_slave_destroy(struct scsi_device *sdev)
1303 struct MPT3SAS_TARGET *sas_target_priv_data;
1304 struct scsi_target *starget;
1305 struct Scsi_Host *shost;
1306 struct MPT3SAS_ADAPTER *ioc;
1307 struct _sas_device *sas_device;
1308 unsigned long flags;
1310 if (!sdev->hostdata)
1313 starget = scsi_target(sdev);
1314 sas_target_priv_data = starget->hostdata;
1315 sas_target_priv_data->num_luns--;
1317 shost = dev_to_shost(&starget->dev);
1318 ioc = shost_priv(shost);
1320 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1321 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1322 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1323 sas_target_priv_data->sas_address);
1324 if (sas_device && !sas_target_priv_data->num_luns)
1325 sas_device->starget = NULL;
1326 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1329 kfree(sdev->hostdata);
1330 sdev->hostdata = NULL;
1334 * _scsih_display_sata_capabilities - sata capabilities
1335 * @ioc: per adapter object
1336 * @handle: device handle
1337 * @sdev: scsi device struct
1340 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1341 u16 handle, struct scsi_device *sdev)
1343 Mpi2ConfigReply_t mpi_reply;
1344 Mpi2SasDevicePage0_t sas_device_pg0;
1349 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1350 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1351 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1352 ioc->name, __FILE__, __LINE__, __func__);
1356 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1357 MPI2_IOCSTATUS_MASK;
1358 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1359 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1360 ioc->name, __FILE__, __LINE__, __func__);
1364 flags = le16_to_cpu(sas_device_pg0.Flags);
1365 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1367 sdev_printk(KERN_INFO, sdev,
1368 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1369 "sw_preserve(%s)\n",
1370 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1371 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1372 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1374 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1375 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1376 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1380 * raid transport support -
1381 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1382 * unloading the driver followed by a load - I beleive that the subroutine
1383 * raid_class_release() is not cleaning up properly.
1387 * _scsih_is_raid - return boolean indicating device is raid volume
1388 * @dev the device struct object
1391 _scsih_is_raid(struct device *dev)
1393 struct scsi_device *sdev = to_scsi_device(dev);
1395 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1399 * _scsih_get_resync - get raid volume resync percent complete
1400 * @dev the device struct object
1403 _scsih_get_resync(struct device *dev)
1405 struct scsi_device *sdev = to_scsi_device(dev);
1406 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1407 static struct _raid_device *raid_device;
1408 unsigned long flags;
1409 Mpi2RaidVolPage0_t vol_pg0;
1410 Mpi2ConfigReply_t mpi_reply;
1411 u32 volume_status_flags;
1412 u8 percent_complete;
1415 percent_complete = 0;
1417 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1418 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1421 handle = raid_device->handle;
1422 percent_complete = raid_device->percent_complete;
1424 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1429 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1430 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1431 sizeof(Mpi2RaidVolPage0_t))) {
1432 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1433 ioc->name, __FILE__, __LINE__, __func__);
1434 percent_complete = 0;
1438 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1439 if (!(volume_status_flags &
1440 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1441 percent_complete = 0;
1444 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1448 * _scsih_get_state - get raid volume level
1449 * @dev the device struct object
1452 _scsih_get_state(struct device *dev)
1454 struct scsi_device *sdev = to_scsi_device(dev);
1455 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1456 static struct _raid_device *raid_device;
1457 unsigned long flags;
1458 Mpi2RaidVolPage0_t vol_pg0;
1459 Mpi2ConfigReply_t mpi_reply;
1461 enum raid_state state = RAID_STATE_UNKNOWN;
1464 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1465 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1468 handle = raid_device->handle;
1469 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1474 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1475 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1476 sizeof(Mpi2RaidVolPage0_t))) {
1477 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1478 ioc->name, __FILE__, __LINE__, __func__);
1482 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1483 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1484 state = RAID_STATE_RESYNCING;
1488 switch (vol_pg0.VolumeState) {
1489 case MPI2_RAID_VOL_STATE_OPTIMAL:
1490 case MPI2_RAID_VOL_STATE_ONLINE:
1491 state = RAID_STATE_ACTIVE;
1493 case MPI2_RAID_VOL_STATE_DEGRADED:
1494 state = RAID_STATE_DEGRADED;
1496 case MPI2_RAID_VOL_STATE_FAILED:
1497 case MPI2_RAID_VOL_STATE_MISSING:
1498 state = RAID_STATE_OFFLINE;
1502 raid_set_state(mpt3sas_raid_template, dev, state);
1506 * _scsih_set_level - set raid level
1507 * @sdev: scsi device struct
1508 * @volume_type: volume type
1511 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1513 enum raid_level level = RAID_LEVEL_UNKNOWN;
1515 switch (volume_type) {
1516 case MPI2_RAID_VOL_TYPE_RAID0:
1517 level = RAID_LEVEL_0;
1519 case MPI2_RAID_VOL_TYPE_RAID10:
1520 level = RAID_LEVEL_10;
1522 case MPI2_RAID_VOL_TYPE_RAID1E:
1523 level = RAID_LEVEL_1E;
1525 case MPI2_RAID_VOL_TYPE_RAID1:
1526 level = RAID_LEVEL_1;
1530 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1535 * _scsih_get_volume_capabilities - volume capabilities
1536 * @ioc: per adapter object
1537 * @sas_device: the raid_device object
1539 * Returns 0 for success, else 1
1542 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1543 struct _raid_device *raid_device)
1545 Mpi2RaidVolPage0_t *vol_pg0;
1546 Mpi2RaidPhysDiskPage0_t pd_pg0;
1547 Mpi2SasDevicePage0_t sas_device_pg0;
1548 Mpi2ConfigReply_t mpi_reply;
1552 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1553 &num_pds)) || !num_pds) {
1554 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1555 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1560 raid_device->num_pds = num_pds;
1561 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1562 sizeof(Mpi2RaidVol0PhysDisk_t));
1563 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1565 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1566 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1571 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1572 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1573 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1574 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1580 raid_device->volume_type = vol_pg0->VolumeType;
1582 /* figure out what the underlying devices are by
1583 * obtaining the device_info bits for the 1st device
1585 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1586 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1587 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1588 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1589 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1590 le16_to_cpu(pd_pg0.DevHandle)))) {
1591 raid_device->device_info =
1592 le32_to_cpu(sas_device_pg0.DeviceInfo);
1603 * _scsih_enable_tlr - setting TLR flags
1604 * @ioc: per adapter object
1605 * @sdev: scsi device struct
1607 * Enabling Transaction Layer Retries for tape devices when
1608 * vpd page 0x90 is present
1612 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1616 if (sdev->type != TYPE_TAPE)
1619 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1622 sas_enable_tlr(sdev);
1623 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1624 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1630 * _scsih_slave_configure - device configure routine.
1631 * @sdev: scsi device struct
1633 * Returns 0 if ok. Any other return is assumed to be an error and
1634 * the device is ignored.
1637 _scsih_slave_configure(struct scsi_device *sdev)
1639 struct Scsi_Host *shost = sdev->host;
1640 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1641 struct MPT3SAS_DEVICE *sas_device_priv_data;
1642 struct MPT3SAS_TARGET *sas_target_priv_data;
1643 struct _sas_device *sas_device;
1644 struct _raid_device *raid_device;
1645 unsigned long flags;
1650 u16 handle, volume_handle = 0;
1651 u64 volume_wwid = 0;
1654 sas_device_priv_data = sdev->hostdata;
1655 sas_device_priv_data->configured_lun = 1;
1656 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1657 sas_target_priv_data = sas_device_priv_data->sas_target;
1658 handle = sas_target_priv_data->handle;
1660 /* raid volume handling */
1661 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1663 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1664 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1665 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1667 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1668 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1669 __LINE__, __func__));
1673 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1674 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1675 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1676 __LINE__, __func__));
1681 /* RAID Queue Depth Support
1682 * IS volume = underlying qdepth of drive type, either
1683 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1684 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1686 if (raid_device->device_info &
1687 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1688 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1691 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1692 if (raid_device->device_info &
1693 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1699 switch (raid_device->volume_type) {
1700 case MPI2_RAID_VOL_TYPE_RAID0:
1703 case MPI2_RAID_VOL_TYPE_RAID1E:
1704 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1705 if (ioc->manu_pg10.OEMIdentifier &&
1706 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1707 MFG10_GF0_R10_DISPLAY) &&
1708 !(raid_device->num_pds % 2))
1713 case MPI2_RAID_VOL_TYPE_RAID1:
1714 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1717 case MPI2_RAID_VOL_TYPE_RAID10:
1718 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1721 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1723 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1728 sdev_printk(KERN_INFO, sdev,
1729 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1730 r_level, raid_device->handle,
1731 (unsigned long long)raid_device->wwid,
1732 raid_device->num_pds, ds);
1735 _scsih_change_queue_depth(sdev, qdepth);
1737 /* raid transport support */
1738 _scsih_set_level(sdev, raid_device->volume_type);
1742 /* non-raid handling */
1743 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1744 if (mpt3sas_config_get_volume_handle(ioc, handle,
1746 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1747 "failure at %s:%d/%s()!\n", ioc->name,
1748 __FILE__, __LINE__, __func__));
1751 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1752 volume_handle, &volume_wwid)) {
1753 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1754 "failure at %s:%d/%s()!\n", ioc->name,
1755 __FILE__, __LINE__, __func__));
1760 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1761 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1762 sas_device_priv_data->sas_target->sas_address);
1764 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1765 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1766 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1771 sas_device->volume_handle = volume_handle;
1772 sas_device->volume_wwid = volume_wwid;
1773 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1774 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1778 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1779 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1781 else if (sas_device->device_info &
1782 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1786 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1787 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1788 ds, handle, (unsigned long long)sas_device->sas_address,
1789 sas_device->phy, (unsigned long long)sas_device->device_name);
1790 sdev_printk(KERN_INFO, sdev,
1791 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1792 ds, (unsigned long long)
1793 sas_device->enclosure_logical_id, sas_device->slot);
1795 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1798 _scsih_display_sata_capabilities(ioc, handle, sdev);
1801 _scsih_change_queue_depth(sdev, qdepth);
1804 sas_read_port_mode_page(sdev);
1805 _scsih_enable_tlr(ioc, sdev);
1812 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1813 * @sdev: scsi device struct
1814 * @bdev: pointer to block device context
1815 * @capacity: device size (in 512 byte sectors)
1816 * @params: three element array to place output:
1817 * params[0] number of heads (max 255)
1818 * params[1] number of sectors (max 63)
1819 * params[2] number of cylinders
1824 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1825 sector_t capacity, int params[])
1835 dummy = heads * sectors;
1836 cylinders = capacity;
1837 sector_div(cylinders, dummy);
1840 * Handle extended translation size for logical drives
1843 if ((ulong)capacity >= 0x200000) {
1846 dummy = heads * sectors;
1847 cylinders = capacity;
1848 sector_div(cylinders, dummy);
1853 params[1] = sectors;
1854 params[2] = cylinders;
1860 * _scsih_response_code - translation of device response code
1861 * @ioc: per adapter object
1862 * @response_code: response code returned by the device
1867 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1871 switch (response_code) {
1872 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1873 desc = "task management request completed";
1875 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1876 desc = "invalid frame";
1878 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1879 desc = "task management request not supported";
1881 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1882 desc = "task management request failed";
1884 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1885 desc = "task management request succeeded";
1887 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1888 desc = "invalid lun";
1891 desc = "overlapped tag attempted";
1893 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1894 desc = "task queued, however not sent to target";
1900 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1901 ioc->name, response_code, desc);
1905 * _scsih_tm_done - tm completion routine
1906 * @ioc: per adapter object
1907 * @smid: system request message index
1908 * @msix_index: MSIX table index supplied by the OS
1909 * @reply: reply message frame(lower 32bit addr)
1912 * The callback handler when using scsih_issue_tm.
1914 * Return 1 meaning mf should be freed from _base_interrupt
1915 * 0 means the mf is freed from this function.
1918 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1920 MPI2DefaultReply_t *mpi_reply;
1922 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1924 if (ioc->tm_cmds.smid != smid)
1926 mpt3sas_base_flush_reply_queues(ioc);
1927 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1928 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1930 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1931 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1933 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1934 complete(&ioc->tm_cmds.done);
1939 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1940 * @ioc: per adapter object
1941 * @handle: device handle
1943 * During taskmangement request, we need to freeze the device queue.
1946 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1948 struct MPT3SAS_DEVICE *sas_device_priv_data;
1949 struct scsi_device *sdev;
1952 shost_for_each_device(sdev, ioc->shost) {
1955 sas_device_priv_data = sdev->hostdata;
1956 if (!sas_device_priv_data)
1958 if (sas_device_priv_data->sas_target->handle == handle) {
1959 sas_device_priv_data->sas_target->tm_busy = 1;
1961 ioc->ignore_loginfos = 1;
1967 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1968 * @ioc: per adapter object
1969 * @handle: device handle
1971 * During taskmangement request, we need to freeze the device queue.
1974 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1976 struct MPT3SAS_DEVICE *sas_device_priv_data;
1977 struct scsi_device *sdev;
1980 shost_for_each_device(sdev, ioc->shost) {
1983 sas_device_priv_data = sdev->hostdata;
1984 if (!sas_device_priv_data)
1986 if (sas_device_priv_data->sas_target->handle == handle) {
1987 sas_device_priv_data->sas_target->tm_busy = 0;
1989 ioc->ignore_loginfos = 0;
1995 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
1996 * @ioc: per adapter struct
1997 * @device_handle: device handle
1998 * @channel: the channel assigned by the OS
1999 * @id: the id assigned by the OS
2001 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2002 * @smid_task: smid assigned to the task
2003 * @timeout: timeout in seconds
2004 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2007 * A generic API for sending task management requests to firmware.
2009 * The callback index is set inside `ioc->tm_cb_idx`.
2011 * Return SUCCESS or FAILED.
2014 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2015 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2016 enum mutex_type m_type)
2018 Mpi2SCSITaskManagementRequest_t *mpi_request;
2019 Mpi2SCSITaskManagementReply_t *mpi_reply;
2022 unsigned long timeleft;
2023 struct scsiio_tracker *scsi_lookup = NULL;
2026 if (m_type == TM_MUTEX_ON)
2027 mutex_lock(&ioc->tm_cmds.mutex);
2028 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2029 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2030 __func__, ioc->name);
2035 if (ioc->shost_recovery || ioc->remove_host ||
2036 ioc->pci_error_recovery) {
2037 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2038 __func__, ioc->name);
2043 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2044 if (ioc_state & MPI2_DOORBELL_USED) {
2045 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2046 "unexpected doorbell active!\n", ioc->name));
2047 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2049 rc = (!rc) ? SUCCESS : FAILED;
2053 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2054 mpt3sas_base_fault_info(ioc, ioc_state &
2055 MPI2_DOORBELL_DATA_MASK);
2056 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2058 rc = (!rc) ? SUCCESS : FAILED;
2062 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2064 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2065 ioc->name, __func__);
2070 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2071 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2073 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2074 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2075 ioc->name, handle, type, smid_task));
2076 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2077 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2078 ioc->tm_cmds.smid = smid;
2079 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2080 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2081 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2082 mpi_request->DevHandle = cpu_to_le16(handle);
2083 mpi_request->TaskType = type;
2084 mpi_request->TaskMID = cpu_to_le16(smid_task);
2085 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2086 mpt3sas_scsih_set_tm_flag(ioc, handle);
2087 init_completion(&ioc->tm_cmds.done);
2088 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2089 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2090 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2091 pr_err(MPT3SAS_FMT "%s: timeout\n",
2092 ioc->name, __func__);
2093 _debug_dump_mf(mpi_request,
2094 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2095 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2096 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2098 rc = (!rc) ? SUCCESS : FAILED;
2099 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2100 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2105 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2106 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2107 mpi_reply = ioc->tm_cmds.reply;
2108 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2109 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2110 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2111 le32_to_cpu(mpi_reply->IOCLogInfo),
2112 le32_to_cpu(mpi_reply->TerminationCount)));
2113 if (ioc->logging_level & MPT_DEBUG_TM) {
2114 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2115 if (mpi_reply->IOCStatus)
2116 _debug_dump_mf(mpi_request,
2117 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2122 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2124 if (scsi_lookup->scmd == NULL)
2129 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2130 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2135 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2136 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2137 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2142 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2150 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2151 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2152 if (m_type == TM_MUTEX_ON)
2153 mutex_unlock(&ioc->tm_cmds.mutex);
2158 if (m_type == TM_MUTEX_ON)
2159 mutex_unlock(&ioc->tm_cmds.mutex);
2164 * _scsih_tm_display_info - displays info about the device
2165 * @ioc: per adapter struct
2166 * @scmd: pointer to scsi command object
2168 * Called by task management callback handlers.
2171 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2173 struct scsi_target *starget = scmd->device->sdev_target;
2174 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2175 struct _sas_device *sas_device = NULL;
2176 unsigned long flags;
2177 char *device_str = NULL;
2181 device_str = "volume";
2183 scsi_print_command(scmd);
2184 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2185 starget_printk(KERN_INFO, starget,
2186 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2187 device_str, priv_target->handle,
2188 device_str, (unsigned long long)priv_target->sas_address);
2190 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2191 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2192 priv_target->sas_address);
2194 if (priv_target->flags &
2195 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2196 starget_printk(KERN_INFO, starget,
2197 "volume handle(0x%04x), "
2198 "volume wwid(0x%016llx)\n",
2199 sas_device->volume_handle,
2200 (unsigned long long)sas_device->volume_wwid);
2202 starget_printk(KERN_INFO, starget,
2203 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2205 (unsigned long long)sas_device->sas_address,
2207 starget_printk(KERN_INFO, starget,
2208 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2209 (unsigned long long)sas_device->enclosure_logical_id,
2212 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2217 * _scsih_abort - eh threads main abort routine
2218 * @scmd: pointer to scsi command object
2220 * Returns SUCCESS if command aborted else FAILED
2223 _scsih_abort(struct scsi_cmnd *scmd)
2225 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2226 struct MPT3SAS_DEVICE *sas_device_priv_data;
2231 sdev_printk(KERN_INFO, scmd->device,
2232 "attempting task abort! scmd(%p)\n", scmd);
2233 _scsih_tm_display_info(ioc, scmd);
2235 sas_device_priv_data = scmd->device->hostdata;
2236 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2237 sdev_printk(KERN_INFO, scmd->device,
2238 "device been deleted! scmd(%p)\n", scmd);
2239 scmd->result = DID_NO_CONNECT << 16;
2240 scmd->scsi_done(scmd);
2245 /* search for the command */
2246 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2248 scmd->result = DID_RESET << 16;
2253 /* for hidden raid components and volumes this is not supported */
2254 if (sas_device_priv_data->sas_target->flags &
2255 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2256 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2257 scmd->result = DID_RESET << 16;
2262 mpt3sas_halt_firmware(ioc);
2264 handle = sas_device_priv_data->sas_target->handle;
2265 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2266 scmd->device->id, scmd->device->lun,
2267 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2270 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2271 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2276 * _scsih_dev_reset - eh threads main device reset routine
2277 * @scmd: pointer to scsi command object
2279 * Returns SUCCESS if command aborted else FAILED
2282 _scsih_dev_reset(struct scsi_cmnd *scmd)
2284 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2285 struct MPT3SAS_DEVICE *sas_device_priv_data;
2286 struct _sas_device *sas_device;
2287 unsigned long flags;
2291 sdev_printk(KERN_INFO, scmd->device,
2292 "attempting device reset! scmd(%p)\n", scmd);
2293 _scsih_tm_display_info(ioc, scmd);
2295 sas_device_priv_data = scmd->device->hostdata;
2296 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2297 sdev_printk(KERN_INFO, scmd->device,
2298 "device been deleted! scmd(%p)\n", scmd);
2299 scmd->result = DID_NO_CONNECT << 16;
2300 scmd->scsi_done(scmd);
2305 /* for hidden raid components obtain the volume_handle */
2307 if (sas_device_priv_data->sas_target->flags &
2308 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2309 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2310 sas_device = _scsih_sas_device_find_by_handle(ioc,
2311 sas_device_priv_data->sas_target->handle);
2313 handle = sas_device->volume_handle;
2314 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2316 handle = sas_device_priv_data->sas_target->handle;
2319 scmd->result = DID_RESET << 16;
2324 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2325 scmd->device->id, scmd->device->lun,
2326 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2329 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2330 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2335 * _scsih_target_reset - eh threads main target reset routine
2336 * @scmd: pointer to scsi command object
2338 * Returns SUCCESS if command aborted else FAILED
2341 _scsih_target_reset(struct scsi_cmnd *scmd)
2343 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2344 struct MPT3SAS_DEVICE *sas_device_priv_data;
2345 struct _sas_device *sas_device;
2346 unsigned long flags;
2349 struct scsi_target *starget = scmd->device->sdev_target;
2351 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2353 _scsih_tm_display_info(ioc, scmd);
2355 sas_device_priv_data = scmd->device->hostdata;
2356 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2357 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2359 scmd->result = DID_NO_CONNECT << 16;
2360 scmd->scsi_done(scmd);
2365 /* for hidden raid components obtain the volume_handle */
2367 if (sas_device_priv_data->sas_target->flags &
2368 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2369 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2370 sas_device = _scsih_sas_device_find_by_handle(ioc,
2371 sas_device_priv_data->sas_target->handle);
2373 handle = sas_device->volume_handle;
2374 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2376 handle = sas_device_priv_data->sas_target->handle;
2379 scmd->result = DID_RESET << 16;
2384 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2385 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2389 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2390 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2396 * _scsih_host_reset - eh threads main host reset routine
2397 * @scmd: pointer to scsi command object
2399 * Returns SUCCESS if command aborted else FAILED
2402 _scsih_host_reset(struct scsi_cmnd *scmd)
2404 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2407 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2409 scsi_print_command(scmd);
2411 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2413 r = (retval < 0) ? FAILED : SUCCESS;
2414 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2415 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2421 * _scsih_fw_event_add - insert and queue up fw_event
2422 * @ioc: per adapter object
2423 * @fw_event: object describing the event
2424 * Context: This function will acquire ioc->fw_event_lock.
2426 * This adds the firmware event object into link list, then queues it up to
2427 * be processed from user context.
2432 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2434 unsigned long flags;
2436 if (ioc->firmware_event_thread == NULL)
2439 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2440 INIT_LIST_HEAD(&fw_event->list);
2441 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2442 INIT_WORK(&fw_event->work, _firmware_event_work);
2443 queue_work(ioc->firmware_event_thread, &fw_event->work);
2444 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2448 * _scsih_fw_event_free - delete fw_event
2449 * @ioc: per adapter object
2450 * @fw_event: object describing the event
2451 * Context: This function will acquire ioc->fw_event_lock.
2453 * This removes firmware event object from link list, frees associated memory.
2458 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2461 unsigned long flags;
2463 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2464 list_del(&fw_event->list);
2466 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2471 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2472 * @ioc: per adapter object
2473 * @event_data: trigger event data
2478 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2479 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2481 struct fw_event_work *fw_event;
2483 if (ioc->is_driver_loading)
2485 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2489 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2490 fw_event->ioc = ioc;
2491 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2492 _scsih_fw_event_add(ioc, fw_event);
2496 * _scsih_error_recovery_delete_devices - remove devices not responding
2497 * @ioc: per adapter object
2502 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2504 struct fw_event_work *fw_event;
2506 if (ioc->is_driver_loading)
2508 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2511 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2512 fw_event->ioc = ioc;
2513 _scsih_fw_event_add(ioc, fw_event);
2517 * mpt3sas_port_enable_complete - port enable completed (fake event)
2518 * @ioc: per adapter object
2523 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2525 struct fw_event_work *fw_event;
2527 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2530 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2531 fw_event->ioc = ioc;
2532 _scsih_fw_event_add(ioc, fw_event);
2536 * _scsih_fw_event_cleanup_queue - cleanup event queue
2537 * @ioc: per adapter object
2539 * Walk the firmware event queue, either killing timers, or waiting
2540 * for outstanding events to complete
2545 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2547 struct fw_event_work *fw_event, *next;
2549 if (list_empty(&ioc->fw_event_list) ||
2550 !ioc->firmware_event_thread || in_interrupt())
2553 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2554 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2555 _scsih_fw_event_free(ioc, fw_event);
2562 * _scsih_ublock_io_all_device - unblock every device
2563 * @ioc: per adapter object
2565 * change the device state from block to running
2568 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2570 struct MPT3SAS_DEVICE *sas_device_priv_data;
2571 struct scsi_device *sdev;
2573 shost_for_each_device(sdev, ioc->shost) {
2574 sas_device_priv_data = sdev->hostdata;
2575 if (!sas_device_priv_data)
2577 if (!sas_device_priv_data->block)
2580 sas_device_priv_data->block = 0;
2581 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2582 "device_running, handle(0x%04x)\n",
2583 sas_device_priv_data->sas_target->handle));
2584 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2590 * _scsih_ublock_io_device - prepare device to be deleted
2591 * @ioc: per adapter object
2592 * @sas_addr: sas address
2594 * unblock then put device in offline state
2597 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2599 struct MPT3SAS_DEVICE *sas_device_priv_data;
2600 struct scsi_device *sdev;
2602 shost_for_each_device(sdev, ioc->shost) {
2603 sas_device_priv_data = sdev->hostdata;
2604 if (!sas_device_priv_data)
2606 if (sas_device_priv_data->sas_target->sas_address
2609 if (sas_device_priv_data->block) {
2610 sas_device_priv_data->block = 0;
2611 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2617 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2618 * @ioc: per adapter object
2619 * @handle: device handle
2621 * During device pull we need to appropiately set the sdev state.
2624 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2626 struct MPT3SAS_DEVICE *sas_device_priv_data;
2627 struct scsi_device *sdev;
2629 shost_for_each_device(sdev, ioc->shost) {
2630 sas_device_priv_data = sdev->hostdata;
2631 if (!sas_device_priv_data)
2633 if (sas_device_priv_data->block)
2635 sas_device_priv_data->block = 1;
2636 scsi_internal_device_block(sdev);
2637 sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n",
2638 sas_device_priv_data->sas_target->handle);
2643 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2644 * @ioc: per adapter object
2645 * @handle: device handle
2647 * During device pull we need to appropiately set the sdev state.
2650 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2652 struct MPT3SAS_DEVICE *sas_device_priv_data;
2653 struct scsi_device *sdev;
2655 shost_for_each_device(sdev, ioc->shost) {
2656 sas_device_priv_data = sdev->hostdata;
2657 if (!sas_device_priv_data)
2659 if (sas_device_priv_data->sas_target->handle != handle)
2661 if (sas_device_priv_data->block)
2663 sas_device_priv_data->block = 1;
2664 scsi_internal_device_block(sdev);
2665 sdev_printk(KERN_INFO, sdev,
2666 "device_blocked, handle(0x%04x)\n", handle);
2671 * _scsih_block_io_to_children_attached_to_ex
2672 * @ioc: per adapter object
2673 * @sas_expander: the sas_device object
2675 * This routine set sdev state to SDEV_BLOCK for all devices
2676 * attached to this expander. This function called when expander is
2680 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2681 struct _sas_node *sas_expander)
2683 struct _sas_port *mpt3sas_port;
2684 struct _sas_device *sas_device;
2685 struct _sas_node *expander_sibling;
2686 unsigned long flags;
2691 list_for_each_entry(mpt3sas_port,
2692 &sas_expander->sas_port_list, port_list) {
2693 if (mpt3sas_port->remote_identify.device_type ==
2695 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2697 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2698 mpt3sas_port->remote_identify.sas_address);
2700 set_bit(sas_device->handle,
2701 ioc->blocking_handles);
2702 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2706 list_for_each_entry(mpt3sas_port,
2707 &sas_expander->sas_port_list, port_list) {
2709 if (mpt3sas_port->remote_identify.device_type ==
2710 SAS_EDGE_EXPANDER_DEVICE ||
2711 mpt3sas_port->remote_identify.device_type ==
2712 SAS_FANOUT_EXPANDER_DEVICE) {
2714 mpt3sas_scsih_expander_find_by_sas_address(
2715 ioc, mpt3sas_port->remote_identify.sas_address);
2716 _scsih_block_io_to_children_attached_to_ex(ioc,
2723 * _scsih_block_io_to_children_attached_directly
2724 * @ioc: per adapter object
2725 * @event_data: topology change event data
2727 * This routine set sdev state to SDEV_BLOCK for all devices
2728 * direct attached during device pull.
2731 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2732 Mpi2EventDataSasTopologyChangeList_t *event_data)
2738 for (i = 0; i < event_data->NumEntries; i++) {
2739 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2742 reason_code = event_data->PHY[i].PhyStatus &
2743 MPI2_EVENT_SAS_TOPO_RC_MASK;
2744 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2745 _scsih_block_io_device(ioc, handle);
2750 * _scsih_tm_tr_send - send task management request
2751 * @ioc: per adapter object
2752 * @handle: device handle
2753 * Context: interrupt time.
2755 * This code is to initiate the device removal handshake protocol
2756 * with controller firmware. This function will issue target reset
2757 * using high priority request queue. It will send a sas iounit
2758 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2760 * This is designed to send muliple task management request at the same
2761 * time to the fifo. If the fifo is full, we will append the request,
2762 * and process it in a future completion.
2765 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2767 Mpi2SCSITaskManagementRequest_t *mpi_request;
2769 struct _sas_device *sas_device;
2770 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2771 u64 sas_address = 0;
2772 unsigned long flags;
2773 struct _tr_list *delayed_tr;
2776 if (ioc->remove_host) {
2777 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2778 "%s: host has been removed: handle(0x%04x)\n",
2779 __func__, ioc->name, handle));
2781 } else if (ioc->pci_error_recovery) {
2782 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2783 "%s: host in pci error recovery: handle(0x%04x)\n",
2784 __func__, ioc->name,
2788 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2789 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2790 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2791 "%s: host is not operational: handle(0x%04x)\n",
2792 __func__, ioc->name,
2797 /* if PD, then return */
2798 if (test_bit(handle, ioc->pd_handles))
2801 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2802 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2803 if (sas_device && sas_device->starget &&
2804 sas_device->starget->hostdata) {
2805 sas_target_priv_data = sas_device->starget->hostdata;
2806 sas_target_priv_data->deleted = 1;
2807 sas_address = sas_device->sas_address;
2809 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2811 if (sas_target_priv_data) {
2812 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2813 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2815 (unsigned long long)sas_address));
2816 _scsih_ublock_io_device(ioc, sas_address);
2817 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2820 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2822 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2825 INIT_LIST_HEAD(&delayed_tr->list);
2826 delayed_tr->handle = handle;
2827 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2828 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2829 "DELAYED:tr:handle(0x%04x), (open)\n",
2830 ioc->name, handle));
2834 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2835 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2836 ioc->name, handle, smid,
2837 ioc->tm_tr_cb_idx));
2838 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2839 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2840 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2841 mpi_request->DevHandle = cpu_to_le16(handle);
2842 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2843 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2844 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2848 * _scsih_tm_tr_complete -
2849 * @ioc: per adapter object
2850 * @smid: system request message index
2851 * @msix_index: MSIX table index supplied by the OS
2852 * @reply: reply message frame(lower 32bit addr)
2853 * Context: interrupt time.
2855 * This is the target reset completion routine.
2856 * This code is part of the code to initiate the device removal
2857 * handshake protocol with controller firmware.
2858 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2860 * Return 1 meaning mf should be freed from _base_interrupt
2861 * 0 means the mf is freed from this function.
2864 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2868 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2869 Mpi2SCSITaskManagementReply_t *mpi_reply =
2870 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2871 Mpi2SasIoUnitControlRequest_t *mpi_request;
2875 if (ioc->remove_host) {
2876 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2877 "%s: host has been removed\n", __func__, ioc->name));
2879 } else if (ioc->pci_error_recovery) {
2880 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2881 "%s: host in pci error recovery\n", __func__,
2885 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2886 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2887 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2888 "%s: host is not operational\n", __func__, ioc->name));
2891 if (unlikely(!mpi_reply)) {
2892 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2893 ioc->name, __FILE__, __LINE__, __func__);
2896 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2897 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2898 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2899 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2900 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2902 le16_to_cpu(mpi_reply->DevHandle), smid));
2906 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2907 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2908 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2909 "loginfo(0x%08x), completed(%d)\n", ioc->name,
2910 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
2911 le32_to_cpu(mpi_reply->IOCLogInfo),
2912 le32_to_cpu(mpi_reply->TerminationCount)));
2914 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2915 if (!smid_sas_ctrl) {
2916 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2917 ioc->name, __func__);
2921 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2922 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2923 ioc->name, handle, smid_sas_ctrl,
2924 ioc->tm_sas_control_cb_idx));
2925 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2926 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2927 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2928 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2929 mpi_request->DevHandle = mpi_request_tm->DevHandle;
2930 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
2932 return _scsih_check_for_pending_tm(ioc, smid);
2937 * _scsih_sas_control_complete - completion routine
2938 * @ioc: per adapter object
2939 * @smid: system request message index
2940 * @msix_index: MSIX table index supplied by the OS
2941 * @reply: reply message frame(lower 32bit addr)
2942 * Context: interrupt time.
2944 * This is the sas iounit control completion routine.
2945 * This code is part of the code to initiate the device removal
2946 * handshake protocol with controller firmware.
2948 * Return 1 meaning mf should be freed from _base_interrupt
2949 * 0 means the mf is freed from this function.
2952 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
2953 u8 msix_index, u32 reply)
2955 Mpi2SasIoUnitControlReply_t *mpi_reply =
2956 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2958 if (likely(mpi_reply)) {
2959 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2960 "sc_complete:handle(0x%04x), (open) "
2961 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2962 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2963 le16_to_cpu(mpi_reply->IOCStatus),
2964 le32_to_cpu(mpi_reply->IOCLogInfo)));
2966 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2967 ioc->name, __FILE__, __LINE__, __func__);
2973 * _scsih_tm_tr_volume_send - send target reset request for volumes
2974 * @ioc: per adapter object
2975 * @handle: device handle
2976 * Context: interrupt time.
2978 * This is designed to send muliple task management request at the same
2979 * time to the fifo. If the fifo is full, we will append the request,
2980 * and process it in a future completion.
2983 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2985 Mpi2SCSITaskManagementRequest_t *mpi_request;
2987 struct _tr_list *delayed_tr;
2989 if (ioc->shost_recovery || ioc->remove_host ||
2990 ioc->pci_error_recovery) {
2991 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2992 "%s: host reset in progress!\n",
2993 __func__, ioc->name));
2997 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
2999 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3002 INIT_LIST_HEAD(&delayed_tr->list);
3003 delayed_tr->handle = handle;
3004 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3005 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3006 "DELAYED:tr:handle(0x%04x), (open)\n",
3007 ioc->name, handle));
3011 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3012 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3013 ioc->name, handle, smid,
3014 ioc->tm_tr_volume_cb_idx));
3015 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3016 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3017 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3018 mpi_request->DevHandle = cpu_to_le16(handle);
3019 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3020 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3024 * _scsih_tm_volume_tr_complete - target reset completion
3025 * @ioc: per adapter object
3026 * @smid: system request message index
3027 * @msix_index: MSIX table index supplied by the OS
3028 * @reply: reply message frame(lower 32bit addr)
3029 * Context: interrupt time.
3031 * Return 1 meaning mf should be freed from _base_interrupt
3032 * 0 means the mf is freed from this function.
3035 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3036 u8 msix_index, u32 reply)
3039 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3040 Mpi2SCSITaskManagementReply_t *mpi_reply =
3041 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3043 if (ioc->shost_recovery || ioc->remove_host ||
3044 ioc->pci_error_recovery) {
3045 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3046 "%s: host reset in progress!\n",
3047 __func__, ioc->name));
3050 if (unlikely(!mpi_reply)) {
3051 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3052 ioc->name, __FILE__, __LINE__, __func__);
3056 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3057 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3058 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3059 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3060 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3062 le16_to_cpu(mpi_reply->DevHandle), smid));
3066 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3067 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3068 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3069 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3070 le32_to_cpu(mpi_reply->IOCLogInfo),
3071 le32_to_cpu(mpi_reply->TerminationCount)));
3073 return _scsih_check_for_pending_tm(ioc, smid);
3078 * _scsih_check_for_pending_tm - check for pending task management
3079 * @ioc: per adapter object
3080 * @smid: system request message index
3082 * This will check delayed target reset list, and feed the
3085 * Return 1 meaning mf should be freed from _base_interrupt
3086 * 0 means the mf is freed from this function.
3089 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3091 struct _tr_list *delayed_tr;
3093 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3094 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3095 struct _tr_list, list);
3096 mpt3sas_base_free_smid(ioc, smid);
3097 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3098 list_del(&delayed_tr->list);
3103 if (!list_empty(&ioc->delayed_tr_list)) {
3104 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3105 struct _tr_list, list);
3106 mpt3sas_base_free_smid(ioc, smid);
3107 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3108 list_del(&delayed_tr->list);
3117 * _scsih_check_topo_delete_events - sanity check on topo events
3118 * @ioc: per adapter object
3119 * @event_data: the event data payload
3121 * This routine added to better handle cable breaker.
3123 * This handles the case where driver receives multiple expander
3124 * add and delete events in a single shot. When there is a delete event
3125 * the routine will void any pending add events waiting in the event queue.
3130 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3131 Mpi2EventDataSasTopologyChangeList_t *event_data)
3133 struct fw_event_work *fw_event;
3134 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3135 u16 expander_handle;
3136 struct _sas_node *sas_expander;
3137 unsigned long flags;
3141 for (i = 0 ; i < event_data->NumEntries; i++) {
3142 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3145 reason_code = event_data->PHY[i].PhyStatus &
3146 MPI2_EVENT_SAS_TOPO_RC_MASK;
3147 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3148 _scsih_tm_tr_send(ioc, handle);
3151 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3152 if (expander_handle < ioc->sas_hba.num_phys) {
3153 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3156 if (event_data->ExpStatus ==
3157 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3158 /* put expander attached devices into blocking state */
3159 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3160 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3162 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3163 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3165 handle = find_first_bit(ioc->blocking_handles,
3166 ioc->facts.MaxDevHandle);
3167 if (handle < ioc->facts.MaxDevHandle)
3168 _scsih_block_io_device(ioc, handle);
3169 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3170 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3171 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3173 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3176 /* mark ignore flag for pending events */
3177 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3178 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3179 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3182 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3183 fw_event->event_data;
3184 if (local_event_data->ExpStatus ==
3185 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3186 local_event_data->ExpStatus ==
3187 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3188 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3190 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3191 "setting ignoring flag\n", ioc->name));
3192 fw_event->ignore = 1;
3196 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3200 * _scsih_set_volume_delete_flag - setting volume delete flag
3201 * @ioc: per adapter object
3202 * @handle: device handle
3204 * This returns nothing.
3207 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3209 struct _raid_device *raid_device;
3210 struct MPT3SAS_TARGET *sas_target_priv_data;
3211 unsigned long flags;
3213 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3214 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3215 if (raid_device && raid_device->starget &&
3216 raid_device->starget->hostdata) {
3217 sas_target_priv_data =
3218 raid_device->starget->hostdata;
3219 sas_target_priv_data->deleted = 1;
3220 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3221 "setting delete flag: handle(0x%04x), "
3222 "wwid(0x%016llx)\n", ioc->name, handle,
3223 (unsigned long long) raid_device->wwid));
3225 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3229 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3230 * @handle: input handle
3231 * @a: handle for volume a
3232 * @b: handle for volume b
3234 * IR firmware only supports two raid volumes. The purpose of this
3235 * routine is to set the volume handle in either a or b. When the given
3236 * input handle is non-zero, or when a and b have not been set before.
3239 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3241 if (!handle || handle == *a || handle == *b)
3250 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3251 * @ioc: per adapter object
3252 * @event_data: the event data payload
3253 * Context: interrupt time.
3255 * This routine will send target reset to volume, followed by target
3256 * resets to the PDs. This is called when a PD has been removed, or
3257 * volume has been deleted or removed. When the target reset is sent
3258 * to volume, the PD target resets need to be queued to start upon
3259 * completion of the volume target reset.
3264 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3265 Mpi2EventDataIrConfigChangeList_t *event_data)
3267 Mpi2EventIrConfigElement_t *element;
3269 u16 handle, volume_handle, a, b;
3270 struct _tr_list *delayed_tr;
3275 /* Volume Resets for Deleted or Removed */
3276 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3277 for (i = 0; i < event_data->NumElements; i++, element++) {
3278 if (le32_to_cpu(event_data->Flags) &
3279 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3281 if (element->ReasonCode ==
3282 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3283 element->ReasonCode ==
3284 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3285 volume_handle = le16_to_cpu(element->VolDevHandle);
3286 _scsih_set_volume_delete_flag(ioc, volume_handle);
3287 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3291 /* Volume Resets for UNHIDE events */
3292 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3293 for (i = 0; i < event_data->NumElements; i++, element++) {
3294 if (le32_to_cpu(event_data->Flags) &
3295 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3297 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3298 volume_handle = le16_to_cpu(element->VolDevHandle);
3299 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3304 _scsih_tm_tr_volume_send(ioc, a);
3306 _scsih_tm_tr_volume_send(ioc, b);
3308 /* PD target resets */
3309 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3310 for (i = 0; i < event_data->NumElements; i++, element++) {
3311 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3313 handle = le16_to_cpu(element->PhysDiskDevHandle);
3314 volume_handle = le16_to_cpu(element->VolDevHandle);
3315 clear_bit(handle, ioc->pd_handles);
3317 _scsih_tm_tr_send(ioc, handle);
3318 else if (volume_handle == a || volume_handle == b) {
3319 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3320 BUG_ON(!delayed_tr);
3321 INIT_LIST_HEAD(&delayed_tr->list);
3322 delayed_tr->handle = handle;
3323 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3324 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3325 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3328 _scsih_tm_tr_send(ioc, handle);
3334 * _scsih_check_volume_delete_events - set delete flag for volumes
3335 * @ioc: per adapter object
3336 * @event_data: the event data payload
3337 * Context: interrupt time.
3339 * This will handle the case when the cable connected to entire volume is
3340 * pulled. We will take care of setting the deleted flag so normal IO will
3346 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3347 Mpi2EventDataIrVolume_t *event_data)
3351 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3353 state = le32_to_cpu(event_data->NewValue);
3354 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3355 MPI2_RAID_VOL_STATE_FAILED)
3356 _scsih_set_volume_delete_flag(ioc,
3357 le16_to_cpu(event_data->VolDevHandle));
3361 * _scsih_flush_running_cmds - completing outstanding commands.
3362 * @ioc: per adapter object
3364 * The flushing out of all pending scmd commands following host reset,
3365 * where all IO is dropped to the floor.
3370 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3372 struct scsi_cmnd *scmd;
3376 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3377 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3381 mpt3sas_base_free_smid(ioc, smid);
3382 scsi_dma_unmap(scmd);
3383 if (ioc->pci_error_recovery)
3384 scmd->result = DID_NO_CONNECT << 16;
3386 scmd->result = DID_RESET << 16;
3387 scmd->scsi_done(scmd);
3389 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3394 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3395 * @ioc: per adapter object
3396 * @scmd: pointer to scsi command object
3397 * @mpi_request: pointer to the SCSI_IO reqest message frame
3399 * Supporting protection 1 and 3.
3404 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3405 Mpi2SCSIIORequest_t *mpi_request)
3408 unsigned char prot_op = scsi_get_prot_op(scmd);
3409 unsigned char prot_type = scsi_get_prot_type(scmd);
3410 Mpi25SCSIIORequest_t *mpi_request_3v =
3411 (Mpi25SCSIIORequest_t *)mpi_request;
3413 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3416 if (prot_op == SCSI_PROT_READ_STRIP)
3417 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3418 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3419 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3423 switch (prot_type) {
3424 case SCSI_PROT_DIF_TYPE1:
3425 case SCSI_PROT_DIF_TYPE2:
3428 * enable ref/guard checking
3429 * auto increment ref tag
3431 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3432 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3433 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3434 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3435 cpu_to_be32(scsi_get_lba(scmd));
3438 case SCSI_PROT_DIF_TYPE3:
3441 * enable guard checking
3443 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3448 mpi_request_3v->EEDPBlockSize =
3449 cpu_to_le16(scmd->device->sector_size);
3450 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3454 * _scsih_eedp_error_handling - return sense code for EEDP errors
3455 * @scmd: pointer to scsi command object
3456 * @ioc_status: ioc status
3461 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3465 switch (ioc_status) {
3466 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3469 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3472 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3479 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3481 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3482 SAM_STAT_CHECK_CONDITION;
3487 * _scsih_qcmd - main scsi request entry point
3488 * @scmd: pointer to scsi command object
3489 * @done: function pointer to be invoked on completion
3491 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3493 * Returns 0 on success. If there's a failure, return either:
3494 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3495 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3498 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3500 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3501 struct MPT3SAS_DEVICE *sas_device_priv_data;
3502 struct MPT3SAS_TARGET *sas_target_priv_data;
3503 Mpi2SCSIIORequest_t *mpi_request;
3508 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3509 if (ioc->logging_level & MPT_DEBUG_SCSI)
3510 scsi_print_command(scmd);
3513 sas_device_priv_data = scmd->device->hostdata;
3514 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3515 scmd->result = DID_NO_CONNECT << 16;
3516 scmd->scsi_done(scmd);
3520 if (ioc->pci_error_recovery || ioc->remove_host) {
3521 scmd->result = DID_NO_CONNECT << 16;
3522 scmd->scsi_done(scmd);
3526 sas_target_priv_data = sas_device_priv_data->sas_target;
3528 /* invalid device handle */
3529 handle = sas_target_priv_data->handle;
3530 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3531 scmd->result = DID_NO_CONNECT << 16;
3532 scmd->scsi_done(scmd);
3537 /* host recovery or link resets sent via IOCTLs */
3538 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3539 return SCSI_MLQUEUE_HOST_BUSY;
3541 /* device has been deleted */
3542 else if (sas_target_priv_data->deleted) {
3543 scmd->result = DID_NO_CONNECT << 16;
3544 scmd->scsi_done(scmd);
3546 /* device busy with task managment */
3547 } else if (sas_target_priv_data->tm_busy ||
3548 sas_device_priv_data->block)
3549 return SCSI_MLQUEUE_DEVICE_BUSY;
3551 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3552 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3553 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3554 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3556 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3559 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3561 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3562 scmd->cmd_len != 32)
3563 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3565 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3567 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3568 ioc->name, __func__);
3571 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3572 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3573 _scsih_setup_eedp(ioc, scmd, mpi_request);
3575 if (scmd->cmd_len == 32)
3576 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3577 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3578 if (sas_device_priv_data->sas_target->flags &
3579 MPT_TARGET_FLAGS_RAID_COMPONENT)
3580 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3582 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3583 mpi_request->DevHandle = cpu_to_le16(handle);
3584 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3585 mpi_request->Control = cpu_to_le32(mpi_control);
3586 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3587 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3588 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3589 mpi_request->SenseBufferLowAddress =
3590 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3591 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3592 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3594 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3596 if (mpi_request->DataLength) {
3597 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3598 mpt3sas_base_free_smid(ioc, smid);
3602 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3604 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3605 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3606 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3607 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3608 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3610 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3612 mpt3sas_base_put_smid_default(ioc, smid);
3616 return SCSI_MLQUEUE_HOST_BUSY;
3620 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3621 * @sense_buffer: sense data returned by target
3622 * @data: normalized skey/asc/ascq
3627 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3629 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3630 /* descriptor format */
3631 data->skey = sense_buffer[1] & 0x0F;
3632 data->asc = sense_buffer[2];
3633 data->ascq = sense_buffer[3];
3636 data->skey = sense_buffer[2] & 0x0F;
3637 data->asc = sense_buffer[12];
3638 data->ascq = sense_buffer[13];
3642 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3644 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3645 * @ioc: per adapter object
3646 * @scmd: pointer to scsi command object
3647 * @mpi_reply: reply mf payload returned from firmware
3649 * scsi_status - SCSI Status code returned from target device
3650 * scsi_state - state info associated with SCSI_IO determined by ioc
3651 * ioc_status - ioc supplied status info
3656 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3657 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3661 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3662 MPI2_IOCSTATUS_MASK;
3663 u8 scsi_state = mpi_reply->SCSIState;
3664 u8 scsi_status = mpi_reply->SCSIStatus;
3665 char *desc_ioc_state = NULL;
3666 char *desc_scsi_status = NULL;
3667 char *desc_scsi_state = ioc->tmp_string;
3668 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3669 struct _sas_device *sas_device = NULL;
3670 unsigned long flags;
3671 struct scsi_target *starget = scmd->device->sdev_target;
3672 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3673 char *device_str = NULL;
3677 device_str = "volume";
3679 if (log_info == 0x31170000)
3682 switch (ioc_status) {
3683 case MPI2_IOCSTATUS_SUCCESS:
3684 desc_ioc_state = "success";
3686 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3687 desc_ioc_state = "invalid function";
3689 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3690 desc_ioc_state = "scsi recovered error";
3692 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3693 desc_ioc_state = "scsi invalid dev handle";
3695 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3696 desc_ioc_state = "scsi device not there";
3698 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3699 desc_ioc_state = "scsi data overrun";
3701 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3702 desc_ioc_state = "scsi data underrun";
3704 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3705 desc_ioc_state = "scsi io data error";
3707 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3708 desc_ioc_state = "scsi protocol error";
3710 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3711 desc_ioc_state = "scsi task terminated";
3713 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3714 desc_ioc_state = "scsi residual mismatch";
3716 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3717 desc_ioc_state = "scsi task mgmt failed";
3719 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3720 desc_ioc_state = "scsi ioc terminated";
3722 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3723 desc_ioc_state = "scsi ext terminated";
3725 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3726 desc_ioc_state = "eedp guard error";
3728 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3729 desc_ioc_state = "eedp ref tag error";
3731 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3732 desc_ioc_state = "eedp app tag error";
3735 desc_ioc_state = "unknown";
3739 switch (scsi_status) {
3740 case MPI2_SCSI_STATUS_GOOD:
3741 desc_scsi_status = "good";
3743 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3744 desc_scsi_status = "check condition";
3746 case MPI2_SCSI_STATUS_CONDITION_MET:
3747 desc_scsi_status = "condition met";
3749 case MPI2_SCSI_STATUS_BUSY:
3750 desc_scsi_status = "busy";
3752 case MPI2_SCSI_STATUS_INTERMEDIATE:
3753 desc_scsi_status = "intermediate";
3755 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3756 desc_scsi_status = "intermediate condmet";
3758 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3759 desc_scsi_status = "reservation conflict";
3761 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3762 desc_scsi_status = "command terminated";
3764 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3765 desc_scsi_status = "task set full";
3767 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3768 desc_scsi_status = "aca active";
3770 case MPI2_SCSI_STATUS_TASK_ABORTED:
3771 desc_scsi_status = "task aborted";
3774 desc_scsi_status = "unknown";
3778 desc_scsi_state[0] = '\0';
3780 desc_scsi_state = " ";
3781 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3782 strcat(desc_scsi_state, "response info ");
3783 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3784 strcat(desc_scsi_state, "state terminated ");
3785 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3786 strcat(desc_scsi_state, "no status ");
3787 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3788 strcat(desc_scsi_state, "autosense failed ");
3789 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3790 strcat(desc_scsi_state, "autosense valid ");
3792 scsi_print_command(scmd);
3794 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3795 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3796 device_str, (unsigned long long)priv_target->sas_address);
3798 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3799 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3800 priv_target->sas_address);
3803 "\tsas_address(0x%016llx), phy(%d)\n",
3804 ioc->name, (unsigned long long)
3805 sas_device->sas_address, sas_device->phy);
3807 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3808 ioc->name, (unsigned long long)
3809 sas_device->enclosure_logical_id, sas_device->slot);
3811 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3815 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3816 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3817 desc_ioc_state, ioc_status, smid);
3819 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3820 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3821 scsi_get_resid(scmd));
3823 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3824 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3825 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3827 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3828 ioc->name, desc_scsi_status,
3829 scsi_status, desc_scsi_state, scsi_state);
3831 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3832 struct sense_info data;
3833 _scsih_normalize_sense(scmd->sense_buffer, &data);
3835 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3836 ioc->name, data.skey,
3837 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3840 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3841 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3842 response_bytes = (u8 *)&response_info;
3843 _scsih_response_code(ioc, response_bytes[0]);
3849 * _scsih_turn_on_pfa_led - illuminate PFA LED
3850 * @ioc: per adapter object
3851 * @handle: device handle
3857 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3859 Mpi2SepReply_t mpi_reply;
3860 Mpi2SepRequest_t mpi_request;
3861 struct _sas_device *sas_device;
3863 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3867 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3868 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3869 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3870 mpi_request.SlotStatus =
3871 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3872 mpi_request.DevHandle = cpu_to_le16(handle);
3873 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3874 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3875 &mpi_request)) != 0) {
3876 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3877 __FILE__, __LINE__, __func__);
3880 sas_device->pfa_led_on = 1;
3882 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3883 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3884 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3885 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3886 le32_to_cpu(mpi_reply.IOCLogInfo)));
3891 * _scsih_turn_off_pfa_led - turn off Fault LED
3892 * @ioc: per adapter object
3893 * @sas_device: sas device whose PFA LED has to turned off
3899 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
3900 struct _sas_device *sas_device)
3902 Mpi2SepReply_t mpi_reply;
3903 Mpi2SepRequest_t mpi_request;
3905 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3906 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3907 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3908 mpi_request.SlotStatus = 0;
3909 mpi_request.Slot = cpu_to_le16(sas_device->slot);
3910 mpi_request.DevHandle = 0;
3911 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
3912 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
3913 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3914 &mpi_request)) != 0) {
3915 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3916 __FILE__, __LINE__, __func__);
3920 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3921 dewtprintk(ioc, printk(MPT3SAS_FMT
3922 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3923 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3924 le32_to_cpu(mpi_reply.IOCLogInfo)));
3929 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
3930 * @ioc: per adapter object
3931 * @handle: device handle
3932 * Context: interrupt.
3937 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3939 struct fw_event_work *fw_event;
3941 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
3944 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
3945 fw_event->device_handle = handle;
3946 fw_event->ioc = ioc;
3947 _scsih_fw_event_add(ioc, fw_event);
3951 * _scsih_smart_predicted_fault - process smart errors
3952 * @ioc: per adapter object
3953 * @handle: device handle
3954 * Context: interrupt.
3959 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3961 struct scsi_target *starget;
3962 struct MPT3SAS_TARGET *sas_target_priv_data;
3963 Mpi2EventNotificationReply_t *event_reply;
3964 Mpi2EventDataSasDeviceStatusChange_t *event_data;
3965 struct _sas_device *sas_device;
3967 unsigned long flags;
3969 /* only handle non-raid devices */
3970 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3971 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3973 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3976 starget = sas_device->starget;
3977 sas_target_priv_data = starget->hostdata;
3979 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
3980 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
3981 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3984 starget_printk(KERN_WARNING, starget, "predicted fault\n");
3985 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3987 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
3988 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
3990 /* insert into event log */
3991 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
3992 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
3993 event_reply = kzalloc(sz, GFP_KERNEL);
3995 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
3996 ioc->name, __FILE__, __LINE__, __func__);
4000 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4001 event_reply->Event =
4002 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4003 event_reply->MsgLength = sz/4;
4004 event_reply->EventDataLength =
4005 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4006 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4007 event_reply->EventData;
4008 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4009 event_data->ASC = 0x5D;
4010 event_data->DevHandle = cpu_to_le16(handle);
4011 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4012 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4017 * _scsih_io_done - scsi request callback
4018 * @ioc: per adapter object
4019 * @smid: system request message index
4020 * @msix_index: MSIX table index supplied by the OS
4021 * @reply: reply message frame(lower 32bit addr)
4023 * Callback handler when using _scsih_qcmd.
4025 * Return 1 meaning mf should be freed from _base_interrupt
4026 * 0 means the mf is freed from this function.
4029 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4031 Mpi2SCSIIORequest_t *mpi_request;
4032 Mpi2SCSIIOReply_t *mpi_reply;
4033 struct scsi_cmnd *scmd;
4039 struct MPT3SAS_DEVICE *sas_device_priv_data;
4040 u32 response_code = 0;
4042 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4043 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4047 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4049 if (mpi_reply == NULL) {
4050 scmd->result = DID_OK << 16;
4054 sas_device_priv_data = scmd->device->hostdata;
4055 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4056 sas_device_priv_data->sas_target->deleted) {
4057 scmd->result = DID_NO_CONNECT << 16;
4060 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4062 /* turning off TLR */
4063 scsi_state = mpi_reply->SCSIState;
4064 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4066 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4067 if (!sas_device_priv_data->tlr_snoop_check) {
4068 sas_device_priv_data->tlr_snoop_check++;
4069 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4070 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4071 sas_device_priv_data->flags &=
4075 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4076 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4077 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4078 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4081 ioc_status &= MPI2_IOCSTATUS_MASK;
4082 scsi_status = mpi_reply->SCSIStatus;
4084 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4085 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4086 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4087 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4088 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4091 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4092 struct sense_info data;
4093 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4095 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4096 le32_to_cpu(mpi_reply->SenseCount));
4097 memcpy(scmd->sense_buffer, sense_data, sz);
4098 _scsih_normalize_sense(scmd->sense_buffer, &data);
4099 /* failure prediction threshold exceeded */
4100 if (data.asc == 0x5D)
4101 _scsih_smart_predicted_fault(ioc,
4102 le16_to_cpu(mpi_reply->DevHandle));
4103 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4106 switch (ioc_status) {
4107 case MPI2_IOCSTATUS_BUSY:
4108 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4109 scmd->result = SAM_STAT_BUSY;
4112 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4113 scmd->result = DID_NO_CONNECT << 16;
4116 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4117 if (sas_device_priv_data->block) {
4118 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4121 if (log_info == 0x31110630) {
4122 if (scmd->retries > 2) {
4123 scmd->result = DID_NO_CONNECT << 16;
4124 scsi_device_set_state(scmd->device,
4127 scmd->result = DID_SOFT_ERROR << 16;
4128 scmd->device->expecting_cc_ua = 1;
4132 scmd->result = DID_SOFT_ERROR << 16;
4134 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4135 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4136 scmd->result = DID_RESET << 16;
4139 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4140 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4141 scmd->result = DID_SOFT_ERROR << 16;
4143 scmd->result = (DID_OK << 16) | scsi_status;
4146 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4147 scmd->result = (DID_OK << 16) | scsi_status;
4149 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4152 if (xfer_cnt < scmd->underflow) {
4153 if (scsi_status == SAM_STAT_BUSY)
4154 scmd->result = SAM_STAT_BUSY;
4156 scmd->result = DID_SOFT_ERROR << 16;
4157 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4158 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4159 scmd->result = DID_SOFT_ERROR << 16;
4160 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4161 scmd->result = DID_RESET << 16;
4162 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4163 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4164 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4165 scmd->result = (DRIVER_SENSE << 24) |
4166 SAM_STAT_CHECK_CONDITION;
4167 scmd->sense_buffer[0] = 0x70;
4168 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4169 scmd->sense_buffer[12] = 0x20;
4170 scmd->sense_buffer[13] = 0;
4174 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4175 scsi_set_resid(scmd, 0);
4176 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4177 case MPI2_IOCSTATUS_SUCCESS:
4178 scmd->result = (DID_OK << 16) | scsi_status;
4179 if (response_code ==
4180 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4181 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4182 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4183 scmd->result = DID_SOFT_ERROR << 16;
4184 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4185 scmd->result = DID_RESET << 16;
4188 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4189 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4190 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4191 _scsih_eedp_error_handling(scmd, ioc_status);
4194 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4195 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4196 case MPI2_IOCSTATUS_INVALID_SGL:
4197 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4198 case MPI2_IOCSTATUS_INVALID_FIELD:
4199 case MPI2_IOCSTATUS_INVALID_STATE:
4200 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4201 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4203 scmd->result = DID_SOFT_ERROR << 16;
4208 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4209 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4210 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4215 scsi_dma_unmap(scmd);
4217 scmd->scsi_done(scmd);
4222 * _scsih_sas_host_refresh - refreshing sas host object contents
4223 * @ioc: per adapter object
4226 * During port enable, fw will send topology events for every device. Its
4227 * possible that the handles may change from the previous setting, so this
4228 * code keeping handles updating if changed.
4233 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4238 Mpi2ConfigReply_t mpi_reply;
4239 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4240 u16 attached_handle;
4243 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4244 "updating handles for sas_host(0x%016llx)\n",
4245 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4247 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4248 * sizeof(Mpi2SasIOUnit0PhyData_t));
4249 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4250 if (!sas_iounit_pg0) {
4251 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4252 ioc->name, __FILE__, __LINE__, __func__);
4256 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4257 sas_iounit_pg0, sz)) != 0)
4259 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4260 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4262 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4263 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4265 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4266 PhyData[0].ControllerDevHandle);
4267 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4268 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4270 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4271 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4272 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4273 attached_handle, i, link_rate);
4276 kfree(sas_iounit_pg0);
4280 * _scsih_sas_host_add - create sas host object
4281 * @ioc: per adapter object
4283 * Creating host side data object, stored in ioc->sas_hba
4288 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4291 Mpi2ConfigReply_t mpi_reply;
4292 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4293 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4294 Mpi2SasPhyPage0_t phy_pg0;
4295 Mpi2SasDevicePage0_t sas_device_pg0;
4296 Mpi2SasEnclosurePage0_t enclosure_pg0;
4299 u8 device_missing_delay;
4301 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4302 if (!ioc->sas_hba.num_phys) {
4303 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4304 ioc->name, __FILE__, __LINE__, __func__);
4308 /* sas_iounit page 0 */
4309 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4310 sizeof(Mpi2SasIOUnit0PhyData_t));
4311 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4312 if (!sas_iounit_pg0) {
4313 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4314 ioc->name, __FILE__, __LINE__, __func__);
4317 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4318 sas_iounit_pg0, sz))) {
4319 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4320 ioc->name, __FILE__, __LINE__, __func__);
4323 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4324 MPI2_IOCSTATUS_MASK;
4325 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4326 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4327 ioc->name, __FILE__, __LINE__, __func__);
4331 /* sas_iounit page 1 */
4332 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4333 sizeof(Mpi2SasIOUnit1PhyData_t));
4334 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4335 if (!sas_iounit_pg1) {
4336 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4337 ioc->name, __FILE__, __LINE__, __func__);
4340 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4341 sas_iounit_pg1, sz))) {
4342 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4343 ioc->name, __FILE__, __LINE__, __func__);
4346 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4347 MPI2_IOCSTATUS_MASK;
4348 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4349 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4350 ioc->name, __FILE__, __LINE__, __func__);
4354 ioc->io_missing_delay =
4355 sas_iounit_pg1->IODeviceMissingDelay;
4356 device_missing_delay =
4357 sas_iounit_pg1->ReportDeviceMissingDelay;
4358 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4359 ioc->device_missing_delay = (device_missing_delay &
4360 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4362 ioc->device_missing_delay = device_missing_delay &
4363 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4365 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4366 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4367 sizeof(struct _sas_phy), GFP_KERNEL);
4368 if (!ioc->sas_hba.phy) {
4369 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4370 ioc->name, __FILE__, __LINE__, __func__);
4373 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4374 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4376 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4377 ioc->name, __FILE__, __LINE__, __func__);
4380 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4381 MPI2_IOCSTATUS_MASK;
4382 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4383 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4384 ioc->name, __FILE__, __LINE__, __func__);
4389 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4390 PhyData[0].ControllerDevHandle);
4391 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4392 ioc->sas_hba.phy[i].phy_id = i;
4393 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4394 phy_pg0, ioc->sas_hba.parent_dev);
4396 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4397 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4398 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4399 ioc->name, __FILE__, __LINE__, __func__);
4402 ioc->sas_hba.enclosure_handle =
4403 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4404 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4406 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4407 ioc->name, ioc->sas_hba.handle,
4408 (unsigned long long) ioc->sas_hba.sas_address,
4409 ioc->sas_hba.num_phys) ;
4411 if (ioc->sas_hba.enclosure_handle) {
4412 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4413 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4414 ioc->sas_hba.enclosure_handle)))
4415 ioc->sas_hba.enclosure_logical_id =
4416 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4420 kfree(sas_iounit_pg1);
4421 kfree(sas_iounit_pg0);
4425 * _scsih_expander_add - creating expander object
4426 * @ioc: per adapter object
4427 * @handle: expander handle
4429 * Creating expander object, stored in ioc->sas_expander_list.
4431 * Return 0 for success, else error.
4434 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4436 struct _sas_node *sas_expander;
4437 Mpi2ConfigReply_t mpi_reply;
4438 Mpi2ExpanderPage0_t expander_pg0;
4439 Mpi2ExpanderPage1_t expander_pg1;
4440 Mpi2SasEnclosurePage0_t enclosure_pg0;
4443 u64 sas_address, sas_address_parent = 0;
4445 unsigned long flags;
4446 struct _sas_port *mpt3sas_port = NULL;
4453 if (ioc->shost_recovery || ioc->pci_error_recovery)
4456 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4457 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4458 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4459 ioc->name, __FILE__, __LINE__, __func__);
4463 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4464 MPI2_IOCSTATUS_MASK;
4465 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4466 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4467 ioc->name, __FILE__, __LINE__, __func__);
4471 /* handle out of order topology events */
4472 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4473 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4475 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4476 ioc->name, __FILE__, __LINE__, __func__);
4479 if (sas_address_parent != ioc->sas_hba.sas_address) {
4480 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4481 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4482 sas_address_parent);
4483 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4484 if (!sas_expander) {
4485 rc = _scsih_expander_add(ioc, parent_handle);
4491 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4492 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4493 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4495 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4500 sas_expander = kzalloc(sizeof(struct _sas_node),
4502 if (!sas_expander) {
4503 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4504 ioc->name, __FILE__, __LINE__, __func__);
4508 sas_expander->handle = handle;
4509 sas_expander->num_phys = expander_pg0.NumPhys;
4510 sas_expander->sas_address_parent = sas_address_parent;
4511 sas_expander->sas_address = sas_address;
4513 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4514 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4515 handle, parent_handle, (unsigned long long)
4516 sas_expander->sas_address, sas_expander->num_phys);
4518 if (!sas_expander->num_phys)
4520 sas_expander->phy = kcalloc(sas_expander->num_phys,
4521 sizeof(struct _sas_phy), GFP_KERNEL);
4522 if (!sas_expander->phy) {
4523 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4524 ioc->name, __FILE__, __LINE__, __func__);
4529 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4530 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4531 sas_address_parent);
4532 if (!mpt3sas_port) {
4533 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4534 ioc->name, __FILE__, __LINE__, __func__);
4538 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4540 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4541 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4542 &expander_pg1, i, handle))) {
4543 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4544 ioc->name, __FILE__, __LINE__, __func__);
4548 sas_expander->phy[i].handle = handle;
4549 sas_expander->phy[i].phy_id = i;
4551 if ((mpt3sas_transport_add_expander_phy(ioc,
4552 &sas_expander->phy[i], expander_pg1,
4553 sas_expander->parent_dev))) {
4554 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4555 ioc->name, __FILE__, __LINE__, __func__);
4561 if (sas_expander->enclosure_handle) {
4562 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4563 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4564 sas_expander->enclosure_handle)))
4565 sas_expander->enclosure_logical_id =
4566 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4569 _scsih_expander_node_add(ioc, sas_expander);
4575 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4576 sas_address_parent);
4577 kfree(sas_expander);
4582 * mpt3sas_expander_remove - removing expander object
4583 * @ioc: per adapter object
4584 * @sas_address: expander sas_address
4589 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4591 struct _sas_node *sas_expander;
4592 unsigned long flags;
4594 if (ioc->shost_recovery)
4597 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4598 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4601 list_del(&sas_expander->list);
4602 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4604 _scsih_expander_node_remove(ioc, sas_expander);
4608 * _scsih_done - internal SCSI_IO callback handler.
4609 * @ioc: per adapter object
4610 * @smid: system request message index
4611 * @msix_index: MSIX table index supplied by the OS
4612 * @reply: reply message frame(lower 32bit addr)
4614 * Callback handler when sending internal generated SCSI_IO.
4615 * The callback index passed is `ioc->scsih_cb_idx`
4617 * Return 1 meaning mf should be freed from _base_interrupt
4618 * 0 means the mf is freed from this function.
4621 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4623 MPI2DefaultReply_t *mpi_reply;
4625 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4626 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4628 if (ioc->scsih_cmds.smid != smid)
4630 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4632 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4633 mpi_reply->MsgLength*4);
4634 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4636 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4637 complete(&ioc->scsih_cmds.done);
4644 #define MPT3_MAX_LUNS (255)
4648 * _scsih_check_access_status - check access flags
4649 * @ioc: per adapter object
4650 * @sas_address: sas address
4651 * @handle: sas device handle
4652 * @access_flags: errors returned during discovery of the device
4654 * Return 0 for success, else failure
4657 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4658 u16 handle, u8 access_status)
4663 switch (access_status) {
4664 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4665 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4668 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4669 desc = "sata capability failed";
4671 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4672 desc = "sata affiliation conflict";
4674 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4675 desc = "route not addressable";
4677 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4678 desc = "smp error not addressable";
4680 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4681 desc = "device blocked";
4683 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4684 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4685 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4686 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4687 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4688 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4689 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4690 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4691 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4692 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4693 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4694 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4695 desc = "sata initialization failed";
4706 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4707 ioc->name, desc, (unsigned long long)sas_address, handle);
4712 * _scsih_check_device - checking device responsiveness
4713 * @ioc: per adapter object
4714 * @parent_sas_address: sas address of parent expander or sas host
4715 * @handle: attached device handle
4716 * @phy_numberv: phy number
4717 * @link_rate: new link rate
4722 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4723 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4725 Mpi2ConfigReply_t mpi_reply;
4726 Mpi2SasDevicePage0_t sas_device_pg0;
4727 struct _sas_device *sas_device;
4729 unsigned long flags;
4731 struct scsi_target *starget;
4732 struct MPT3SAS_TARGET *sas_target_priv_data;
4736 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4737 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4740 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4741 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4744 /* wide port handling ~ we need only handle device once for the phy that
4745 * is matched in sas device page zero
4747 if (phy_number != sas_device_pg0.PhyNum)
4750 /* check if this is end device */
4751 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4752 if (!(_scsih_is_end_device(device_info)))
4755 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4756 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4757 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4761 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4765 if (unlikely(sas_device->handle != handle)) {
4766 starget = sas_device->starget;
4767 sas_target_priv_data = starget->hostdata;
4768 starget_printk(KERN_INFO, starget,
4769 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4770 sas_device->handle, handle);
4771 sas_target_priv_data->handle = handle;
4772 sas_device->handle = handle;
4775 /* check if device is present */
4776 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4777 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4779 "device is not present handle(0x%04x), flags!!!\n",
4781 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4785 /* check if there were any issues with discovery */
4786 if (_scsih_check_access_status(ioc, sas_address, handle,
4787 sas_device_pg0.AccessStatus)) {
4788 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4792 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4793 _scsih_ublock_io_device(ioc, sas_address);
4798 * _scsih_add_device - creating sas device object
4799 * @ioc: per adapter object
4800 * @handle: sas device handle
4801 * @phy_num: phy number end device attached to
4802 * @is_pd: is this hidden raid component
4804 * Creating end device object, stored in ioc->sas_device_list.
4806 * Returns 0 for success, non-zero for failure.
4809 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4812 Mpi2ConfigReply_t mpi_reply;
4813 Mpi2SasDevicePage0_t sas_device_pg0;
4814 Mpi2SasEnclosurePage0_t enclosure_pg0;
4815 struct _sas_device *sas_device;
4819 unsigned long flags;
4821 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4822 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4823 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4824 ioc->name, __FILE__, __LINE__, __func__);
4828 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4829 MPI2_IOCSTATUS_MASK;
4830 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4831 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4832 ioc->name, __FILE__, __LINE__, __func__);
4836 /* check if this is end device */
4837 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4838 if (!(_scsih_is_end_device(device_info)))
4840 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4842 /* check if device is present */
4843 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4844 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4845 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4850 /* check if there were any issues with discovery */
4851 if (_scsih_check_access_status(ioc, sas_address, handle,
4852 sas_device_pg0.AccessStatus))
4855 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4856 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4858 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4863 sas_device = kzalloc(sizeof(struct _sas_device),
4866 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4867 ioc->name, __FILE__, __LINE__, __func__);
4871 sas_device->handle = handle;
4872 if (_scsih_get_sas_address(ioc,
4873 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4874 &sas_device->sas_address_parent) != 0)
4875 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4876 ioc->name, __FILE__, __LINE__, __func__);
4877 sas_device->enclosure_handle =
4878 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4880 le16_to_cpu(sas_device_pg0.Slot);
4881 sas_device->device_info = device_info;
4882 sas_device->sas_address = sas_address;
4883 sas_device->phy = sas_device_pg0.PhyNum;
4884 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
4885 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
4887 /* get enclosure_logical_id */
4888 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
4889 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4890 sas_device->enclosure_handle)))
4891 sas_device->enclosure_logical_id =
4892 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4894 /* get device name */
4895 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
4897 if (ioc->wait_for_discovery_to_complete)
4898 _scsih_sas_device_init_add(ioc, sas_device);
4900 _scsih_sas_device_add(ioc, sas_device);
4906 * _scsih_remove_device - removing sas device object
4907 * @ioc: per adapter object
4908 * @sas_device_delete: the sas_device object
4913 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
4914 struct _sas_device *sas_device)
4916 struct MPT3SAS_TARGET *sas_target_priv_data;
4918 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
4919 (sas_device->pfa_led_on)) {
4920 _scsih_turn_off_pfa_led(ioc, sas_device);
4921 sas_device->pfa_led_on = 0;
4923 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4924 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4925 ioc->name, __func__,
4926 sas_device->handle, (unsigned long long)
4927 sas_device->sas_address));
4929 if (sas_device->starget && sas_device->starget->hostdata) {
4930 sas_target_priv_data = sas_device->starget->hostdata;
4931 sas_target_priv_data->deleted = 1;
4932 _scsih_ublock_io_device(ioc, sas_device->sas_address);
4933 sas_target_priv_data->handle =
4934 MPT3SAS_INVALID_DEVICE_HANDLE;
4936 mpt3sas_transport_port_remove(ioc,
4937 sas_device->sas_address,
4938 sas_device->sas_address_parent);
4941 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4942 ioc->name, sas_device->handle,
4943 (unsigned long long) sas_device->sas_address);
4945 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4946 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4947 ioc->name, __func__,
4948 sas_device->handle, (unsigned long long)
4949 sas_device->sas_address));
4954 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4956 * _scsih_sas_topology_change_event_debug - debug for topology event
4957 * @ioc: per adapter object
4958 * @event_data: event data payload
4962 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
4963 Mpi2EventDataSasTopologyChangeList_t *event_data)
4969 char *status_str = NULL;
4970 u8 link_rate, prev_link_rate;
4972 switch (event_data->ExpStatus) {
4973 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
4976 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
4977 status_str = "remove";
4979 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
4981 status_str = "responding";
4983 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
4984 status_str = "remove delay";
4987 status_str = "unknown status";
4990 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
4991 ioc->name, status_str);
4992 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
4993 "start_phy(%02d), count(%d)\n",
4994 le16_to_cpu(event_data->ExpanderDevHandle),
4995 le16_to_cpu(event_data->EnclosureHandle),
4996 event_data->StartPhyNum, event_data->NumEntries);
4997 for (i = 0; i < event_data->NumEntries; i++) {
4998 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5001 phy_number = event_data->StartPhyNum + i;
5002 reason_code = event_data->PHY[i].PhyStatus &
5003 MPI2_EVENT_SAS_TOPO_RC_MASK;
5004 switch (reason_code) {
5005 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5006 status_str = "target add";
5008 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5009 status_str = "target remove";
5011 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5012 status_str = "delay target remove";
5014 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5015 status_str = "link rate change";
5017 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5018 status_str = "target responding";
5021 status_str = "unknown";
5024 link_rate = event_data->PHY[i].LinkRate >> 4;
5025 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5026 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5027 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5028 handle, status_str, link_rate, prev_link_rate);
5035 * _scsih_sas_topology_change_event - handle topology changes
5036 * @ioc: per adapter object
5037 * @fw_event: The fw_event_work object
5042 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5043 struct fw_event_work *fw_event)
5046 u16 parent_handle, handle;
5048 u8 phy_number, max_phys;
5049 struct _sas_node *sas_expander;
5051 unsigned long flags;
5052 u8 link_rate, prev_link_rate;
5053 Mpi2EventDataSasTopologyChangeList_t *event_data =
5054 (Mpi2EventDataSasTopologyChangeList_t *)
5055 fw_event->event_data;
5057 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5058 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5059 _scsih_sas_topology_change_event_debug(ioc, event_data);
5062 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5065 if (!ioc->sas_hba.num_phys)
5066 _scsih_sas_host_add(ioc);
5068 _scsih_sas_host_refresh(ioc);
5070 if (fw_event->ignore) {
5071 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5072 "ignoring expander event\n", ioc->name));
5076 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5078 /* handle expander add */
5079 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5080 if (_scsih_expander_add(ioc, parent_handle) != 0)
5083 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5084 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5087 sas_address = sas_expander->sas_address;
5088 max_phys = sas_expander->num_phys;
5089 } else if (parent_handle < ioc->sas_hba.num_phys) {
5090 sas_address = ioc->sas_hba.sas_address;
5091 max_phys = ioc->sas_hba.num_phys;
5093 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5096 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5098 /* handle siblings events */
5099 for (i = 0; i < event_data->NumEntries; i++) {
5100 if (fw_event->ignore) {
5101 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5102 "ignoring expander event\n", ioc->name));
5105 if (ioc->remove_host || ioc->pci_error_recovery)
5107 phy_number = event_data->StartPhyNum + i;
5108 if (phy_number >= max_phys)
5110 reason_code = event_data->PHY[i].PhyStatus &
5111 MPI2_EVENT_SAS_TOPO_RC_MASK;
5112 if ((event_data->PHY[i].PhyStatus &
5113 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5114 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5116 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5119 link_rate = event_data->PHY[i].LinkRate >> 4;
5120 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5121 switch (reason_code) {
5122 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5124 if (ioc->shost_recovery)
5127 if (link_rate == prev_link_rate)
5130 mpt3sas_transport_update_links(ioc, sas_address,
5131 handle, phy_number, link_rate);
5133 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5136 _scsih_check_device(ioc, sas_address, handle,
5137 phy_number, link_rate);
5140 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5142 if (ioc->shost_recovery)
5145 mpt3sas_transport_update_links(ioc, sas_address,
5146 handle, phy_number, link_rate);
5148 _scsih_add_device(ioc, handle, phy_number, 0);
5151 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5153 _scsih_device_remove_by_handle(ioc, handle);
5158 /* handle expander removal */
5159 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5161 mpt3sas_expander_remove(ioc, sas_address);
5166 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5168 * _scsih_sas_device_status_change_event_debug - debug for device event
5169 * @event_data: event data payload
5175 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5176 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5178 char *reason_str = NULL;
5180 switch (event_data->ReasonCode) {
5181 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5182 reason_str = "smart data";
5184 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5185 reason_str = "unsupported device discovered";
5187 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5188 reason_str = "internal device reset";
5190 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5191 reason_str = "internal task abort";
5193 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5194 reason_str = "internal task abort set";
5196 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5197 reason_str = "internal clear task set";
5199 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5200 reason_str = "internal query task";
5202 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5203 reason_str = "sata init failure";
5205 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5206 reason_str = "internal device reset complete";
5208 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5209 reason_str = "internal task abort complete";
5211 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5212 reason_str = "internal async notification";
5214 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5215 reason_str = "expander reduced functionality";
5217 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5218 reason_str = "expander reduced functionality complete";
5221 reason_str = "unknown reason";
5224 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5225 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5226 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5227 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5228 le16_to_cpu(event_data->TaskTag));
5229 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5230 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5231 event_data->ASC, event_data->ASCQ);
5237 * _scsih_sas_device_status_change_event - handle device status change
5238 * @ioc: per adapter object
5239 * @fw_event: The fw_event_work object
5245 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5246 struct fw_event_work *fw_event)
5248 struct MPT3SAS_TARGET *target_priv_data;
5249 struct _sas_device *sas_device;
5251 unsigned long flags;
5252 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5253 (Mpi2EventDataSasDeviceStatusChange_t *)
5254 fw_event->event_data;
5256 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5257 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5258 _scsih_sas_device_status_change_event_debug(ioc,
5262 /* In MPI Revision K (0xC), the internal device reset complete was
5263 * implemented, so avoid setting tm_busy flag for older firmware.
5265 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5268 if (event_data->ReasonCode !=
5269 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5270 event_data->ReasonCode !=
5271 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5274 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5275 sas_address = le64_to_cpu(event_data->SASAddress);
5276 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5279 if (!sas_device || !sas_device->starget) {
5280 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5284 target_priv_data = sas_device->starget->hostdata;
5285 if (!target_priv_data) {
5286 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5290 if (event_data->ReasonCode ==
5291 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5292 target_priv_data->tm_busy = 1;
5294 target_priv_data->tm_busy = 0;
5295 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5298 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5300 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5302 * @ioc: per adapter object
5303 * @event_data: event data payload
5309 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5310 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5312 char *reason_str = NULL;
5314 switch (event_data->ReasonCode) {
5315 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5316 reason_str = "enclosure add";
5318 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5319 reason_str = "enclosure remove";
5322 reason_str = "unknown reason";
5326 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5327 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5328 " number slots(%d)\n", ioc->name, reason_str,
5329 le16_to_cpu(event_data->EnclosureHandle),
5330 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5331 le16_to_cpu(event_data->StartSlot));
5336 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5337 * @ioc: per adapter object
5338 * @fw_event: The fw_event_work object
5344 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5345 struct fw_event_work *fw_event)
5347 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5348 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5349 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5350 (Mpi2EventDataSasEnclDevStatusChange_t *)
5351 fw_event->event_data);
5356 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5357 * @ioc: per adapter object
5358 * @fw_event: The fw_event_work object
5364 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5365 struct fw_event_work *fw_event)
5367 struct scsi_cmnd *scmd;
5368 struct scsi_device *sdev;
5371 struct MPT3SAS_DEVICE *sas_device_priv_data;
5372 u32 termination_count;
5374 Mpi2SCSITaskManagementReply_t *mpi_reply;
5375 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5376 (Mpi2EventDataSasBroadcastPrimitive_t *)
5377 fw_event->event_data;
5379 unsigned long flags;
5382 u8 task_abort_retries;
5384 mutex_lock(&ioc->tm_cmds.mutex);
5386 "%s: enter: phy number(%d), width(%d)\n",
5387 ioc->name, __func__, event_data->PhyNum,
5388 event_data->PortWidth);
5390 _scsih_block_io_all_device(ioc);
5392 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5393 mpi_reply = ioc->tm_cmds.reply;
5394 broadcast_aen_retry:
5396 /* sanity checks for retrying this loop */
5397 if (max_retries++ == 5) {
5398 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5399 ioc->name, __func__));
5401 } else if (max_retries > 1)
5402 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5403 ioc->name, __func__, max_retries - 1));
5405 termination_count = 0;
5407 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5408 if (ioc->shost_recovery)
5410 scmd = _scsih_scsi_lookup_get(ioc, smid);
5413 sdev = scmd->device;
5414 sas_device_priv_data = sdev->hostdata;
5415 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5417 /* skip hidden raid components */
5418 if (sas_device_priv_data->sas_target->flags &
5419 MPT_TARGET_FLAGS_RAID_COMPONENT)
5422 if (sas_device_priv_data->sas_target->flags &
5423 MPT_TARGET_FLAGS_VOLUME)
5426 handle = sas_device_priv_data->sas_target->handle;
5427 lun = sas_device_priv_data->lun;
5430 if (ioc->shost_recovery)
5433 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5434 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5435 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5438 sdev_printk(KERN_WARNING, sdev,
5439 "mpt3sas_scsih_issue_tm: FAILED when sending "
5440 "QUERY_TASK: scmd(%p)\n", scmd);
5441 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5442 goto broadcast_aen_retry;
5444 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5445 & MPI2_IOCSTATUS_MASK;
5446 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5447 sdev_printk(KERN_WARNING, sdev,
5448 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5450 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5451 goto broadcast_aen_retry;
5454 /* see if IO is still owned by IOC and target */
5455 if (mpi_reply->ResponseCode ==
5456 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5457 mpi_reply->ResponseCode ==
5458 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5459 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5462 task_abort_retries = 0;
5464 if (task_abort_retries++ == 60) {
5465 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5466 "%s: ABORT_TASK: giving up\n", ioc->name,
5468 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5469 goto broadcast_aen_retry;
5472 if (ioc->shost_recovery)
5475 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5476 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5479 sdev_printk(KERN_WARNING, sdev,
5480 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5481 "scmd(%p)\n", scmd);
5485 if (task_abort_retries > 1)
5486 sdev_printk(KERN_WARNING, sdev,
5487 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5489 task_abort_retries - 1, scmd);
5491 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5492 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5495 if (ioc->broadcast_aen_pending) {
5496 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5497 "%s: loop back due to pending AEN\n",
5498 ioc->name, __func__));
5499 ioc->broadcast_aen_pending = 0;
5500 goto broadcast_aen_retry;
5504 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5507 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5508 "%s - exit, query_count = %d termination_count = %d\n",
5509 ioc->name, __func__, query_count, termination_count));
5511 ioc->broadcast_aen_busy = 0;
5512 if (!ioc->shost_recovery)
5513 _scsih_ublock_io_all_device(ioc);
5514 mutex_unlock(&ioc->tm_cmds.mutex);
5518 * _scsih_sas_discovery_event - handle discovery events
5519 * @ioc: per adapter object
5520 * @fw_event: The fw_event_work object
5526 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5527 struct fw_event_work *fw_event)
5529 Mpi2EventDataSasDiscovery_t *event_data =
5530 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5532 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5533 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5534 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5535 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5537 if (event_data->DiscoveryStatus)
5538 pr_info("discovery_status(0x%08x)",
5539 le32_to_cpu(event_data->DiscoveryStatus));
5544 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5545 !ioc->sas_hba.num_phys) {
5546 if (disable_discovery > 0 && ioc->shost_recovery) {
5547 /* Wait for the reset to complete */
5548 while (ioc->shost_recovery)
5551 _scsih_sas_host_add(ioc);
5556 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5557 * @ioc: per adapter object
5558 * @handle: device handle for physical disk
5559 * @phys_disk_num: physical disk number
5561 * Return 0 for success, else failure.
5564 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5566 Mpi2RaidActionRequest_t *mpi_request;
5567 Mpi2RaidActionReply_t *mpi_reply;
5575 mutex_lock(&ioc->scsih_cmds.mutex);
5577 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5578 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5579 ioc->name, __func__);
5583 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5585 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5587 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5588 ioc->name, __func__);
5589 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5594 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5595 ioc->scsih_cmds.smid = smid;
5596 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5598 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5599 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5600 mpi_request->PhysDiskNum = phys_disk_num;
5602 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5603 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5604 handle, phys_disk_num));
5606 init_completion(&ioc->scsih_cmds.done);
5607 mpt3sas_base_put_smid_default(ioc, smid);
5608 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5610 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5611 pr_err(MPT3SAS_FMT "%s: timeout\n",
5612 ioc->name, __func__);
5613 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5619 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5621 mpi_reply = ioc->scsih_cmds.reply;
5622 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5623 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5624 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5627 ioc_status &= MPI2_IOCSTATUS_MASK;
5628 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5629 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5630 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5631 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5635 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5636 "IR RAID_ACTION: completed successfully\n",
5641 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5642 mutex_unlock(&ioc->scsih_cmds.mutex);
5645 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5651 * _scsih_reprobe_lun - reprobing lun
5652 * @sdev: scsi device struct
5653 * @no_uld_attach: sdev->no_uld_attach flag setting
5657 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5660 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5661 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5662 sdev->no_uld_attach ? "hidding" : "exposing");
5663 rc = scsi_device_reprobe(sdev);
5667 * _scsih_sas_volume_add - add new volume
5668 * @ioc: per adapter object
5669 * @element: IR config element data
5675 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5676 Mpi2EventIrConfigElement_t *element)
5678 struct _raid_device *raid_device;
5679 unsigned long flags;
5681 u16 handle = le16_to_cpu(element->VolDevHandle);
5684 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5687 "failure at %s:%d/%s()!\n", ioc->name,
5688 __FILE__, __LINE__, __func__);
5692 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5693 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5694 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5699 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5702 "failure at %s:%d/%s()!\n", ioc->name,
5703 __FILE__, __LINE__, __func__);
5707 raid_device->id = ioc->sas_id++;
5708 raid_device->channel = RAID_CHANNEL;
5709 raid_device->handle = handle;
5710 raid_device->wwid = wwid;
5711 _scsih_raid_device_add(ioc, raid_device);
5712 if (!ioc->wait_for_discovery_to_complete) {
5713 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5714 raid_device->id, 0);
5716 _scsih_raid_device_remove(ioc, raid_device);
5718 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5719 _scsih_determine_boot_device(ioc, raid_device, 1);
5720 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5725 * _scsih_sas_volume_delete - delete volume
5726 * @ioc: per adapter object
5727 * @handle: volume device handle
5733 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5735 struct _raid_device *raid_device;
5736 unsigned long flags;
5737 struct MPT3SAS_TARGET *sas_target_priv_data;
5738 struct scsi_target *starget = NULL;
5740 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5741 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5743 if (raid_device->starget) {
5744 starget = raid_device->starget;
5745 sas_target_priv_data = starget->hostdata;
5746 sas_target_priv_data->deleted = 1;
5748 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5749 ioc->name, raid_device->handle,
5750 (unsigned long long) raid_device->wwid);
5751 list_del(&raid_device->list);
5754 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5756 scsi_remove_target(&starget->dev);
5760 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5761 * @ioc: per adapter object
5762 * @element: IR config element data
5768 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5769 Mpi2EventIrConfigElement_t *element)
5771 struct _sas_device *sas_device;
5772 struct scsi_target *starget = NULL;
5773 struct MPT3SAS_TARGET *sas_target_priv_data;
5774 unsigned long flags;
5775 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5777 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5778 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5780 sas_device->volume_handle = 0;
5781 sas_device->volume_wwid = 0;
5782 clear_bit(handle, ioc->pd_handles);
5783 if (sas_device->starget && sas_device->starget->hostdata) {
5784 starget = sas_device->starget;
5785 sas_target_priv_data = starget->hostdata;
5786 sas_target_priv_data->flags &=
5787 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5790 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5794 /* exposing raid component */
5796 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5800 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5801 * @ioc: per adapter object
5802 * @element: IR config element data
5808 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5809 Mpi2EventIrConfigElement_t *element)
5811 struct _sas_device *sas_device;
5812 struct scsi_target *starget = NULL;
5813 struct MPT3SAS_TARGET *sas_target_priv_data;
5814 unsigned long flags;
5815 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5816 u16 volume_handle = 0;
5817 u64 volume_wwid = 0;
5819 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
5821 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
5824 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5825 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5827 set_bit(handle, ioc->pd_handles);
5828 if (sas_device->starget && sas_device->starget->hostdata) {
5829 starget = sas_device->starget;
5830 sas_target_priv_data = starget->hostdata;
5831 sas_target_priv_data->flags |=
5832 MPT_TARGET_FLAGS_RAID_COMPONENT;
5833 sas_device->volume_handle = volume_handle;
5834 sas_device->volume_wwid = volume_wwid;
5837 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5841 /* hiding raid component */
5842 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5844 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
5848 * _scsih_sas_pd_delete - delete pd component
5849 * @ioc: per adapter object
5850 * @element: IR config element data
5856 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
5857 Mpi2EventIrConfigElement_t *element)
5859 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5861 _scsih_device_remove_by_handle(ioc, handle);
5865 * _scsih_sas_pd_add - remove pd component
5866 * @ioc: per adapter object
5867 * @element: IR config element data
5873 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
5874 Mpi2EventIrConfigElement_t *element)
5876 struct _sas_device *sas_device;
5877 unsigned long flags;
5878 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5879 Mpi2ConfigReply_t mpi_reply;
5880 Mpi2SasDevicePage0_t sas_device_pg0;
5885 set_bit(handle, ioc->pd_handles);
5887 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5888 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5889 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5891 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5895 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5896 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5897 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5898 ioc->name, __FILE__, __LINE__, __func__);
5902 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5903 MPI2_IOCSTATUS_MASK;
5904 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5905 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5906 ioc->name, __FILE__, __LINE__, __func__);
5910 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5911 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5912 mpt3sas_transport_update_links(ioc, sas_address, handle,
5913 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5915 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5916 _scsih_add_device(ioc, handle, 0, 1);
5919 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5921 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5922 * @ioc: per adapter object
5923 * @event_data: event data payload
5929 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5930 Mpi2EventDataIrConfigChangeList_t *event_data)
5932 Mpi2EventIrConfigElement_t *element;
5935 char *reason_str = NULL, *element_str = NULL;
5937 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5939 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
5940 ioc->name, (le32_to_cpu(event_data->Flags) &
5941 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5942 "foreign" : "native", event_data->NumElements);
5943 for (i = 0; i < event_data->NumElements; i++, element++) {
5944 switch (element->ReasonCode) {
5945 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5948 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5949 reason_str = "remove";
5951 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5952 reason_str = "no change";
5954 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5955 reason_str = "hide";
5957 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5958 reason_str = "unhide";
5960 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5961 reason_str = "volume_created";
5963 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
5964 reason_str = "volume_deleted";
5966 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
5967 reason_str = "pd_created";
5969 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
5970 reason_str = "pd_deleted";
5973 reason_str = "unknown reason";
5976 element_type = le16_to_cpu(element->ElementFlags) &
5977 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
5978 switch (element_type) {
5979 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
5980 element_str = "volume";
5982 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
5983 element_str = "phys disk";
5985 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
5986 element_str = "hot spare";
5989 element_str = "unknown element";
5992 pr_info("\t(%s:%s), vol handle(0x%04x), " \
5993 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
5994 reason_str, le16_to_cpu(element->VolDevHandle),
5995 le16_to_cpu(element->PhysDiskDevHandle),
5996 element->PhysDiskNum);
6002 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6003 * @ioc: per adapter object
6004 * @fw_event: The fw_event_work object
6010 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6011 struct fw_event_work *fw_event)
6013 Mpi2EventIrConfigElement_t *element;
6016 Mpi2EventDataIrConfigChangeList_t *event_data =
6017 (Mpi2EventDataIrConfigChangeList_t *)
6018 fw_event->event_data;
6020 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6021 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6022 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6026 foreign_config = (le32_to_cpu(event_data->Flags) &
6027 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6029 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6030 if (ioc->shost_recovery) {
6032 for (i = 0; i < event_data->NumElements; i++, element++) {
6033 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6034 _scsih_ir_fastpath(ioc,
6035 le16_to_cpu(element->PhysDiskDevHandle),
6036 element->PhysDiskNum);
6040 for (i = 0; i < event_data->NumElements; i++, element++) {
6042 switch (element->ReasonCode) {
6043 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6044 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6045 if (!foreign_config)
6046 _scsih_sas_volume_add(ioc, element);
6048 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6049 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6050 if (!foreign_config)
6051 _scsih_sas_volume_delete(ioc,
6052 le16_to_cpu(element->VolDevHandle));
6054 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6055 _scsih_sas_pd_hide(ioc, element);
6057 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6058 _scsih_sas_pd_expose(ioc, element);
6060 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6061 _scsih_sas_pd_add(ioc, element);
6063 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6064 _scsih_sas_pd_delete(ioc, element);
6071 * _scsih_sas_ir_volume_event - IR volume event
6072 * @ioc: per adapter object
6073 * @fw_event: The fw_event_work object
6079 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6080 struct fw_event_work *fw_event)
6083 unsigned long flags;
6084 struct _raid_device *raid_device;
6088 Mpi2EventDataIrVolume_t *event_data =
6089 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6091 if (ioc->shost_recovery)
6094 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6097 handle = le16_to_cpu(event_data->VolDevHandle);
6098 state = le32_to_cpu(event_data->NewValue);
6099 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6100 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6101 ioc->name, __func__, handle,
6102 le32_to_cpu(event_data->PreviousValue), state));
6104 case MPI2_RAID_VOL_STATE_MISSING:
6105 case MPI2_RAID_VOL_STATE_FAILED:
6106 _scsih_sas_volume_delete(ioc, handle);
6109 case MPI2_RAID_VOL_STATE_ONLINE:
6110 case MPI2_RAID_VOL_STATE_DEGRADED:
6111 case MPI2_RAID_VOL_STATE_OPTIMAL:
6113 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6114 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6115 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6120 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6123 "failure at %s:%d/%s()!\n", ioc->name,
6124 __FILE__, __LINE__, __func__);
6128 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6131 "failure at %s:%d/%s()!\n", ioc->name,
6132 __FILE__, __LINE__, __func__);
6136 raid_device->id = ioc->sas_id++;
6137 raid_device->channel = RAID_CHANNEL;
6138 raid_device->handle = handle;
6139 raid_device->wwid = wwid;
6140 _scsih_raid_device_add(ioc, raid_device);
6141 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6142 raid_device->id, 0);
6144 _scsih_raid_device_remove(ioc, raid_device);
6147 case MPI2_RAID_VOL_STATE_INITIALIZING:
6154 * _scsih_sas_ir_physical_disk_event - PD event
6155 * @ioc: per adapter object
6156 * @fw_event: The fw_event_work object
6162 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6163 struct fw_event_work *fw_event)
6165 u16 handle, parent_handle;
6167 struct _sas_device *sas_device;
6168 unsigned long flags;
6169 Mpi2ConfigReply_t mpi_reply;
6170 Mpi2SasDevicePage0_t sas_device_pg0;
6172 Mpi2EventDataIrPhysicalDisk_t *event_data =
6173 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6176 if (ioc->shost_recovery)
6179 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6182 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6183 state = le32_to_cpu(event_data->NewValue);
6185 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6186 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6187 ioc->name, __func__, handle,
6188 le32_to_cpu(event_data->PreviousValue), state));
6190 case MPI2_RAID_PD_STATE_ONLINE:
6191 case MPI2_RAID_PD_STATE_DEGRADED:
6192 case MPI2_RAID_PD_STATE_REBUILDING:
6193 case MPI2_RAID_PD_STATE_OPTIMAL:
6194 case MPI2_RAID_PD_STATE_HOT_SPARE:
6196 set_bit(handle, ioc->pd_handles);
6197 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6198 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6199 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6204 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6205 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6207 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6208 ioc->name, __FILE__, __LINE__, __func__);
6212 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6213 MPI2_IOCSTATUS_MASK;
6214 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6215 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6216 ioc->name, __FILE__, __LINE__, __func__);
6220 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6221 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6222 mpt3sas_transport_update_links(ioc, sas_address, handle,
6223 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6225 _scsih_add_device(ioc, handle, 0, 1);
6229 case MPI2_RAID_PD_STATE_OFFLINE:
6230 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6231 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6237 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6239 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6240 * @ioc: per adapter object
6241 * @event_data: event data payload
6247 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6248 Mpi2EventDataIrOperationStatus_t *event_data)
6250 char *reason_str = NULL;
6252 switch (event_data->RAIDOperation) {
6253 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6254 reason_str = "resync";
6256 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6257 reason_str = "online capacity expansion";
6259 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6260 reason_str = "consistency check";
6262 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6263 reason_str = "background init";
6265 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6266 reason_str = "make data consistent";
6273 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6274 "\thandle(0x%04x), percent complete(%d)\n",
6275 ioc->name, reason_str,
6276 le16_to_cpu(event_data->VolDevHandle),
6277 event_data->PercentComplete);
6282 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6283 * @ioc: per adapter object
6284 * @fw_event: The fw_event_work object
6290 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6291 struct fw_event_work *fw_event)
6293 Mpi2EventDataIrOperationStatus_t *event_data =
6294 (Mpi2EventDataIrOperationStatus_t *)
6295 fw_event->event_data;
6296 static struct _raid_device *raid_device;
6297 unsigned long flags;
6300 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6301 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6302 _scsih_sas_ir_operation_status_event_debug(ioc,
6306 /* code added for raid transport support */
6307 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6309 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6310 handle = le16_to_cpu(event_data->VolDevHandle);
6311 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6313 raid_device->percent_complete =
6314 event_data->PercentComplete;
6315 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6320 * _scsih_prep_device_scan - initialize parameters prior to device scan
6321 * @ioc: per adapter object
6323 * Set the deleted flag prior to device scan. If the device is found during
6324 * the scan, then we clear the deleted flag.
6327 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6329 struct MPT3SAS_DEVICE *sas_device_priv_data;
6330 struct scsi_device *sdev;
6332 shost_for_each_device(sdev, ioc->shost) {
6333 sas_device_priv_data = sdev->hostdata;
6334 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6335 sas_device_priv_data->sas_target->deleted = 1;
6340 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6341 * @ioc: per adapter object
6342 * @sas_address: sas address
6343 * @slot: enclosure slot id
6344 * @handle: device handle
6346 * After host reset, find out whether devices are still responding.
6347 * Used in _scsih_remove_unresponsive_sas_devices.
6352 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6353 u16 slot, u16 handle)
6355 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6356 struct scsi_target *starget;
6357 struct _sas_device *sas_device;
6358 unsigned long flags;
6360 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6361 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6362 if (sas_device->sas_address == sas_address &&
6363 sas_device->slot == slot) {
6364 sas_device->responding = 1;
6365 starget = sas_device->starget;
6366 if (starget && starget->hostdata) {
6367 sas_target_priv_data = starget->hostdata;
6368 sas_target_priv_data->tm_busy = 0;
6369 sas_target_priv_data->deleted = 0;
6371 sas_target_priv_data = NULL;
6373 starget_printk(KERN_INFO, starget,
6374 "handle(0x%04x), sas_addr(0x%016llx), "
6375 "enclosure logical id(0x%016llx), "
6376 "slot(%d)\n", handle,
6377 (unsigned long long)sas_device->sas_address,
6378 (unsigned long long)
6379 sas_device->enclosure_logical_id,
6381 if (sas_device->handle == handle)
6383 pr_info("\thandle changed from(0x%04x)!!!\n",
6384 sas_device->handle);
6385 sas_device->handle = handle;
6386 if (sas_target_priv_data)
6387 sas_target_priv_data->handle = handle;
6392 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6396 * _scsih_search_responding_sas_devices -
6397 * @ioc: per adapter object
6399 * After host reset, find out whether devices are still responding.
6405 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6407 Mpi2SasDevicePage0_t sas_device_pg0;
6408 Mpi2ConfigReply_t mpi_reply;
6413 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6415 if (list_empty(&ioc->sas_device_list))
6419 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6420 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6422 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6423 MPI2_IOCSTATUS_MASK;
6424 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6426 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6427 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6428 if (!(_scsih_is_end_device(device_info)))
6430 _scsih_mark_responding_sas_device(ioc,
6431 le64_to_cpu(sas_device_pg0.SASAddress),
6432 le16_to_cpu(sas_device_pg0.Slot), handle);
6436 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6441 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6442 * @ioc: per adapter object
6443 * @wwid: world wide identifier for raid volume
6444 * @handle: device handle
6446 * After host reset, find out whether devices are still responding.
6447 * Used in _scsih_remove_unresponsive_raid_devices.
6452 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6455 struct MPT3SAS_TARGET *sas_target_priv_data;
6456 struct scsi_target *starget;
6457 struct _raid_device *raid_device;
6458 unsigned long flags;
6460 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6461 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6462 if (raid_device->wwid == wwid && raid_device->starget) {
6463 starget = raid_device->starget;
6464 if (starget && starget->hostdata) {
6465 sas_target_priv_data = starget->hostdata;
6466 sas_target_priv_data->deleted = 0;
6468 sas_target_priv_data = NULL;
6469 raid_device->responding = 1;
6470 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6471 starget_printk(KERN_INFO, raid_device->starget,
6472 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6473 (unsigned long long)raid_device->wwid);
6474 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6475 if (raid_device->handle == handle) {
6476 spin_unlock_irqrestore(&ioc->raid_device_lock,
6480 pr_info("\thandle changed from(0x%04x)!!!\n",
6481 raid_device->handle);
6482 raid_device->handle = handle;
6483 if (sas_target_priv_data)
6484 sas_target_priv_data->handle = handle;
6485 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6489 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6493 * _scsih_search_responding_raid_devices -
6494 * @ioc: per adapter object
6496 * After host reset, find out whether devices are still responding.
6502 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6504 Mpi2RaidVolPage1_t volume_pg1;
6505 Mpi2RaidVolPage0_t volume_pg0;
6506 Mpi2RaidPhysDiskPage0_t pd_pg0;
6507 Mpi2ConfigReply_t mpi_reply;
6512 if (!ioc->ir_firmware)
6515 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6518 if (list_empty(&ioc->raid_device_list))
6522 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6523 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6524 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6525 MPI2_IOCSTATUS_MASK;
6526 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6528 handle = le16_to_cpu(volume_pg1.DevHandle);
6530 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6531 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6532 sizeof(Mpi2RaidVolPage0_t)))
6535 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6536 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6537 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6538 _scsih_mark_responding_raid_device(ioc,
6539 le64_to_cpu(volume_pg1.WWID), handle);
6542 /* refresh the pd_handles */
6543 phys_disk_num = 0xFF;
6544 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6545 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6546 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6548 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6549 MPI2_IOCSTATUS_MASK;
6550 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6552 phys_disk_num = pd_pg0.PhysDiskNum;
6553 handle = le16_to_cpu(pd_pg0.DevHandle);
6554 set_bit(handle, ioc->pd_handles);
6557 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6562 * _scsih_mark_responding_expander - mark a expander as responding
6563 * @ioc: per adapter object
6564 * @sas_address: sas address
6567 * After host reset, find out whether devices are still responding.
6568 * Used in _scsih_remove_unresponsive_expanders.
6573 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6576 struct _sas_node *sas_expander;
6577 unsigned long flags;
6580 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6581 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6582 if (sas_expander->sas_address != sas_address)
6584 sas_expander->responding = 1;
6585 if (sas_expander->handle == handle)
6587 pr_info("\texpander(0x%016llx): handle changed" \
6588 " from(0x%04x) to (0x%04x)!!!\n",
6589 (unsigned long long)sas_expander->sas_address,
6590 sas_expander->handle, handle);
6591 sas_expander->handle = handle;
6592 for (i = 0 ; i < sas_expander->num_phys ; i++)
6593 sas_expander->phy[i].handle = handle;
6597 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6601 * _scsih_search_responding_expanders -
6602 * @ioc: per adapter object
6604 * After host reset, find out whether devices are still responding.
6610 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6612 Mpi2ExpanderPage0_t expander_pg0;
6613 Mpi2ConfigReply_t mpi_reply;
6618 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6620 if (list_empty(&ioc->sas_expander_list))
6624 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6625 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6627 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6628 MPI2_IOCSTATUS_MASK;
6629 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6632 handle = le16_to_cpu(expander_pg0.DevHandle);
6633 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6634 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6636 (unsigned long long)sas_address);
6637 _scsih_mark_responding_expander(ioc, sas_address, handle);
6641 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6645 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6646 * @ioc: per adapter object
6651 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6653 struct _sas_device *sas_device, *sas_device_next;
6654 struct _sas_node *sas_expander, *sas_expander_next;
6655 struct _raid_device *raid_device, *raid_device_next;
6656 struct list_head tmp_list;
6657 unsigned long flags;
6659 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6662 /* removing unresponding end devices */
6663 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6665 list_for_each_entry_safe(sas_device, sas_device_next,
6666 &ioc->sas_device_list, list) {
6667 if (!sas_device->responding)
6668 mpt3sas_device_remove_by_sas_address(ioc,
6669 sas_device->sas_address);
6671 sas_device->responding = 0;
6674 /* removing unresponding volumes */
6675 if (ioc->ir_firmware) {
6676 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6678 list_for_each_entry_safe(raid_device, raid_device_next,
6679 &ioc->raid_device_list, list) {
6680 if (!raid_device->responding)
6681 _scsih_sas_volume_delete(ioc,
6682 raid_device->handle);
6684 raid_device->responding = 0;
6688 /* removing unresponding expanders */
6689 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6691 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6692 INIT_LIST_HEAD(&tmp_list);
6693 list_for_each_entry_safe(sas_expander, sas_expander_next,
6694 &ioc->sas_expander_list, list) {
6695 if (!sas_expander->responding)
6696 list_move_tail(&sas_expander->list, &tmp_list);
6698 sas_expander->responding = 0;
6700 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6701 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6703 list_del(&sas_expander->list);
6704 _scsih_expander_node_remove(ioc, sas_expander);
6707 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6710 /* unblock devices */
6711 _scsih_ublock_io_all_device(ioc);
6715 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6716 struct _sas_node *sas_expander, u16 handle)
6718 Mpi2ExpanderPage1_t expander_pg1;
6719 Mpi2ConfigReply_t mpi_reply;
6722 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6723 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6724 &expander_pg1, i, handle))) {
6725 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6726 ioc->name, __FILE__, __LINE__, __func__);
6730 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6731 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6732 expander_pg1.NegotiatedLinkRate >> 4);
6737 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6738 * @ioc: per adapter object
6743 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6745 Mpi2ExpanderPage0_t expander_pg0;
6746 Mpi2SasDevicePage0_t sas_device_pg0;
6747 Mpi2RaidVolPage1_t volume_pg1;
6748 Mpi2RaidVolPage0_t volume_pg0;
6749 Mpi2RaidPhysDiskPage0_t pd_pg0;
6750 Mpi2EventIrConfigElement_t element;
6751 Mpi2ConfigReply_t mpi_reply;
6754 u16 handle, parent_handle;
6756 struct _sas_device *sas_device;
6757 struct _sas_node *expander_device;
6758 static struct _raid_device *raid_device;
6760 unsigned long flags;
6762 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6764 _scsih_sas_host_refresh(ioc);
6766 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6770 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6771 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6772 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6773 MPI2_IOCSTATUS_MASK;
6774 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6775 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6776 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6777 ioc->name, ioc_status,
6778 le32_to_cpu(mpi_reply.IOCLogInfo));
6781 handle = le16_to_cpu(expander_pg0.DevHandle);
6782 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6783 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6784 ioc, le64_to_cpu(expander_pg0.SASAddress));
6785 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6786 if (expander_device)
6787 _scsih_refresh_expander_links(ioc, expander_device,
6790 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6791 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6792 handle, (unsigned long long)
6793 le64_to_cpu(expander_pg0.SASAddress));
6794 _scsih_expander_add(ioc, handle);
6795 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6796 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6797 handle, (unsigned long long)
6798 le64_to_cpu(expander_pg0.SASAddress));
6802 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6805 if (!ioc->ir_firmware)
6808 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6811 phys_disk_num = 0xFF;
6812 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6813 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6815 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6816 MPI2_IOCSTATUS_MASK;
6817 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6818 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
6819 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6820 ioc->name, ioc_status,
6821 le32_to_cpu(mpi_reply.IOCLogInfo));
6824 phys_disk_num = pd_pg0.PhysDiskNum;
6825 handle = le16_to_cpu(pd_pg0.DevHandle);
6826 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6827 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6828 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6831 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6832 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6835 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6836 MPI2_IOCSTATUS_MASK;
6837 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6838 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
6839 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6840 ioc->name, ioc_status,
6841 le32_to_cpu(mpi_reply.IOCLogInfo));
6844 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6845 if (!_scsih_get_sas_address(ioc, parent_handle,
6847 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
6848 " handle (0x%04x), sas_addr(0x%016llx)\n",
6849 ioc->name, handle, (unsigned long long)
6850 le64_to_cpu(sas_device_pg0.SASAddress));
6851 mpt3sas_transport_update_links(ioc, sas_address,
6852 handle, sas_device_pg0.PhyNum,
6853 MPI2_SAS_NEG_LINK_RATE_1_5);
6854 set_bit(handle, ioc->pd_handles);
6856 /* This will retry adding the end device.
6857 * _scsih_add_device() will decide on retries and
6858 * return "1" when it should be retried
6860 while (_scsih_add_device(ioc, handle, retry_count++,
6864 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
6865 " handle (0x%04x), sas_addr(0x%016llx)\n",
6866 ioc->name, handle, (unsigned long long)
6867 le64_to_cpu(sas_device_pg0.SASAddress));
6871 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
6874 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
6878 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6879 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6880 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6881 MPI2_IOCSTATUS_MASK;
6882 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6883 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6884 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6885 ioc->name, ioc_status,
6886 le32_to_cpu(mpi_reply.IOCLogInfo));
6889 handle = le16_to_cpu(volume_pg1.DevHandle);
6890 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6891 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6892 le64_to_cpu(volume_pg1.WWID));
6893 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6896 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6897 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6898 sizeof(Mpi2RaidVolPage0_t)))
6900 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6901 MPI2_IOCSTATUS_MASK;
6902 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6903 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6904 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6905 ioc->name, ioc_status,
6906 le32_to_cpu(mpi_reply.IOCLogInfo));
6909 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6910 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6911 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6912 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6913 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6914 element.VolDevHandle = volume_pg1.DevHandle;
6916 "\tBEFORE adding volume: handle (0x%04x)\n",
6917 ioc->name, volume_pg1.DevHandle);
6918 _scsih_sas_volume_add(ioc, &element);
6920 "\tAFTER adding volume: handle (0x%04x)\n",
6921 ioc->name, volume_pg1.DevHandle);
6925 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
6930 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
6935 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6936 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6938 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6939 MPI2_IOCSTATUS_MASK;
6940 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6941 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
6942 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6943 ioc->name, ioc_status,
6944 le32_to_cpu(mpi_reply.IOCLogInfo));
6947 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6948 if (!(_scsih_is_end_device(
6949 le32_to_cpu(sas_device_pg0.DeviceInfo))))
6951 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6952 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
6953 le64_to_cpu(sas_device_pg0.SASAddress));
6954 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6957 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6958 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
6959 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
6960 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6961 handle, (unsigned long long)
6962 le64_to_cpu(sas_device_pg0.SASAddress));
6963 mpt3sas_transport_update_links(ioc, sas_address, handle,
6964 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6966 /* This will retry adding the end device.
6967 * _scsih_add_device() will decide on retries and
6968 * return "1" when it should be retried
6970 while (_scsih_add_device(ioc, handle, retry_count++,
6974 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
6975 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6976 handle, (unsigned long long)
6977 le64_to_cpu(sas_device_pg0.SASAddress));
6980 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
6983 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
6986 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
6987 * @ioc: per adapter object
6988 * @reset_phase: phase
6990 * The handler for doing any required cleanup or initialization.
6992 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
6993 * MPT3_IOC_DONE_RESET
6998 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7000 switch (reset_phase) {
7001 case MPT3_IOC_PRE_RESET:
7002 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7003 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7005 case MPT3_IOC_AFTER_RESET:
7006 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7007 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7008 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7009 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7010 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7011 complete(&ioc->scsih_cmds.done);
7013 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7014 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7015 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7016 complete(&ioc->tm_cmds.done);
7019 _scsih_fw_event_cleanup_queue(ioc);
7020 _scsih_flush_running_cmds(ioc);
7022 case MPT3_IOC_DONE_RESET:
7023 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7024 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7025 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7026 !ioc->sas_hba.num_phys)) {
7027 _scsih_prep_device_scan(ioc);
7028 _scsih_search_responding_sas_devices(ioc);
7029 _scsih_search_responding_raid_devices(ioc);
7030 _scsih_search_responding_expanders(ioc);
7031 _scsih_error_recovery_delete_devices(ioc);
7038 * _mpt3sas_fw_work - delayed task for processing firmware events
7039 * @ioc: per adapter object
7040 * @fw_event: The fw_event_work object
7046 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7048 /* the queue is being flushed so ignore this event */
7049 if (ioc->remove_host ||
7050 ioc->pci_error_recovery) {
7051 _scsih_fw_event_free(ioc, fw_event);
7055 switch (fw_event->event) {
7056 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7057 mpt3sas_process_trigger_data(ioc,
7058 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7059 fw_event->event_data);
7061 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7062 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7064 _scsih_remove_unresponding_sas_devices(ioc);
7065 _scsih_scan_for_devices_after_reset(ioc);
7067 case MPT3SAS_PORT_ENABLE_COMPLETE:
7068 ioc->start_scan = 0;
7069 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7070 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7072 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7073 "port enable: complete from worker thread\n",
7076 case MPT3SAS_TURN_ON_PFA_LED:
7077 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7079 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7080 _scsih_sas_topology_change_event(ioc, fw_event);
7082 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7083 _scsih_sas_device_status_change_event(ioc, fw_event);
7085 case MPI2_EVENT_SAS_DISCOVERY:
7086 _scsih_sas_discovery_event(ioc, fw_event);
7088 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7089 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7091 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7092 _scsih_sas_enclosure_dev_status_change_event(ioc,
7095 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7096 _scsih_sas_ir_config_change_event(ioc, fw_event);
7098 case MPI2_EVENT_IR_VOLUME:
7099 _scsih_sas_ir_volume_event(ioc, fw_event);
7101 case MPI2_EVENT_IR_PHYSICAL_DISK:
7102 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7104 case MPI2_EVENT_IR_OPERATION_STATUS:
7105 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7108 _scsih_fw_event_free(ioc, fw_event);
7112 * _firmware_event_work
7113 * @ioc: per adapter object
7114 * @work: The fw_event_work object
7117 * wrappers for the work thread handling firmware events
7123 _firmware_event_work(struct work_struct *work)
7125 struct fw_event_work *fw_event = container_of(work,
7126 struct fw_event_work, work);
7128 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7132 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7133 * @ioc: per adapter object
7134 * @msix_index: MSIX table index supplied by the OS
7135 * @reply: reply message frame(lower 32bit addr)
7136 * Context: interrupt.
7138 * This function merely adds a new work task into ioc->firmware_event_thread.
7139 * The tasks are worked from _firmware_event_work in user context.
7141 * Return 1 meaning mf should be freed from _base_interrupt
7142 * 0 means the mf is freed from this function.
7145 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7148 struct fw_event_work *fw_event;
7149 Mpi2EventNotificationReply_t *mpi_reply;
7153 /* events turned off due to host reset or driver unloading */
7154 if (ioc->remove_host || ioc->pci_error_recovery)
7157 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7159 if (unlikely(!mpi_reply)) {
7160 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7161 ioc->name, __FILE__, __LINE__, __func__);
7165 event = le16_to_cpu(mpi_reply->Event);
7167 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7168 mpt3sas_trigger_event(ioc, event, 0);
7172 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7174 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7175 (Mpi2EventDataSasBroadcastPrimitive_t *)
7176 mpi_reply->EventData;
7178 if (baen_data->Primitive !=
7179 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7182 if (ioc->broadcast_aen_busy) {
7183 ioc->broadcast_aen_pending++;
7186 ioc->broadcast_aen_busy = 1;
7190 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7191 _scsih_check_topo_delete_events(ioc,
7192 (Mpi2EventDataSasTopologyChangeList_t *)
7193 mpi_reply->EventData);
7195 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7196 _scsih_check_ir_config_unhide_events(ioc,
7197 (Mpi2EventDataIrConfigChangeList_t *)
7198 mpi_reply->EventData);
7200 case MPI2_EVENT_IR_VOLUME:
7201 _scsih_check_volume_delete_events(ioc,
7202 (Mpi2EventDataIrVolume_t *)
7203 mpi_reply->EventData);
7206 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7207 case MPI2_EVENT_IR_OPERATION_STATUS:
7208 case MPI2_EVENT_SAS_DISCOVERY:
7209 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7210 case MPI2_EVENT_IR_PHYSICAL_DISK:
7213 default: /* ignore the rest */
7217 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7218 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7220 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7221 ioc->name, __FILE__, __LINE__, __func__);
7225 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7226 fw_event->ioc = ioc;
7227 fw_event->VF_ID = mpi_reply->VF_ID;
7228 fw_event->VP_ID = mpi_reply->VP_ID;
7229 fw_event->event = event;
7230 _scsih_fw_event_add(ioc, fw_event);
7234 /* shost template */
7235 static struct scsi_host_template scsih_driver_template = {
7236 .module = THIS_MODULE,
7237 .name = "Fusion MPT SAS Host",
7238 .proc_name = MPT3SAS_DRIVER_NAME,
7239 .queuecommand = _scsih_qcmd,
7240 .target_alloc = _scsih_target_alloc,
7241 .slave_alloc = _scsih_slave_alloc,
7242 .slave_configure = _scsih_slave_configure,
7243 .target_destroy = _scsih_target_destroy,
7244 .slave_destroy = _scsih_slave_destroy,
7245 .scan_finished = _scsih_scan_finished,
7246 .scan_start = _scsih_scan_start,
7247 .change_queue_depth = _scsih_change_queue_depth,
7248 .change_queue_type = scsi_change_queue_type,
7249 .eh_abort_handler = _scsih_abort,
7250 .eh_device_reset_handler = _scsih_dev_reset,
7251 .eh_target_reset_handler = _scsih_target_reset,
7252 .eh_host_reset_handler = _scsih_host_reset,
7253 .bios_param = _scsih_bios_param,
7256 .sg_tablesize = MPT3SAS_SG_DEPTH,
7257 .max_sectors = 32767,
7259 .use_clustering = ENABLE_CLUSTERING,
7260 .shost_attrs = mpt3sas_host_attrs,
7261 .sdev_attrs = mpt3sas_dev_attrs,
7262 .track_queue_depth = 1,
7266 * _scsih_expander_node_remove - removing expander device from list.
7267 * @ioc: per adapter object
7268 * @sas_expander: the sas_device object
7269 * Context: Calling function should acquire ioc->sas_node_lock.
7271 * Removing object and freeing associated memory from the
7272 * ioc->sas_expander_list.
7277 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7278 struct _sas_node *sas_expander)
7280 struct _sas_port *mpt3sas_port, *next;
7282 /* remove sibling ports attached to this expander */
7283 list_for_each_entry_safe(mpt3sas_port, next,
7284 &sas_expander->sas_port_list, port_list) {
7285 if (ioc->shost_recovery)
7287 if (mpt3sas_port->remote_identify.device_type ==
7289 mpt3sas_device_remove_by_sas_address(ioc,
7290 mpt3sas_port->remote_identify.sas_address);
7291 else if (mpt3sas_port->remote_identify.device_type ==
7292 SAS_EDGE_EXPANDER_DEVICE ||
7293 mpt3sas_port->remote_identify.device_type ==
7294 SAS_FANOUT_EXPANDER_DEVICE)
7295 mpt3sas_expander_remove(ioc,
7296 mpt3sas_port->remote_identify.sas_address);
7299 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7300 sas_expander->sas_address_parent);
7303 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7305 sas_expander->handle, (unsigned long long)
7306 sas_expander->sas_address);
7308 kfree(sas_expander->phy);
7309 kfree(sas_expander);
7313 * _scsih_ir_shutdown - IR shutdown notification
7314 * @ioc: per adapter object
7316 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7317 * the host system is shutting down.
7322 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7324 Mpi2RaidActionRequest_t *mpi_request;
7325 Mpi2RaidActionReply_t *mpi_reply;
7328 /* is IR firmware build loaded ? */
7329 if (!ioc->ir_firmware)
7332 /* are there any volumes ? */
7333 if (list_empty(&ioc->raid_device_list))
7336 mutex_lock(&ioc->scsih_cmds.mutex);
7338 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7339 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7340 ioc->name, __func__);
7343 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7345 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7347 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7348 ioc->name, __func__);
7349 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7353 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7354 ioc->scsih_cmds.smid = smid;
7355 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7357 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7358 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7360 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7361 init_completion(&ioc->scsih_cmds.done);
7362 mpt3sas_base_put_smid_default(ioc, smid);
7363 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7365 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7366 pr_err(MPT3SAS_FMT "%s: timeout\n",
7367 ioc->name, __func__);
7371 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7372 mpi_reply = ioc->scsih_cmds.reply;
7374 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7375 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7376 le32_to_cpu(mpi_reply->IOCLogInfo));
7380 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7381 mutex_unlock(&ioc->scsih_cmds.mutex);
7385 * _scsih_remove - detach and remove add host
7386 * @pdev: PCI device struct
7388 * Routine called when unloading the driver.
7391 static void _scsih_remove(struct pci_dev *pdev)
7393 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7394 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7395 struct _sas_port *mpt3sas_port, *next_port;
7396 struct _raid_device *raid_device, *next;
7397 struct MPT3SAS_TARGET *sas_target_priv_data;
7398 struct workqueue_struct *wq;
7399 unsigned long flags;
7401 ioc->remove_host = 1;
7402 _scsih_fw_event_cleanup_queue(ioc);
7404 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7405 wq = ioc->firmware_event_thread;
7406 ioc->firmware_event_thread = NULL;
7407 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7409 destroy_workqueue(wq);
7411 /* release all the volumes */
7412 _scsih_ir_shutdown(ioc);
7413 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7415 if (raid_device->starget) {
7416 sas_target_priv_data =
7417 raid_device->starget->hostdata;
7418 sas_target_priv_data->deleted = 1;
7419 scsi_remove_target(&raid_device->starget->dev);
7421 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7422 ioc->name, raid_device->handle,
7423 (unsigned long long) raid_device->wwid);
7424 _scsih_raid_device_remove(ioc, raid_device);
7427 /* free ports attached to the sas_host */
7428 list_for_each_entry_safe(mpt3sas_port, next_port,
7429 &ioc->sas_hba.sas_port_list, port_list) {
7430 if (mpt3sas_port->remote_identify.device_type ==
7432 mpt3sas_device_remove_by_sas_address(ioc,
7433 mpt3sas_port->remote_identify.sas_address);
7434 else if (mpt3sas_port->remote_identify.device_type ==
7435 SAS_EDGE_EXPANDER_DEVICE ||
7436 mpt3sas_port->remote_identify.device_type ==
7437 SAS_FANOUT_EXPANDER_DEVICE)
7438 mpt3sas_expander_remove(ioc,
7439 mpt3sas_port->remote_identify.sas_address);
7442 /* free phys attached to the sas_host */
7443 if (ioc->sas_hba.num_phys) {
7444 kfree(ioc->sas_hba.phy);
7445 ioc->sas_hba.phy = NULL;
7446 ioc->sas_hba.num_phys = 0;
7449 sas_remove_host(shost);
7450 scsi_remove_host(shost);
7451 mpt3sas_base_detach(ioc);
7452 list_del(&ioc->list);
7453 scsi_host_put(shost);
7457 * _scsih_shutdown - routine call during system shutdown
7458 * @pdev: PCI device struct
7463 _scsih_shutdown(struct pci_dev *pdev)
7465 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7466 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7467 struct workqueue_struct *wq;
7468 unsigned long flags;
7470 ioc->remove_host = 1;
7471 _scsih_fw_event_cleanup_queue(ioc);
7473 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7474 wq = ioc->firmware_event_thread;
7475 ioc->firmware_event_thread = NULL;
7476 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7478 destroy_workqueue(wq);
7480 _scsih_ir_shutdown(ioc);
7481 mpt3sas_base_detach(ioc);
7486 * _scsih_probe_boot_devices - reports 1st device
7487 * @ioc: per adapter object
7489 * If specified in bios page 2, this routine reports the 1st
7490 * device scsi-ml or sas transport for persistent boot device
7491 * purposes. Please refer to function _scsih_determine_boot_device()
7494 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7498 struct _sas_device *sas_device;
7499 struct _raid_device *raid_device;
7501 u64 sas_address_parent;
7503 unsigned long flags;
7506 /* no Bios, return immediately */
7507 if (!ioc->bios_pg3.BiosVersion)
7512 if (ioc->req_boot_device.device) {
7513 device = ioc->req_boot_device.device;
7514 is_raid = ioc->req_boot_device.is_raid;
7515 } else if (ioc->req_alt_boot_device.device) {
7516 device = ioc->req_alt_boot_device.device;
7517 is_raid = ioc->req_alt_boot_device.is_raid;
7518 } else if (ioc->current_boot_device.device) {
7519 device = ioc->current_boot_device.device;
7520 is_raid = ioc->current_boot_device.is_raid;
7527 raid_device = device;
7528 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7529 raid_device->id, 0);
7531 _scsih_raid_device_remove(ioc, raid_device);
7533 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7534 sas_device = device;
7535 handle = sas_device->handle;
7536 sas_address_parent = sas_device->sas_address_parent;
7537 sas_address = sas_device->sas_address;
7538 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7539 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7541 if (!mpt3sas_transport_port_add(ioc, handle,
7542 sas_address_parent)) {
7543 _scsih_sas_device_remove(ioc, sas_device);
7544 } else if (!sas_device->starget) {
7545 if (!ioc->is_driver_loading) {
7546 mpt3sas_transport_port_remove(ioc,
7548 sas_address_parent);
7549 _scsih_sas_device_remove(ioc, sas_device);
7556 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7557 * @ioc: per adapter object
7559 * Called during initial loading of the driver.
7562 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7564 struct _raid_device *raid_device, *raid_next;
7567 list_for_each_entry_safe(raid_device, raid_next,
7568 &ioc->raid_device_list, list) {
7569 if (raid_device->starget)
7571 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7572 raid_device->id, 0);
7574 _scsih_raid_device_remove(ioc, raid_device);
7579 * _scsih_probe_sas - reporting sas devices to sas transport
7580 * @ioc: per adapter object
7582 * Called during initial loading of the driver.
7585 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7587 struct _sas_device *sas_device, *next;
7588 unsigned long flags;
7590 /* SAS Device List */
7591 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7594 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7595 sas_device->sas_address_parent)) {
7596 list_del(&sas_device->list);
7599 } else if (!sas_device->starget) {
7601 * When asyn scanning is enabled, its not possible to
7602 * remove devices while scanning is turned on due to an
7603 * oops in scsi_sysfs_add_sdev()->add_device()->
7604 * sysfs_addrm_start()
7606 if (!ioc->is_driver_loading) {
7607 mpt3sas_transport_port_remove(ioc,
7608 sas_device->sas_address,
7609 sas_device->sas_address_parent);
7610 list_del(&sas_device->list);
7616 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7617 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7618 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7623 * _scsih_probe_devices - probing for devices
7624 * @ioc: per adapter object
7626 * Called during initial loading of the driver.
7629 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7631 u16 volume_mapping_flags;
7633 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7634 return; /* return when IOC doesn't support initiator mode */
7636 _scsih_probe_boot_devices(ioc);
7638 if (ioc->ir_firmware) {
7639 volume_mapping_flags =
7640 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7641 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7642 if (volume_mapping_flags ==
7643 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7644 _scsih_probe_raid(ioc);
7645 _scsih_probe_sas(ioc);
7647 _scsih_probe_sas(ioc);
7648 _scsih_probe_raid(ioc);
7651 _scsih_probe_sas(ioc);
7655 * _scsih_scan_start - scsi lld callback for .scan_start
7656 * @shost: SCSI host pointer
7658 * The shost has the ability to discover targets on its own instead
7659 * of scanning the entire bus. In our implemention, we will kick off
7660 * firmware discovery.
7663 _scsih_scan_start(struct Scsi_Host *shost)
7665 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7667 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7668 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7670 if (disable_discovery > 0)
7673 ioc->start_scan = 1;
7674 rc = mpt3sas_port_enable(ioc);
7677 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7681 * _scsih_scan_finished - scsi lld callback for .scan_finished
7682 * @shost: SCSI host pointer
7683 * @time: elapsed time of the scan in jiffies
7685 * This function will be called periodicallyn until it returns 1 with the
7686 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7687 * we wait for firmware discovery to complete, then return 1.
7690 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7692 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7694 if (disable_discovery > 0) {
7695 ioc->is_driver_loading = 0;
7696 ioc->wait_for_discovery_to_complete = 0;
7700 if (time >= (300 * HZ)) {
7701 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7703 "port enable: FAILED with timeout (timeout=300s)\n",
7705 ioc->is_driver_loading = 0;
7709 if (ioc->start_scan)
7712 if (ioc->start_scan_failed) {
7714 "port enable: FAILED with (ioc_status=0x%08x)\n",
7715 ioc->name, ioc->start_scan_failed);
7716 ioc->is_driver_loading = 0;
7717 ioc->wait_for_discovery_to_complete = 0;
7718 ioc->remove_host = 1;
7722 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7723 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7725 if (ioc->wait_for_discovery_to_complete) {
7726 ioc->wait_for_discovery_to_complete = 0;
7727 _scsih_probe_devices(ioc);
7729 mpt3sas_base_start_watchdog(ioc);
7730 ioc->is_driver_loading = 0;
7735 * _scsih_probe - attach and add scsi host
7736 * @pdev: PCI device struct
7737 * @id: pci device id
7739 * Returns 0 success, anything else error.
7742 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7744 struct MPT3SAS_ADAPTER *ioc;
7745 struct Scsi_Host *shost;
7748 shost = scsi_host_alloc(&scsih_driver_template,
7749 sizeof(struct MPT3SAS_ADAPTER));
7753 /* init local params */
7754 ioc = shost_priv(shost);
7755 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7756 INIT_LIST_HEAD(&ioc->list);
7757 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7759 ioc->id = mpt_ids++;
7760 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
7762 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7763 ioc->tm_cb_idx = tm_cb_idx;
7764 ioc->ctl_cb_idx = ctl_cb_idx;
7765 ioc->base_cb_idx = base_cb_idx;
7766 ioc->port_enable_cb_idx = port_enable_cb_idx;
7767 ioc->transport_cb_idx = transport_cb_idx;
7768 ioc->scsih_cb_idx = scsih_cb_idx;
7769 ioc->config_cb_idx = config_cb_idx;
7770 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7771 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7772 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7773 ioc->logging_level = logging_level;
7774 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7775 /* misc semaphores and spin locks */
7776 mutex_init(&ioc->reset_in_progress_mutex);
7777 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7778 spin_lock_init(&ioc->scsi_lookup_lock);
7779 spin_lock_init(&ioc->sas_device_lock);
7780 spin_lock_init(&ioc->sas_node_lock);
7781 spin_lock_init(&ioc->fw_event_lock);
7782 spin_lock_init(&ioc->raid_device_lock);
7783 spin_lock_init(&ioc->diag_trigger_lock);
7785 INIT_LIST_HEAD(&ioc->sas_device_list);
7786 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7787 INIT_LIST_HEAD(&ioc->sas_expander_list);
7788 INIT_LIST_HEAD(&ioc->fw_event_list);
7789 INIT_LIST_HEAD(&ioc->raid_device_list);
7790 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7791 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7792 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7793 INIT_LIST_HEAD(&ioc->reply_queue_list);
7795 /* init shost parameters */
7796 shost->max_cmd_len = 32;
7797 shost->max_lun = max_lun;
7798 shost->transportt = mpt3sas_transport_template;
7799 shost->unique_id = ioc->id;
7801 if (max_sectors != 0xFFFF) {
7802 if (max_sectors < 64) {
7803 shost->max_sectors = 64;
7804 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7805 "for max_sectors, range is 64 to 32767. Assigning "
7806 "value of 64.\n", ioc->name, max_sectors);
7807 } else if (max_sectors > 32767) {
7808 shost->max_sectors = 32767;
7809 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7810 "for max_sectors, range is 64 to 32767. Assigning "
7811 "default value of 32767.\n", ioc->name,
7814 shost->max_sectors = max_sectors & 0xFFFE;
7816 "The max_sectors value is set to %d\n",
7817 ioc->name, shost->max_sectors);
7821 /* register EEDP capabilities with SCSI layer */
7823 scsi_host_set_prot(shost, prot_mask);
7825 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7826 | SHOST_DIF_TYPE2_PROTECTION
7827 | SHOST_DIF_TYPE3_PROTECTION);
7829 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7832 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7833 "fw_event%d", ioc->id);
7834 ioc->firmware_event_thread = create_singlethread_workqueue(
7835 ioc->firmware_event_name);
7836 if (!ioc->firmware_event_thread) {
7837 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7838 ioc->name, __FILE__, __LINE__, __func__);
7840 goto out_thread_fail;
7843 ioc->is_driver_loading = 1;
7844 if ((mpt3sas_base_attach(ioc))) {
7845 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7846 ioc->name, __FILE__, __LINE__, __func__);
7848 goto out_attach_fail;
7850 rv = scsi_add_host(shost, &pdev->dev);
7852 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7853 ioc->name, __FILE__, __LINE__, __func__);
7854 goto out_add_shost_fail;
7857 scsi_scan_host(shost);
7860 mpt3sas_base_detach(ioc);
7862 destroy_workqueue(ioc->firmware_event_thread);
7864 list_del(&ioc->list);
7865 scsi_host_put(shost);
7871 * _scsih_suspend - power management suspend main entry point
7872 * @pdev: PCI device struct
7873 * @state: PM state change to (usually PCI_D3)
7875 * Returns 0 success, anything else error.
7878 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7880 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7881 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7882 pci_power_t device_state;
7884 mpt3sas_base_stop_watchdog(ioc);
7885 flush_scheduled_work();
7886 scsi_block_requests(shost);
7887 device_state = pci_choose_state(pdev, state);
7889 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7890 ioc->name, pdev, pci_name(pdev), device_state);
7892 pci_save_state(pdev);
7893 mpt3sas_base_free_resources(ioc);
7894 pci_set_power_state(pdev, device_state);
7899 * _scsih_resume - power management resume main entry point
7900 * @pdev: PCI device struct
7902 * Returns 0 success, anything else error.
7905 _scsih_resume(struct pci_dev *pdev)
7907 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7908 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7909 pci_power_t device_state = pdev->current_state;
7913 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7914 ioc->name, pdev, pci_name(pdev), device_state);
7916 pci_set_power_state(pdev, PCI_D0);
7917 pci_enable_wake(pdev, PCI_D0, 0);
7918 pci_restore_state(pdev);
7920 r = mpt3sas_base_map_resources(ioc);
7924 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7925 scsi_unblock_requests(shost);
7926 mpt3sas_base_start_watchdog(ioc);
7929 #endif /* CONFIG_PM */
7932 * _scsih_pci_error_detected - Called when a PCI error is detected.
7933 * @pdev: PCI device struct
7934 * @state: PCI channel state
7936 * Description: Called when a PCI error is detected.
7939 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7941 static pci_ers_result_t
7942 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7944 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7945 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7947 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
7951 case pci_channel_io_normal:
7952 return PCI_ERS_RESULT_CAN_RECOVER;
7953 case pci_channel_io_frozen:
7954 /* Fatal error, prepare for slot reset */
7955 ioc->pci_error_recovery = 1;
7956 scsi_block_requests(ioc->shost);
7957 mpt3sas_base_stop_watchdog(ioc);
7958 mpt3sas_base_free_resources(ioc);
7959 return PCI_ERS_RESULT_NEED_RESET;
7960 case pci_channel_io_perm_failure:
7961 /* Permanent error, prepare for device removal */
7962 ioc->pci_error_recovery = 1;
7963 mpt3sas_base_stop_watchdog(ioc);
7964 _scsih_flush_running_cmds(ioc);
7965 return PCI_ERS_RESULT_DISCONNECT;
7967 return PCI_ERS_RESULT_NEED_RESET;
7971 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7972 * @pdev: PCI device struct
7974 * Description: This routine is called by the pci error recovery
7975 * code after the PCI slot has been reset, just before we
7976 * should resume normal operations.
7978 static pci_ers_result_t
7979 _scsih_pci_slot_reset(struct pci_dev *pdev)
7981 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7982 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7985 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
7988 ioc->pci_error_recovery = 0;
7990 pci_restore_state(pdev);
7991 rc = mpt3sas_base_map_resources(ioc);
7993 return PCI_ERS_RESULT_DISCONNECT;
7995 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
7998 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
7999 (rc == 0) ? "success" : "failed");
8002 return PCI_ERS_RESULT_RECOVERED;
8004 return PCI_ERS_RESULT_DISCONNECT;
8008 * _scsih_pci_resume() - resume normal ops after PCI reset
8009 * @pdev: pointer to PCI device
8011 * Called when the error recovery driver tells us that its
8012 * OK to resume normal operation. Use completion to allow
8013 * halted scsi ops to resume.
8016 _scsih_pci_resume(struct pci_dev *pdev)
8018 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8019 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8021 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8023 pci_cleanup_aer_uncorrect_error_status(pdev);
8024 mpt3sas_base_start_watchdog(ioc);
8025 scsi_unblock_requests(ioc->shost);
8029 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8030 * @pdev: pointer to PCI device
8032 static pci_ers_result_t
8033 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8035 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8036 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8038 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8041 /* TODO - dump whatever for debugging purposes */
8043 /* Request a slot reset. */
8044 return PCI_ERS_RESULT_NEED_RESET;
8047 /* raid transport support */
8048 static struct raid_function_template mpt3sas_raid_functions = {
8049 .cookie = &scsih_driver_template,
8050 .is_raid = _scsih_is_raid,
8051 .get_resync = _scsih_get_resync,
8052 .get_state = _scsih_get_state,
8055 static struct pci_error_handlers _scsih_err_handler = {
8056 .error_detected = _scsih_pci_error_detected,
8057 .mmio_enabled = _scsih_pci_mmio_enabled,
8058 .slot_reset = _scsih_pci_slot_reset,
8059 .resume = _scsih_pci_resume,
8062 static struct pci_driver scsih_driver = {
8063 .name = MPT3SAS_DRIVER_NAME,
8064 .id_table = scsih_pci_table,
8065 .probe = _scsih_probe,
8066 .remove = _scsih_remove,
8067 .shutdown = _scsih_shutdown,
8068 .err_handler = &_scsih_err_handler,
8070 .suspend = _scsih_suspend,
8071 .resume = _scsih_resume,
8077 * _scsih_init - main entry point for this driver.
8079 * Returns 0 success, anything else error.
8088 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8089 MPT3SAS_DRIVER_VERSION);
8091 mpt3sas_transport_template =
8092 sas_attach_transport(&mpt3sas_transport_functions);
8093 if (!mpt3sas_transport_template)
8096 /* raid transport support */
8097 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8098 if (!mpt3sas_raid_template) {
8099 sas_release_transport(mpt3sas_transport_template);
8103 mpt3sas_base_initialize_callback_handler();
8105 /* queuecommand callback hander */
8106 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8108 /* task managment callback handler */
8109 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8111 /* base internal commands callback handler */
8112 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8113 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8114 mpt3sas_port_enable_done);
8116 /* transport internal commands callback handler */
8117 transport_cb_idx = mpt3sas_base_register_callback_handler(
8118 mpt3sas_transport_done);
8120 /* scsih internal commands callback handler */
8121 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8123 /* configuration page API internal commands callback handler */
8124 config_cb_idx = mpt3sas_base_register_callback_handler(
8125 mpt3sas_config_done);
8127 /* ctl module callback handler */
8128 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8130 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8131 _scsih_tm_tr_complete);
8133 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8134 _scsih_tm_volume_tr_complete);
8136 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8137 _scsih_sas_control_complete);
8141 error = pci_register_driver(&scsih_driver);
8143 /* raid transport support */
8144 raid_class_release(mpt3sas_raid_template);
8145 sas_release_transport(mpt3sas_transport_template);
8152 * _scsih_exit - exit point for this driver (when it is a module).
8154 * Returns 0 success, anything else error.
8159 pr_info("mpt3sas version %s unloading\n",
8160 MPT3SAS_DRIVER_VERSION);
8164 pci_unregister_driver(&scsih_driver);
8167 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8168 mpt3sas_base_release_callback_handler(tm_cb_idx);
8169 mpt3sas_base_release_callback_handler(base_cb_idx);
8170 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8171 mpt3sas_base_release_callback_handler(transport_cb_idx);
8172 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8173 mpt3sas_base_release_callback_handler(config_cb_idx);
8174 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8176 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8177 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8178 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8180 /* raid transport support */
8181 raid_class_release(mpt3sas_raid_template);
8182 sas_release_transport(mpt3sas_transport_template);
8185 module_init(_scsih_init);
8186 module_exit(_scsih_exit);