2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
57 #include "mpt3sas_base.h"
59 MODULE_AUTHOR(MPT3SAS_AUTHOR);
60 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
64 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
67 struct _sas_node *sas_expander);
68 static void _firmware_event_work(struct work_struct *work);
70 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
71 struct _sas_device *sas_device);
72 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
73 u8 retry_count, u8 is_pd);
75 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
77 static void _scsih_scan_start(struct Scsi_Host *shost);
78 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
80 /* global parameters */
81 LIST_HEAD(mpt3sas_ioc_list);
83 /* local parameters */
84 static u8 scsi_io_cb_idx = -1;
85 static u8 tm_cb_idx = -1;
86 static u8 ctl_cb_idx = -1;
87 static u8 base_cb_idx = -1;
88 static u8 port_enable_cb_idx = -1;
89 static u8 transport_cb_idx = -1;
90 static u8 scsih_cb_idx = -1;
91 static u8 config_cb_idx = -1;
94 static u8 tm_tr_cb_idx = -1 ;
95 static u8 tm_tr_volume_cb_idx = -1 ;
96 static u8 tm_sas_control_cb_idx = -1;
98 /* command line options */
99 static u32 logging_level;
100 MODULE_PARM_DESC(logging_level,
101 " bits for enabling additional logging info (default=0)");
104 static ushort max_sectors = 0xFFFF;
105 module_param(max_sectors, ushort, 0);
106 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
109 static int missing_delay[2] = {-1, -1};
110 module_param_array(missing_delay, int, NULL, 0);
111 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
113 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
114 #define MPT3SAS_MAX_LUN (16895)
115 static u64 max_lun = MPT3SAS_MAX_LUN;
116 module_param(max_lun, ullong, 0);
117 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
122 /* diag_buffer_enable is bitwise
124 * bit 1 set = SNAPSHOT
125 * bit 2 set = EXTENDED
127 * Either bit can be set, or both
129 static int diag_buffer_enable = -1;
130 module_param(diag_buffer_enable, int, 0);
131 MODULE_PARM_DESC(diag_buffer_enable,
132 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
133 static int disable_discovery = -1;
134 module_param(disable_discovery, int, 0);
135 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
138 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
139 static int prot_mask = -1;
140 module_param(prot_mask, int, 0);
141 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
144 /* raid transport support */
146 static struct raid_template *mpt3sas_raid_template;
150 * struct sense_info - common structure for obtaining sense keys
152 * @asc: additional sense code
153 * @ascq: additional sense code qualifier
161 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
162 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
163 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
164 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
165 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
167 * struct fw_event_work - firmware event struct
168 * @list: link list framework
169 * @work: work object (ioc->fault_reset_work_q)
170 * @cancel_pending_work: flag set during reset handling
171 * @ioc: per adapter object
172 * @device_handle: device handle
173 * @VF_ID: virtual function id
174 * @VP_ID: virtual port id
175 * @ignore: flag meaning this event has been marked to ignore
176 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
177 * @event_data: reply event data payload follows
179 * This object stored on ioc->fw_event_list.
181 struct fw_event_work {
182 struct list_head list;
183 struct work_struct work;
184 u8 cancel_pending_work;
185 struct delayed_work delayed_work;
187 struct MPT3SAS_ADAPTER *ioc;
193 char event_data[0] __aligned(4);
196 /* raid transport support */
197 static struct raid_template *mpt3sas_raid_template;
200 * struct _scsi_io_transfer - scsi io transfer
201 * @handle: sas device handle (assigned by firmware)
202 * @is_raid: flag set for hidden raid components
203 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
204 * @data_length: data transfer length
205 * @data_dma: dma pointer to data
208 * @cdb_length: cdb length
210 * @timeout: timeout for this command
211 * @VF_ID: virtual function id
212 * @VP_ID: virtual port id
213 * @valid_reply: flag set for reply message
214 * @sense_length: sense length
215 * @ioc_status: ioc status
216 * @scsi_state: scsi state
217 * @scsi_status: scsi staus
218 * @log_info: log information
219 * @transfer_length: data length transfer when there is a reply message
221 * Used for sending internal scsi commands to devices within this module.
222 * Refer to _scsi_send_scsi_io().
224 struct _scsi_io_transfer {
227 enum dma_data_direction dir;
230 u8 sense[SCSI_SENSE_BUFFERSIZE];
238 /* the following bits are only valid when 'valid_reply = 1' */
248 * The pci device ids are defined in mpi/mpi2_cnfg.h.
250 static const struct pci_device_id scsih_pci_table[] = {
251 /* Fury ~ 3004 and 3008 */
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
253 PCI_ANY_ID, PCI_ANY_ID },
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
255 PCI_ANY_ID, PCI_ANY_ID },
257 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
258 PCI_ANY_ID, PCI_ANY_ID },
259 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
260 PCI_ANY_ID, PCI_ANY_ID },
261 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
262 PCI_ANY_ID, PCI_ANY_ID },
263 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
264 PCI_ANY_ID, PCI_ANY_ID },
265 {0} /* Terminating entry */
267 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
270 * _scsih_set_debug_level - global setting of ioc->logging_level.
272 * Note: The logging levels are defined in mpt3sas_debug.h.
275 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
277 int ret = param_set_int(val, kp);
278 struct MPT3SAS_ADAPTER *ioc;
283 pr_info("setting logging_level(0x%08x)\n", logging_level);
284 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
285 ioc->logging_level = logging_level;
288 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
289 &logging_level, 0644);
292 * _scsih_srch_boot_sas_address - search based on sas_address
293 * @sas_address: sas address
294 * @boot_device: boot device object from bios page 2
296 * Returns 1 when there's a match, 0 means no match.
299 _scsih_srch_boot_sas_address(u64 sas_address,
300 Mpi2BootDeviceSasWwid_t *boot_device)
302 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
306 * _scsih_srch_boot_device_name - search based on device name
307 * @device_name: device name specified in INDENTIFY fram
308 * @boot_device: boot device object from bios page 2
310 * Returns 1 when there's a match, 0 means no match.
313 _scsih_srch_boot_device_name(u64 device_name,
314 Mpi2BootDeviceDeviceName_t *boot_device)
316 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
320 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
321 * @enclosure_logical_id: enclosure logical id
322 * @slot_number: slot number
323 * @boot_device: boot device object from bios page 2
325 * Returns 1 when there's a match, 0 means no match.
328 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
329 Mpi2BootDeviceEnclosureSlot_t *boot_device)
331 return (enclosure_logical_id == le64_to_cpu(boot_device->
332 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
333 SlotNumber)) ? 1 : 0;
337 * _scsih_is_boot_device - search for matching boot device.
338 * @sas_address: sas address
339 * @device_name: device name specified in INDENTIFY fram
340 * @enclosure_logical_id: enclosure logical id
341 * @slot_number: slot number
342 * @form: specifies boot device form
343 * @boot_device: boot device object from bios page 2
345 * Returns 1 when there's a match, 0 means no match.
348 _scsih_is_boot_device(u64 sas_address, u64 device_name,
349 u64 enclosure_logical_id, u16 slot, u8 form,
350 Mpi2BiosPage2BootDevice_t *boot_device)
355 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
358 rc = _scsih_srch_boot_sas_address(
359 sas_address, &boot_device->SasWwid);
361 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
362 if (!enclosure_logical_id)
364 rc = _scsih_srch_boot_encl_slot(
365 enclosure_logical_id,
366 slot, &boot_device->EnclosureSlot);
368 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
371 rc = _scsih_srch_boot_device_name(
372 device_name, &boot_device->DeviceName);
374 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
382 * _scsih_get_sas_address - set the sas_address for given device handle
383 * @handle: device handle
384 * @sas_address: sas address
386 * Returns 0 success, non-zero when failure
389 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
392 Mpi2SasDevicePage0_t sas_device_pg0;
393 Mpi2ConfigReply_t mpi_reply;
398 if (handle <= ioc->sas_hba.num_phys) {
399 *sas_address = ioc->sas_hba.sas_address;
403 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
404 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
405 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
406 __FILE__, __LINE__, __func__);
410 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
411 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
412 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
416 /* we hit this becuase the given parent handle doesn't exist */
417 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
420 /* else error case */
422 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
423 ioc->name, handle, ioc_status,
424 __FILE__, __LINE__, __func__);
429 * _scsih_determine_boot_device - determine boot device.
430 * @ioc: per adapter object
431 * @device: either sas_device or raid_device object
432 * @is_raid: [flag] 1 = raid object, 0 = sas object
434 * Determines whether this device should be first reported device to
435 * to scsi-ml or sas transport, this purpose is for persistent boot device.
436 * There are primary, alternate, and current entries in bios page 2. The order
437 * priority is primary, alternate, then current. This routine saves
438 * the corresponding device object and is_raid flag in the ioc object.
439 * The saved data to be used later in _scsih_probe_boot_devices().
442 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
443 void *device, u8 is_raid)
445 struct _sas_device *sas_device;
446 struct _raid_device *raid_device;
449 u64 enclosure_logical_id;
452 /* only process this function when driver loads */
453 if (!ioc->is_driver_loading)
456 /* no Bios, return immediately */
457 if (!ioc->bios_pg3.BiosVersion)
462 sas_address = sas_device->sas_address;
463 device_name = sas_device->device_name;
464 enclosure_logical_id = sas_device->enclosure_logical_id;
465 slot = sas_device->slot;
467 raid_device = device;
468 sas_address = raid_device->wwid;
470 enclosure_logical_id = 0;
474 if (!ioc->req_boot_device.device) {
475 if (_scsih_is_boot_device(sas_address, device_name,
476 enclosure_logical_id, slot,
477 (ioc->bios_pg2.ReqBootDeviceForm &
478 MPI2_BIOSPAGE2_FORM_MASK),
479 &ioc->bios_pg2.RequestedBootDevice)) {
480 dinitprintk(ioc, pr_info(MPT3SAS_FMT
481 "%s: req_boot_device(0x%016llx)\n",
483 (unsigned long long)sas_address));
484 ioc->req_boot_device.device = device;
485 ioc->req_boot_device.is_raid = is_raid;
489 if (!ioc->req_alt_boot_device.device) {
490 if (_scsih_is_boot_device(sas_address, device_name,
491 enclosure_logical_id, slot,
492 (ioc->bios_pg2.ReqAltBootDeviceForm &
493 MPI2_BIOSPAGE2_FORM_MASK),
494 &ioc->bios_pg2.RequestedAltBootDevice)) {
495 dinitprintk(ioc, pr_info(MPT3SAS_FMT
496 "%s: req_alt_boot_device(0x%016llx)\n",
498 (unsigned long long)sas_address));
499 ioc->req_alt_boot_device.device = device;
500 ioc->req_alt_boot_device.is_raid = is_raid;
504 if (!ioc->current_boot_device.device) {
505 if (_scsih_is_boot_device(sas_address, device_name,
506 enclosure_logical_id, slot,
507 (ioc->bios_pg2.CurrentBootDeviceForm &
508 MPI2_BIOSPAGE2_FORM_MASK),
509 &ioc->bios_pg2.CurrentBootDevice)) {
510 dinitprintk(ioc, pr_info(MPT3SAS_FMT
511 "%s: current_boot_device(0x%016llx)\n",
513 (unsigned long long)sas_address));
514 ioc->current_boot_device.device = device;
515 ioc->current_boot_device.is_raid = is_raid;
521 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
522 * @ioc: per adapter object
523 * @sas_address: sas address
524 * Context: Calling function should acquire ioc->sas_device_lock
526 * This searches for sas_device based on sas_address, then return sas_device
530 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
533 struct _sas_device *sas_device;
535 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
536 if (sas_device->sas_address == sas_address)
539 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
540 if (sas_device->sas_address == sas_address)
547 * _scsih_sas_device_find_by_handle - sas device search
548 * @ioc: per adapter object
549 * @handle: sas device handle (assigned by firmware)
550 * Context: Calling function should acquire ioc->sas_device_lock
552 * This searches for sas_device based on sas_address, then return sas_device
555 static struct _sas_device *
556 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
558 struct _sas_device *sas_device;
560 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
561 if (sas_device->handle == handle)
564 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
565 if (sas_device->handle == handle)
572 * _scsih_sas_device_remove - remove sas_device from list.
573 * @ioc: per adapter object
574 * @sas_device: the sas_device object
575 * Context: This function will acquire ioc->sas_device_lock.
577 * Removing object and freeing associated memory from the ioc->sas_device_list.
580 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
581 struct _sas_device *sas_device)
588 spin_lock_irqsave(&ioc->sas_device_lock, flags);
589 list_del(&sas_device->list);
591 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
595 * _scsih_device_remove_by_handle - removing device object by handle
596 * @ioc: per adapter object
597 * @handle: device handle
602 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
604 struct _sas_device *sas_device;
607 if (ioc->shost_recovery)
610 spin_lock_irqsave(&ioc->sas_device_lock, flags);
611 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
613 list_del(&sas_device->list);
614 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
616 _scsih_remove_device(ioc, sas_device);
620 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
621 * @ioc: per adapter object
622 * @sas_address: device sas_address
627 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
630 struct _sas_device *sas_device;
633 if (ioc->shost_recovery)
636 spin_lock_irqsave(&ioc->sas_device_lock, flags);
637 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
640 list_del(&sas_device->list);
641 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
643 _scsih_remove_device(ioc, sas_device);
647 * _scsih_sas_device_add - insert sas_device to the list.
648 * @ioc: per adapter object
649 * @sas_device: the sas_device object
650 * Context: This function will acquire ioc->sas_device_lock.
652 * Adding new object to the ioc->sas_device_list.
655 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
656 struct _sas_device *sas_device)
660 dewtprintk(ioc, pr_info(MPT3SAS_FMT
661 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
662 ioc->name, __func__, sas_device->handle,
663 (unsigned long long)sas_device->sas_address));
665 spin_lock_irqsave(&ioc->sas_device_lock, flags);
666 list_add_tail(&sas_device->list, &ioc->sas_device_list);
667 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
669 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
670 sas_device->sas_address_parent)) {
671 _scsih_sas_device_remove(ioc, sas_device);
672 } else if (!sas_device->starget) {
674 * When asyn scanning is enabled, its not possible to remove
675 * devices while scanning is turned on due to an oops in
676 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
678 if (!ioc->is_driver_loading) {
679 mpt3sas_transport_port_remove(ioc,
680 sas_device->sas_address,
681 sas_device->sas_address_parent);
682 _scsih_sas_device_remove(ioc, sas_device);
688 * _scsih_sas_device_init_add - insert sas_device to the list.
689 * @ioc: per adapter object
690 * @sas_device: the sas_device object
691 * Context: This function will acquire ioc->sas_device_lock.
693 * Adding new object at driver load time to the ioc->sas_device_init_list.
696 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
697 struct _sas_device *sas_device)
701 dewtprintk(ioc, pr_info(MPT3SAS_FMT
702 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
703 __func__, sas_device->handle,
704 (unsigned long long)sas_device->sas_address));
706 spin_lock_irqsave(&ioc->sas_device_lock, flags);
707 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
708 _scsih_determine_boot_device(ioc, sas_device, 0);
709 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
713 * _scsih_raid_device_find_by_id - raid device search
714 * @ioc: per adapter object
715 * @id: sas device target id
716 * @channel: sas device channel
717 * Context: Calling function should acquire ioc->raid_device_lock
719 * This searches for raid_device based on target id, then return raid_device
722 static struct _raid_device *
723 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
725 struct _raid_device *raid_device, *r;
728 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
729 if (raid_device->id == id && raid_device->channel == channel) {
740 * _scsih_raid_device_find_by_handle - raid device search
741 * @ioc: per adapter object
742 * @handle: sas device handle (assigned by firmware)
743 * Context: Calling function should acquire ioc->raid_device_lock
745 * This searches for raid_device based on handle, then return raid_device
748 static struct _raid_device *
749 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
751 struct _raid_device *raid_device, *r;
754 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
755 if (raid_device->handle != handle)
766 * _scsih_raid_device_find_by_wwid - raid device search
767 * @ioc: per adapter object
768 * @handle: sas device handle (assigned by firmware)
769 * Context: Calling function should acquire ioc->raid_device_lock
771 * This searches for raid_device based on wwid, then return raid_device
774 static struct _raid_device *
775 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
777 struct _raid_device *raid_device, *r;
780 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
781 if (raid_device->wwid != wwid)
792 * _scsih_raid_device_add - add raid_device object
793 * @ioc: per adapter object
794 * @raid_device: raid_device object
796 * This is added to the raid_device_list link list.
799 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
800 struct _raid_device *raid_device)
804 dewtprintk(ioc, pr_info(MPT3SAS_FMT
805 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
806 raid_device->handle, (unsigned long long)raid_device->wwid));
808 spin_lock_irqsave(&ioc->raid_device_lock, flags);
809 list_add_tail(&raid_device->list, &ioc->raid_device_list);
810 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
814 * _scsih_raid_device_remove - delete raid_device object
815 * @ioc: per adapter object
816 * @raid_device: raid_device object
820 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
821 struct _raid_device *raid_device)
825 spin_lock_irqsave(&ioc->raid_device_lock, flags);
826 list_del(&raid_device->list);
828 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
832 * mpt3sas_scsih_expander_find_by_handle - expander device search
833 * @ioc: per adapter object
834 * @handle: expander handle (assigned by firmware)
835 * Context: Calling function should acquire ioc->sas_device_lock
837 * This searches for expander device based on handle, then returns the
841 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
843 struct _sas_node *sas_expander, *r;
846 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
847 if (sas_expander->handle != handle)
857 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
858 * @ioc: per adapter object
859 * @sas_address: sas address
860 * Context: Calling function should acquire ioc->sas_node_lock.
862 * This searches for expander device based on sas_address, then returns the
866 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
869 struct _sas_node *sas_expander, *r;
872 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
873 if (sas_expander->sas_address != sas_address)
883 * _scsih_expander_node_add - insert expander device to the list.
884 * @ioc: per adapter object
885 * @sas_expander: the sas_device object
886 * Context: This function will acquire ioc->sas_node_lock.
888 * Adding new object to the ioc->sas_expander_list.
893 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
894 struct _sas_node *sas_expander)
898 spin_lock_irqsave(&ioc->sas_node_lock, flags);
899 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
900 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
904 * _scsih_is_end_device - determines if device is an end device
905 * @device_info: bitfield providing information about the device.
908 * Returns 1 if end device.
911 _scsih_is_end_device(u32 device_info)
913 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
914 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
915 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
916 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
923 * _scsih_scsi_lookup_get - returns scmd entry
924 * @ioc: per adapter object
925 * @smid: system request message index
927 * Returns the smid stored scmd pointer.
929 static struct scsi_cmnd *
930 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
932 return ioc->scsi_lookup[smid - 1].scmd;
936 * _scsih_scsi_lookup_get_clear - returns scmd entry
937 * @ioc: per adapter object
938 * @smid: system request message index
940 * Returns the smid stored scmd pointer.
941 * Then will derefrence the stored scmd pointer.
943 static inline struct scsi_cmnd *
944 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
947 struct scsi_cmnd *scmd;
949 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
950 scmd = ioc->scsi_lookup[smid - 1].scmd;
951 ioc->scsi_lookup[smid - 1].scmd = NULL;
952 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
958 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
959 * @ioc: per adapter object
960 * @smid: system request message index
961 * @scmd: pointer to scsi command object
962 * Context: This function will acquire ioc->scsi_lookup_lock.
964 * This will search for a scmd pointer in the scsi_lookup array,
965 * returning the revelent smid. A returned value of zero means invalid.
968 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
975 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
977 for (i = 0; i < ioc->scsiio_depth; i++) {
978 if (ioc->scsi_lookup[i].scmd == scmd) {
979 smid = ioc->scsi_lookup[i].smid;
984 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
989 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
990 * @ioc: per adapter object
993 * Context: This function will acquire ioc->scsi_lookup_lock.
995 * This will search for a matching channel:id in the scsi_lookup array,
996 * returning 1 if found.
999 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1003 unsigned long flags;
1006 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1008 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1009 if (ioc->scsi_lookup[i].scmd &&
1010 (ioc->scsi_lookup[i].scmd->device->id == id &&
1011 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1017 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1022 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1023 * @ioc: per adapter object
1027 * Context: This function will acquire ioc->scsi_lookup_lock.
1029 * This will search for a matching channel:id:lun in the scsi_lookup array,
1030 * returning 1 if found.
1033 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1034 unsigned int lun, int channel)
1037 unsigned long flags;
1040 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1042 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1043 if (ioc->scsi_lookup[i].scmd &&
1044 (ioc->scsi_lookup[i].scmd->device->id == id &&
1045 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1046 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1052 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1058 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1060 struct Scsi_Host *shost = sdev->host;
1062 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1063 struct MPT3SAS_DEVICE *sas_device_priv_data;
1064 struct MPT3SAS_TARGET *sas_target_priv_data;
1065 struct _sas_device *sas_device;
1066 unsigned long flags;
1068 max_depth = shost->can_queue;
1070 /* limit max device queue for SATA to 32 */
1071 sas_device_priv_data = sdev->hostdata;
1072 if (!sas_device_priv_data)
1074 sas_target_priv_data = sas_device_priv_data->sas_target;
1075 if (!sas_target_priv_data)
1077 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1079 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1080 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1081 sas_device_priv_data->sas_target->sas_address);
1082 if (sas_device && sas_device->device_info &
1083 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1084 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1085 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1089 if (!sdev->tagged_supported)
1091 if (qdepth > max_depth)
1093 scsi_adjust_queue_depth(sdev, qdepth);
1097 * _scsih_change_queue_depth - setting device queue depth
1098 * @sdev: scsi device struct
1099 * @qdepth: requested queue depth
1100 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1101 * (see include/scsi/scsi_host.h for definition)
1103 * Returns queue depth.
1106 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1108 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1109 _scsih_adjust_queue_depth(sdev, qdepth);
1110 else if (reason == SCSI_QDEPTH_QFULL)
1111 scsi_track_queue_full(sdev, qdepth);
1115 if (sdev->inquiry_len > 7)
1116 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \
1117 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
1118 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1120 (sdev->inquiry[7] & 2) >> 1);
1122 return sdev->queue_depth;
1126 * _scsih_target_alloc - target add routine
1127 * @starget: scsi target struct
1129 * Returns 0 if ok. Any other return is assumed to be an error and
1130 * the device is ignored.
1133 _scsih_target_alloc(struct scsi_target *starget)
1135 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1136 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1137 struct MPT3SAS_TARGET *sas_target_priv_data;
1138 struct _sas_device *sas_device;
1139 struct _raid_device *raid_device;
1140 unsigned long flags;
1141 struct sas_rphy *rphy;
1143 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1145 if (!sas_target_priv_data)
1148 starget->hostdata = sas_target_priv_data;
1149 sas_target_priv_data->starget = starget;
1150 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1153 if (starget->channel == RAID_CHANNEL) {
1154 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1155 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1158 sas_target_priv_data->handle = raid_device->handle;
1159 sas_target_priv_data->sas_address = raid_device->wwid;
1160 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1161 raid_device->starget = starget;
1163 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1167 /* sas/sata devices */
1168 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1169 rphy = dev_to_rphy(starget->dev.parent);
1170 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1171 rphy->identify.sas_address);
1174 sas_target_priv_data->handle = sas_device->handle;
1175 sas_target_priv_data->sas_address = sas_device->sas_address;
1176 sas_device->starget = starget;
1177 sas_device->id = starget->id;
1178 sas_device->channel = starget->channel;
1179 if (test_bit(sas_device->handle, ioc->pd_handles))
1180 sas_target_priv_data->flags |=
1181 MPT_TARGET_FLAGS_RAID_COMPONENT;
1182 if (sas_device->fast_path)
1183 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1191 * _scsih_target_destroy - target destroy routine
1192 * @starget: scsi target struct
1197 _scsih_target_destroy(struct scsi_target *starget)
1199 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1200 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1201 struct MPT3SAS_TARGET *sas_target_priv_data;
1202 struct _sas_device *sas_device;
1203 struct _raid_device *raid_device;
1204 unsigned long flags;
1205 struct sas_rphy *rphy;
1207 sas_target_priv_data = starget->hostdata;
1208 if (!sas_target_priv_data)
1211 if (starget->channel == RAID_CHANNEL) {
1212 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1213 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1216 raid_device->starget = NULL;
1217 raid_device->sdev = NULL;
1219 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1223 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1224 rphy = dev_to_rphy(starget->dev.parent);
1225 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1226 rphy->identify.sas_address);
1227 if (sas_device && (sas_device->starget == starget) &&
1228 (sas_device->id == starget->id) &&
1229 (sas_device->channel == starget->channel))
1230 sas_device->starget = NULL;
1232 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1235 kfree(sas_target_priv_data);
1236 starget->hostdata = NULL;
1240 * _scsih_slave_alloc - device add routine
1241 * @sdev: scsi device struct
1243 * Returns 0 if ok. Any other return is assumed to be an error and
1244 * the device is ignored.
1247 _scsih_slave_alloc(struct scsi_device *sdev)
1249 struct Scsi_Host *shost;
1250 struct MPT3SAS_ADAPTER *ioc;
1251 struct MPT3SAS_TARGET *sas_target_priv_data;
1252 struct MPT3SAS_DEVICE *sas_device_priv_data;
1253 struct scsi_target *starget;
1254 struct _raid_device *raid_device;
1255 struct _sas_device *sas_device;
1256 unsigned long flags;
1258 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1260 if (!sas_device_priv_data)
1263 sas_device_priv_data->lun = sdev->lun;
1264 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1266 starget = scsi_target(sdev);
1267 sas_target_priv_data = starget->hostdata;
1268 sas_target_priv_data->num_luns++;
1269 sas_device_priv_data->sas_target = sas_target_priv_data;
1270 sdev->hostdata = sas_device_priv_data;
1271 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1272 sdev->no_uld_attach = 1;
1274 shost = dev_to_shost(&starget->dev);
1275 ioc = shost_priv(shost);
1276 if (starget->channel == RAID_CHANNEL) {
1277 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1278 raid_device = _scsih_raid_device_find_by_id(ioc,
1279 starget->id, starget->channel);
1281 raid_device->sdev = sdev; /* raid is single lun */
1282 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1285 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1286 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1287 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1288 sas_target_priv_data->sas_address);
1289 if (sas_device && (sas_device->starget == NULL)) {
1290 sdev_printk(KERN_INFO, sdev,
1291 "%s : sas_device->starget set to starget @ %d\n",
1292 __func__, __LINE__);
1293 sas_device->starget = starget;
1295 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1302 * _scsih_slave_destroy - device destroy routine
1303 * @sdev: scsi device struct
1308 _scsih_slave_destroy(struct scsi_device *sdev)
1310 struct MPT3SAS_TARGET *sas_target_priv_data;
1311 struct scsi_target *starget;
1312 struct Scsi_Host *shost;
1313 struct MPT3SAS_ADAPTER *ioc;
1314 struct _sas_device *sas_device;
1315 unsigned long flags;
1317 if (!sdev->hostdata)
1320 starget = scsi_target(sdev);
1321 sas_target_priv_data = starget->hostdata;
1322 sas_target_priv_data->num_luns--;
1324 shost = dev_to_shost(&starget->dev);
1325 ioc = shost_priv(shost);
1327 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1328 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1329 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1330 sas_target_priv_data->sas_address);
1331 if (sas_device && !sas_target_priv_data->num_luns)
1332 sas_device->starget = NULL;
1333 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1336 kfree(sdev->hostdata);
1337 sdev->hostdata = NULL;
1341 * _scsih_display_sata_capabilities - sata capabilities
1342 * @ioc: per adapter object
1343 * @handle: device handle
1344 * @sdev: scsi device struct
1347 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1348 u16 handle, struct scsi_device *sdev)
1350 Mpi2ConfigReply_t mpi_reply;
1351 Mpi2SasDevicePage0_t sas_device_pg0;
1356 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1357 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1358 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1359 ioc->name, __FILE__, __LINE__, __func__);
1363 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1364 MPI2_IOCSTATUS_MASK;
1365 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1366 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1367 ioc->name, __FILE__, __LINE__, __func__);
1371 flags = le16_to_cpu(sas_device_pg0.Flags);
1372 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1374 sdev_printk(KERN_INFO, sdev,
1375 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1376 "sw_preserve(%s)\n",
1377 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1378 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1379 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1381 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1382 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1383 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1387 * raid transport support -
1388 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1389 * unloading the driver followed by a load - I beleive that the subroutine
1390 * raid_class_release() is not cleaning up properly.
1394 * _scsih_is_raid - return boolean indicating device is raid volume
1395 * @dev the device struct object
1398 _scsih_is_raid(struct device *dev)
1400 struct scsi_device *sdev = to_scsi_device(dev);
1402 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1406 * _scsih_get_resync - get raid volume resync percent complete
1407 * @dev the device struct object
1410 _scsih_get_resync(struct device *dev)
1412 struct scsi_device *sdev = to_scsi_device(dev);
1413 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1414 static struct _raid_device *raid_device;
1415 unsigned long flags;
1416 Mpi2RaidVolPage0_t vol_pg0;
1417 Mpi2ConfigReply_t mpi_reply;
1418 u32 volume_status_flags;
1419 u8 percent_complete;
1422 percent_complete = 0;
1424 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1425 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1428 handle = raid_device->handle;
1429 percent_complete = raid_device->percent_complete;
1431 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1436 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1437 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1438 sizeof(Mpi2RaidVolPage0_t))) {
1439 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1440 ioc->name, __FILE__, __LINE__, __func__);
1441 percent_complete = 0;
1445 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1446 if (!(volume_status_flags &
1447 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1448 percent_complete = 0;
1451 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1455 * _scsih_get_state - get raid volume level
1456 * @dev the device struct object
1459 _scsih_get_state(struct device *dev)
1461 struct scsi_device *sdev = to_scsi_device(dev);
1462 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1463 static struct _raid_device *raid_device;
1464 unsigned long flags;
1465 Mpi2RaidVolPage0_t vol_pg0;
1466 Mpi2ConfigReply_t mpi_reply;
1468 enum raid_state state = RAID_STATE_UNKNOWN;
1471 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1472 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1475 handle = raid_device->handle;
1476 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1481 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1482 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1483 sizeof(Mpi2RaidVolPage0_t))) {
1484 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1485 ioc->name, __FILE__, __LINE__, __func__);
1489 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1490 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1491 state = RAID_STATE_RESYNCING;
1495 switch (vol_pg0.VolumeState) {
1496 case MPI2_RAID_VOL_STATE_OPTIMAL:
1497 case MPI2_RAID_VOL_STATE_ONLINE:
1498 state = RAID_STATE_ACTIVE;
1500 case MPI2_RAID_VOL_STATE_DEGRADED:
1501 state = RAID_STATE_DEGRADED;
1503 case MPI2_RAID_VOL_STATE_FAILED:
1504 case MPI2_RAID_VOL_STATE_MISSING:
1505 state = RAID_STATE_OFFLINE;
1509 raid_set_state(mpt3sas_raid_template, dev, state);
1513 * _scsih_set_level - set raid level
1514 * @sdev: scsi device struct
1515 * @volume_type: volume type
1518 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1520 enum raid_level level = RAID_LEVEL_UNKNOWN;
1522 switch (volume_type) {
1523 case MPI2_RAID_VOL_TYPE_RAID0:
1524 level = RAID_LEVEL_0;
1526 case MPI2_RAID_VOL_TYPE_RAID10:
1527 level = RAID_LEVEL_10;
1529 case MPI2_RAID_VOL_TYPE_RAID1E:
1530 level = RAID_LEVEL_1E;
1532 case MPI2_RAID_VOL_TYPE_RAID1:
1533 level = RAID_LEVEL_1;
1537 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1542 * _scsih_get_volume_capabilities - volume capabilities
1543 * @ioc: per adapter object
1544 * @sas_device: the raid_device object
1546 * Returns 0 for success, else 1
1549 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1550 struct _raid_device *raid_device)
1552 Mpi2RaidVolPage0_t *vol_pg0;
1553 Mpi2RaidPhysDiskPage0_t pd_pg0;
1554 Mpi2SasDevicePage0_t sas_device_pg0;
1555 Mpi2ConfigReply_t mpi_reply;
1559 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1560 &num_pds)) || !num_pds) {
1561 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1562 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1567 raid_device->num_pds = num_pds;
1568 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1569 sizeof(Mpi2RaidVol0PhysDisk_t));
1570 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1572 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1573 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1578 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1579 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1580 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1581 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1587 raid_device->volume_type = vol_pg0->VolumeType;
1589 /* figure out what the underlying devices are by
1590 * obtaining the device_info bits for the 1st device
1592 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1593 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1594 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1595 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1596 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1597 le16_to_cpu(pd_pg0.DevHandle)))) {
1598 raid_device->device_info =
1599 le32_to_cpu(sas_device_pg0.DeviceInfo);
1610 * _scsih_enable_tlr - setting TLR flags
1611 * @ioc: per adapter object
1612 * @sdev: scsi device struct
1614 * Enabling Transaction Layer Retries for tape devices when
1615 * vpd page 0x90 is present
1619 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1623 if (sdev->type != TYPE_TAPE)
1626 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1629 sas_enable_tlr(sdev);
1630 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1631 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1637 * _scsih_slave_configure - device configure routine.
1638 * @sdev: scsi device struct
1640 * Returns 0 if ok. Any other return is assumed to be an error and
1641 * the device is ignored.
1644 _scsih_slave_configure(struct scsi_device *sdev)
1646 struct Scsi_Host *shost = sdev->host;
1647 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1648 struct MPT3SAS_DEVICE *sas_device_priv_data;
1649 struct MPT3SAS_TARGET *sas_target_priv_data;
1650 struct _sas_device *sas_device;
1651 struct _raid_device *raid_device;
1652 unsigned long flags;
1657 u16 handle, volume_handle = 0;
1658 u64 volume_wwid = 0;
1661 sas_device_priv_data = sdev->hostdata;
1662 sas_device_priv_data->configured_lun = 1;
1663 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1664 sas_target_priv_data = sas_device_priv_data->sas_target;
1665 handle = sas_target_priv_data->handle;
1667 /* raid volume handling */
1668 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1670 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1671 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1672 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1674 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1675 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1676 __LINE__, __func__));
1680 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1681 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1682 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1683 __LINE__, __func__));
1688 /* RAID Queue Depth Support
1689 * IS volume = underlying qdepth of drive type, either
1690 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1691 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1693 if (raid_device->device_info &
1694 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1695 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1698 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1699 if (raid_device->device_info &
1700 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1706 switch (raid_device->volume_type) {
1707 case MPI2_RAID_VOL_TYPE_RAID0:
1710 case MPI2_RAID_VOL_TYPE_RAID1E:
1711 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1712 if (ioc->manu_pg10.OEMIdentifier &&
1713 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1714 MFG10_GF0_R10_DISPLAY) &&
1715 !(raid_device->num_pds % 2))
1720 case MPI2_RAID_VOL_TYPE_RAID1:
1721 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1724 case MPI2_RAID_VOL_TYPE_RAID10:
1725 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1728 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1730 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1735 sdev_printk(KERN_INFO, sdev,
1736 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1737 r_level, raid_device->handle,
1738 (unsigned long long)raid_device->wwid,
1739 raid_device->num_pds, ds);
1742 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1744 /* raid transport support */
1745 _scsih_set_level(sdev, raid_device->volume_type);
1749 /* non-raid handling */
1750 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1751 if (mpt3sas_config_get_volume_handle(ioc, handle,
1753 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1754 "failure at %s:%d/%s()!\n", ioc->name,
1755 __FILE__, __LINE__, __func__));
1758 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1759 volume_handle, &volume_wwid)) {
1760 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1761 "failure at %s:%d/%s()!\n", ioc->name,
1762 __FILE__, __LINE__, __func__));
1767 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1768 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1769 sas_device_priv_data->sas_target->sas_address);
1771 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1772 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1773 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1778 sas_device->volume_handle = volume_handle;
1779 sas_device->volume_wwid = volume_wwid;
1780 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1781 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1785 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1786 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1788 else if (sas_device->device_info &
1789 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1793 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1794 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1795 ds, handle, (unsigned long long)sas_device->sas_address,
1796 sas_device->phy, (unsigned long long)sas_device->device_name);
1797 sdev_printk(KERN_INFO, sdev,
1798 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1799 ds, (unsigned long long)
1800 sas_device->enclosure_logical_id, sas_device->slot);
1802 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1805 _scsih_display_sata_capabilities(ioc, handle, sdev);
1808 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1811 sas_read_port_mode_page(sdev);
1812 _scsih_enable_tlr(ioc, sdev);
1819 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1820 * @sdev: scsi device struct
1821 * @bdev: pointer to block device context
1822 * @capacity: device size (in 512 byte sectors)
1823 * @params: three element array to place output:
1824 * params[0] number of heads (max 255)
1825 * params[1] number of sectors (max 63)
1826 * params[2] number of cylinders
1831 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1832 sector_t capacity, int params[])
1842 dummy = heads * sectors;
1843 cylinders = capacity;
1844 sector_div(cylinders, dummy);
1847 * Handle extended translation size for logical drives
1850 if ((ulong)capacity >= 0x200000) {
1853 dummy = heads * sectors;
1854 cylinders = capacity;
1855 sector_div(cylinders, dummy);
1860 params[1] = sectors;
1861 params[2] = cylinders;
1867 * _scsih_response_code - translation of device response code
1868 * @ioc: per adapter object
1869 * @response_code: response code returned by the device
1874 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1878 switch (response_code) {
1879 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1880 desc = "task management request completed";
1882 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1883 desc = "invalid frame";
1885 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1886 desc = "task management request not supported";
1888 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1889 desc = "task management request failed";
1891 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1892 desc = "task management request succeeded";
1894 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1895 desc = "invalid lun";
1898 desc = "overlapped tag attempted";
1900 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1901 desc = "task queued, however not sent to target";
1907 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1908 ioc->name, response_code, desc);
1912 * _scsih_tm_done - tm completion routine
1913 * @ioc: per adapter object
1914 * @smid: system request message index
1915 * @msix_index: MSIX table index supplied by the OS
1916 * @reply: reply message frame(lower 32bit addr)
1919 * The callback handler when using scsih_issue_tm.
1921 * Return 1 meaning mf should be freed from _base_interrupt
1922 * 0 means the mf is freed from this function.
1925 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1927 MPI2DefaultReply_t *mpi_reply;
1929 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1931 if (ioc->tm_cmds.smid != smid)
1933 mpt3sas_base_flush_reply_queues(ioc);
1934 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1935 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1937 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1938 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1940 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1941 complete(&ioc->tm_cmds.done);
1946 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1947 * @ioc: per adapter object
1948 * @handle: device handle
1950 * During taskmangement request, we need to freeze the device queue.
1953 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1955 struct MPT3SAS_DEVICE *sas_device_priv_data;
1956 struct scsi_device *sdev;
1959 shost_for_each_device(sdev, ioc->shost) {
1962 sas_device_priv_data = sdev->hostdata;
1963 if (!sas_device_priv_data)
1965 if (sas_device_priv_data->sas_target->handle == handle) {
1966 sas_device_priv_data->sas_target->tm_busy = 1;
1968 ioc->ignore_loginfos = 1;
1974 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1975 * @ioc: per adapter object
1976 * @handle: device handle
1978 * During taskmangement request, we need to freeze the device queue.
1981 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1983 struct MPT3SAS_DEVICE *sas_device_priv_data;
1984 struct scsi_device *sdev;
1987 shost_for_each_device(sdev, ioc->shost) {
1990 sas_device_priv_data = sdev->hostdata;
1991 if (!sas_device_priv_data)
1993 if (sas_device_priv_data->sas_target->handle == handle) {
1994 sas_device_priv_data->sas_target->tm_busy = 0;
1996 ioc->ignore_loginfos = 0;
2002 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2003 * @ioc: per adapter struct
2004 * @device_handle: device handle
2005 * @channel: the channel assigned by the OS
2006 * @id: the id assigned by the OS
2008 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2009 * @smid_task: smid assigned to the task
2010 * @timeout: timeout in seconds
2011 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2014 * A generic API for sending task management requests to firmware.
2016 * The callback index is set inside `ioc->tm_cb_idx`.
2018 * Return SUCCESS or FAILED.
2021 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2022 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2023 enum mutex_type m_type)
2025 Mpi2SCSITaskManagementRequest_t *mpi_request;
2026 Mpi2SCSITaskManagementReply_t *mpi_reply;
2029 unsigned long timeleft;
2030 struct scsiio_tracker *scsi_lookup = NULL;
2033 if (m_type == TM_MUTEX_ON)
2034 mutex_lock(&ioc->tm_cmds.mutex);
2035 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2036 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2037 __func__, ioc->name);
2042 if (ioc->shost_recovery || ioc->remove_host ||
2043 ioc->pci_error_recovery) {
2044 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2045 __func__, ioc->name);
2050 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2051 if (ioc_state & MPI2_DOORBELL_USED) {
2052 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2053 "unexpected doorbell active!\n", ioc->name));
2054 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2056 rc = (!rc) ? SUCCESS : FAILED;
2060 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2061 mpt3sas_base_fault_info(ioc, ioc_state &
2062 MPI2_DOORBELL_DATA_MASK);
2063 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2065 rc = (!rc) ? SUCCESS : FAILED;
2069 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2071 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2072 ioc->name, __func__);
2077 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2078 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2080 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2081 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2082 ioc->name, handle, type, smid_task));
2083 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2084 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2085 ioc->tm_cmds.smid = smid;
2086 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2087 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2088 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2089 mpi_request->DevHandle = cpu_to_le16(handle);
2090 mpi_request->TaskType = type;
2091 mpi_request->TaskMID = cpu_to_le16(smid_task);
2092 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2093 mpt3sas_scsih_set_tm_flag(ioc, handle);
2094 init_completion(&ioc->tm_cmds.done);
2095 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2096 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2097 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2098 pr_err(MPT3SAS_FMT "%s: timeout\n",
2099 ioc->name, __func__);
2100 _debug_dump_mf(mpi_request,
2101 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2102 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2103 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2105 rc = (!rc) ? SUCCESS : FAILED;
2106 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2107 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2112 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2113 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2114 mpi_reply = ioc->tm_cmds.reply;
2115 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2116 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2117 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2118 le32_to_cpu(mpi_reply->IOCLogInfo),
2119 le32_to_cpu(mpi_reply->TerminationCount)));
2120 if (ioc->logging_level & MPT_DEBUG_TM) {
2121 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2122 if (mpi_reply->IOCStatus)
2123 _debug_dump_mf(mpi_request,
2124 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2129 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2131 if (scsi_lookup->scmd == NULL)
2136 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2137 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2142 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2143 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2144 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2149 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2157 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2158 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2159 if (m_type == TM_MUTEX_ON)
2160 mutex_unlock(&ioc->tm_cmds.mutex);
2165 if (m_type == TM_MUTEX_ON)
2166 mutex_unlock(&ioc->tm_cmds.mutex);
2171 * _scsih_tm_display_info - displays info about the device
2172 * @ioc: per adapter struct
2173 * @scmd: pointer to scsi command object
2175 * Called by task management callback handlers.
2178 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2180 struct scsi_target *starget = scmd->device->sdev_target;
2181 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2182 struct _sas_device *sas_device = NULL;
2183 unsigned long flags;
2184 char *device_str = NULL;
2188 device_str = "volume";
2190 scsi_print_command(scmd);
2191 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2192 starget_printk(KERN_INFO, starget,
2193 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2194 device_str, priv_target->handle,
2195 device_str, (unsigned long long)priv_target->sas_address);
2197 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2198 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2199 priv_target->sas_address);
2201 if (priv_target->flags &
2202 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2203 starget_printk(KERN_INFO, starget,
2204 "volume handle(0x%04x), "
2205 "volume wwid(0x%016llx)\n",
2206 sas_device->volume_handle,
2207 (unsigned long long)sas_device->volume_wwid);
2209 starget_printk(KERN_INFO, starget,
2210 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2212 (unsigned long long)sas_device->sas_address,
2214 starget_printk(KERN_INFO, starget,
2215 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2216 (unsigned long long)sas_device->enclosure_logical_id,
2219 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2224 * _scsih_abort - eh threads main abort routine
2225 * @scmd: pointer to scsi command object
2227 * Returns SUCCESS if command aborted else FAILED
2230 _scsih_abort(struct scsi_cmnd *scmd)
2232 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2233 struct MPT3SAS_DEVICE *sas_device_priv_data;
2238 sdev_printk(KERN_INFO, scmd->device,
2239 "attempting task abort! scmd(%p)\n", scmd);
2240 _scsih_tm_display_info(ioc, scmd);
2242 sas_device_priv_data = scmd->device->hostdata;
2243 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2244 sdev_printk(KERN_INFO, scmd->device,
2245 "device been deleted! scmd(%p)\n", scmd);
2246 scmd->result = DID_NO_CONNECT << 16;
2247 scmd->scsi_done(scmd);
2252 /* search for the command */
2253 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2255 scmd->result = DID_RESET << 16;
2260 /* for hidden raid components and volumes this is not supported */
2261 if (sas_device_priv_data->sas_target->flags &
2262 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2263 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2264 scmd->result = DID_RESET << 16;
2269 mpt3sas_halt_firmware(ioc);
2271 handle = sas_device_priv_data->sas_target->handle;
2272 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2273 scmd->device->id, scmd->device->lun,
2274 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2277 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2278 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2283 * _scsih_dev_reset - eh threads main device reset routine
2284 * @scmd: pointer to scsi command object
2286 * Returns SUCCESS if command aborted else FAILED
2289 _scsih_dev_reset(struct scsi_cmnd *scmd)
2291 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2292 struct MPT3SAS_DEVICE *sas_device_priv_data;
2293 struct _sas_device *sas_device;
2294 unsigned long flags;
2298 sdev_printk(KERN_INFO, scmd->device,
2299 "attempting device reset! scmd(%p)\n", scmd);
2300 _scsih_tm_display_info(ioc, scmd);
2302 sas_device_priv_data = scmd->device->hostdata;
2303 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2304 sdev_printk(KERN_INFO, scmd->device,
2305 "device been deleted! scmd(%p)\n", scmd);
2306 scmd->result = DID_NO_CONNECT << 16;
2307 scmd->scsi_done(scmd);
2312 /* for hidden raid components obtain the volume_handle */
2314 if (sas_device_priv_data->sas_target->flags &
2315 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2316 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2317 sas_device = _scsih_sas_device_find_by_handle(ioc,
2318 sas_device_priv_data->sas_target->handle);
2320 handle = sas_device->volume_handle;
2321 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2323 handle = sas_device_priv_data->sas_target->handle;
2326 scmd->result = DID_RESET << 16;
2331 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2332 scmd->device->id, scmd->device->lun,
2333 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2336 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2337 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2342 * _scsih_target_reset - eh threads main target reset routine
2343 * @scmd: pointer to scsi command object
2345 * Returns SUCCESS if command aborted else FAILED
2348 _scsih_target_reset(struct scsi_cmnd *scmd)
2350 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2351 struct MPT3SAS_DEVICE *sas_device_priv_data;
2352 struct _sas_device *sas_device;
2353 unsigned long flags;
2356 struct scsi_target *starget = scmd->device->sdev_target;
2358 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2360 _scsih_tm_display_info(ioc, scmd);
2362 sas_device_priv_data = scmd->device->hostdata;
2363 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2364 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2366 scmd->result = DID_NO_CONNECT << 16;
2367 scmd->scsi_done(scmd);
2372 /* for hidden raid components obtain the volume_handle */
2374 if (sas_device_priv_data->sas_target->flags &
2375 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2376 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2377 sas_device = _scsih_sas_device_find_by_handle(ioc,
2378 sas_device_priv_data->sas_target->handle);
2380 handle = sas_device->volume_handle;
2381 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2383 handle = sas_device_priv_data->sas_target->handle;
2386 scmd->result = DID_RESET << 16;
2391 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2392 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2396 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2397 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2403 * _scsih_host_reset - eh threads main host reset routine
2404 * @scmd: pointer to scsi command object
2406 * Returns SUCCESS if command aborted else FAILED
2409 _scsih_host_reset(struct scsi_cmnd *scmd)
2411 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2414 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2416 scsi_print_command(scmd);
2418 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2420 r = (retval < 0) ? FAILED : SUCCESS;
2421 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2422 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2428 * _scsih_fw_event_add - insert and queue up fw_event
2429 * @ioc: per adapter object
2430 * @fw_event: object describing the event
2431 * Context: This function will acquire ioc->fw_event_lock.
2433 * This adds the firmware event object into link list, then queues it up to
2434 * be processed from user context.
2439 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2441 unsigned long flags;
2443 if (ioc->firmware_event_thread == NULL)
2446 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2447 INIT_LIST_HEAD(&fw_event->list);
2448 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2449 INIT_WORK(&fw_event->work, _firmware_event_work);
2450 queue_work(ioc->firmware_event_thread, &fw_event->work);
2451 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2455 * _scsih_fw_event_free - delete fw_event
2456 * @ioc: per adapter object
2457 * @fw_event: object describing the event
2458 * Context: This function will acquire ioc->fw_event_lock.
2460 * This removes firmware event object from link list, frees associated memory.
2465 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2468 unsigned long flags;
2470 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2471 list_del(&fw_event->list);
2473 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2478 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2479 * @ioc: per adapter object
2480 * @event_data: trigger event data
2485 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2486 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2488 struct fw_event_work *fw_event;
2490 if (ioc->is_driver_loading)
2492 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2496 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2497 fw_event->ioc = ioc;
2498 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2499 _scsih_fw_event_add(ioc, fw_event);
2503 * _scsih_error_recovery_delete_devices - remove devices not responding
2504 * @ioc: per adapter object
2509 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2511 struct fw_event_work *fw_event;
2513 if (ioc->is_driver_loading)
2515 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2518 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2519 fw_event->ioc = ioc;
2520 _scsih_fw_event_add(ioc, fw_event);
2524 * mpt3sas_port_enable_complete - port enable completed (fake event)
2525 * @ioc: per adapter object
2530 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2532 struct fw_event_work *fw_event;
2534 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2537 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2538 fw_event->ioc = ioc;
2539 _scsih_fw_event_add(ioc, fw_event);
2543 * _scsih_fw_event_cleanup_queue - cleanup event queue
2544 * @ioc: per adapter object
2546 * Walk the firmware event queue, either killing timers, or waiting
2547 * for outstanding events to complete
2552 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2554 struct fw_event_work *fw_event, *next;
2556 if (list_empty(&ioc->fw_event_list) ||
2557 !ioc->firmware_event_thread || in_interrupt())
2560 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2561 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2562 _scsih_fw_event_free(ioc, fw_event);
2569 * _scsih_ublock_io_all_device - unblock every device
2570 * @ioc: per adapter object
2572 * change the device state from block to running
2575 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2577 struct MPT3SAS_DEVICE *sas_device_priv_data;
2578 struct scsi_device *sdev;
2580 shost_for_each_device(sdev, ioc->shost) {
2581 sas_device_priv_data = sdev->hostdata;
2582 if (!sas_device_priv_data)
2584 if (!sas_device_priv_data->block)
2587 sas_device_priv_data->block = 0;
2588 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2589 "device_running, handle(0x%04x)\n",
2590 sas_device_priv_data->sas_target->handle));
2591 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2597 * _scsih_ublock_io_device - prepare device to be deleted
2598 * @ioc: per adapter object
2599 * @sas_addr: sas address
2601 * unblock then put device in offline state
2604 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2606 struct MPT3SAS_DEVICE *sas_device_priv_data;
2607 struct scsi_device *sdev;
2609 shost_for_each_device(sdev, ioc->shost) {
2610 sas_device_priv_data = sdev->hostdata;
2611 if (!sas_device_priv_data)
2613 if (sas_device_priv_data->sas_target->sas_address
2616 if (sas_device_priv_data->block) {
2617 sas_device_priv_data->block = 0;
2618 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2624 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2625 * @ioc: per adapter object
2626 * @handle: device handle
2628 * During device pull we need to appropiately set the sdev state.
2631 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2633 struct MPT3SAS_DEVICE *sas_device_priv_data;
2634 struct scsi_device *sdev;
2636 shost_for_each_device(sdev, ioc->shost) {
2637 sas_device_priv_data = sdev->hostdata;
2638 if (!sas_device_priv_data)
2640 if (sas_device_priv_data->block)
2642 sas_device_priv_data->block = 1;
2643 scsi_internal_device_block(sdev);
2644 sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n",
2645 sas_device_priv_data->sas_target->handle);
2650 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2651 * @ioc: per adapter object
2652 * @handle: device handle
2654 * During device pull we need to appropiately set the sdev state.
2657 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2659 struct MPT3SAS_DEVICE *sas_device_priv_data;
2660 struct scsi_device *sdev;
2662 shost_for_each_device(sdev, ioc->shost) {
2663 sas_device_priv_data = sdev->hostdata;
2664 if (!sas_device_priv_data)
2666 if (sas_device_priv_data->sas_target->handle != handle)
2668 if (sas_device_priv_data->block)
2670 sas_device_priv_data->block = 1;
2671 scsi_internal_device_block(sdev);
2672 sdev_printk(KERN_INFO, sdev,
2673 "device_blocked, handle(0x%04x)\n", handle);
2678 * _scsih_block_io_to_children_attached_to_ex
2679 * @ioc: per adapter object
2680 * @sas_expander: the sas_device object
2682 * This routine set sdev state to SDEV_BLOCK for all devices
2683 * attached to this expander. This function called when expander is
2687 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2688 struct _sas_node *sas_expander)
2690 struct _sas_port *mpt3sas_port;
2691 struct _sas_device *sas_device;
2692 struct _sas_node *expander_sibling;
2693 unsigned long flags;
2698 list_for_each_entry(mpt3sas_port,
2699 &sas_expander->sas_port_list, port_list) {
2700 if (mpt3sas_port->remote_identify.device_type ==
2702 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2704 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2705 mpt3sas_port->remote_identify.sas_address);
2707 set_bit(sas_device->handle,
2708 ioc->blocking_handles);
2709 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2713 list_for_each_entry(mpt3sas_port,
2714 &sas_expander->sas_port_list, port_list) {
2716 if (mpt3sas_port->remote_identify.device_type ==
2717 SAS_EDGE_EXPANDER_DEVICE ||
2718 mpt3sas_port->remote_identify.device_type ==
2719 SAS_FANOUT_EXPANDER_DEVICE) {
2721 mpt3sas_scsih_expander_find_by_sas_address(
2722 ioc, mpt3sas_port->remote_identify.sas_address);
2723 _scsih_block_io_to_children_attached_to_ex(ioc,
2730 * _scsih_block_io_to_children_attached_directly
2731 * @ioc: per adapter object
2732 * @event_data: topology change event data
2734 * This routine set sdev state to SDEV_BLOCK for all devices
2735 * direct attached during device pull.
2738 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2739 Mpi2EventDataSasTopologyChangeList_t *event_data)
2745 for (i = 0; i < event_data->NumEntries; i++) {
2746 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2749 reason_code = event_data->PHY[i].PhyStatus &
2750 MPI2_EVENT_SAS_TOPO_RC_MASK;
2751 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2752 _scsih_block_io_device(ioc, handle);
2757 * _scsih_tm_tr_send - send task management request
2758 * @ioc: per adapter object
2759 * @handle: device handle
2760 * Context: interrupt time.
2762 * This code is to initiate the device removal handshake protocol
2763 * with controller firmware. This function will issue target reset
2764 * using high priority request queue. It will send a sas iounit
2765 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2767 * This is designed to send muliple task management request at the same
2768 * time to the fifo. If the fifo is full, we will append the request,
2769 * and process it in a future completion.
2772 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2774 Mpi2SCSITaskManagementRequest_t *mpi_request;
2776 struct _sas_device *sas_device;
2777 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2778 u64 sas_address = 0;
2779 unsigned long flags;
2780 struct _tr_list *delayed_tr;
2783 if (ioc->remove_host) {
2784 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2785 "%s: host has been removed: handle(0x%04x)\n",
2786 __func__, ioc->name, handle));
2788 } else if (ioc->pci_error_recovery) {
2789 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2790 "%s: host in pci error recovery: handle(0x%04x)\n",
2791 __func__, ioc->name,
2795 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2796 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2797 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2798 "%s: host is not operational: handle(0x%04x)\n",
2799 __func__, ioc->name,
2804 /* if PD, then return */
2805 if (test_bit(handle, ioc->pd_handles))
2808 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2809 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2810 if (sas_device && sas_device->starget &&
2811 sas_device->starget->hostdata) {
2812 sas_target_priv_data = sas_device->starget->hostdata;
2813 sas_target_priv_data->deleted = 1;
2814 sas_address = sas_device->sas_address;
2816 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2818 if (sas_target_priv_data) {
2819 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2820 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2822 (unsigned long long)sas_address));
2823 _scsih_ublock_io_device(ioc, sas_address);
2824 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2827 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2829 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2832 INIT_LIST_HEAD(&delayed_tr->list);
2833 delayed_tr->handle = handle;
2834 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2835 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2836 "DELAYED:tr:handle(0x%04x), (open)\n",
2837 ioc->name, handle));
2841 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2842 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2843 ioc->name, handle, smid,
2844 ioc->tm_tr_cb_idx));
2845 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2846 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2847 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2848 mpi_request->DevHandle = cpu_to_le16(handle);
2849 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2850 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2851 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2855 * _scsih_tm_tr_complete -
2856 * @ioc: per adapter object
2857 * @smid: system request message index
2858 * @msix_index: MSIX table index supplied by the OS
2859 * @reply: reply message frame(lower 32bit addr)
2860 * Context: interrupt time.
2862 * This is the target reset completion routine.
2863 * This code is part of the code to initiate the device removal
2864 * handshake protocol with controller firmware.
2865 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2867 * Return 1 meaning mf should be freed from _base_interrupt
2868 * 0 means the mf is freed from this function.
2871 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2875 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2876 Mpi2SCSITaskManagementReply_t *mpi_reply =
2877 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2878 Mpi2SasIoUnitControlRequest_t *mpi_request;
2882 if (ioc->remove_host) {
2883 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2884 "%s: host has been removed\n", __func__, ioc->name));
2886 } else if (ioc->pci_error_recovery) {
2887 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2888 "%s: host in pci error recovery\n", __func__,
2892 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2893 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2894 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2895 "%s: host is not operational\n", __func__, ioc->name));
2898 if (unlikely(!mpi_reply)) {
2899 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2900 ioc->name, __FILE__, __LINE__, __func__);
2903 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2904 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2905 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2906 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2907 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2909 le16_to_cpu(mpi_reply->DevHandle), smid));
2913 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2914 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2915 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2916 "loginfo(0x%08x), completed(%d)\n", ioc->name,
2917 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
2918 le32_to_cpu(mpi_reply->IOCLogInfo),
2919 le32_to_cpu(mpi_reply->TerminationCount)));
2921 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2922 if (!smid_sas_ctrl) {
2923 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2924 ioc->name, __func__);
2928 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2929 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2930 ioc->name, handle, smid_sas_ctrl,
2931 ioc->tm_sas_control_cb_idx));
2932 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2933 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2934 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2935 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2936 mpi_request->DevHandle = mpi_request_tm->DevHandle;
2937 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
2939 return _scsih_check_for_pending_tm(ioc, smid);
2944 * _scsih_sas_control_complete - completion routine
2945 * @ioc: per adapter object
2946 * @smid: system request message index
2947 * @msix_index: MSIX table index supplied by the OS
2948 * @reply: reply message frame(lower 32bit addr)
2949 * Context: interrupt time.
2951 * This is the sas iounit control completion routine.
2952 * This code is part of the code to initiate the device removal
2953 * handshake protocol with controller firmware.
2955 * Return 1 meaning mf should be freed from _base_interrupt
2956 * 0 means the mf is freed from this function.
2959 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
2960 u8 msix_index, u32 reply)
2962 Mpi2SasIoUnitControlReply_t *mpi_reply =
2963 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2965 if (likely(mpi_reply)) {
2966 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2967 "sc_complete:handle(0x%04x), (open) "
2968 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2969 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2970 le16_to_cpu(mpi_reply->IOCStatus),
2971 le32_to_cpu(mpi_reply->IOCLogInfo)));
2973 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2974 ioc->name, __FILE__, __LINE__, __func__);
2980 * _scsih_tm_tr_volume_send - send target reset request for volumes
2981 * @ioc: per adapter object
2982 * @handle: device handle
2983 * Context: interrupt time.
2985 * This is designed to send muliple task management request at the same
2986 * time to the fifo. If the fifo is full, we will append the request,
2987 * and process it in a future completion.
2990 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2992 Mpi2SCSITaskManagementRequest_t *mpi_request;
2994 struct _tr_list *delayed_tr;
2996 if (ioc->shost_recovery || ioc->remove_host ||
2997 ioc->pci_error_recovery) {
2998 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2999 "%s: host reset in progress!\n",
3000 __func__, ioc->name));
3004 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3006 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3009 INIT_LIST_HEAD(&delayed_tr->list);
3010 delayed_tr->handle = handle;
3011 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3012 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3013 "DELAYED:tr:handle(0x%04x), (open)\n",
3014 ioc->name, handle));
3018 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3019 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3020 ioc->name, handle, smid,
3021 ioc->tm_tr_volume_cb_idx));
3022 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3023 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3024 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3025 mpi_request->DevHandle = cpu_to_le16(handle);
3026 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3027 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3031 * _scsih_tm_volume_tr_complete - target reset completion
3032 * @ioc: per adapter object
3033 * @smid: system request message index
3034 * @msix_index: MSIX table index supplied by the OS
3035 * @reply: reply message frame(lower 32bit addr)
3036 * Context: interrupt time.
3038 * Return 1 meaning mf should be freed from _base_interrupt
3039 * 0 means the mf is freed from this function.
3042 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3043 u8 msix_index, u32 reply)
3046 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3047 Mpi2SCSITaskManagementReply_t *mpi_reply =
3048 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3050 if (ioc->shost_recovery || ioc->remove_host ||
3051 ioc->pci_error_recovery) {
3052 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3053 "%s: host reset in progress!\n",
3054 __func__, ioc->name));
3057 if (unlikely(!mpi_reply)) {
3058 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3059 ioc->name, __FILE__, __LINE__, __func__);
3063 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3064 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3065 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3066 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3067 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3069 le16_to_cpu(mpi_reply->DevHandle), smid));
3073 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3074 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3075 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3076 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3077 le32_to_cpu(mpi_reply->IOCLogInfo),
3078 le32_to_cpu(mpi_reply->TerminationCount)));
3080 return _scsih_check_for_pending_tm(ioc, smid);
3085 * _scsih_check_for_pending_tm - check for pending task management
3086 * @ioc: per adapter object
3087 * @smid: system request message index
3089 * This will check delayed target reset list, and feed the
3092 * Return 1 meaning mf should be freed from _base_interrupt
3093 * 0 means the mf is freed from this function.
3096 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3098 struct _tr_list *delayed_tr;
3100 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3101 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3102 struct _tr_list, list);
3103 mpt3sas_base_free_smid(ioc, smid);
3104 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3105 list_del(&delayed_tr->list);
3110 if (!list_empty(&ioc->delayed_tr_list)) {
3111 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3112 struct _tr_list, list);
3113 mpt3sas_base_free_smid(ioc, smid);
3114 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3115 list_del(&delayed_tr->list);
3124 * _scsih_check_topo_delete_events - sanity check on topo events
3125 * @ioc: per adapter object
3126 * @event_data: the event data payload
3128 * This routine added to better handle cable breaker.
3130 * This handles the case where driver receives multiple expander
3131 * add and delete events in a single shot. When there is a delete event
3132 * the routine will void any pending add events waiting in the event queue.
3137 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3138 Mpi2EventDataSasTopologyChangeList_t *event_data)
3140 struct fw_event_work *fw_event;
3141 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3142 u16 expander_handle;
3143 struct _sas_node *sas_expander;
3144 unsigned long flags;
3148 for (i = 0 ; i < event_data->NumEntries; i++) {
3149 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3152 reason_code = event_data->PHY[i].PhyStatus &
3153 MPI2_EVENT_SAS_TOPO_RC_MASK;
3154 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3155 _scsih_tm_tr_send(ioc, handle);
3158 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3159 if (expander_handle < ioc->sas_hba.num_phys) {
3160 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3163 if (event_data->ExpStatus ==
3164 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3165 /* put expander attached devices into blocking state */
3166 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3167 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3169 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3170 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3172 handle = find_first_bit(ioc->blocking_handles,
3173 ioc->facts.MaxDevHandle);
3174 if (handle < ioc->facts.MaxDevHandle)
3175 _scsih_block_io_device(ioc, handle);
3176 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3177 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3178 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3180 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3183 /* mark ignore flag for pending events */
3184 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3185 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3186 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3189 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3190 fw_event->event_data;
3191 if (local_event_data->ExpStatus ==
3192 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3193 local_event_data->ExpStatus ==
3194 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3195 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3197 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3198 "setting ignoring flag\n", ioc->name));
3199 fw_event->ignore = 1;
3203 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3207 * _scsih_set_volume_delete_flag - setting volume delete flag
3208 * @ioc: per adapter object
3209 * @handle: device handle
3211 * This returns nothing.
3214 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3216 struct _raid_device *raid_device;
3217 struct MPT3SAS_TARGET *sas_target_priv_data;
3218 unsigned long flags;
3220 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3221 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3222 if (raid_device && raid_device->starget &&
3223 raid_device->starget->hostdata) {
3224 sas_target_priv_data =
3225 raid_device->starget->hostdata;
3226 sas_target_priv_data->deleted = 1;
3227 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3228 "setting delete flag: handle(0x%04x), "
3229 "wwid(0x%016llx)\n", ioc->name, handle,
3230 (unsigned long long) raid_device->wwid));
3232 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3236 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3237 * @handle: input handle
3238 * @a: handle for volume a
3239 * @b: handle for volume b
3241 * IR firmware only supports two raid volumes. The purpose of this
3242 * routine is to set the volume handle in either a or b. When the given
3243 * input handle is non-zero, or when a and b have not been set before.
3246 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3248 if (!handle || handle == *a || handle == *b)
3257 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3258 * @ioc: per adapter object
3259 * @event_data: the event data payload
3260 * Context: interrupt time.
3262 * This routine will send target reset to volume, followed by target
3263 * resets to the PDs. This is called when a PD has been removed, or
3264 * volume has been deleted or removed. When the target reset is sent
3265 * to volume, the PD target resets need to be queued to start upon
3266 * completion of the volume target reset.
3271 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3272 Mpi2EventDataIrConfigChangeList_t *event_data)
3274 Mpi2EventIrConfigElement_t *element;
3276 u16 handle, volume_handle, a, b;
3277 struct _tr_list *delayed_tr;
3282 /* Volume Resets for Deleted or Removed */
3283 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3284 for (i = 0; i < event_data->NumElements; i++, element++) {
3285 if (le32_to_cpu(event_data->Flags) &
3286 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3288 if (element->ReasonCode ==
3289 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3290 element->ReasonCode ==
3291 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3292 volume_handle = le16_to_cpu(element->VolDevHandle);
3293 _scsih_set_volume_delete_flag(ioc, volume_handle);
3294 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3298 /* Volume Resets for UNHIDE events */
3299 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3300 for (i = 0; i < event_data->NumElements; i++, element++) {
3301 if (le32_to_cpu(event_data->Flags) &
3302 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3304 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3305 volume_handle = le16_to_cpu(element->VolDevHandle);
3306 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3311 _scsih_tm_tr_volume_send(ioc, a);
3313 _scsih_tm_tr_volume_send(ioc, b);
3315 /* PD target resets */
3316 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3317 for (i = 0; i < event_data->NumElements; i++, element++) {
3318 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3320 handle = le16_to_cpu(element->PhysDiskDevHandle);
3321 volume_handle = le16_to_cpu(element->VolDevHandle);
3322 clear_bit(handle, ioc->pd_handles);
3324 _scsih_tm_tr_send(ioc, handle);
3325 else if (volume_handle == a || volume_handle == b) {
3326 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3327 BUG_ON(!delayed_tr);
3328 INIT_LIST_HEAD(&delayed_tr->list);
3329 delayed_tr->handle = handle;
3330 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3331 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3332 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3335 _scsih_tm_tr_send(ioc, handle);
3341 * _scsih_check_volume_delete_events - set delete flag for volumes
3342 * @ioc: per adapter object
3343 * @event_data: the event data payload
3344 * Context: interrupt time.
3346 * This will handle the case when the cable connected to entire volume is
3347 * pulled. We will take care of setting the deleted flag so normal IO will
3353 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3354 Mpi2EventDataIrVolume_t *event_data)
3358 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3360 state = le32_to_cpu(event_data->NewValue);
3361 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3362 MPI2_RAID_VOL_STATE_FAILED)
3363 _scsih_set_volume_delete_flag(ioc,
3364 le16_to_cpu(event_data->VolDevHandle));
3368 * _scsih_flush_running_cmds - completing outstanding commands.
3369 * @ioc: per adapter object
3371 * The flushing out of all pending scmd commands following host reset,
3372 * where all IO is dropped to the floor.
3377 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3379 struct scsi_cmnd *scmd;
3383 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3384 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3388 mpt3sas_base_free_smid(ioc, smid);
3389 scsi_dma_unmap(scmd);
3390 if (ioc->pci_error_recovery)
3391 scmd->result = DID_NO_CONNECT << 16;
3393 scmd->result = DID_RESET << 16;
3394 scmd->scsi_done(scmd);
3396 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3401 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3402 * @ioc: per adapter object
3403 * @scmd: pointer to scsi command object
3404 * @mpi_request: pointer to the SCSI_IO reqest message frame
3406 * Supporting protection 1 and 3.
3411 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3412 Mpi2SCSIIORequest_t *mpi_request)
3415 unsigned char prot_op = scsi_get_prot_op(scmd);
3416 unsigned char prot_type = scsi_get_prot_type(scmd);
3417 Mpi25SCSIIORequest_t *mpi_request_3v =
3418 (Mpi25SCSIIORequest_t *)mpi_request;
3420 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3423 if (prot_op == SCSI_PROT_READ_STRIP)
3424 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3425 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3426 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3430 switch (prot_type) {
3431 case SCSI_PROT_DIF_TYPE1:
3432 case SCSI_PROT_DIF_TYPE2:
3435 * enable ref/guard checking
3436 * auto increment ref tag
3438 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3439 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3440 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3441 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3442 cpu_to_be32(scsi_get_lba(scmd));
3445 case SCSI_PROT_DIF_TYPE3:
3448 * enable guard checking
3450 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3455 mpi_request_3v->EEDPBlockSize =
3456 cpu_to_le16(scmd->device->sector_size);
3457 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3461 * _scsih_eedp_error_handling - return sense code for EEDP errors
3462 * @scmd: pointer to scsi command object
3463 * @ioc_status: ioc status
3468 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3472 switch (ioc_status) {
3473 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3476 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3479 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3486 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3488 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3489 SAM_STAT_CHECK_CONDITION;
3494 * _scsih_qcmd - main scsi request entry point
3495 * @scmd: pointer to scsi command object
3496 * @done: function pointer to be invoked on completion
3498 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3500 * Returns 0 on success. If there's a failure, return either:
3501 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3502 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3505 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3507 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3508 struct MPT3SAS_DEVICE *sas_device_priv_data;
3509 struct MPT3SAS_TARGET *sas_target_priv_data;
3510 Mpi2SCSIIORequest_t *mpi_request;
3515 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3516 if (ioc->logging_level & MPT_DEBUG_SCSI)
3517 scsi_print_command(scmd);
3520 sas_device_priv_data = scmd->device->hostdata;
3521 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3522 scmd->result = DID_NO_CONNECT << 16;
3523 scmd->scsi_done(scmd);
3527 if (ioc->pci_error_recovery || ioc->remove_host) {
3528 scmd->result = DID_NO_CONNECT << 16;
3529 scmd->scsi_done(scmd);
3533 sas_target_priv_data = sas_device_priv_data->sas_target;
3535 /* invalid device handle */
3536 handle = sas_target_priv_data->handle;
3537 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3538 scmd->result = DID_NO_CONNECT << 16;
3539 scmd->scsi_done(scmd);
3544 /* host recovery or link resets sent via IOCTLs */
3545 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3546 return SCSI_MLQUEUE_HOST_BUSY;
3548 /* device has been deleted */
3549 else if (sas_target_priv_data->deleted) {
3550 scmd->result = DID_NO_CONNECT << 16;
3551 scmd->scsi_done(scmd);
3553 /* device busy with task managment */
3554 } else if (sas_target_priv_data->tm_busy ||
3555 sas_device_priv_data->block)
3556 return SCSI_MLQUEUE_DEVICE_BUSY;
3558 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3559 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3560 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3561 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3563 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3566 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3568 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3569 scmd->cmd_len != 32)
3570 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3572 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3574 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3575 ioc->name, __func__);
3578 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3579 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3580 _scsih_setup_eedp(ioc, scmd, mpi_request);
3582 if (scmd->cmd_len == 32)
3583 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3584 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3585 if (sas_device_priv_data->sas_target->flags &
3586 MPT_TARGET_FLAGS_RAID_COMPONENT)
3587 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3589 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3590 mpi_request->DevHandle = cpu_to_le16(handle);
3591 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3592 mpi_request->Control = cpu_to_le32(mpi_control);
3593 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3594 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3595 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3596 mpi_request->SenseBufferLowAddress =
3597 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3598 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3599 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3601 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3603 if (mpi_request->DataLength) {
3604 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3605 mpt3sas_base_free_smid(ioc, smid);
3609 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3611 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3612 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3613 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3614 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3615 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3617 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3619 mpt3sas_base_put_smid_default(ioc, smid);
3623 return SCSI_MLQUEUE_HOST_BUSY;
3627 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3628 * @sense_buffer: sense data returned by target
3629 * @data: normalized skey/asc/ascq
3634 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3636 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3637 /* descriptor format */
3638 data->skey = sense_buffer[1] & 0x0F;
3639 data->asc = sense_buffer[2];
3640 data->ascq = sense_buffer[3];
3643 data->skey = sense_buffer[2] & 0x0F;
3644 data->asc = sense_buffer[12];
3645 data->ascq = sense_buffer[13];
3649 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3651 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3652 * @ioc: per adapter object
3653 * @scmd: pointer to scsi command object
3654 * @mpi_reply: reply mf payload returned from firmware
3656 * scsi_status - SCSI Status code returned from target device
3657 * scsi_state - state info associated with SCSI_IO determined by ioc
3658 * ioc_status - ioc supplied status info
3663 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3664 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3668 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3669 MPI2_IOCSTATUS_MASK;
3670 u8 scsi_state = mpi_reply->SCSIState;
3671 u8 scsi_status = mpi_reply->SCSIStatus;
3672 char *desc_ioc_state = NULL;
3673 char *desc_scsi_status = NULL;
3674 char *desc_scsi_state = ioc->tmp_string;
3675 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3676 struct _sas_device *sas_device = NULL;
3677 unsigned long flags;
3678 struct scsi_target *starget = scmd->device->sdev_target;
3679 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3680 char *device_str = NULL;
3684 device_str = "volume";
3686 if (log_info == 0x31170000)
3689 switch (ioc_status) {
3690 case MPI2_IOCSTATUS_SUCCESS:
3691 desc_ioc_state = "success";
3693 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3694 desc_ioc_state = "invalid function";
3696 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3697 desc_ioc_state = "scsi recovered error";
3699 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3700 desc_ioc_state = "scsi invalid dev handle";
3702 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3703 desc_ioc_state = "scsi device not there";
3705 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3706 desc_ioc_state = "scsi data overrun";
3708 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3709 desc_ioc_state = "scsi data underrun";
3711 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3712 desc_ioc_state = "scsi io data error";
3714 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3715 desc_ioc_state = "scsi protocol error";
3717 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3718 desc_ioc_state = "scsi task terminated";
3720 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3721 desc_ioc_state = "scsi residual mismatch";
3723 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3724 desc_ioc_state = "scsi task mgmt failed";
3726 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3727 desc_ioc_state = "scsi ioc terminated";
3729 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3730 desc_ioc_state = "scsi ext terminated";
3732 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3733 desc_ioc_state = "eedp guard error";
3735 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3736 desc_ioc_state = "eedp ref tag error";
3738 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3739 desc_ioc_state = "eedp app tag error";
3742 desc_ioc_state = "unknown";
3746 switch (scsi_status) {
3747 case MPI2_SCSI_STATUS_GOOD:
3748 desc_scsi_status = "good";
3750 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3751 desc_scsi_status = "check condition";
3753 case MPI2_SCSI_STATUS_CONDITION_MET:
3754 desc_scsi_status = "condition met";
3756 case MPI2_SCSI_STATUS_BUSY:
3757 desc_scsi_status = "busy";
3759 case MPI2_SCSI_STATUS_INTERMEDIATE:
3760 desc_scsi_status = "intermediate";
3762 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3763 desc_scsi_status = "intermediate condmet";
3765 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3766 desc_scsi_status = "reservation conflict";
3768 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3769 desc_scsi_status = "command terminated";
3771 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3772 desc_scsi_status = "task set full";
3774 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3775 desc_scsi_status = "aca active";
3777 case MPI2_SCSI_STATUS_TASK_ABORTED:
3778 desc_scsi_status = "task aborted";
3781 desc_scsi_status = "unknown";
3785 desc_scsi_state[0] = '\0';
3787 desc_scsi_state = " ";
3788 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3789 strcat(desc_scsi_state, "response info ");
3790 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3791 strcat(desc_scsi_state, "state terminated ");
3792 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3793 strcat(desc_scsi_state, "no status ");
3794 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3795 strcat(desc_scsi_state, "autosense failed ");
3796 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3797 strcat(desc_scsi_state, "autosense valid ");
3799 scsi_print_command(scmd);
3801 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3802 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3803 device_str, (unsigned long long)priv_target->sas_address);
3805 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3806 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3807 priv_target->sas_address);
3810 "\tsas_address(0x%016llx), phy(%d)\n",
3811 ioc->name, (unsigned long long)
3812 sas_device->sas_address, sas_device->phy);
3814 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3815 ioc->name, (unsigned long long)
3816 sas_device->enclosure_logical_id, sas_device->slot);
3818 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3822 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3823 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3824 desc_ioc_state, ioc_status, smid);
3826 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3827 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3828 scsi_get_resid(scmd));
3830 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3831 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3832 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3834 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3835 ioc->name, desc_scsi_status,
3836 scsi_status, desc_scsi_state, scsi_state);
3838 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3839 struct sense_info data;
3840 _scsih_normalize_sense(scmd->sense_buffer, &data);
3842 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3843 ioc->name, data.skey,
3844 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3847 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3848 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3849 response_bytes = (u8 *)&response_info;
3850 _scsih_response_code(ioc, response_bytes[0]);
3856 * _scsih_turn_on_pfa_led - illuminate PFA LED
3857 * @ioc: per adapter object
3858 * @handle: device handle
3864 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3866 Mpi2SepReply_t mpi_reply;
3867 Mpi2SepRequest_t mpi_request;
3868 struct _sas_device *sas_device;
3870 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3874 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3875 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3876 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3877 mpi_request.SlotStatus =
3878 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3879 mpi_request.DevHandle = cpu_to_le16(handle);
3880 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3881 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3882 &mpi_request)) != 0) {
3883 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3884 __FILE__, __LINE__, __func__);
3887 sas_device->pfa_led_on = 1;
3889 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3890 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3891 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3892 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3893 le32_to_cpu(mpi_reply.IOCLogInfo)));
3898 * _scsih_turn_off_pfa_led - turn off Fault LED
3899 * @ioc: per adapter object
3900 * @sas_device: sas device whose PFA LED has to turned off
3906 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
3907 struct _sas_device *sas_device)
3909 Mpi2SepReply_t mpi_reply;
3910 Mpi2SepRequest_t mpi_request;
3912 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3913 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3914 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3915 mpi_request.SlotStatus = 0;
3916 mpi_request.Slot = cpu_to_le16(sas_device->slot);
3917 mpi_request.DevHandle = 0;
3918 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
3919 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
3920 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3921 &mpi_request)) != 0) {
3922 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3923 __FILE__, __LINE__, __func__);
3927 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3928 dewtprintk(ioc, printk(MPT3SAS_FMT
3929 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3930 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3931 le32_to_cpu(mpi_reply.IOCLogInfo)));
3936 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
3937 * @ioc: per adapter object
3938 * @handle: device handle
3939 * Context: interrupt.
3944 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3946 struct fw_event_work *fw_event;
3948 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
3951 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
3952 fw_event->device_handle = handle;
3953 fw_event->ioc = ioc;
3954 _scsih_fw_event_add(ioc, fw_event);
3958 * _scsih_smart_predicted_fault - process smart errors
3959 * @ioc: per adapter object
3960 * @handle: device handle
3961 * Context: interrupt.
3966 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3968 struct scsi_target *starget;
3969 struct MPT3SAS_TARGET *sas_target_priv_data;
3970 Mpi2EventNotificationReply_t *event_reply;
3971 Mpi2EventDataSasDeviceStatusChange_t *event_data;
3972 struct _sas_device *sas_device;
3974 unsigned long flags;
3976 /* only handle non-raid devices */
3977 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3978 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3980 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3983 starget = sas_device->starget;
3984 sas_target_priv_data = starget->hostdata;
3986 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
3987 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
3988 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3991 starget_printk(KERN_WARNING, starget, "predicted fault\n");
3992 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3994 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
3995 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
3997 /* insert into event log */
3998 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
3999 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4000 event_reply = kzalloc(sz, GFP_KERNEL);
4002 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4003 ioc->name, __FILE__, __LINE__, __func__);
4007 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4008 event_reply->Event =
4009 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4010 event_reply->MsgLength = sz/4;
4011 event_reply->EventDataLength =
4012 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4013 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4014 event_reply->EventData;
4015 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4016 event_data->ASC = 0x5D;
4017 event_data->DevHandle = cpu_to_le16(handle);
4018 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4019 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4024 * _scsih_io_done - scsi request callback
4025 * @ioc: per adapter object
4026 * @smid: system request message index
4027 * @msix_index: MSIX table index supplied by the OS
4028 * @reply: reply message frame(lower 32bit addr)
4030 * Callback handler when using _scsih_qcmd.
4032 * Return 1 meaning mf should be freed from _base_interrupt
4033 * 0 means the mf is freed from this function.
4036 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4038 Mpi2SCSIIORequest_t *mpi_request;
4039 Mpi2SCSIIOReply_t *mpi_reply;
4040 struct scsi_cmnd *scmd;
4046 struct MPT3SAS_DEVICE *sas_device_priv_data;
4047 u32 response_code = 0;
4049 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4050 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4054 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4056 if (mpi_reply == NULL) {
4057 scmd->result = DID_OK << 16;
4061 sas_device_priv_data = scmd->device->hostdata;
4062 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4063 sas_device_priv_data->sas_target->deleted) {
4064 scmd->result = DID_NO_CONNECT << 16;
4067 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4069 /* turning off TLR */
4070 scsi_state = mpi_reply->SCSIState;
4071 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4073 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4074 if (!sas_device_priv_data->tlr_snoop_check) {
4075 sas_device_priv_data->tlr_snoop_check++;
4076 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4077 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4078 sas_device_priv_data->flags &=
4082 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4083 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4084 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4085 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4088 ioc_status &= MPI2_IOCSTATUS_MASK;
4089 scsi_status = mpi_reply->SCSIStatus;
4091 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4092 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4093 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4094 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4095 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4098 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4099 struct sense_info data;
4100 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4102 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4103 le32_to_cpu(mpi_reply->SenseCount));
4104 memcpy(scmd->sense_buffer, sense_data, sz);
4105 _scsih_normalize_sense(scmd->sense_buffer, &data);
4106 /* failure prediction threshold exceeded */
4107 if (data.asc == 0x5D)
4108 _scsih_smart_predicted_fault(ioc,
4109 le16_to_cpu(mpi_reply->DevHandle));
4110 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4113 switch (ioc_status) {
4114 case MPI2_IOCSTATUS_BUSY:
4115 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4116 scmd->result = SAM_STAT_BUSY;
4119 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4120 scmd->result = DID_NO_CONNECT << 16;
4123 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4124 if (sas_device_priv_data->block) {
4125 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4128 if (log_info == 0x31110630) {
4129 if (scmd->retries > 2) {
4130 scmd->result = DID_NO_CONNECT << 16;
4131 scsi_device_set_state(scmd->device,
4134 scmd->result = DID_SOFT_ERROR << 16;
4135 scmd->device->expecting_cc_ua = 1;
4139 scmd->result = DID_SOFT_ERROR << 16;
4141 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4142 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4143 scmd->result = DID_RESET << 16;
4146 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4147 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4148 scmd->result = DID_SOFT_ERROR << 16;
4150 scmd->result = (DID_OK << 16) | scsi_status;
4153 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4154 scmd->result = (DID_OK << 16) | scsi_status;
4156 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4159 if (xfer_cnt < scmd->underflow) {
4160 if (scsi_status == SAM_STAT_BUSY)
4161 scmd->result = SAM_STAT_BUSY;
4163 scmd->result = DID_SOFT_ERROR << 16;
4164 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4165 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4166 scmd->result = DID_SOFT_ERROR << 16;
4167 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4168 scmd->result = DID_RESET << 16;
4169 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4170 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4171 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4172 scmd->result = (DRIVER_SENSE << 24) |
4173 SAM_STAT_CHECK_CONDITION;
4174 scmd->sense_buffer[0] = 0x70;
4175 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4176 scmd->sense_buffer[12] = 0x20;
4177 scmd->sense_buffer[13] = 0;
4181 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4182 scsi_set_resid(scmd, 0);
4183 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4184 case MPI2_IOCSTATUS_SUCCESS:
4185 scmd->result = (DID_OK << 16) | scsi_status;
4186 if (response_code ==
4187 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4188 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4189 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4190 scmd->result = DID_SOFT_ERROR << 16;
4191 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4192 scmd->result = DID_RESET << 16;
4195 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4196 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4197 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4198 _scsih_eedp_error_handling(scmd, ioc_status);
4201 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4202 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4203 case MPI2_IOCSTATUS_INVALID_SGL:
4204 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4205 case MPI2_IOCSTATUS_INVALID_FIELD:
4206 case MPI2_IOCSTATUS_INVALID_STATE:
4207 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4208 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4210 scmd->result = DID_SOFT_ERROR << 16;
4215 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4216 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4217 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4222 scsi_dma_unmap(scmd);
4224 scmd->scsi_done(scmd);
4229 * _scsih_sas_host_refresh - refreshing sas host object contents
4230 * @ioc: per adapter object
4233 * During port enable, fw will send topology events for every device. Its
4234 * possible that the handles may change from the previous setting, so this
4235 * code keeping handles updating if changed.
4240 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4245 Mpi2ConfigReply_t mpi_reply;
4246 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4247 u16 attached_handle;
4250 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4251 "updating handles for sas_host(0x%016llx)\n",
4252 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4254 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4255 * sizeof(Mpi2SasIOUnit0PhyData_t));
4256 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4257 if (!sas_iounit_pg0) {
4258 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4259 ioc->name, __FILE__, __LINE__, __func__);
4263 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4264 sas_iounit_pg0, sz)) != 0)
4266 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4267 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4269 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4270 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4272 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4273 PhyData[0].ControllerDevHandle);
4274 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4275 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4277 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4278 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4279 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4280 attached_handle, i, link_rate);
4283 kfree(sas_iounit_pg0);
4287 * _scsih_sas_host_add - create sas host object
4288 * @ioc: per adapter object
4290 * Creating host side data object, stored in ioc->sas_hba
4295 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4298 Mpi2ConfigReply_t mpi_reply;
4299 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4300 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4301 Mpi2SasPhyPage0_t phy_pg0;
4302 Mpi2SasDevicePage0_t sas_device_pg0;
4303 Mpi2SasEnclosurePage0_t enclosure_pg0;
4306 u8 device_missing_delay;
4308 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4309 if (!ioc->sas_hba.num_phys) {
4310 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4311 ioc->name, __FILE__, __LINE__, __func__);
4315 /* sas_iounit page 0 */
4316 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4317 sizeof(Mpi2SasIOUnit0PhyData_t));
4318 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4319 if (!sas_iounit_pg0) {
4320 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4321 ioc->name, __FILE__, __LINE__, __func__);
4324 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4325 sas_iounit_pg0, sz))) {
4326 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4327 ioc->name, __FILE__, __LINE__, __func__);
4330 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4331 MPI2_IOCSTATUS_MASK;
4332 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4333 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4334 ioc->name, __FILE__, __LINE__, __func__);
4338 /* sas_iounit page 1 */
4339 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4340 sizeof(Mpi2SasIOUnit1PhyData_t));
4341 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4342 if (!sas_iounit_pg1) {
4343 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4344 ioc->name, __FILE__, __LINE__, __func__);
4347 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4348 sas_iounit_pg1, sz))) {
4349 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4350 ioc->name, __FILE__, __LINE__, __func__);
4353 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4354 MPI2_IOCSTATUS_MASK;
4355 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4356 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4357 ioc->name, __FILE__, __LINE__, __func__);
4361 ioc->io_missing_delay =
4362 sas_iounit_pg1->IODeviceMissingDelay;
4363 device_missing_delay =
4364 sas_iounit_pg1->ReportDeviceMissingDelay;
4365 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4366 ioc->device_missing_delay = (device_missing_delay &
4367 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4369 ioc->device_missing_delay = device_missing_delay &
4370 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4372 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4373 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4374 sizeof(struct _sas_phy), GFP_KERNEL);
4375 if (!ioc->sas_hba.phy) {
4376 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4377 ioc->name, __FILE__, __LINE__, __func__);
4380 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4381 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4383 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4384 ioc->name, __FILE__, __LINE__, __func__);
4387 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4388 MPI2_IOCSTATUS_MASK;
4389 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4390 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4391 ioc->name, __FILE__, __LINE__, __func__);
4396 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4397 PhyData[0].ControllerDevHandle);
4398 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4399 ioc->sas_hba.phy[i].phy_id = i;
4400 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4401 phy_pg0, ioc->sas_hba.parent_dev);
4403 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4404 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4405 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4406 ioc->name, __FILE__, __LINE__, __func__);
4409 ioc->sas_hba.enclosure_handle =
4410 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4411 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4413 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4414 ioc->name, ioc->sas_hba.handle,
4415 (unsigned long long) ioc->sas_hba.sas_address,
4416 ioc->sas_hba.num_phys) ;
4418 if (ioc->sas_hba.enclosure_handle) {
4419 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4420 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4421 ioc->sas_hba.enclosure_handle)))
4422 ioc->sas_hba.enclosure_logical_id =
4423 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4427 kfree(sas_iounit_pg1);
4428 kfree(sas_iounit_pg0);
4432 * _scsih_expander_add - creating expander object
4433 * @ioc: per adapter object
4434 * @handle: expander handle
4436 * Creating expander object, stored in ioc->sas_expander_list.
4438 * Return 0 for success, else error.
4441 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4443 struct _sas_node *sas_expander;
4444 Mpi2ConfigReply_t mpi_reply;
4445 Mpi2ExpanderPage0_t expander_pg0;
4446 Mpi2ExpanderPage1_t expander_pg1;
4447 Mpi2SasEnclosurePage0_t enclosure_pg0;
4450 u64 sas_address, sas_address_parent = 0;
4452 unsigned long flags;
4453 struct _sas_port *mpt3sas_port = NULL;
4460 if (ioc->shost_recovery || ioc->pci_error_recovery)
4463 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4464 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4465 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4466 ioc->name, __FILE__, __LINE__, __func__);
4470 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4471 MPI2_IOCSTATUS_MASK;
4472 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4473 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4474 ioc->name, __FILE__, __LINE__, __func__);
4478 /* handle out of order topology events */
4479 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4480 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4482 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4483 ioc->name, __FILE__, __LINE__, __func__);
4486 if (sas_address_parent != ioc->sas_hba.sas_address) {
4487 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4488 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4489 sas_address_parent);
4490 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4491 if (!sas_expander) {
4492 rc = _scsih_expander_add(ioc, parent_handle);
4498 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4499 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4500 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4502 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4507 sas_expander = kzalloc(sizeof(struct _sas_node),
4509 if (!sas_expander) {
4510 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4511 ioc->name, __FILE__, __LINE__, __func__);
4515 sas_expander->handle = handle;
4516 sas_expander->num_phys = expander_pg0.NumPhys;
4517 sas_expander->sas_address_parent = sas_address_parent;
4518 sas_expander->sas_address = sas_address;
4520 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4521 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4522 handle, parent_handle, (unsigned long long)
4523 sas_expander->sas_address, sas_expander->num_phys);
4525 if (!sas_expander->num_phys)
4527 sas_expander->phy = kcalloc(sas_expander->num_phys,
4528 sizeof(struct _sas_phy), GFP_KERNEL);
4529 if (!sas_expander->phy) {
4530 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4531 ioc->name, __FILE__, __LINE__, __func__);
4536 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4537 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4538 sas_address_parent);
4539 if (!mpt3sas_port) {
4540 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4541 ioc->name, __FILE__, __LINE__, __func__);
4545 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4547 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4548 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4549 &expander_pg1, i, handle))) {
4550 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4551 ioc->name, __FILE__, __LINE__, __func__);
4555 sas_expander->phy[i].handle = handle;
4556 sas_expander->phy[i].phy_id = i;
4558 if ((mpt3sas_transport_add_expander_phy(ioc,
4559 &sas_expander->phy[i], expander_pg1,
4560 sas_expander->parent_dev))) {
4561 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4562 ioc->name, __FILE__, __LINE__, __func__);
4568 if (sas_expander->enclosure_handle) {
4569 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4570 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4571 sas_expander->enclosure_handle)))
4572 sas_expander->enclosure_logical_id =
4573 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4576 _scsih_expander_node_add(ioc, sas_expander);
4582 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4583 sas_address_parent);
4584 kfree(sas_expander);
4589 * mpt3sas_expander_remove - removing expander object
4590 * @ioc: per adapter object
4591 * @sas_address: expander sas_address
4596 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4598 struct _sas_node *sas_expander;
4599 unsigned long flags;
4601 if (ioc->shost_recovery)
4604 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4605 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4608 list_del(&sas_expander->list);
4609 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4611 _scsih_expander_node_remove(ioc, sas_expander);
4615 * _scsih_done - internal SCSI_IO callback handler.
4616 * @ioc: per adapter object
4617 * @smid: system request message index
4618 * @msix_index: MSIX table index supplied by the OS
4619 * @reply: reply message frame(lower 32bit addr)
4621 * Callback handler when sending internal generated SCSI_IO.
4622 * The callback index passed is `ioc->scsih_cb_idx`
4624 * Return 1 meaning mf should be freed from _base_interrupt
4625 * 0 means the mf is freed from this function.
4628 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4630 MPI2DefaultReply_t *mpi_reply;
4632 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4633 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4635 if (ioc->scsih_cmds.smid != smid)
4637 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4639 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4640 mpi_reply->MsgLength*4);
4641 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4643 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4644 complete(&ioc->scsih_cmds.done);
4651 #define MPT3_MAX_LUNS (255)
4655 * _scsih_check_access_status - check access flags
4656 * @ioc: per adapter object
4657 * @sas_address: sas address
4658 * @handle: sas device handle
4659 * @access_flags: errors returned during discovery of the device
4661 * Return 0 for success, else failure
4664 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4665 u16 handle, u8 access_status)
4670 switch (access_status) {
4671 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4672 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4675 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4676 desc = "sata capability failed";
4678 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4679 desc = "sata affiliation conflict";
4681 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4682 desc = "route not addressable";
4684 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4685 desc = "smp error not addressable";
4687 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4688 desc = "device blocked";
4690 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4691 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4692 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4693 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4694 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4695 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4696 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4697 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4698 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4699 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4700 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4701 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4702 desc = "sata initialization failed";
4713 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4714 ioc->name, desc, (unsigned long long)sas_address, handle);
4719 * _scsih_check_device - checking device responsiveness
4720 * @ioc: per adapter object
4721 * @parent_sas_address: sas address of parent expander or sas host
4722 * @handle: attached device handle
4723 * @phy_numberv: phy number
4724 * @link_rate: new link rate
4729 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4730 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4732 Mpi2ConfigReply_t mpi_reply;
4733 Mpi2SasDevicePage0_t sas_device_pg0;
4734 struct _sas_device *sas_device;
4736 unsigned long flags;
4738 struct scsi_target *starget;
4739 struct MPT3SAS_TARGET *sas_target_priv_data;
4743 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4744 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4747 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4748 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4751 /* wide port handling ~ we need only handle device once for the phy that
4752 * is matched in sas device page zero
4754 if (phy_number != sas_device_pg0.PhyNum)
4757 /* check if this is end device */
4758 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4759 if (!(_scsih_is_end_device(device_info)))
4762 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4763 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4764 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4768 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4772 if (unlikely(sas_device->handle != handle)) {
4773 starget = sas_device->starget;
4774 sas_target_priv_data = starget->hostdata;
4775 starget_printk(KERN_INFO, starget,
4776 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4777 sas_device->handle, handle);
4778 sas_target_priv_data->handle = handle;
4779 sas_device->handle = handle;
4782 /* check if device is present */
4783 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4784 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4786 "device is not present handle(0x%04x), flags!!!\n",
4788 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4792 /* check if there were any issues with discovery */
4793 if (_scsih_check_access_status(ioc, sas_address, handle,
4794 sas_device_pg0.AccessStatus)) {
4795 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4799 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4800 _scsih_ublock_io_device(ioc, sas_address);
4805 * _scsih_add_device - creating sas device object
4806 * @ioc: per adapter object
4807 * @handle: sas device handle
4808 * @phy_num: phy number end device attached to
4809 * @is_pd: is this hidden raid component
4811 * Creating end device object, stored in ioc->sas_device_list.
4813 * Returns 0 for success, non-zero for failure.
4816 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4819 Mpi2ConfigReply_t mpi_reply;
4820 Mpi2SasDevicePage0_t sas_device_pg0;
4821 Mpi2SasEnclosurePage0_t enclosure_pg0;
4822 struct _sas_device *sas_device;
4826 unsigned long flags;
4828 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4829 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4830 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4831 ioc->name, __FILE__, __LINE__, __func__);
4835 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4836 MPI2_IOCSTATUS_MASK;
4837 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4838 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4839 ioc->name, __FILE__, __LINE__, __func__);
4843 /* check if this is end device */
4844 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4845 if (!(_scsih_is_end_device(device_info)))
4847 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4849 /* check if device is present */
4850 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4851 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4852 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4857 /* check if there were any issues with discovery */
4858 if (_scsih_check_access_status(ioc, sas_address, handle,
4859 sas_device_pg0.AccessStatus))
4862 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4863 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4865 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4870 sas_device = kzalloc(sizeof(struct _sas_device),
4873 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4874 ioc->name, __FILE__, __LINE__, __func__);
4878 sas_device->handle = handle;
4879 if (_scsih_get_sas_address(ioc,
4880 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4881 &sas_device->sas_address_parent) != 0)
4882 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4883 ioc->name, __FILE__, __LINE__, __func__);
4884 sas_device->enclosure_handle =
4885 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4887 le16_to_cpu(sas_device_pg0.Slot);
4888 sas_device->device_info = device_info;
4889 sas_device->sas_address = sas_address;
4890 sas_device->phy = sas_device_pg0.PhyNum;
4891 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
4892 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
4894 /* get enclosure_logical_id */
4895 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
4896 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4897 sas_device->enclosure_handle)))
4898 sas_device->enclosure_logical_id =
4899 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4901 /* get device name */
4902 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
4904 if (ioc->wait_for_discovery_to_complete)
4905 _scsih_sas_device_init_add(ioc, sas_device);
4907 _scsih_sas_device_add(ioc, sas_device);
4913 * _scsih_remove_device - removing sas device object
4914 * @ioc: per adapter object
4915 * @sas_device_delete: the sas_device object
4920 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
4921 struct _sas_device *sas_device)
4923 struct MPT3SAS_TARGET *sas_target_priv_data;
4925 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
4926 (sas_device->pfa_led_on)) {
4927 _scsih_turn_off_pfa_led(ioc, sas_device);
4928 sas_device->pfa_led_on = 0;
4930 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4931 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4932 ioc->name, __func__,
4933 sas_device->handle, (unsigned long long)
4934 sas_device->sas_address));
4936 if (sas_device->starget && sas_device->starget->hostdata) {
4937 sas_target_priv_data = sas_device->starget->hostdata;
4938 sas_target_priv_data->deleted = 1;
4939 _scsih_ublock_io_device(ioc, sas_device->sas_address);
4940 sas_target_priv_data->handle =
4941 MPT3SAS_INVALID_DEVICE_HANDLE;
4943 mpt3sas_transport_port_remove(ioc,
4944 sas_device->sas_address,
4945 sas_device->sas_address_parent);
4948 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4949 ioc->name, sas_device->handle,
4950 (unsigned long long) sas_device->sas_address);
4952 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4953 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4954 ioc->name, __func__,
4955 sas_device->handle, (unsigned long long)
4956 sas_device->sas_address));
4961 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4963 * _scsih_sas_topology_change_event_debug - debug for topology event
4964 * @ioc: per adapter object
4965 * @event_data: event data payload
4969 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
4970 Mpi2EventDataSasTopologyChangeList_t *event_data)
4976 char *status_str = NULL;
4977 u8 link_rate, prev_link_rate;
4979 switch (event_data->ExpStatus) {
4980 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
4983 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
4984 status_str = "remove";
4986 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
4988 status_str = "responding";
4990 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
4991 status_str = "remove delay";
4994 status_str = "unknown status";
4997 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
4998 ioc->name, status_str);
4999 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5000 "start_phy(%02d), count(%d)\n",
5001 le16_to_cpu(event_data->ExpanderDevHandle),
5002 le16_to_cpu(event_data->EnclosureHandle),
5003 event_data->StartPhyNum, event_data->NumEntries);
5004 for (i = 0; i < event_data->NumEntries; i++) {
5005 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5008 phy_number = event_data->StartPhyNum + i;
5009 reason_code = event_data->PHY[i].PhyStatus &
5010 MPI2_EVENT_SAS_TOPO_RC_MASK;
5011 switch (reason_code) {
5012 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5013 status_str = "target add";
5015 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5016 status_str = "target remove";
5018 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5019 status_str = "delay target remove";
5021 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5022 status_str = "link rate change";
5024 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5025 status_str = "target responding";
5028 status_str = "unknown";
5031 link_rate = event_data->PHY[i].LinkRate >> 4;
5032 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5033 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5034 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5035 handle, status_str, link_rate, prev_link_rate);
5042 * _scsih_sas_topology_change_event - handle topology changes
5043 * @ioc: per adapter object
5044 * @fw_event: The fw_event_work object
5049 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5050 struct fw_event_work *fw_event)
5053 u16 parent_handle, handle;
5055 u8 phy_number, max_phys;
5056 struct _sas_node *sas_expander;
5058 unsigned long flags;
5059 u8 link_rate, prev_link_rate;
5060 Mpi2EventDataSasTopologyChangeList_t *event_data =
5061 (Mpi2EventDataSasTopologyChangeList_t *)
5062 fw_event->event_data;
5064 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5065 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5066 _scsih_sas_topology_change_event_debug(ioc, event_data);
5069 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5072 if (!ioc->sas_hba.num_phys)
5073 _scsih_sas_host_add(ioc);
5075 _scsih_sas_host_refresh(ioc);
5077 if (fw_event->ignore) {
5078 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5079 "ignoring expander event\n", ioc->name));
5083 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5085 /* handle expander add */
5086 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5087 if (_scsih_expander_add(ioc, parent_handle) != 0)
5090 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5091 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5094 sas_address = sas_expander->sas_address;
5095 max_phys = sas_expander->num_phys;
5096 } else if (parent_handle < ioc->sas_hba.num_phys) {
5097 sas_address = ioc->sas_hba.sas_address;
5098 max_phys = ioc->sas_hba.num_phys;
5100 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5103 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5105 /* handle siblings events */
5106 for (i = 0; i < event_data->NumEntries; i++) {
5107 if (fw_event->ignore) {
5108 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5109 "ignoring expander event\n", ioc->name));
5112 if (ioc->remove_host || ioc->pci_error_recovery)
5114 phy_number = event_data->StartPhyNum + i;
5115 if (phy_number >= max_phys)
5117 reason_code = event_data->PHY[i].PhyStatus &
5118 MPI2_EVENT_SAS_TOPO_RC_MASK;
5119 if ((event_data->PHY[i].PhyStatus &
5120 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5121 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5123 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5126 link_rate = event_data->PHY[i].LinkRate >> 4;
5127 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5128 switch (reason_code) {
5129 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5131 if (ioc->shost_recovery)
5134 if (link_rate == prev_link_rate)
5137 mpt3sas_transport_update_links(ioc, sas_address,
5138 handle, phy_number, link_rate);
5140 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5143 _scsih_check_device(ioc, sas_address, handle,
5144 phy_number, link_rate);
5147 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5149 if (ioc->shost_recovery)
5152 mpt3sas_transport_update_links(ioc, sas_address,
5153 handle, phy_number, link_rate);
5155 _scsih_add_device(ioc, handle, phy_number, 0);
5158 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5160 _scsih_device_remove_by_handle(ioc, handle);
5165 /* handle expander removal */
5166 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5168 mpt3sas_expander_remove(ioc, sas_address);
5173 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5175 * _scsih_sas_device_status_change_event_debug - debug for device event
5176 * @event_data: event data payload
5182 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5183 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5185 char *reason_str = NULL;
5187 switch (event_data->ReasonCode) {
5188 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5189 reason_str = "smart data";
5191 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5192 reason_str = "unsupported device discovered";
5194 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5195 reason_str = "internal device reset";
5197 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5198 reason_str = "internal task abort";
5200 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5201 reason_str = "internal task abort set";
5203 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5204 reason_str = "internal clear task set";
5206 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5207 reason_str = "internal query task";
5209 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5210 reason_str = "sata init failure";
5212 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5213 reason_str = "internal device reset complete";
5215 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5216 reason_str = "internal task abort complete";
5218 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5219 reason_str = "internal async notification";
5221 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5222 reason_str = "expander reduced functionality";
5224 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5225 reason_str = "expander reduced functionality complete";
5228 reason_str = "unknown reason";
5231 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5232 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5233 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5234 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5235 le16_to_cpu(event_data->TaskTag));
5236 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5237 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5238 event_data->ASC, event_data->ASCQ);
5244 * _scsih_sas_device_status_change_event - handle device status change
5245 * @ioc: per adapter object
5246 * @fw_event: The fw_event_work object
5252 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5253 struct fw_event_work *fw_event)
5255 struct MPT3SAS_TARGET *target_priv_data;
5256 struct _sas_device *sas_device;
5258 unsigned long flags;
5259 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5260 (Mpi2EventDataSasDeviceStatusChange_t *)
5261 fw_event->event_data;
5263 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5264 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5265 _scsih_sas_device_status_change_event_debug(ioc,
5269 /* In MPI Revision K (0xC), the internal device reset complete was
5270 * implemented, so avoid setting tm_busy flag for older firmware.
5272 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5275 if (event_data->ReasonCode !=
5276 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5277 event_data->ReasonCode !=
5278 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5281 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5282 sas_address = le64_to_cpu(event_data->SASAddress);
5283 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5286 if (!sas_device || !sas_device->starget) {
5287 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5291 target_priv_data = sas_device->starget->hostdata;
5292 if (!target_priv_data) {
5293 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5297 if (event_data->ReasonCode ==
5298 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5299 target_priv_data->tm_busy = 1;
5301 target_priv_data->tm_busy = 0;
5302 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5305 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5307 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5309 * @ioc: per adapter object
5310 * @event_data: event data payload
5316 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5317 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5319 char *reason_str = NULL;
5321 switch (event_data->ReasonCode) {
5322 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5323 reason_str = "enclosure add";
5325 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5326 reason_str = "enclosure remove";
5329 reason_str = "unknown reason";
5333 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5334 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5335 " number slots(%d)\n", ioc->name, reason_str,
5336 le16_to_cpu(event_data->EnclosureHandle),
5337 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5338 le16_to_cpu(event_data->StartSlot));
5343 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5344 * @ioc: per adapter object
5345 * @fw_event: The fw_event_work object
5351 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5352 struct fw_event_work *fw_event)
5354 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5355 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5356 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5357 (Mpi2EventDataSasEnclDevStatusChange_t *)
5358 fw_event->event_data);
5363 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5364 * @ioc: per adapter object
5365 * @fw_event: The fw_event_work object
5371 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5372 struct fw_event_work *fw_event)
5374 struct scsi_cmnd *scmd;
5375 struct scsi_device *sdev;
5378 struct MPT3SAS_DEVICE *sas_device_priv_data;
5379 u32 termination_count;
5381 Mpi2SCSITaskManagementReply_t *mpi_reply;
5382 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5383 (Mpi2EventDataSasBroadcastPrimitive_t *)
5384 fw_event->event_data;
5386 unsigned long flags;
5389 u8 task_abort_retries;
5391 mutex_lock(&ioc->tm_cmds.mutex);
5393 "%s: enter: phy number(%d), width(%d)\n",
5394 ioc->name, __func__, event_data->PhyNum,
5395 event_data->PortWidth);
5397 _scsih_block_io_all_device(ioc);
5399 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5400 mpi_reply = ioc->tm_cmds.reply;
5401 broadcast_aen_retry:
5403 /* sanity checks for retrying this loop */
5404 if (max_retries++ == 5) {
5405 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5406 ioc->name, __func__));
5408 } else if (max_retries > 1)
5409 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5410 ioc->name, __func__, max_retries - 1));
5412 termination_count = 0;
5414 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5415 if (ioc->shost_recovery)
5417 scmd = _scsih_scsi_lookup_get(ioc, smid);
5420 sdev = scmd->device;
5421 sas_device_priv_data = sdev->hostdata;
5422 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5424 /* skip hidden raid components */
5425 if (sas_device_priv_data->sas_target->flags &
5426 MPT_TARGET_FLAGS_RAID_COMPONENT)
5429 if (sas_device_priv_data->sas_target->flags &
5430 MPT_TARGET_FLAGS_VOLUME)
5433 handle = sas_device_priv_data->sas_target->handle;
5434 lun = sas_device_priv_data->lun;
5437 if (ioc->shost_recovery)
5440 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5441 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5442 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5445 sdev_printk(KERN_WARNING, sdev,
5446 "mpt3sas_scsih_issue_tm: FAILED when sending "
5447 "QUERY_TASK: scmd(%p)\n", scmd);
5448 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5449 goto broadcast_aen_retry;
5451 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5452 & MPI2_IOCSTATUS_MASK;
5453 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5454 sdev_printk(KERN_WARNING, sdev,
5455 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5457 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5458 goto broadcast_aen_retry;
5461 /* see if IO is still owned by IOC and target */
5462 if (mpi_reply->ResponseCode ==
5463 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5464 mpi_reply->ResponseCode ==
5465 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5466 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5469 task_abort_retries = 0;
5471 if (task_abort_retries++ == 60) {
5472 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5473 "%s: ABORT_TASK: giving up\n", ioc->name,
5475 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5476 goto broadcast_aen_retry;
5479 if (ioc->shost_recovery)
5482 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5483 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5486 sdev_printk(KERN_WARNING, sdev,
5487 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5488 "scmd(%p)\n", scmd);
5492 if (task_abort_retries > 1)
5493 sdev_printk(KERN_WARNING, sdev,
5494 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5496 task_abort_retries - 1, scmd);
5498 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5499 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5502 if (ioc->broadcast_aen_pending) {
5503 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5504 "%s: loop back due to pending AEN\n",
5505 ioc->name, __func__));
5506 ioc->broadcast_aen_pending = 0;
5507 goto broadcast_aen_retry;
5511 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5514 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5515 "%s - exit, query_count = %d termination_count = %d\n",
5516 ioc->name, __func__, query_count, termination_count));
5518 ioc->broadcast_aen_busy = 0;
5519 if (!ioc->shost_recovery)
5520 _scsih_ublock_io_all_device(ioc);
5521 mutex_unlock(&ioc->tm_cmds.mutex);
5525 * _scsih_sas_discovery_event - handle discovery events
5526 * @ioc: per adapter object
5527 * @fw_event: The fw_event_work object
5533 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5534 struct fw_event_work *fw_event)
5536 Mpi2EventDataSasDiscovery_t *event_data =
5537 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5539 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5540 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5541 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5542 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5544 if (event_data->DiscoveryStatus)
5545 pr_info("discovery_status(0x%08x)",
5546 le32_to_cpu(event_data->DiscoveryStatus));
5551 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5552 !ioc->sas_hba.num_phys) {
5553 if (disable_discovery > 0 && ioc->shost_recovery) {
5554 /* Wait for the reset to complete */
5555 while (ioc->shost_recovery)
5558 _scsih_sas_host_add(ioc);
5563 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5564 * @ioc: per adapter object
5565 * @handle: device handle for physical disk
5566 * @phys_disk_num: physical disk number
5568 * Return 0 for success, else failure.
5571 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5573 Mpi2RaidActionRequest_t *mpi_request;
5574 Mpi2RaidActionReply_t *mpi_reply;
5582 mutex_lock(&ioc->scsih_cmds.mutex);
5584 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5585 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5586 ioc->name, __func__);
5590 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5592 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5594 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5595 ioc->name, __func__);
5596 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5601 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5602 ioc->scsih_cmds.smid = smid;
5603 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5605 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5606 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5607 mpi_request->PhysDiskNum = phys_disk_num;
5609 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5610 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5611 handle, phys_disk_num));
5613 init_completion(&ioc->scsih_cmds.done);
5614 mpt3sas_base_put_smid_default(ioc, smid);
5615 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5617 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5618 pr_err(MPT3SAS_FMT "%s: timeout\n",
5619 ioc->name, __func__);
5620 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5626 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5628 mpi_reply = ioc->scsih_cmds.reply;
5629 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5630 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5631 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5634 ioc_status &= MPI2_IOCSTATUS_MASK;
5635 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5636 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5637 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5638 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5642 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5643 "IR RAID_ACTION: completed successfully\n",
5648 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5649 mutex_unlock(&ioc->scsih_cmds.mutex);
5652 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5658 * _scsih_reprobe_lun - reprobing lun
5659 * @sdev: scsi device struct
5660 * @no_uld_attach: sdev->no_uld_attach flag setting
5664 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5667 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5668 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5669 sdev->no_uld_attach ? "hidding" : "exposing");
5670 rc = scsi_device_reprobe(sdev);
5674 * _scsih_sas_volume_add - add new volume
5675 * @ioc: per adapter object
5676 * @element: IR config element data
5682 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5683 Mpi2EventIrConfigElement_t *element)
5685 struct _raid_device *raid_device;
5686 unsigned long flags;
5688 u16 handle = le16_to_cpu(element->VolDevHandle);
5691 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5694 "failure at %s:%d/%s()!\n", ioc->name,
5695 __FILE__, __LINE__, __func__);
5699 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5700 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5701 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5706 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5709 "failure at %s:%d/%s()!\n", ioc->name,
5710 __FILE__, __LINE__, __func__);
5714 raid_device->id = ioc->sas_id++;
5715 raid_device->channel = RAID_CHANNEL;
5716 raid_device->handle = handle;
5717 raid_device->wwid = wwid;
5718 _scsih_raid_device_add(ioc, raid_device);
5719 if (!ioc->wait_for_discovery_to_complete) {
5720 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5721 raid_device->id, 0);
5723 _scsih_raid_device_remove(ioc, raid_device);
5725 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5726 _scsih_determine_boot_device(ioc, raid_device, 1);
5727 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5732 * _scsih_sas_volume_delete - delete volume
5733 * @ioc: per adapter object
5734 * @handle: volume device handle
5740 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5742 struct _raid_device *raid_device;
5743 unsigned long flags;
5744 struct MPT3SAS_TARGET *sas_target_priv_data;
5745 struct scsi_target *starget = NULL;
5747 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5748 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5750 if (raid_device->starget) {
5751 starget = raid_device->starget;
5752 sas_target_priv_data = starget->hostdata;
5753 sas_target_priv_data->deleted = 1;
5755 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5756 ioc->name, raid_device->handle,
5757 (unsigned long long) raid_device->wwid);
5758 list_del(&raid_device->list);
5761 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5763 scsi_remove_target(&starget->dev);
5767 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5768 * @ioc: per adapter object
5769 * @element: IR config element data
5775 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5776 Mpi2EventIrConfigElement_t *element)
5778 struct _sas_device *sas_device;
5779 struct scsi_target *starget = NULL;
5780 struct MPT3SAS_TARGET *sas_target_priv_data;
5781 unsigned long flags;
5782 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5784 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5785 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5787 sas_device->volume_handle = 0;
5788 sas_device->volume_wwid = 0;
5789 clear_bit(handle, ioc->pd_handles);
5790 if (sas_device->starget && sas_device->starget->hostdata) {
5791 starget = sas_device->starget;
5792 sas_target_priv_data = starget->hostdata;
5793 sas_target_priv_data->flags &=
5794 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5797 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5801 /* exposing raid component */
5803 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5807 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5808 * @ioc: per adapter object
5809 * @element: IR config element data
5815 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5816 Mpi2EventIrConfigElement_t *element)
5818 struct _sas_device *sas_device;
5819 struct scsi_target *starget = NULL;
5820 struct MPT3SAS_TARGET *sas_target_priv_data;
5821 unsigned long flags;
5822 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5823 u16 volume_handle = 0;
5824 u64 volume_wwid = 0;
5826 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
5828 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
5831 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5832 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5834 set_bit(handle, ioc->pd_handles);
5835 if (sas_device->starget && sas_device->starget->hostdata) {
5836 starget = sas_device->starget;
5837 sas_target_priv_data = starget->hostdata;
5838 sas_target_priv_data->flags |=
5839 MPT_TARGET_FLAGS_RAID_COMPONENT;
5840 sas_device->volume_handle = volume_handle;
5841 sas_device->volume_wwid = volume_wwid;
5844 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5848 /* hiding raid component */
5849 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5851 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
5855 * _scsih_sas_pd_delete - delete pd component
5856 * @ioc: per adapter object
5857 * @element: IR config element data
5863 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
5864 Mpi2EventIrConfigElement_t *element)
5866 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5868 _scsih_device_remove_by_handle(ioc, handle);
5872 * _scsih_sas_pd_add - remove pd component
5873 * @ioc: per adapter object
5874 * @element: IR config element data
5880 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
5881 Mpi2EventIrConfigElement_t *element)
5883 struct _sas_device *sas_device;
5884 unsigned long flags;
5885 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5886 Mpi2ConfigReply_t mpi_reply;
5887 Mpi2SasDevicePage0_t sas_device_pg0;
5892 set_bit(handle, ioc->pd_handles);
5894 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5895 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5896 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5898 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5902 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5903 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5904 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5905 ioc->name, __FILE__, __LINE__, __func__);
5909 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5910 MPI2_IOCSTATUS_MASK;
5911 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5912 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5913 ioc->name, __FILE__, __LINE__, __func__);
5917 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5918 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5919 mpt3sas_transport_update_links(ioc, sas_address, handle,
5920 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5922 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5923 _scsih_add_device(ioc, handle, 0, 1);
5926 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5928 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5929 * @ioc: per adapter object
5930 * @event_data: event data payload
5936 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5937 Mpi2EventDataIrConfigChangeList_t *event_data)
5939 Mpi2EventIrConfigElement_t *element;
5942 char *reason_str = NULL, *element_str = NULL;
5944 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5946 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
5947 ioc->name, (le32_to_cpu(event_data->Flags) &
5948 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5949 "foreign" : "native", event_data->NumElements);
5950 for (i = 0; i < event_data->NumElements; i++, element++) {
5951 switch (element->ReasonCode) {
5952 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5955 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5956 reason_str = "remove";
5958 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5959 reason_str = "no change";
5961 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5962 reason_str = "hide";
5964 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5965 reason_str = "unhide";
5967 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5968 reason_str = "volume_created";
5970 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
5971 reason_str = "volume_deleted";
5973 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
5974 reason_str = "pd_created";
5976 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
5977 reason_str = "pd_deleted";
5980 reason_str = "unknown reason";
5983 element_type = le16_to_cpu(element->ElementFlags) &
5984 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
5985 switch (element_type) {
5986 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
5987 element_str = "volume";
5989 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
5990 element_str = "phys disk";
5992 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
5993 element_str = "hot spare";
5996 element_str = "unknown element";
5999 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6000 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6001 reason_str, le16_to_cpu(element->VolDevHandle),
6002 le16_to_cpu(element->PhysDiskDevHandle),
6003 element->PhysDiskNum);
6009 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6010 * @ioc: per adapter object
6011 * @fw_event: The fw_event_work object
6017 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6018 struct fw_event_work *fw_event)
6020 Mpi2EventIrConfigElement_t *element;
6023 Mpi2EventDataIrConfigChangeList_t *event_data =
6024 (Mpi2EventDataIrConfigChangeList_t *)
6025 fw_event->event_data;
6027 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6028 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6029 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6033 foreign_config = (le32_to_cpu(event_data->Flags) &
6034 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6036 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6037 if (ioc->shost_recovery) {
6039 for (i = 0; i < event_data->NumElements; i++, element++) {
6040 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6041 _scsih_ir_fastpath(ioc,
6042 le16_to_cpu(element->PhysDiskDevHandle),
6043 element->PhysDiskNum);
6047 for (i = 0; i < event_data->NumElements; i++, element++) {
6049 switch (element->ReasonCode) {
6050 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6051 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6052 if (!foreign_config)
6053 _scsih_sas_volume_add(ioc, element);
6055 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6056 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6057 if (!foreign_config)
6058 _scsih_sas_volume_delete(ioc,
6059 le16_to_cpu(element->VolDevHandle));
6061 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6062 _scsih_sas_pd_hide(ioc, element);
6064 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6065 _scsih_sas_pd_expose(ioc, element);
6067 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6068 _scsih_sas_pd_add(ioc, element);
6070 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6071 _scsih_sas_pd_delete(ioc, element);
6078 * _scsih_sas_ir_volume_event - IR volume event
6079 * @ioc: per adapter object
6080 * @fw_event: The fw_event_work object
6086 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6087 struct fw_event_work *fw_event)
6090 unsigned long flags;
6091 struct _raid_device *raid_device;
6095 Mpi2EventDataIrVolume_t *event_data =
6096 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6098 if (ioc->shost_recovery)
6101 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6104 handle = le16_to_cpu(event_data->VolDevHandle);
6105 state = le32_to_cpu(event_data->NewValue);
6106 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6107 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6108 ioc->name, __func__, handle,
6109 le32_to_cpu(event_data->PreviousValue), state));
6111 case MPI2_RAID_VOL_STATE_MISSING:
6112 case MPI2_RAID_VOL_STATE_FAILED:
6113 _scsih_sas_volume_delete(ioc, handle);
6116 case MPI2_RAID_VOL_STATE_ONLINE:
6117 case MPI2_RAID_VOL_STATE_DEGRADED:
6118 case MPI2_RAID_VOL_STATE_OPTIMAL:
6120 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6121 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6122 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6127 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6130 "failure at %s:%d/%s()!\n", ioc->name,
6131 __FILE__, __LINE__, __func__);
6135 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6138 "failure at %s:%d/%s()!\n", ioc->name,
6139 __FILE__, __LINE__, __func__);
6143 raid_device->id = ioc->sas_id++;
6144 raid_device->channel = RAID_CHANNEL;
6145 raid_device->handle = handle;
6146 raid_device->wwid = wwid;
6147 _scsih_raid_device_add(ioc, raid_device);
6148 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6149 raid_device->id, 0);
6151 _scsih_raid_device_remove(ioc, raid_device);
6154 case MPI2_RAID_VOL_STATE_INITIALIZING:
6161 * _scsih_sas_ir_physical_disk_event - PD event
6162 * @ioc: per adapter object
6163 * @fw_event: The fw_event_work object
6169 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6170 struct fw_event_work *fw_event)
6172 u16 handle, parent_handle;
6174 struct _sas_device *sas_device;
6175 unsigned long flags;
6176 Mpi2ConfigReply_t mpi_reply;
6177 Mpi2SasDevicePage0_t sas_device_pg0;
6179 Mpi2EventDataIrPhysicalDisk_t *event_data =
6180 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6183 if (ioc->shost_recovery)
6186 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6189 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6190 state = le32_to_cpu(event_data->NewValue);
6192 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6193 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6194 ioc->name, __func__, handle,
6195 le32_to_cpu(event_data->PreviousValue), state));
6197 case MPI2_RAID_PD_STATE_ONLINE:
6198 case MPI2_RAID_PD_STATE_DEGRADED:
6199 case MPI2_RAID_PD_STATE_REBUILDING:
6200 case MPI2_RAID_PD_STATE_OPTIMAL:
6201 case MPI2_RAID_PD_STATE_HOT_SPARE:
6203 set_bit(handle, ioc->pd_handles);
6204 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6205 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6206 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6211 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6212 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6214 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6215 ioc->name, __FILE__, __LINE__, __func__);
6219 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6220 MPI2_IOCSTATUS_MASK;
6221 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6222 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6223 ioc->name, __FILE__, __LINE__, __func__);
6227 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6228 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6229 mpt3sas_transport_update_links(ioc, sas_address, handle,
6230 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6232 _scsih_add_device(ioc, handle, 0, 1);
6236 case MPI2_RAID_PD_STATE_OFFLINE:
6237 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6238 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6244 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6246 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6247 * @ioc: per adapter object
6248 * @event_data: event data payload
6254 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6255 Mpi2EventDataIrOperationStatus_t *event_data)
6257 char *reason_str = NULL;
6259 switch (event_data->RAIDOperation) {
6260 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6261 reason_str = "resync";
6263 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6264 reason_str = "online capacity expansion";
6266 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6267 reason_str = "consistency check";
6269 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6270 reason_str = "background init";
6272 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6273 reason_str = "make data consistent";
6280 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6281 "\thandle(0x%04x), percent complete(%d)\n",
6282 ioc->name, reason_str,
6283 le16_to_cpu(event_data->VolDevHandle),
6284 event_data->PercentComplete);
6289 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6290 * @ioc: per adapter object
6291 * @fw_event: The fw_event_work object
6297 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6298 struct fw_event_work *fw_event)
6300 Mpi2EventDataIrOperationStatus_t *event_data =
6301 (Mpi2EventDataIrOperationStatus_t *)
6302 fw_event->event_data;
6303 static struct _raid_device *raid_device;
6304 unsigned long flags;
6307 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6308 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6309 _scsih_sas_ir_operation_status_event_debug(ioc,
6313 /* code added for raid transport support */
6314 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6316 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6317 handle = le16_to_cpu(event_data->VolDevHandle);
6318 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6320 raid_device->percent_complete =
6321 event_data->PercentComplete;
6322 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6327 * _scsih_prep_device_scan - initialize parameters prior to device scan
6328 * @ioc: per adapter object
6330 * Set the deleted flag prior to device scan. If the device is found during
6331 * the scan, then we clear the deleted flag.
6334 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6336 struct MPT3SAS_DEVICE *sas_device_priv_data;
6337 struct scsi_device *sdev;
6339 shost_for_each_device(sdev, ioc->shost) {
6340 sas_device_priv_data = sdev->hostdata;
6341 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6342 sas_device_priv_data->sas_target->deleted = 1;
6347 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6348 * @ioc: per adapter object
6349 * @sas_address: sas address
6350 * @slot: enclosure slot id
6351 * @handle: device handle
6353 * After host reset, find out whether devices are still responding.
6354 * Used in _scsih_remove_unresponsive_sas_devices.
6359 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6360 u16 slot, u16 handle)
6362 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6363 struct scsi_target *starget;
6364 struct _sas_device *sas_device;
6365 unsigned long flags;
6367 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6368 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6369 if (sas_device->sas_address == sas_address &&
6370 sas_device->slot == slot) {
6371 sas_device->responding = 1;
6372 starget = sas_device->starget;
6373 if (starget && starget->hostdata) {
6374 sas_target_priv_data = starget->hostdata;
6375 sas_target_priv_data->tm_busy = 0;
6376 sas_target_priv_data->deleted = 0;
6378 sas_target_priv_data = NULL;
6380 starget_printk(KERN_INFO, starget,
6381 "handle(0x%04x), sas_addr(0x%016llx), "
6382 "enclosure logical id(0x%016llx), "
6383 "slot(%d)\n", handle,
6384 (unsigned long long)sas_device->sas_address,
6385 (unsigned long long)
6386 sas_device->enclosure_logical_id,
6388 if (sas_device->handle == handle)
6390 pr_info("\thandle changed from(0x%04x)!!!\n",
6391 sas_device->handle);
6392 sas_device->handle = handle;
6393 if (sas_target_priv_data)
6394 sas_target_priv_data->handle = handle;
6399 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6403 * _scsih_search_responding_sas_devices -
6404 * @ioc: per adapter object
6406 * After host reset, find out whether devices are still responding.
6412 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6414 Mpi2SasDevicePage0_t sas_device_pg0;
6415 Mpi2ConfigReply_t mpi_reply;
6420 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6422 if (list_empty(&ioc->sas_device_list))
6426 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6427 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6429 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6430 MPI2_IOCSTATUS_MASK;
6431 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6433 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6434 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6435 if (!(_scsih_is_end_device(device_info)))
6437 _scsih_mark_responding_sas_device(ioc,
6438 le64_to_cpu(sas_device_pg0.SASAddress),
6439 le16_to_cpu(sas_device_pg0.Slot), handle);
6443 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6448 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6449 * @ioc: per adapter object
6450 * @wwid: world wide identifier for raid volume
6451 * @handle: device handle
6453 * After host reset, find out whether devices are still responding.
6454 * Used in _scsih_remove_unresponsive_raid_devices.
6459 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6462 struct MPT3SAS_TARGET *sas_target_priv_data;
6463 struct scsi_target *starget;
6464 struct _raid_device *raid_device;
6465 unsigned long flags;
6467 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6468 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6469 if (raid_device->wwid == wwid && raid_device->starget) {
6470 starget = raid_device->starget;
6471 if (starget && starget->hostdata) {
6472 sas_target_priv_data = starget->hostdata;
6473 sas_target_priv_data->deleted = 0;
6475 sas_target_priv_data = NULL;
6476 raid_device->responding = 1;
6477 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6478 starget_printk(KERN_INFO, raid_device->starget,
6479 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6480 (unsigned long long)raid_device->wwid);
6481 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6482 if (raid_device->handle == handle) {
6483 spin_unlock_irqrestore(&ioc->raid_device_lock,
6487 pr_info("\thandle changed from(0x%04x)!!!\n",
6488 raid_device->handle);
6489 raid_device->handle = handle;
6490 if (sas_target_priv_data)
6491 sas_target_priv_data->handle = handle;
6492 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6496 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6500 * _scsih_search_responding_raid_devices -
6501 * @ioc: per adapter object
6503 * After host reset, find out whether devices are still responding.
6509 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6511 Mpi2RaidVolPage1_t volume_pg1;
6512 Mpi2RaidVolPage0_t volume_pg0;
6513 Mpi2RaidPhysDiskPage0_t pd_pg0;
6514 Mpi2ConfigReply_t mpi_reply;
6519 if (!ioc->ir_firmware)
6522 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6525 if (list_empty(&ioc->raid_device_list))
6529 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6530 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6531 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6532 MPI2_IOCSTATUS_MASK;
6533 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6535 handle = le16_to_cpu(volume_pg1.DevHandle);
6537 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6538 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6539 sizeof(Mpi2RaidVolPage0_t)))
6542 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6543 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6544 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6545 _scsih_mark_responding_raid_device(ioc,
6546 le64_to_cpu(volume_pg1.WWID), handle);
6549 /* refresh the pd_handles */
6550 phys_disk_num = 0xFF;
6551 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6552 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6553 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6555 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6556 MPI2_IOCSTATUS_MASK;
6557 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6559 phys_disk_num = pd_pg0.PhysDiskNum;
6560 handle = le16_to_cpu(pd_pg0.DevHandle);
6561 set_bit(handle, ioc->pd_handles);
6564 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6569 * _scsih_mark_responding_expander - mark a expander as responding
6570 * @ioc: per adapter object
6571 * @sas_address: sas address
6574 * After host reset, find out whether devices are still responding.
6575 * Used in _scsih_remove_unresponsive_expanders.
6580 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6583 struct _sas_node *sas_expander;
6584 unsigned long flags;
6587 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6588 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6589 if (sas_expander->sas_address != sas_address)
6591 sas_expander->responding = 1;
6592 if (sas_expander->handle == handle)
6594 pr_info("\texpander(0x%016llx): handle changed" \
6595 " from(0x%04x) to (0x%04x)!!!\n",
6596 (unsigned long long)sas_expander->sas_address,
6597 sas_expander->handle, handle);
6598 sas_expander->handle = handle;
6599 for (i = 0 ; i < sas_expander->num_phys ; i++)
6600 sas_expander->phy[i].handle = handle;
6604 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6608 * _scsih_search_responding_expanders -
6609 * @ioc: per adapter object
6611 * After host reset, find out whether devices are still responding.
6617 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6619 Mpi2ExpanderPage0_t expander_pg0;
6620 Mpi2ConfigReply_t mpi_reply;
6625 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6627 if (list_empty(&ioc->sas_expander_list))
6631 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6632 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6634 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6635 MPI2_IOCSTATUS_MASK;
6636 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6639 handle = le16_to_cpu(expander_pg0.DevHandle);
6640 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6641 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6643 (unsigned long long)sas_address);
6644 _scsih_mark_responding_expander(ioc, sas_address, handle);
6648 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6652 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6653 * @ioc: per adapter object
6658 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6660 struct _sas_device *sas_device, *sas_device_next;
6661 struct _sas_node *sas_expander, *sas_expander_next;
6662 struct _raid_device *raid_device, *raid_device_next;
6663 struct list_head tmp_list;
6664 unsigned long flags;
6666 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6669 /* removing unresponding end devices */
6670 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6672 list_for_each_entry_safe(sas_device, sas_device_next,
6673 &ioc->sas_device_list, list) {
6674 if (!sas_device->responding)
6675 mpt3sas_device_remove_by_sas_address(ioc,
6676 sas_device->sas_address);
6678 sas_device->responding = 0;
6681 /* removing unresponding volumes */
6682 if (ioc->ir_firmware) {
6683 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6685 list_for_each_entry_safe(raid_device, raid_device_next,
6686 &ioc->raid_device_list, list) {
6687 if (!raid_device->responding)
6688 _scsih_sas_volume_delete(ioc,
6689 raid_device->handle);
6691 raid_device->responding = 0;
6695 /* removing unresponding expanders */
6696 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6698 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6699 INIT_LIST_HEAD(&tmp_list);
6700 list_for_each_entry_safe(sas_expander, sas_expander_next,
6701 &ioc->sas_expander_list, list) {
6702 if (!sas_expander->responding)
6703 list_move_tail(&sas_expander->list, &tmp_list);
6705 sas_expander->responding = 0;
6707 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6708 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6710 list_del(&sas_expander->list);
6711 _scsih_expander_node_remove(ioc, sas_expander);
6714 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6717 /* unblock devices */
6718 _scsih_ublock_io_all_device(ioc);
6722 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6723 struct _sas_node *sas_expander, u16 handle)
6725 Mpi2ExpanderPage1_t expander_pg1;
6726 Mpi2ConfigReply_t mpi_reply;
6729 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6730 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6731 &expander_pg1, i, handle))) {
6732 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6733 ioc->name, __FILE__, __LINE__, __func__);
6737 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6738 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6739 expander_pg1.NegotiatedLinkRate >> 4);
6744 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6745 * @ioc: per adapter object
6750 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6752 Mpi2ExpanderPage0_t expander_pg0;
6753 Mpi2SasDevicePage0_t sas_device_pg0;
6754 Mpi2RaidVolPage1_t volume_pg1;
6755 Mpi2RaidVolPage0_t volume_pg0;
6756 Mpi2RaidPhysDiskPage0_t pd_pg0;
6757 Mpi2EventIrConfigElement_t element;
6758 Mpi2ConfigReply_t mpi_reply;
6761 u16 handle, parent_handle;
6763 struct _sas_device *sas_device;
6764 struct _sas_node *expander_device;
6765 static struct _raid_device *raid_device;
6767 unsigned long flags;
6769 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6771 _scsih_sas_host_refresh(ioc);
6773 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6777 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6778 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6779 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6780 MPI2_IOCSTATUS_MASK;
6781 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6782 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6783 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6784 ioc->name, ioc_status,
6785 le32_to_cpu(mpi_reply.IOCLogInfo));
6788 handle = le16_to_cpu(expander_pg0.DevHandle);
6789 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6790 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6791 ioc, le64_to_cpu(expander_pg0.SASAddress));
6792 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6793 if (expander_device)
6794 _scsih_refresh_expander_links(ioc, expander_device,
6797 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6798 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6799 handle, (unsigned long long)
6800 le64_to_cpu(expander_pg0.SASAddress));
6801 _scsih_expander_add(ioc, handle);
6802 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6803 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6804 handle, (unsigned long long)
6805 le64_to_cpu(expander_pg0.SASAddress));
6809 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6812 if (!ioc->ir_firmware)
6815 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6818 phys_disk_num = 0xFF;
6819 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6820 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6822 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6823 MPI2_IOCSTATUS_MASK;
6824 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6825 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
6826 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6827 ioc->name, ioc_status,
6828 le32_to_cpu(mpi_reply.IOCLogInfo));
6831 phys_disk_num = pd_pg0.PhysDiskNum;
6832 handle = le16_to_cpu(pd_pg0.DevHandle);
6833 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6834 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6835 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6838 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6839 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6842 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6843 MPI2_IOCSTATUS_MASK;
6844 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6845 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
6846 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6847 ioc->name, ioc_status,
6848 le32_to_cpu(mpi_reply.IOCLogInfo));
6851 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6852 if (!_scsih_get_sas_address(ioc, parent_handle,
6854 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
6855 " handle (0x%04x), sas_addr(0x%016llx)\n",
6856 ioc->name, handle, (unsigned long long)
6857 le64_to_cpu(sas_device_pg0.SASAddress));
6858 mpt3sas_transport_update_links(ioc, sas_address,
6859 handle, sas_device_pg0.PhyNum,
6860 MPI2_SAS_NEG_LINK_RATE_1_5);
6861 set_bit(handle, ioc->pd_handles);
6863 /* This will retry adding the end device.
6864 * _scsih_add_device() will decide on retries and
6865 * return "1" when it should be retried
6867 while (_scsih_add_device(ioc, handle, retry_count++,
6871 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
6872 " handle (0x%04x), sas_addr(0x%016llx)\n",
6873 ioc->name, handle, (unsigned long long)
6874 le64_to_cpu(sas_device_pg0.SASAddress));
6878 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
6881 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
6885 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6886 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6887 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6888 MPI2_IOCSTATUS_MASK;
6889 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6890 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6891 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6892 ioc->name, ioc_status,
6893 le32_to_cpu(mpi_reply.IOCLogInfo));
6896 handle = le16_to_cpu(volume_pg1.DevHandle);
6897 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6898 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6899 le64_to_cpu(volume_pg1.WWID));
6900 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6903 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6904 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6905 sizeof(Mpi2RaidVolPage0_t)))
6907 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6908 MPI2_IOCSTATUS_MASK;
6909 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6910 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6911 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6912 ioc->name, ioc_status,
6913 le32_to_cpu(mpi_reply.IOCLogInfo));
6916 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6917 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6918 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6919 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6920 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6921 element.VolDevHandle = volume_pg1.DevHandle;
6923 "\tBEFORE adding volume: handle (0x%04x)\n",
6924 ioc->name, volume_pg1.DevHandle);
6925 _scsih_sas_volume_add(ioc, &element);
6927 "\tAFTER adding volume: handle (0x%04x)\n",
6928 ioc->name, volume_pg1.DevHandle);
6932 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
6937 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
6942 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6943 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6945 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6946 MPI2_IOCSTATUS_MASK;
6947 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6948 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
6949 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6950 ioc->name, ioc_status,
6951 le32_to_cpu(mpi_reply.IOCLogInfo));
6954 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6955 if (!(_scsih_is_end_device(
6956 le32_to_cpu(sas_device_pg0.DeviceInfo))))
6958 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6959 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
6960 le64_to_cpu(sas_device_pg0.SASAddress));
6961 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6964 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6965 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
6966 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
6967 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6968 handle, (unsigned long long)
6969 le64_to_cpu(sas_device_pg0.SASAddress));
6970 mpt3sas_transport_update_links(ioc, sas_address, handle,
6971 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6973 /* This will retry adding the end device.
6974 * _scsih_add_device() will decide on retries and
6975 * return "1" when it should be retried
6977 while (_scsih_add_device(ioc, handle, retry_count++,
6981 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
6982 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6983 handle, (unsigned long long)
6984 le64_to_cpu(sas_device_pg0.SASAddress));
6987 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
6990 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
6993 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
6994 * @ioc: per adapter object
6995 * @reset_phase: phase
6997 * The handler for doing any required cleanup or initialization.
6999 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7000 * MPT3_IOC_DONE_RESET
7005 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7007 switch (reset_phase) {
7008 case MPT3_IOC_PRE_RESET:
7009 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7010 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7012 case MPT3_IOC_AFTER_RESET:
7013 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7014 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7015 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7016 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7017 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7018 complete(&ioc->scsih_cmds.done);
7020 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7021 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7022 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7023 complete(&ioc->tm_cmds.done);
7026 _scsih_fw_event_cleanup_queue(ioc);
7027 _scsih_flush_running_cmds(ioc);
7029 case MPT3_IOC_DONE_RESET:
7030 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7031 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7032 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7033 !ioc->sas_hba.num_phys)) {
7034 _scsih_prep_device_scan(ioc);
7035 _scsih_search_responding_sas_devices(ioc);
7036 _scsih_search_responding_raid_devices(ioc);
7037 _scsih_search_responding_expanders(ioc);
7038 _scsih_error_recovery_delete_devices(ioc);
7045 * _mpt3sas_fw_work - delayed task for processing firmware events
7046 * @ioc: per adapter object
7047 * @fw_event: The fw_event_work object
7053 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7055 /* the queue is being flushed so ignore this event */
7056 if (ioc->remove_host ||
7057 ioc->pci_error_recovery) {
7058 _scsih_fw_event_free(ioc, fw_event);
7062 switch (fw_event->event) {
7063 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7064 mpt3sas_process_trigger_data(ioc,
7065 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7066 fw_event->event_data);
7068 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7069 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7071 _scsih_remove_unresponding_sas_devices(ioc);
7072 _scsih_scan_for_devices_after_reset(ioc);
7074 case MPT3SAS_PORT_ENABLE_COMPLETE:
7075 ioc->start_scan = 0;
7076 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7077 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7079 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7080 "port enable: complete from worker thread\n",
7083 case MPT3SAS_TURN_ON_PFA_LED:
7084 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7086 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7087 _scsih_sas_topology_change_event(ioc, fw_event);
7089 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7090 _scsih_sas_device_status_change_event(ioc, fw_event);
7092 case MPI2_EVENT_SAS_DISCOVERY:
7093 _scsih_sas_discovery_event(ioc, fw_event);
7095 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7096 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7098 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7099 _scsih_sas_enclosure_dev_status_change_event(ioc,
7102 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7103 _scsih_sas_ir_config_change_event(ioc, fw_event);
7105 case MPI2_EVENT_IR_VOLUME:
7106 _scsih_sas_ir_volume_event(ioc, fw_event);
7108 case MPI2_EVENT_IR_PHYSICAL_DISK:
7109 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7111 case MPI2_EVENT_IR_OPERATION_STATUS:
7112 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7115 _scsih_fw_event_free(ioc, fw_event);
7119 * _firmware_event_work
7120 * @ioc: per adapter object
7121 * @work: The fw_event_work object
7124 * wrappers for the work thread handling firmware events
7130 _firmware_event_work(struct work_struct *work)
7132 struct fw_event_work *fw_event = container_of(work,
7133 struct fw_event_work, work);
7135 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7139 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7140 * @ioc: per adapter object
7141 * @msix_index: MSIX table index supplied by the OS
7142 * @reply: reply message frame(lower 32bit addr)
7143 * Context: interrupt.
7145 * This function merely adds a new work task into ioc->firmware_event_thread.
7146 * The tasks are worked from _firmware_event_work in user context.
7148 * Return 1 meaning mf should be freed from _base_interrupt
7149 * 0 means the mf is freed from this function.
7152 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7155 struct fw_event_work *fw_event;
7156 Mpi2EventNotificationReply_t *mpi_reply;
7160 /* events turned off due to host reset or driver unloading */
7161 if (ioc->remove_host || ioc->pci_error_recovery)
7164 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7166 if (unlikely(!mpi_reply)) {
7167 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7168 ioc->name, __FILE__, __LINE__, __func__);
7172 event = le16_to_cpu(mpi_reply->Event);
7174 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7175 mpt3sas_trigger_event(ioc, event, 0);
7179 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7181 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7182 (Mpi2EventDataSasBroadcastPrimitive_t *)
7183 mpi_reply->EventData;
7185 if (baen_data->Primitive !=
7186 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7189 if (ioc->broadcast_aen_busy) {
7190 ioc->broadcast_aen_pending++;
7193 ioc->broadcast_aen_busy = 1;
7197 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7198 _scsih_check_topo_delete_events(ioc,
7199 (Mpi2EventDataSasTopologyChangeList_t *)
7200 mpi_reply->EventData);
7202 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7203 _scsih_check_ir_config_unhide_events(ioc,
7204 (Mpi2EventDataIrConfigChangeList_t *)
7205 mpi_reply->EventData);
7207 case MPI2_EVENT_IR_VOLUME:
7208 _scsih_check_volume_delete_events(ioc,
7209 (Mpi2EventDataIrVolume_t *)
7210 mpi_reply->EventData);
7213 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7214 case MPI2_EVENT_IR_OPERATION_STATUS:
7215 case MPI2_EVENT_SAS_DISCOVERY:
7216 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7217 case MPI2_EVENT_IR_PHYSICAL_DISK:
7220 default: /* ignore the rest */
7224 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7225 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7227 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7228 ioc->name, __FILE__, __LINE__, __func__);
7232 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7233 fw_event->ioc = ioc;
7234 fw_event->VF_ID = mpi_reply->VF_ID;
7235 fw_event->VP_ID = mpi_reply->VP_ID;
7236 fw_event->event = event;
7237 _scsih_fw_event_add(ioc, fw_event);
7241 /* shost template */
7242 static struct scsi_host_template scsih_driver_template = {
7243 .module = THIS_MODULE,
7244 .name = "Fusion MPT SAS Host",
7245 .proc_name = MPT3SAS_DRIVER_NAME,
7246 .queuecommand = _scsih_qcmd,
7247 .target_alloc = _scsih_target_alloc,
7248 .slave_alloc = _scsih_slave_alloc,
7249 .slave_configure = _scsih_slave_configure,
7250 .target_destroy = _scsih_target_destroy,
7251 .slave_destroy = _scsih_slave_destroy,
7252 .scan_finished = _scsih_scan_finished,
7253 .scan_start = _scsih_scan_start,
7254 .change_queue_depth = _scsih_change_queue_depth,
7255 .change_queue_type = scsi_change_queue_type,
7256 .eh_abort_handler = _scsih_abort,
7257 .eh_device_reset_handler = _scsih_dev_reset,
7258 .eh_target_reset_handler = _scsih_target_reset,
7259 .eh_host_reset_handler = _scsih_host_reset,
7260 .bios_param = _scsih_bios_param,
7263 .sg_tablesize = MPT3SAS_SG_DEPTH,
7264 .max_sectors = 32767,
7266 .use_clustering = ENABLE_CLUSTERING,
7267 .shost_attrs = mpt3sas_host_attrs,
7268 .sdev_attrs = mpt3sas_dev_attrs,
7272 * _scsih_expander_node_remove - removing expander device from list.
7273 * @ioc: per adapter object
7274 * @sas_expander: the sas_device object
7275 * Context: Calling function should acquire ioc->sas_node_lock.
7277 * Removing object and freeing associated memory from the
7278 * ioc->sas_expander_list.
7283 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7284 struct _sas_node *sas_expander)
7286 struct _sas_port *mpt3sas_port, *next;
7288 /* remove sibling ports attached to this expander */
7289 list_for_each_entry_safe(mpt3sas_port, next,
7290 &sas_expander->sas_port_list, port_list) {
7291 if (ioc->shost_recovery)
7293 if (mpt3sas_port->remote_identify.device_type ==
7295 mpt3sas_device_remove_by_sas_address(ioc,
7296 mpt3sas_port->remote_identify.sas_address);
7297 else if (mpt3sas_port->remote_identify.device_type ==
7298 SAS_EDGE_EXPANDER_DEVICE ||
7299 mpt3sas_port->remote_identify.device_type ==
7300 SAS_FANOUT_EXPANDER_DEVICE)
7301 mpt3sas_expander_remove(ioc,
7302 mpt3sas_port->remote_identify.sas_address);
7305 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7306 sas_expander->sas_address_parent);
7309 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7311 sas_expander->handle, (unsigned long long)
7312 sas_expander->sas_address);
7314 kfree(sas_expander->phy);
7315 kfree(sas_expander);
7319 * _scsih_ir_shutdown - IR shutdown notification
7320 * @ioc: per adapter object
7322 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7323 * the host system is shutting down.
7328 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7330 Mpi2RaidActionRequest_t *mpi_request;
7331 Mpi2RaidActionReply_t *mpi_reply;
7334 /* is IR firmware build loaded ? */
7335 if (!ioc->ir_firmware)
7338 /* are there any volumes ? */
7339 if (list_empty(&ioc->raid_device_list))
7342 mutex_lock(&ioc->scsih_cmds.mutex);
7344 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7345 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7346 ioc->name, __func__);
7349 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7351 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7353 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7354 ioc->name, __func__);
7355 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7359 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7360 ioc->scsih_cmds.smid = smid;
7361 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7363 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7364 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7366 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7367 init_completion(&ioc->scsih_cmds.done);
7368 mpt3sas_base_put_smid_default(ioc, smid);
7369 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7371 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7372 pr_err(MPT3SAS_FMT "%s: timeout\n",
7373 ioc->name, __func__);
7377 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7378 mpi_reply = ioc->scsih_cmds.reply;
7380 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7381 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7382 le32_to_cpu(mpi_reply->IOCLogInfo));
7386 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7387 mutex_unlock(&ioc->scsih_cmds.mutex);
7391 * _scsih_remove - detach and remove add host
7392 * @pdev: PCI device struct
7394 * Routine called when unloading the driver.
7397 static void _scsih_remove(struct pci_dev *pdev)
7399 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7400 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7401 struct _sas_port *mpt3sas_port, *next_port;
7402 struct _raid_device *raid_device, *next;
7403 struct MPT3SAS_TARGET *sas_target_priv_data;
7404 struct workqueue_struct *wq;
7405 unsigned long flags;
7407 ioc->remove_host = 1;
7408 _scsih_fw_event_cleanup_queue(ioc);
7410 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7411 wq = ioc->firmware_event_thread;
7412 ioc->firmware_event_thread = NULL;
7413 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7415 destroy_workqueue(wq);
7417 /* release all the volumes */
7418 _scsih_ir_shutdown(ioc);
7419 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7421 if (raid_device->starget) {
7422 sas_target_priv_data =
7423 raid_device->starget->hostdata;
7424 sas_target_priv_data->deleted = 1;
7425 scsi_remove_target(&raid_device->starget->dev);
7427 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7428 ioc->name, raid_device->handle,
7429 (unsigned long long) raid_device->wwid);
7430 _scsih_raid_device_remove(ioc, raid_device);
7433 /* free ports attached to the sas_host */
7434 list_for_each_entry_safe(mpt3sas_port, next_port,
7435 &ioc->sas_hba.sas_port_list, port_list) {
7436 if (mpt3sas_port->remote_identify.device_type ==
7438 mpt3sas_device_remove_by_sas_address(ioc,
7439 mpt3sas_port->remote_identify.sas_address);
7440 else if (mpt3sas_port->remote_identify.device_type ==
7441 SAS_EDGE_EXPANDER_DEVICE ||
7442 mpt3sas_port->remote_identify.device_type ==
7443 SAS_FANOUT_EXPANDER_DEVICE)
7444 mpt3sas_expander_remove(ioc,
7445 mpt3sas_port->remote_identify.sas_address);
7448 /* free phys attached to the sas_host */
7449 if (ioc->sas_hba.num_phys) {
7450 kfree(ioc->sas_hba.phy);
7451 ioc->sas_hba.phy = NULL;
7452 ioc->sas_hba.num_phys = 0;
7455 sas_remove_host(shost);
7456 scsi_remove_host(shost);
7457 mpt3sas_base_detach(ioc);
7458 list_del(&ioc->list);
7459 scsi_host_put(shost);
7463 * _scsih_shutdown - routine call during system shutdown
7464 * @pdev: PCI device struct
7469 _scsih_shutdown(struct pci_dev *pdev)
7471 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7472 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7473 struct workqueue_struct *wq;
7474 unsigned long flags;
7476 ioc->remove_host = 1;
7477 _scsih_fw_event_cleanup_queue(ioc);
7479 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7480 wq = ioc->firmware_event_thread;
7481 ioc->firmware_event_thread = NULL;
7482 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7484 destroy_workqueue(wq);
7486 _scsih_ir_shutdown(ioc);
7487 mpt3sas_base_detach(ioc);
7492 * _scsih_probe_boot_devices - reports 1st device
7493 * @ioc: per adapter object
7495 * If specified in bios page 2, this routine reports the 1st
7496 * device scsi-ml or sas transport for persistent boot device
7497 * purposes. Please refer to function _scsih_determine_boot_device()
7500 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7504 struct _sas_device *sas_device;
7505 struct _raid_device *raid_device;
7507 u64 sas_address_parent;
7509 unsigned long flags;
7512 /* no Bios, return immediately */
7513 if (!ioc->bios_pg3.BiosVersion)
7518 if (ioc->req_boot_device.device) {
7519 device = ioc->req_boot_device.device;
7520 is_raid = ioc->req_boot_device.is_raid;
7521 } else if (ioc->req_alt_boot_device.device) {
7522 device = ioc->req_alt_boot_device.device;
7523 is_raid = ioc->req_alt_boot_device.is_raid;
7524 } else if (ioc->current_boot_device.device) {
7525 device = ioc->current_boot_device.device;
7526 is_raid = ioc->current_boot_device.is_raid;
7533 raid_device = device;
7534 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7535 raid_device->id, 0);
7537 _scsih_raid_device_remove(ioc, raid_device);
7539 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7540 sas_device = device;
7541 handle = sas_device->handle;
7542 sas_address_parent = sas_device->sas_address_parent;
7543 sas_address = sas_device->sas_address;
7544 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7545 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7547 if (!mpt3sas_transport_port_add(ioc, handle,
7548 sas_address_parent)) {
7549 _scsih_sas_device_remove(ioc, sas_device);
7550 } else if (!sas_device->starget) {
7551 if (!ioc->is_driver_loading) {
7552 mpt3sas_transport_port_remove(ioc,
7554 sas_address_parent);
7555 _scsih_sas_device_remove(ioc, sas_device);
7562 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7563 * @ioc: per adapter object
7565 * Called during initial loading of the driver.
7568 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7570 struct _raid_device *raid_device, *raid_next;
7573 list_for_each_entry_safe(raid_device, raid_next,
7574 &ioc->raid_device_list, list) {
7575 if (raid_device->starget)
7577 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7578 raid_device->id, 0);
7580 _scsih_raid_device_remove(ioc, raid_device);
7585 * _scsih_probe_sas - reporting sas devices to sas transport
7586 * @ioc: per adapter object
7588 * Called during initial loading of the driver.
7591 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7593 struct _sas_device *sas_device, *next;
7594 unsigned long flags;
7596 /* SAS Device List */
7597 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7600 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7601 sas_device->sas_address_parent)) {
7602 list_del(&sas_device->list);
7605 } else if (!sas_device->starget) {
7607 * When asyn scanning is enabled, its not possible to
7608 * remove devices while scanning is turned on due to an
7609 * oops in scsi_sysfs_add_sdev()->add_device()->
7610 * sysfs_addrm_start()
7612 if (!ioc->is_driver_loading) {
7613 mpt3sas_transport_port_remove(ioc,
7614 sas_device->sas_address,
7615 sas_device->sas_address_parent);
7616 list_del(&sas_device->list);
7622 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7623 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7624 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7629 * _scsih_probe_devices - probing for devices
7630 * @ioc: per adapter object
7632 * Called during initial loading of the driver.
7635 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7637 u16 volume_mapping_flags;
7639 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7640 return; /* return when IOC doesn't support initiator mode */
7642 _scsih_probe_boot_devices(ioc);
7644 if (ioc->ir_firmware) {
7645 volume_mapping_flags =
7646 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7647 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7648 if (volume_mapping_flags ==
7649 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7650 _scsih_probe_raid(ioc);
7651 _scsih_probe_sas(ioc);
7653 _scsih_probe_sas(ioc);
7654 _scsih_probe_raid(ioc);
7657 _scsih_probe_sas(ioc);
7661 * _scsih_scan_start - scsi lld callback for .scan_start
7662 * @shost: SCSI host pointer
7664 * The shost has the ability to discover targets on its own instead
7665 * of scanning the entire bus. In our implemention, we will kick off
7666 * firmware discovery.
7669 _scsih_scan_start(struct Scsi_Host *shost)
7671 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7673 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7674 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7676 if (disable_discovery > 0)
7679 ioc->start_scan = 1;
7680 rc = mpt3sas_port_enable(ioc);
7683 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7687 * _scsih_scan_finished - scsi lld callback for .scan_finished
7688 * @shost: SCSI host pointer
7689 * @time: elapsed time of the scan in jiffies
7691 * This function will be called periodicallyn until it returns 1 with the
7692 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7693 * we wait for firmware discovery to complete, then return 1.
7696 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7698 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7700 if (disable_discovery > 0) {
7701 ioc->is_driver_loading = 0;
7702 ioc->wait_for_discovery_to_complete = 0;
7706 if (time >= (300 * HZ)) {
7707 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7709 "port enable: FAILED with timeout (timeout=300s)\n",
7711 ioc->is_driver_loading = 0;
7715 if (ioc->start_scan)
7718 if (ioc->start_scan_failed) {
7720 "port enable: FAILED with (ioc_status=0x%08x)\n",
7721 ioc->name, ioc->start_scan_failed);
7722 ioc->is_driver_loading = 0;
7723 ioc->wait_for_discovery_to_complete = 0;
7724 ioc->remove_host = 1;
7728 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7729 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7731 if (ioc->wait_for_discovery_to_complete) {
7732 ioc->wait_for_discovery_to_complete = 0;
7733 _scsih_probe_devices(ioc);
7735 mpt3sas_base_start_watchdog(ioc);
7736 ioc->is_driver_loading = 0;
7741 * _scsih_probe - attach and add scsi host
7742 * @pdev: PCI device struct
7743 * @id: pci device id
7745 * Returns 0 success, anything else error.
7748 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7750 struct MPT3SAS_ADAPTER *ioc;
7751 struct Scsi_Host *shost;
7754 shost = scsi_host_alloc(&scsih_driver_template,
7755 sizeof(struct MPT3SAS_ADAPTER));
7759 /* init local params */
7760 ioc = shost_priv(shost);
7761 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7762 INIT_LIST_HEAD(&ioc->list);
7763 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7765 ioc->id = mpt_ids++;
7766 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
7768 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7769 ioc->tm_cb_idx = tm_cb_idx;
7770 ioc->ctl_cb_idx = ctl_cb_idx;
7771 ioc->base_cb_idx = base_cb_idx;
7772 ioc->port_enable_cb_idx = port_enable_cb_idx;
7773 ioc->transport_cb_idx = transport_cb_idx;
7774 ioc->scsih_cb_idx = scsih_cb_idx;
7775 ioc->config_cb_idx = config_cb_idx;
7776 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7777 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7778 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7779 ioc->logging_level = logging_level;
7780 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7781 /* misc semaphores and spin locks */
7782 mutex_init(&ioc->reset_in_progress_mutex);
7783 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7784 spin_lock_init(&ioc->scsi_lookup_lock);
7785 spin_lock_init(&ioc->sas_device_lock);
7786 spin_lock_init(&ioc->sas_node_lock);
7787 spin_lock_init(&ioc->fw_event_lock);
7788 spin_lock_init(&ioc->raid_device_lock);
7789 spin_lock_init(&ioc->diag_trigger_lock);
7791 INIT_LIST_HEAD(&ioc->sas_device_list);
7792 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7793 INIT_LIST_HEAD(&ioc->sas_expander_list);
7794 INIT_LIST_HEAD(&ioc->fw_event_list);
7795 INIT_LIST_HEAD(&ioc->raid_device_list);
7796 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7797 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7798 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7799 INIT_LIST_HEAD(&ioc->reply_queue_list);
7801 /* init shost parameters */
7802 shost->max_cmd_len = 32;
7803 shost->max_lun = max_lun;
7804 shost->transportt = mpt3sas_transport_template;
7805 shost->unique_id = ioc->id;
7807 if (max_sectors != 0xFFFF) {
7808 if (max_sectors < 64) {
7809 shost->max_sectors = 64;
7810 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7811 "for max_sectors, range is 64 to 32767. Assigning "
7812 "value of 64.\n", ioc->name, max_sectors);
7813 } else if (max_sectors > 32767) {
7814 shost->max_sectors = 32767;
7815 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7816 "for max_sectors, range is 64 to 32767. Assigning "
7817 "default value of 32767.\n", ioc->name,
7820 shost->max_sectors = max_sectors & 0xFFFE;
7822 "The max_sectors value is set to %d\n",
7823 ioc->name, shost->max_sectors);
7827 /* register EEDP capabilities with SCSI layer */
7829 scsi_host_set_prot(shost, prot_mask);
7831 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7832 | SHOST_DIF_TYPE2_PROTECTION
7833 | SHOST_DIF_TYPE3_PROTECTION);
7835 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7838 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7839 "fw_event%d", ioc->id);
7840 ioc->firmware_event_thread = create_singlethread_workqueue(
7841 ioc->firmware_event_name);
7842 if (!ioc->firmware_event_thread) {
7843 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7844 ioc->name, __FILE__, __LINE__, __func__);
7846 goto out_thread_fail;
7849 ioc->is_driver_loading = 1;
7850 if ((mpt3sas_base_attach(ioc))) {
7851 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7852 ioc->name, __FILE__, __LINE__, __func__);
7854 goto out_attach_fail;
7856 rv = scsi_add_host(shost, &pdev->dev);
7858 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7859 ioc->name, __FILE__, __LINE__, __func__);
7860 goto out_add_shost_fail;
7863 scsi_scan_host(shost);
7866 mpt3sas_base_detach(ioc);
7868 destroy_workqueue(ioc->firmware_event_thread);
7870 list_del(&ioc->list);
7871 scsi_host_put(shost);
7877 * _scsih_suspend - power management suspend main entry point
7878 * @pdev: PCI device struct
7879 * @state: PM state change to (usually PCI_D3)
7881 * Returns 0 success, anything else error.
7884 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7886 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7887 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7888 pci_power_t device_state;
7890 mpt3sas_base_stop_watchdog(ioc);
7891 flush_scheduled_work();
7892 scsi_block_requests(shost);
7893 device_state = pci_choose_state(pdev, state);
7895 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7896 ioc->name, pdev, pci_name(pdev), device_state);
7898 pci_save_state(pdev);
7899 mpt3sas_base_free_resources(ioc);
7900 pci_set_power_state(pdev, device_state);
7905 * _scsih_resume - power management resume main entry point
7906 * @pdev: PCI device struct
7908 * Returns 0 success, anything else error.
7911 _scsih_resume(struct pci_dev *pdev)
7913 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7914 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7915 pci_power_t device_state = pdev->current_state;
7919 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7920 ioc->name, pdev, pci_name(pdev), device_state);
7922 pci_set_power_state(pdev, PCI_D0);
7923 pci_enable_wake(pdev, PCI_D0, 0);
7924 pci_restore_state(pdev);
7926 r = mpt3sas_base_map_resources(ioc);
7930 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7931 scsi_unblock_requests(shost);
7932 mpt3sas_base_start_watchdog(ioc);
7935 #endif /* CONFIG_PM */
7938 * _scsih_pci_error_detected - Called when a PCI error is detected.
7939 * @pdev: PCI device struct
7940 * @state: PCI channel state
7942 * Description: Called when a PCI error is detected.
7945 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7947 static pci_ers_result_t
7948 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7950 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7951 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7953 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
7957 case pci_channel_io_normal:
7958 return PCI_ERS_RESULT_CAN_RECOVER;
7959 case pci_channel_io_frozen:
7960 /* Fatal error, prepare for slot reset */
7961 ioc->pci_error_recovery = 1;
7962 scsi_block_requests(ioc->shost);
7963 mpt3sas_base_stop_watchdog(ioc);
7964 mpt3sas_base_free_resources(ioc);
7965 return PCI_ERS_RESULT_NEED_RESET;
7966 case pci_channel_io_perm_failure:
7967 /* Permanent error, prepare for device removal */
7968 ioc->pci_error_recovery = 1;
7969 mpt3sas_base_stop_watchdog(ioc);
7970 _scsih_flush_running_cmds(ioc);
7971 return PCI_ERS_RESULT_DISCONNECT;
7973 return PCI_ERS_RESULT_NEED_RESET;
7977 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7978 * @pdev: PCI device struct
7980 * Description: This routine is called by the pci error recovery
7981 * code after the PCI slot has been reset, just before we
7982 * should resume normal operations.
7984 static pci_ers_result_t
7985 _scsih_pci_slot_reset(struct pci_dev *pdev)
7987 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7988 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7991 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
7994 ioc->pci_error_recovery = 0;
7996 pci_restore_state(pdev);
7997 rc = mpt3sas_base_map_resources(ioc);
7999 return PCI_ERS_RESULT_DISCONNECT;
8001 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8004 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8005 (rc == 0) ? "success" : "failed");
8008 return PCI_ERS_RESULT_RECOVERED;
8010 return PCI_ERS_RESULT_DISCONNECT;
8014 * _scsih_pci_resume() - resume normal ops after PCI reset
8015 * @pdev: pointer to PCI device
8017 * Called when the error recovery driver tells us that its
8018 * OK to resume normal operation. Use completion to allow
8019 * halted scsi ops to resume.
8022 _scsih_pci_resume(struct pci_dev *pdev)
8024 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8025 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8027 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8029 pci_cleanup_aer_uncorrect_error_status(pdev);
8030 mpt3sas_base_start_watchdog(ioc);
8031 scsi_unblock_requests(ioc->shost);
8035 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8036 * @pdev: pointer to PCI device
8038 static pci_ers_result_t
8039 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8041 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8042 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8044 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8047 /* TODO - dump whatever for debugging purposes */
8049 /* Request a slot reset. */
8050 return PCI_ERS_RESULT_NEED_RESET;
8053 /* raid transport support */
8054 static struct raid_function_template mpt3sas_raid_functions = {
8055 .cookie = &scsih_driver_template,
8056 .is_raid = _scsih_is_raid,
8057 .get_resync = _scsih_get_resync,
8058 .get_state = _scsih_get_state,
8061 static struct pci_error_handlers _scsih_err_handler = {
8062 .error_detected = _scsih_pci_error_detected,
8063 .mmio_enabled = _scsih_pci_mmio_enabled,
8064 .slot_reset = _scsih_pci_slot_reset,
8065 .resume = _scsih_pci_resume,
8068 static struct pci_driver scsih_driver = {
8069 .name = MPT3SAS_DRIVER_NAME,
8070 .id_table = scsih_pci_table,
8071 .probe = _scsih_probe,
8072 .remove = _scsih_remove,
8073 .shutdown = _scsih_shutdown,
8074 .err_handler = &_scsih_err_handler,
8076 .suspend = _scsih_suspend,
8077 .resume = _scsih_resume,
8083 * _scsih_init - main entry point for this driver.
8085 * Returns 0 success, anything else error.
8094 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8095 MPT3SAS_DRIVER_VERSION);
8097 mpt3sas_transport_template =
8098 sas_attach_transport(&mpt3sas_transport_functions);
8099 if (!mpt3sas_transport_template)
8102 /* raid transport support */
8103 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8104 if (!mpt3sas_raid_template) {
8105 sas_release_transport(mpt3sas_transport_template);
8109 mpt3sas_base_initialize_callback_handler();
8111 /* queuecommand callback hander */
8112 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8114 /* task managment callback handler */
8115 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8117 /* base internal commands callback handler */
8118 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8119 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8120 mpt3sas_port_enable_done);
8122 /* transport internal commands callback handler */
8123 transport_cb_idx = mpt3sas_base_register_callback_handler(
8124 mpt3sas_transport_done);
8126 /* scsih internal commands callback handler */
8127 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8129 /* configuration page API internal commands callback handler */
8130 config_cb_idx = mpt3sas_base_register_callback_handler(
8131 mpt3sas_config_done);
8133 /* ctl module callback handler */
8134 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8136 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8137 _scsih_tm_tr_complete);
8139 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8140 _scsih_tm_volume_tr_complete);
8142 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8143 _scsih_sas_control_complete);
8147 error = pci_register_driver(&scsih_driver);
8149 /* raid transport support */
8150 raid_class_release(mpt3sas_raid_template);
8151 sas_release_transport(mpt3sas_transport_template);
8158 * _scsih_exit - exit point for this driver (when it is a module).
8160 * Returns 0 success, anything else error.
8165 pr_info("mpt3sas version %s unloading\n",
8166 MPT3SAS_DRIVER_VERSION);
8170 pci_unregister_driver(&scsih_driver);
8173 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8174 mpt3sas_base_release_callback_handler(tm_cb_idx);
8175 mpt3sas_base_release_callback_handler(base_cb_idx);
8176 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8177 mpt3sas_base_release_callback_handler(transport_cb_idx);
8178 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8179 mpt3sas_base_release_callback_handler(config_cb_idx);
8180 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8182 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8183 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8184 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8186 /* raid transport support */
8187 raid_class_release(mpt3sas_raid_template);
8188 sas_release_transport(mpt3sas_transport_template);
8191 module_init(_scsih_init);
8192 module_exit(_scsih_exit);