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
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, scsi_get_tag_type(sdev), qdepth);
1097 * _scsih_change_queue_depth - setting device queue depth
1098 * @sdev: scsi device struct
1099 * @qdepth: requested queue depth
1100 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1101 * (see include/scsi/scsi_host.h for definition)
1103 * Returns queue depth.
1106 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1108 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1109 _scsih_adjust_queue_depth(sdev, qdepth);
1110 else if (reason == SCSI_QDEPTH_QFULL)
1111 scsi_track_queue_full(sdev, qdepth);
1115 if (sdev->inquiry_len > 7)
1116 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \
1117 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1118 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1119 sdev->ordered_tags, sdev->scsi_level,
1120 (sdev->inquiry[7] & 2) >> 1);
1122 return sdev->queue_depth;
1126 * _scsih_change_queue_type - changing device queue tag type
1127 * @sdev: scsi device struct
1128 * @tag_type: requested tag type
1130 * Returns queue tag type.
1133 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1135 if (sdev->tagged_supported) {
1136 scsi_set_tag_type(sdev, tag_type);
1138 scsi_activate_tcq(sdev, sdev->queue_depth);
1140 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1149 * _scsih_target_alloc - target add routine
1150 * @starget: scsi target struct
1152 * Returns 0 if ok. Any other return is assumed to be an error and
1153 * the device is ignored.
1156 _scsih_target_alloc(struct scsi_target *starget)
1158 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1159 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1160 struct MPT3SAS_TARGET *sas_target_priv_data;
1161 struct _sas_device *sas_device;
1162 struct _raid_device *raid_device;
1163 unsigned long flags;
1164 struct sas_rphy *rphy;
1166 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1168 if (!sas_target_priv_data)
1171 starget->hostdata = sas_target_priv_data;
1172 sas_target_priv_data->starget = starget;
1173 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1176 if (starget->channel == RAID_CHANNEL) {
1177 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1178 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1181 sas_target_priv_data->handle = raid_device->handle;
1182 sas_target_priv_data->sas_address = raid_device->wwid;
1183 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1184 raid_device->starget = starget;
1186 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1190 /* sas/sata devices */
1191 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1192 rphy = dev_to_rphy(starget->dev.parent);
1193 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1194 rphy->identify.sas_address);
1197 sas_target_priv_data->handle = sas_device->handle;
1198 sas_target_priv_data->sas_address = sas_device->sas_address;
1199 sas_device->starget = starget;
1200 sas_device->id = starget->id;
1201 sas_device->channel = starget->channel;
1202 if (test_bit(sas_device->handle, ioc->pd_handles))
1203 sas_target_priv_data->flags |=
1204 MPT_TARGET_FLAGS_RAID_COMPONENT;
1205 if (sas_device->fast_path)
1206 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1208 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1214 * _scsih_target_destroy - target destroy routine
1215 * @starget: scsi target struct
1220 _scsih_target_destroy(struct scsi_target *starget)
1222 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1223 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1224 struct MPT3SAS_TARGET *sas_target_priv_data;
1225 struct _sas_device *sas_device;
1226 struct _raid_device *raid_device;
1227 unsigned long flags;
1228 struct sas_rphy *rphy;
1230 sas_target_priv_data = starget->hostdata;
1231 if (!sas_target_priv_data)
1234 if (starget->channel == RAID_CHANNEL) {
1235 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1236 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1239 raid_device->starget = NULL;
1240 raid_device->sdev = NULL;
1242 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1246 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1247 rphy = dev_to_rphy(starget->dev.parent);
1248 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1249 rphy->identify.sas_address);
1250 if (sas_device && (sas_device->starget == starget) &&
1251 (sas_device->id == starget->id) &&
1252 (sas_device->channel == starget->channel))
1253 sas_device->starget = NULL;
1255 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1258 kfree(sas_target_priv_data);
1259 starget->hostdata = NULL;
1263 * _scsih_slave_alloc - device add routine
1264 * @sdev: scsi device struct
1266 * Returns 0 if ok. Any other return is assumed to be an error and
1267 * the device is ignored.
1270 _scsih_slave_alloc(struct scsi_device *sdev)
1272 struct Scsi_Host *shost;
1273 struct MPT3SAS_ADAPTER *ioc;
1274 struct MPT3SAS_TARGET *sas_target_priv_data;
1275 struct MPT3SAS_DEVICE *sas_device_priv_data;
1276 struct scsi_target *starget;
1277 struct _raid_device *raid_device;
1278 struct _sas_device *sas_device;
1279 unsigned long flags;
1281 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1283 if (!sas_device_priv_data)
1286 sas_device_priv_data->lun = sdev->lun;
1287 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1289 starget = scsi_target(sdev);
1290 sas_target_priv_data = starget->hostdata;
1291 sas_target_priv_data->num_luns++;
1292 sas_device_priv_data->sas_target = sas_target_priv_data;
1293 sdev->hostdata = sas_device_priv_data;
1294 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1295 sdev->no_uld_attach = 1;
1297 shost = dev_to_shost(&starget->dev);
1298 ioc = shost_priv(shost);
1299 if (starget->channel == RAID_CHANNEL) {
1300 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1301 raid_device = _scsih_raid_device_find_by_id(ioc,
1302 starget->id, starget->channel);
1304 raid_device->sdev = sdev; /* raid is single lun */
1305 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1308 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1309 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1310 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1311 sas_target_priv_data->sas_address);
1312 if (sas_device && (sas_device->starget == NULL)) {
1313 sdev_printk(KERN_INFO, sdev,
1314 "%s : sas_device->starget set to starget @ %d\n",
1315 __func__, __LINE__);
1316 sas_device->starget = starget;
1318 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1325 * _scsih_slave_destroy - device destroy routine
1326 * @sdev: scsi device struct
1331 _scsih_slave_destroy(struct scsi_device *sdev)
1333 struct MPT3SAS_TARGET *sas_target_priv_data;
1334 struct scsi_target *starget;
1335 struct Scsi_Host *shost;
1336 struct MPT3SAS_ADAPTER *ioc;
1337 struct _sas_device *sas_device;
1338 unsigned long flags;
1340 if (!sdev->hostdata)
1343 starget = scsi_target(sdev);
1344 sas_target_priv_data = starget->hostdata;
1345 sas_target_priv_data->num_luns--;
1347 shost = dev_to_shost(&starget->dev);
1348 ioc = shost_priv(shost);
1350 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1351 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1352 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1353 sas_target_priv_data->sas_address);
1354 if (sas_device && !sas_target_priv_data->num_luns)
1355 sas_device->starget = NULL;
1356 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1359 kfree(sdev->hostdata);
1360 sdev->hostdata = NULL;
1364 * _scsih_display_sata_capabilities - sata capabilities
1365 * @ioc: per adapter object
1366 * @handle: device handle
1367 * @sdev: scsi device struct
1370 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1371 u16 handle, struct scsi_device *sdev)
1373 Mpi2ConfigReply_t mpi_reply;
1374 Mpi2SasDevicePage0_t sas_device_pg0;
1379 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1380 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1381 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1382 ioc->name, __FILE__, __LINE__, __func__);
1386 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1387 MPI2_IOCSTATUS_MASK;
1388 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1389 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1390 ioc->name, __FILE__, __LINE__, __func__);
1394 flags = le16_to_cpu(sas_device_pg0.Flags);
1395 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1397 sdev_printk(KERN_INFO, sdev,
1398 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1399 "sw_preserve(%s)\n",
1400 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1401 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1402 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1404 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1405 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1406 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1410 * raid transport support -
1411 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1412 * unloading the driver followed by a load - I beleive that the subroutine
1413 * raid_class_release() is not cleaning up properly.
1417 * _scsih_is_raid - return boolean indicating device is raid volume
1418 * @dev the device struct object
1421 _scsih_is_raid(struct device *dev)
1423 struct scsi_device *sdev = to_scsi_device(dev);
1425 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1429 * _scsih_get_resync - get raid volume resync percent complete
1430 * @dev the device struct object
1433 _scsih_get_resync(struct device *dev)
1435 struct scsi_device *sdev = to_scsi_device(dev);
1436 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1437 static struct _raid_device *raid_device;
1438 unsigned long flags;
1439 Mpi2RaidVolPage0_t vol_pg0;
1440 Mpi2ConfigReply_t mpi_reply;
1441 u32 volume_status_flags;
1442 u8 percent_complete;
1445 percent_complete = 0;
1447 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1448 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1451 handle = raid_device->handle;
1452 percent_complete = raid_device->percent_complete;
1454 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1459 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1460 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1461 sizeof(Mpi2RaidVolPage0_t))) {
1462 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1463 ioc->name, __FILE__, __LINE__, __func__);
1464 percent_complete = 0;
1468 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1469 if (!(volume_status_flags &
1470 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1471 percent_complete = 0;
1474 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1478 * _scsih_get_state - get raid volume level
1479 * @dev the device struct object
1482 _scsih_get_state(struct device *dev)
1484 struct scsi_device *sdev = to_scsi_device(dev);
1485 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1486 static struct _raid_device *raid_device;
1487 unsigned long flags;
1488 Mpi2RaidVolPage0_t vol_pg0;
1489 Mpi2ConfigReply_t mpi_reply;
1491 enum raid_state state = RAID_STATE_UNKNOWN;
1494 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1495 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1498 handle = raid_device->handle;
1499 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1504 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1505 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1506 sizeof(Mpi2RaidVolPage0_t))) {
1507 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1508 ioc->name, __FILE__, __LINE__, __func__);
1512 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1513 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1514 state = RAID_STATE_RESYNCING;
1518 switch (vol_pg0.VolumeState) {
1519 case MPI2_RAID_VOL_STATE_OPTIMAL:
1520 case MPI2_RAID_VOL_STATE_ONLINE:
1521 state = RAID_STATE_ACTIVE;
1523 case MPI2_RAID_VOL_STATE_DEGRADED:
1524 state = RAID_STATE_DEGRADED;
1526 case MPI2_RAID_VOL_STATE_FAILED:
1527 case MPI2_RAID_VOL_STATE_MISSING:
1528 state = RAID_STATE_OFFLINE;
1532 raid_set_state(mpt3sas_raid_template, dev, state);
1536 * _scsih_set_level - set raid level
1537 * @sdev: scsi device struct
1538 * @volume_type: volume type
1541 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1543 enum raid_level level = RAID_LEVEL_UNKNOWN;
1545 switch (volume_type) {
1546 case MPI2_RAID_VOL_TYPE_RAID0:
1547 level = RAID_LEVEL_0;
1549 case MPI2_RAID_VOL_TYPE_RAID10:
1550 level = RAID_LEVEL_10;
1552 case MPI2_RAID_VOL_TYPE_RAID1E:
1553 level = RAID_LEVEL_1E;
1555 case MPI2_RAID_VOL_TYPE_RAID1:
1556 level = RAID_LEVEL_1;
1560 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1565 * _scsih_get_volume_capabilities - volume capabilities
1566 * @ioc: per adapter object
1567 * @sas_device: the raid_device object
1569 * Returns 0 for success, else 1
1572 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1573 struct _raid_device *raid_device)
1575 Mpi2RaidVolPage0_t *vol_pg0;
1576 Mpi2RaidPhysDiskPage0_t pd_pg0;
1577 Mpi2SasDevicePage0_t sas_device_pg0;
1578 Mpi2ConfigReply_t mpi_reply;
1582 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1583 &num_pds)) || !num_pds) {
1584 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1585 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1590 raid_device->num_pds = num_pds;
1591 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1592 sizeof(Mpi2RaidVol0PhysDisk_t));
1593 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1595 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1596 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1601 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1602 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1603 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1604 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1610 raid_device->volume_type = vol_pg0->VolumeType;
1612 /* figure out what the underlying devices are by
1613 * obtaining the device_info bits for the 1st device
1615 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1616 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1617 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1618 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1619 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1620 le16_to_cpu(pd_pg0.DevHandle)))) {
1621 raid_device->device_info =
1622 le32_to_cpu(sas_device_pg0.DeviceInfo);
1633 * _scsih_enable_tlr - setting TLR flags
1634 * @ioc: per adapter object
1635 * @sdev: scsi device struct
1637 * Enabling Transaction Layer Retries for tape devices when
1638 * vpd page 0x90 is present
1642 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1646 if (sdev->type != TYPE_TAPE)
1649 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1652 sas_enable_tlr(sdev);
1653 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1654 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1660 * _scsih_slave_configure - device configure routine.
1661 * @sdev: scsi device struct
1663 * Returns 0 if ok. Any other return is assumed to be an error and
1664 * the device is ignored.
1667 _scsih_slave_configure(struct scsi_device *sdev)
1669 struct Scsi_Host *shost = sdev->host;
1670 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1671 struct MPT3SAS_DEVICE *sas_device_priv_data;
1672 struct MPT3SAS_TARGET *sas_target_priv_data;
1673 struct _sas_device *sas_device;
1674 struct _raid_device *raid_device;
1675 unsigned long flags;
1680 u16 handle, volume_handle = 0;
1681 u64 volume_wwid = 0;
1684 sas_device_priv_data = sdev->hostdata;
1685 sas_device_priv_data->configured_lun = 1;
1686 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1687 sas_target_priv_data = sas_device_priv_data->sas_target;
1688 handle = sas_target_priv_data->handle;
1690 /* raid volume handling */
1691 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1693 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1694 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1695 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1697 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1698 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1699 __LINE__, __func__));
1703 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1704 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1705 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1706 __LINE__, __func__));
1711 /* RAID Queue Depth Support
1712 * IS volume = underlying qdepth of drive type, either
1713 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1714 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1716 if (raid_device->device_info &
1717 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1718 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1721 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1722 if (raid_device->device_info &
1723 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1729 switch (raid_device->volume_type) {
1730 case MPI2_RAID_VOL_TYPE_RAID0:
1733 case MPI2_RAID_VOL_TYPE_RAID1E:
1734 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1735 if (ioc->manu_pg10.OEMIdentifier &&
1736 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1737 MFG10_GF0_R10_DISPLAY) &&
1738 !(raid_device->num_pds % 2))
1743 case MPI2_RAID_VOL_TYPE_RAID1:
1744 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1747 case MPI2_RAID_VOL_TYPE_RAID10:
1748 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1751 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1753 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1758 sdev_printk(KERN_INFO, sdev,
1759 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1760 r_level, raid_device->handle,
1761 (unsigned long long)raid_device->wwid,
1762 raid_device->num_pds, ds);
1765 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1767 /* raid transport support */
1768 _scsih_set_level(sdev, raid_device->volume_type);
1772 /* non-raid handling */
1773 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1774 if (mpt3sas_config_get_volume_handle(ioc, handle,
1776 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1777 "failure at %s:%d/%s()!\n", ioc->name,
1778 __FILE__, __LINE__, __func__));
1781 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1782 volume_handle, &volume_wwid)) {
1783 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1784 "failure at %s:%d/%s()!\n", ioc->name,
1785 __FILE__, __LINE__, __func__));
1790 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1791 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1792 sas_device_priv_data->sas_target->sas_address);
1794 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1795 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1796 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1801 sas_device->volume_handle = volume_handle;
1802 sas_device->volume_wwid = volume_wwid;
1803 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1804 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1808 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1809 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1811 else if (sas_device->device_info &
1812 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1816 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1817 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1818 ds, handle, (unsigned long long)sas_device->sas_address,
1819 sas_device->phy, (unsigned long long)sas_device->device_name);
1820 sdev_printk(KERN_INFO, sdev,
1821 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1822 ds, (unsigned long long)
1823 sas_device->enclosure_logical_id, sas_device->slot);
1825 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1828 _scsih_display_sata_capabilities(ioc, handle, sdev);
1831 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1834 sas_read_port_mode_page(sdev);
1835 _scsih_enable_tlr(ioc, sdev);
1842 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1843 * @sdev: scsi device struct
1844 * @bdev: pointer to block device context
1845 * @capacity: device size (in 512 byte sectors)
1846 * @params: three element array to place output:
1847 * params[0] number of heads (max 255)
1848 * params[1] number of sectors (max 63)
1849 * params[2] number of cylinders
1854 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1855 sector_t capacity, int params[])
1865 dummy = heads * sectors;
1866 cylinders = capacity;
1867 sector_div(cylinders, dummy);
1870 * Handle extended translation size for logical drives
1873 if ((ulong)capacity >= 0x200000) {
1876 dummy = heads * sectors;
1877 cylinders = capacity;
1878 sector_div(cylinders, dummy);
1883 params[1] = sectors;
1884 params[2] = cylinders;
1890 * _scsih_response_code - translation of device response code
1891 * @ioc: per adapter object
1892 * @response_code: response code returned by the device
1897 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1901 switch (response_code) {
1902 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1903 desc = "task management request completed";
1905 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1906 desc = "invalid frame";
1908 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1909 desc = "task management request not supported";
1911 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1912 desc = "task management request failed";
1914 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1915 desc = "task management request succeeded";
1917 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1918 desc = "invalid lun";
1921 desc = "overlapped tag attempted";
1923 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1924 desc = "task queued, however not sent to target";
1930 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1931 ioc->name, response_code, desc);
1935 * _scsih_tm_done - tm completion routine
1936 * @ioc: per adapter object
1937 * @smid: system request message index
1938 * @msix_index: MSIX table index supplied by the OS
1939 * @reply: reply message frame(lower 32bit addr)
1942 * The callback handler when using scsih_issue_tm.
1944 * Return 1 meaning mf should be freed from _base_interrupt
1945 * 0 means the mf is freed from this function.
1948 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1950 MPI2DefaultReply_t *mpi_reply;
1952 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1954 if (ioc->tm_cmds.smid != smid)
1956 mpt3sas_base_flush_reply_queues(ioc);
1957 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1958 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1960 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1961 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1963 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1964 complete(&ioc->tm_cmds.done);
1969 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1970 * @ioc: per adapter object
1971 * @handle: device handle
1973 * During taskmangement request, we need to freeze the device queue.
1976 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1978 struct MPT3SAS_DEVICE *sas_device_priv_data;
1979 struct scsi_device *sdev;
1982 shost_for_each_device(sdev, ioc->shost) {
1985 sas_device_priv_data = sdev->hostdata;
1986 if (!sas_device_priv_data)
1988 if (sas_device_priv_data->sas_target->handle == handle) {
1989 sas_device_priv_data->sas_target->tm_busy = 1;
1991 ioc->ignore_loginfos = 1;
1997 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1998 * @ioc: per adapter object
1999 * @handle: device handle
2001 * During taskmangement request, we need to freeze the device queue.
2004 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2006 struct MPT3SAS_DEVICE *sas_device_priv_data;
2007 struct scsi_device *sdev;
2010 shost_for_each_device(sdev, ioc->shost) {
2013 sas_device_priv_data = sdev->hostdata;
2014 if (!sas_device_priv_data)
2016 if (sas_device_priv_data->sas_target->handle == handle) {
2017 sas_device_priv_data->sas_target->tm_busy = 0;
2019 ioc->ignore_loginfos = 0;
2025 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2026 * @ioc: per adapter struct
2027 * @device_handle: device handle
2028 * @channel: the channel assigned by the OS
2029 * @id: the id assigned by the OS
2031 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2032 * @smid_task: smid assigned to the task
2033 * @timeout: timeout in seconds
2034 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2037 * A generic API for sending task management requests to firmware.
2039 * The callback index is set inside `ioc->tm_cb_idx`.
2041 * Return SUCCESS or FAILED.
2044 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2045 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2046 enum mutex_type m_type)
2048 Mpi2SCSITaskManagementRequest_t *mpi_request;
2049 Mpi2SCSITaskManagementReply_t *mpi_reply;
2052 unsigned long timeleft;
2053 struct scsiio_tracker *scsi_lookup = NULL;
2056 if (m_type == TM_MUTEX_ON)
2057 mutex_lock(&ioc->tm_cmds.mutex);
2058 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2059 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2060 __func__, ioc->name);
2065 if (ioc->shost_recovery || ioc->remove_host ||
2066 ioc->pci_error_recovery) {
2067 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2068 __func__, ioc->name);
2073 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2074 if (ioc_state & MPI2_DOORBELL_USED) {
2075 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2076 "unexpected doorbell active!\n", ioc->name));
2077 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2079 rc = (!rc) ? SUCCESS : FAILED;
2083 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2084 mpt3sas_base_fault_info(ioc, ioc_state &
2085 MPI2_DOORBELL_DATA_MASK);
2086 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2088 rc = (!rc) ? SUCCESS : FAILED;
2092 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2094 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2095 ioc->name, __func__);
2100 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2101 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2103 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2104 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2105 ioc->name, handle, type, smid_task));
2106 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2107 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2108 ioc->tm_cmds.smid = smid;
2109 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2110 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2111 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2112 mpi_request->DevHandle = cpu_to_le16(handle);
2113 mpi_request->TaskType = type;
2114 mpi_request->TaskMID = cpu_to_le16(smid_task);
2115 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2116 mpt3sas_scsih_set_tm_flag(ioc, handle);
2117 init_completion(&ioc->tm_cmds.done);
2118 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2119 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2120 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2121 pr_err(MPT3SAS_FMT "%s: timeout\n",
2122 ioc->name, __func__);
2123 _debug_dump_mf(mpi_request,
2124 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2125 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2126 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2128 rc = (!rc) ? SUCCESS : FAILED;
2129 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2130 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2135 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2136 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2137 mpi_reply = ioc->tm_cmds.reply;
2138 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2139 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2140 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2141 le32_to_cpu(mpi_reply->IOCLogInfo),
2142 le32_to_cpu(mpi_reply->TerminationCount)));
2143 if (ioc->logging_level & MPT_DEBUG_TM) {
2144 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2145 if (mpi_reply->IOCStatus)
2146 _debug_dump_mf(mpi_request,
2147 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2152 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2154 if (scsi_lookup->scmd == NULL)
2159 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2160 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2165 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2166 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2167 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2172 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2180 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2181 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2182 if (m_type == TM_MUTEX_ON)
2183 mutex_unlock(&ioc->tm_cmds.mutex);
2188 if (m_type == TM_MUTEX_ON)
2189 mutex_unlock(&ioc->tm_cmds.mutex);
2194 * _scsih_tm_display_info - displays info about the device
2195 * @ioc: per adapter struct
2196 * @scmd: pointer to scsi command object
2198 * Called by task management callback handlers.
2201 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2203 struct scsi_target *starget = scmd->device->sdev_target;
2204 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2205 struct _sas_device *sas_device = NULL;
2206 unsigned long flags;
2207 char *device_str = NULL;
2211 device_str = "volume";
2213 scsi_print_command(scmd);
2214 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2215 starget_printk(KERN_INFO, starget,
2216 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2217 device_str, priv_target->handle,
2218 device_str, (unsigned long long)priv_target->sas_address);
2220 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2221 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2222 priv_target->sas_address);
2224 if (priv_target->flags &
2225 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2226 starget_printk(KERN_INFO, starget,
2227 "volume handle(0x%04x), "
2228 "volume wwid(0x%016llx)\n",
2229 sas_device->volume_handle,
2230 (unsigned long long)sas_device->volume_wwid);
2232 starget_printk(KERN_INFO, starget,
2233 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2235 (unsigned long long)sas_device->sas_address,
2237 starget_printk(KERN_INFO, starget,
2238 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2239 (unsigned long long)sas_device->enclosure_logical_id,
2242 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2247 * _scsih_abort - eh threads main abort routine
2248 * @scmd: pointer to scsi command object
2250 * Returns SUCCESS if command aborted else FAILED
2253 _scsih_abort(struct scsi_cmnd *scmd)
2255 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2256 struct MPT3SAS_DEVICE *sas_device_priv_data;
2261 sdev_printk(KERN_INFO, scmd->device,
2262 "attempting task abort! scmd(%p)\n", scmd);
2263 _scsih_tm_display_info(ioc, scmd);
2265 sas_device_priv_data = scmd->device->hostdata;
2266 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2267 sdev_printk(KERN_INFO, scmd->device,
2268 "device been deleted! scmd(%p)\n", scmd);
2269 scmd->result = DID_NO_CONNECT << 16;
2270 scmd->scsi_done(scmd);
2275 /* search for the command */
2276 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2278 scmd->result = DID_RESET << 16;
2283 /* for hidden raid components and volumes this is not supported */
2284 if (sas_device_priv_data->sas_target->flags &
2285 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2286 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2287 scmd->result = DID_RESET << 16;
2292 mpt3sas_halt_firmware(ioc);
2294 handle = sas_device_priv_data->sas_target->handle;
2295 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2296 scmd->device->id, scmd->device->lun,
2297 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2300 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2301 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2306 * _scsih_dev_reset - eh threads main device reset routine
2307 * @scmd: pointer to scsi command object
2309 * Returns SUCCESS if command aborted else FAILED
2312 _scsih_dev_reset(struct scsi_cmnd *scmd)
2314 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2315 struct MPT3SAS_DEVICE *sas_device_priv_data;
2316 struct _sas_device *sas_device;
2317 unsigned long flags;
2321 sdev_printk(KERN_INFO, scmd->device,
2322 "attempting device reset! scmd(%p)\n", scmd);
2323 _scsih_tm_display_info(ioc, scmd);
2325 sas_device_priv_data = scmd->device->hostdata;
2326 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2327 sdev_printk(KERN_INFO, scmd->device,
2328 "device been deleted! scmd(%p)\n", scmd);
2329 scmd->result = DID_NO_CONNECT << 16;
2330 scmd->scsi_done(scmd);
2335 /* for hidden raid components obtain the volume_handle */
2337 if (sas_device_priv_data->sas_target->flags &
2338 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2339 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2340 sas_device = _scsih_sas_device_find_by_handle(ioc,
2341 sas_device_priv_data->sas_target->handle);
2343 handle = sas_device->volume_handle;
2344 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2346 handle = sas_device_priv_data->sas_target->handle;
2349 scmd->result = DID_RESET << 16;
2354 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2355 scmd->device->id, scmd->device->lun,
2356 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2359 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2360 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2365 * _scsih_target_reset - eh threads main target reset routine
2366 * @scmd: pointer to scsi command object
2368 * Returns SUCCESS if command aborted else FAILED
2371 _scsih_target_reset(struct scsi_cmnd *scmd)
2373 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2374 struct MPT3SAS_DEVICE *sas_device_priv_data;
2375 struct _sas_device *sas_device;
2376 unsigned long flags;
2379 struct scsi_target *starget = scmd->device->sdev_target;
2381 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2383 _scsih_tm_display_info(ioc, scmd);
2385 sas_device_priv_data = scmd->device->hostdata;
2386 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2387 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2389 scmd->result = DID_NO_CONNECT << 16;
2390 scmd->scsi_done(scmd);
2395 /* for hidden raid components obtain the volume_handle */
2397 if (sas_device_priv_data->sas_target->flags &
2398 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2399 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2400 sas_device = _scsih_sas_device_find_by_handle(ioc,
2401 sas_device_priv_data->sas_target->handle);
2403 handle = sas_device->volume_handle;
2404 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2406 handle = sas_device_priv_data->sas_target->handle;
2409 scmd->result = DID_RESET << 16;
2414 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2415 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2419 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2420 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2426 * _scsih_host_reset - eh threads main host reset routine
2427 * @scmd: pointer to scsi command object
2429 * Returns SUCCESS if command aborted else FAILED
2432 _scsih_host_reset(struct scsi_cmnd *scmd)
2434 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2437 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2439 scsi_print_command(scmd);
2441 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2443 r = (retval < 0) ? FAILED : SUCCESS;
2444 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2445 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2451 * _scsih_fw_event_add - insert and queue up fw_event
2452 * @ioc: per adapter object
2453 * @fw_event: object describing the event
2454 * Context: This function will acquire ioc->fw_event_lock.
2456 * This adds the firmware event object into link list, then queues it up to
2457 * be processed from user context.
2462 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2464 unsigned long flags;
2466 if (ioc->firmware_event_thread == NULL)
2469 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2470 INIT_LIST_HEAD(&fw_event->list);
2471 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2472 INIT_WORK(&fw_event->work, _firmware_event_work);
2473 queue_work(ioc->firmware_event_thread, &fw_event->work);
2474 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2478 * _scsih_fw_event_free - delete fw_event
2479 * @ioc: per adapter object
2480 * @fw_event: object describing the event
2481 * Context: This function will acquire ioc->fw_event_lock.
2483 * This removes firmware event object from link list, frees associated memory.
2488 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2491 unsigned long flags;
2493 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2494 list_del(&fw_event->list);
2496 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2501 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2502 * @ioc: per adapter object
2503 * @event_data: trigger event data
2508 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2509 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2511 struct fw_event_work *fw_event;
2513 if (ioc->is_driver_loading)
2515 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2519 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2520 fw_event->ioc = ioc;
2521 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2522 _scsih_fw_event_add(ioc, fw_event);
2526 * _scsih_error_recovery_delete_devices - remove devices not responding
2527 * @ioc: per adapter object
2532 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2534 struct fw_event_work *fw_event;
2536 if (ioc->is_driver_loading)
2538 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2541 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2542 fw_event->ioc = ioc;
2543 _scsih_fw_event_add(ioc, fw_event);
2547 * mpt3sas_port_enable_complete - port enable completed (fake event)
2548 * @ioc: per adapter object
2553 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2555 struct fw_event_work *fw_event;
2557 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2560 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2561 fw_event->ioc = ioc;
2562 _scsih_fw_event_add(ioc, fw_event);
2566 * _scsih_fw_event_cleanup_queue - cleanup event queue
2567 * @ioc: per adapter object
2569 * Walk the firmware event queue, either killing timers, or waiting
2570 * for outstanding events to complete
2575 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2577 struct fw_event_work *fw_event, *next;
2579 if (list_empty(&ioc->fw_event_list) ||
2580 !ioc->firmware_event_thread || in_interrupt())
2583 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2584 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2585 _scsih_fw_event_free(ioc, fw_event);
2592 * _scsih_ublock_io_all_device - unblock every device
2593 * @ioc: per adapter object
2595 * change the device state from block to running
2598 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2600 struct MPT3SAS_DEVICE *sas_device_priv_data;
2601 struct scsi_device *sdev;
2603 shost_for_each_device(sdev, ioc->shost) {
2604 sas_device_priv_data = sdev->hostdata;
2605 if (!sas_device_priv_data)
2607 if (!sas_device_priv_data->block)
2610 sas_device_priv_data->block = 0;
2611 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2612 "device_running, handle(0x%04x)\n",
2613 sas_device_priv_data->sas_target->handle));
2614 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2620 * _scsih_ublock_io_device - prepare device to be deleted
2621 * @ioc: per adapter object
2622 * @sas_addr: sas address
2624 * unblock then put device in offline state
2627 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2629 struct MPT3SAS_DEVICE *sas_device_priv_data;
2630 struct scsi_device *sdev;
2632 shost_for_each_device(sdev, ioc->shost) {
2633 sas_device_priv_data = sdev->hostdata;
2634 if (!sas_device_priv_data)
2636 if (sas_device_priv_data->sas_target->sas_address
2639 if (sas_device_priv_data->block) {
2640 sas_device_priv_data->block = 0;
2641 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2647 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2648 * @ioc: per adapter object
2649 * @handle: device handle
2651 * During device pull we need to appropiately set the sdev state.
2654 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2656 struct MPT3SAS_DEVICE *sas_device_priv_data;
2657 struct scsi_device *sdev;
2659 shost_for_each_device(sdev, ioc->shost) {
2660 sas_device_priv_data = sdev->hostdata;
2661 if (!sas_device_priv_data)
2663 if (sas_device_priv_data->block)
2665 sas_device_priv_data->block = 1;
2666 scsi_internal_device_block(sdev);
2667 sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n",
2668 sas_device_priv_data->sas_target->handle);
2673 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2674 * @ioc: per adapter object
2675 * @handle: device handle
2677 * During device pull we need to appropiately set the sdev state.
2680 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2682 struct MPT3SAS_DEVICE *sas_device_priv_data;
2683 struct scsi_device *sdev;
2685 shost_for_each_device(sdev, ioc->shost) {
2686 sas_device_priv_data = sdev->hostdata;
2687 if (!sas_device_priv_data)
2689 if (sas_device_priv_data->sas_target->handle != handle)
2691 if (sas_device_priv_data->block)
2693 sas_device_priv_data->block = 1;
2694 scsi_internal_device_block(sdev);
2695 sdev_printk(KERN_INFO, sdev,
2696 "device_blocked, handle(0x%04x)\n", handle);
2701 * _scsih_block_io_to_children_attached_to_ex
2702 * @ioc: per adapter object
2703 * @sas_expander: the sas_device object
2705 * This routine set sdev state to SDEV_BLOCK for all devices
2706 * attached to this expander. This function called when expander is
2710 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2711 struct _sas_node *sas_expander)
2713 struct _sas_port *mpt3sas_port;
2714 struct _sas_device *sas_device;
2715 struct _sas_node *expander_sibling;
2716 unsigned long flags;
2721 list_for_each_entry(mpt3sas_port,
2722 &sas_expander->sas_port_list, port_list) {
2723 if (mpt3sas_port->remote_identify.device_type ==
2725 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2727 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2728 mpt3sas_port->remote_identify.sas_address);
2730 set_bit(sas_device->handle,
2731 ioc->blocking_handles);
2732 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2736 list_for_each_entry(mpt3sas_port,
2737 &sas_expander->sas_port_list, port_list) {
2739 if (mpt3sas_port->remote_identify.device_type ==
2740 SAS_EDGE_EXPANDER_DEVICE ||
2741 mpt3sas_port->remote_identify.device_type ==
2742 SAS_FANOUT_EXPANDER_DEVICE) {
2744 mpt3sas_scsih_expander_find_by_sas_address(
2745 ioc, mpt3sas_port->remote_identify.sas_address);
2746 _scsih_block_io_to_children_attached_to_ex(ioc,
2753 * _scsih_block_io_to_children_attached_directly
2754 * @ioc: per adapter object
2755 * @event_data: topology change event data
2757 * This routine set sdev state to SDEV_BLOCK for all devices
2758 * direct attached during device pull.
2761 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2762 Mpi2EventDataSasTopologyChangeList_t *event_data)
2768 for (i = 0; i < event_data->NumEntries; i++) {
2769 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2772 reason_code = event_data->PHY[i].PhyStatus &
2773 MPI2_EVENT_SAS_TOPO_RC_MASK;
2774 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2775 _scsih_block_io_device(ioc, handle);
2780 * _scsih_tm_tr_send - send task management request
2781 * @ioc: per adapter object
2782 * @handle: device handle
2783 * Context: interrupt time.
2785 * This code is to initiate the device removal handshake protocol
2786 * with controller firmware. This function will issue target reset
2787 * using high priority request queue. It will send a sas iounit
2788 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2790 * This is designed to send muliple task management request at the same
2791 * time to the fifo. If the fifo is full, we will append the request,
2792 * and process it in a future completion.
2795 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2797 Mpi2SCSITaskManagementRequest_t *mpi_request;
2799 struct _sas_device *sas_device;
2800 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2801 u64 sas_address = 0;
2802 unsigned long flags;
2803 struct _tr_list *delayed_tr;
2806 if (ioc->remove_host) {
2807 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2808 "%s: host has been removed: handle(0x%04x)\n",
2809 __func__, ioc->name, handle));
2811 } else if (ioc->pci_error_recovery) {
2812 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2813 "%s: host in pci error recovery: handle(0x%04x)\n",
2814 __func__, ioc->name,
2818 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2819 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2820 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2821 "%s: host is not operational: handle(0x%04x)\n",
2822 __func__, ioc->name,
2827 /* if PD, then return */
2828 if (test_bit(handle, ioc->pd_handles))
2831 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2832 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2833 if (sas_device && sas_device->starget &&
2834 sas_device->starget->hostdata) {
2835 sas_target_priv_data = sas_device->starget->hostdata;
2836 sas_target_priv_data->deleted = 1;
2837 sas_address = sas_device->sas_address;
2839 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2841 if (sas_target_priv_data) {
2842 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2843 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2845 (unsigned long long)sas_address));
2846 _scsih_ublock_io_device(ioc, sas_address);
2847 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2850 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2852 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2855 INIT_LIST_HEAD(&delayed_tr->list);
2856 delayed_tr->handle = handle;
2857 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2858 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2859 "DELAYED:tr:handle(0x%04x), (open)\n",
2860 ioc->name, handle));
2864 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2865 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2866 ioc->name, handle, smid,
2867 ioc->tm_tr_cb_idx));
2868 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2869 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2870 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2871 mpi_request->DevHandle = cpu_to_le16(handle);
2872 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2873 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2874 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2878 * _scsih_tm_tr_complete -
2879 * @ioc: per adapter object
2880 * @smid: system request message index
2881 * @msix_index: MSIX table index supplied by the OS
2882 * @reply: reply message frame(lower 32bit addr)
2883 * Context: interrupt time.
2885 * This is the target reset completion routine.
2886 * This code is part of the code to initiate the device removal
2887 * handshake protocol with controller firmware.
2888 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2890 * Return 1 meaning mf should be freed from _base_interrupt
2891 * 0 means the mf is freed from this function.
2894 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2898 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2899 Mpi2SCSITaskManagementReply_t *mpi_reply =
2900 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2901 Mpi2SasIoUnitControlRequest_t *mpi_request;
2905 if (ioc->remove_host) {
2906 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2907 "%s: host has been removed\n", __func__, ioc->name));
2909 } else if (ioc->pci_error_recovery) {
2910 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2911 "%s: host in pci error recovery\n", __func__,
2915 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2916 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2917 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2918 "%s: host is not operational\n", __func__, ioc->name));
2921 if (unlikely(!mpi_reply)) {
2922 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2923 ioc->name, __FILE__, __LINE__, __func__);
2926 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2927 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2928 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2929 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2930 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2932 le16_to_cpu(mpi_reply->DevHandle), smid));
2936 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2937 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2938 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2939 "loginfo(0x%08x), completed(%d)\n", ioc->name,
2940 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
2941 le32_to_cpu(mpi_reply->IOCLogInfo),
2942 le32_to_cpu(mpi_reply->TerminationCount)));
2944 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2945 if (!smid_sas_ctrl) {
2946 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2947 ioc->name, __func__);
2951 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2952 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2953 ioc->name, handle, smid_sas_ctrl,
2954 ioc->tm_sas_control_cb_idx));
2955 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2956 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2957 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2958 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2959 mpi_request->DevHandle = mpi_request_tm->DevHandle;
2960 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
2962 return _scsih_check_for_pending_tm(ioc, smid);
2967 * _scsih_sas_control_complete - completion routine
2968 * @ioc: per adapter object
2969 * @smid: system request message index
2970 * @msix_index: MSIX table index supplied by the OS
2971 * @reply: reply message frame(lower 32bit addr)
2972 * Context: interrupt time.
2974 * This is the sas iounit control completion routine.
2975 * This code is part of the code to initiate the device removal
2976 * handshake protocol with controller firmware.
2978 * Return 1 meaning mf should be freed from _base_interrupt
2979 * 0 means the mf is freed from this function.
2982 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
2983 u8 msix_index, u32 reply)
2985 Mpi2SasIoUnitControlReply_t *mpi_reply =
2986 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2988 if (likely(mpi_reply)) {
2989 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2990 "sc_complete:handle(0x%04x), (open) "
2991 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2992 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2993 le16_to_cpu(mpi_reply->IOCStatus),
2994 le32_to_cpu(mpi_reply->IOCLogInfo)));
2996 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2997 ioc->name, __FILE__, __LINE__, __func__);
3003 * _scsih_tm_tr_volume_send - send target reset request for volumes
3004 * @ioc: per adapter object
3005 * @handle: device handle
3006 * Context: interrupt time.
3008 * This is designed to send muliple task management request at the same
3009 * time to the fifo. If the fifo is full, we will append the request,
3010 * and process it in a future completion.
3013 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3015 Mpi2SCSITaskManagementRequest_t *mpi_request;
3017 struct _tr_list *delayed_tr;
3019 if (ioc->shost_recovery || ioc->remove_host ||
3020 ioc->pci_error_recovery) {
3021 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3022 "%s: host reset in progress!\n",
3023 __func__, ioc->name));
3027 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3029 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3032 INIT_LIST_HEAD(&delayed_tr->list);
3033 delayed_tr->handle = handle;
3034 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3035 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3036 "DELAYED:tr:handle(0x%04x), (open)\n",
3037 ioc->name, handle));
3041 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3042 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3043 ioc->name, handle, smid,
3044 ioc->tm_tr_volume_cb_idx));
3045 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3046 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3047 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3048 mpi_request->DevHandle = cpu_to_le16(handle);
3049 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3050 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3054 * _scsih_tm_volume_tr_complete - target reset completion
3055 * @ioc: per adapter object
3056 * @smid: system request message index
3057 * @msix_index: MSIX table index supplied by the OS
3058 * @reply: reply message frame(lower 32bit addr)
3059 * Context: interrupt time.
3061 * Return 1 meaning mf should be freed from _base_interrupt
3062 * 0 means the mf is freed from this function.
3065 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3066 u8 msix_index, u32 reply)
3069 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3070 Mpi2SCSITaskManagementReply_t *mpi_reply =
3071 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3073 if (ioc->shost_recovery || ioc->remove_host ||
3074 ioc->pci_error_recovery) {
3075 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3076 "%s: host reset in progress!\n",
3077 __func__, ioc->name));
3080 if (unlikely(!mpi_reply)) {
3081 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3082 ioc->name, __FILE__, __LINE__, __func__);
3086 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3087 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3088 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3089 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3090 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3092 le16_to_cpu(mpi_reply->DevHandle), smid));
3096 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3097 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3098 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3099 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3100 le32_to_cpu(mpi_reply->IOCLogInfo),
3101 le32_to_cpu(mpi_reply->TerminationCount)));
3103 return _scsih_check_for_pending_tm(ioc, smid);
3108 * _scsih_check_for_pending_tm - check for pending task management
3109 * @ioc: per adapter object
3110 * @smid: system request message index
3112 * This will check delayed target reset list, and feed the
3115 * Return 1 meaning mf should be freed from _base_interrupt
3116 * 0 means the mf is freed from this function.
3119 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3121 struct _tr_list *delayed_tr;
3123 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3124 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3125 struct _tr_list, list);
3126 mpt3sas_base_free_smid(ioc, smid);
3127 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3128 list_del(&delayed_tr->list);
3133 if (!list_empty(&ioc->delayed_tr_list)) {
3134 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3135 struct _tr_list, list);
3136 mpt3sas_base_free_smid(ioc, smid);
3137 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3138 list_del(&delayed_tr->list);
3147 * _scsih_check_topo_delete_events - sanity check on topo events
3148 * @ioc: per adapter object
3149 * @event_data: the event data payload
3151 * This routine added to better handle cable breaker.
3153 * This handles the case where driver receives multiple expander
3154 * add and delete events in a single shot. When there is a delete event
3155 * the routine will void any pending add events waiting in the event queue.
3160 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3161 Mpi2EventDataSasTopologyChangeList_t *event_data)
3163 struct fw_event_work *fw_event;
3164 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3165 u16 expander_handle;
3166 struct _sas_node *sas_expander;
3167 unsigned long flags;
3171 for (i = 0 ; i < event_data->NumEntries; i++) {
3172 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3175 reason_code = event_data->PHY[i].PhyStatus &
3176 MPI2_EVENT_SAS_TOPO_RC_MASK;
3177 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3178 _scsih_tm_tr_send(ioc, handle);
3181 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3182 if (expander_handle < ioc->sas_hba.num_phys) {
3183 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3186 if (event_data->ExpStatus ==
3187 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3188 /* put expander attached devices into blocking state */
3189 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3190 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3192 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3193 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3195 handle = find_first_bit(ioc->blocking_handles,
3196 ioc->facts.MaxDevHandle);
3197 if (handle < ioc->facts.MaxDevHandle)
3198 _scsih_block_io_device(ioc, handle);
3199 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3200 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3201 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3203 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3206 /* mark ignore flag for pending events */
3207 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3208 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3209 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3212 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3213 fw_event->event_data;
3214 if (local_event_data->ExpStatus ==
3215 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3216 local_event_data->ExpStatus ==
3217 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3218 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3220 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3221 "setting ignoring flag\n", ioc->name));
3222 fw_event->ignore = 1;
3226 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3230 * _scsih_set_volume_delete_flag - setting volume delete flag
3231 * @ioc: per adapter object
3232 * @handle: device handle
3234 * This returns nothing.
3237 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3239 struct _raid_device *raid_device;
3240 struct MPT3SAS_TARGET *sas_target_priv_data;
3241 unsigned long flags;
3243 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3244 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3245 if (raid_device && raid_device->starget &&
3246 raid_device->starget->hostdata) {
3247 sas_target_priv_data =
3248 raid_device->starget->hostdata;
3249 sas_target_priv_data->deleted = 1;
3250 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3251 "setting delete flag: handle(0x%04x), "
3252 "wwid(0x%016llx)\n", ioc->name, handle,
3253 (unsigned long long) raid_device->wwid));
3255 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3259 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3260 * @handle: input handle
3261 * @a: handle for volume a
3262 * @b: handle for volume b
3264 * IR firmware only supports two raid volumes. The purpose of this
3265 * routine is to set the volume handle in either a or b. When the given
3266 * input handle is non-zero, or when a and b have not been set before.
3269 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3271 if (!handle || handle == *a || handle == *b)
3280 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3281 * @ioc: per adapter object
3282 * @event_data: the event data payload
3283 * Context: interrupt time.
3285 * This routine will send target reset to volume, followed by target
3286 * resets to the PDs. This is called when a PD has been removed, or
3287 * volume has been deleted or removed. When the target reset is sent
3288 * to volume, the PD target resets need to be queued to start upon
3289 * completion of the volume target reset.
3294 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3295 Mpi2EventDataIrConfigChangeList_t *event_data)
3297 Mpi2EventIrConfigElement_t *element;
3299 u16 handle, volume_handle, a, b;
3300 struct _tr_list *delayed_tr;
3305 /* Volume Resets for Deleted or Removed */
3306 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3307 for (i = 0; i < event_data->NumElements; i++, element++) {
3308 if (le32_to_cpu(event_data->Flags) &
3309 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3311 if (element->ReasonCode ==
3312 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3313 element->ReasonCode ==
3314 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3315 volume_handle = le16_to_cpu(element->VolDevHandle);
3316 _scsih_set_volume_delete_flag(ioc, volume_handle);
3317 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3321 /* Volume Resets for UNHIDE events */
3322 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3323 for (i = 0; i < event_data->NumElements; i++, element++) {
3324 if (le32_to_cpu(event_data->Flags) &
3325 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3327 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3328 volume_handle = le16_to_cpu(element->VolDevHandle);
3329 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3334 _scsih_tm_tr_volume_send(ioc, a);
3336 _scsih_tm_tr_volume_send(ioc, b);
3338 /* PD target resets */
3339 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3340 for (i = 0; i < event_data->NumElements; i++, element++) {
3341 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3343 handle = le16_to_cpu(element->PhysDiskDevHandle);
3344 volume_handle = le16_to_cpu(element->VolDevHandle);
3345 clear_bit(handle, ioc->pd_handles);
3347 _scsih_tm_tr_send(ioc, handle);
3348 else if (volume_handle == a || volume_handle == b) {
3349 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3350 BUG_ON(!delayed_tr);
3351 INIT_LIST_HEAD(&delayed_tr->list);
3352 delayed_tr->handle = handle;
3353 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3354 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3355 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3358 _scsih_tm_tr_send(ioc, handle);
3364 * _scsih_check_volume_delete_events - set delete flag for volumes
3365 * @ioc: per adapter object
3366 * @event_data: the event data payload
3367 * Context: interrupt time.
3369 * This will handle the case when the cable connected to entire volume is
3370 * pulled. We will take care of setting the deleted flag so normal IO will
3376 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3377 Mpi2EventDataIrVolume_t *event_data)
3381 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3383 state = le32_to_cpu(event_data->NewValue);
3384 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3385 MPI2_RAID_VOL_STATE_FAILED)
3386 _scsih_set_volume_delete_flag(ioc,
3387 le16_to_cpu(event_data->VolDevHandle));
3391 * _scsih_flush_running_cmds - completing outstanding commands.
3392 * @ioc: per adapter object
3394 * The flushing out of all pending scmd commands following host reset,
3395 * where all IO is dropped to the floor.
3400 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3402 struct scsi_cmnd *scmd;
3406 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3407 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3411 mpt3sas_base_free_smid(ioc, smid);
3412 scsi_dma_unmap(scmd);
3413 if (ioc->pci_error_recovery)
3414 scmd->result = DID_NO_CONNECT << 16;
3416 scmd->result = DID_RESET << 16;
3417 scmd->scsi_done(scmd);
3419 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3424 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3425 * @ioc: per adapter object
3426 * @scmd: pointer to scsi command object
3427 * @mpi_request: pointer to the SCSI_IO reqest message frame
3429 * Supporting protection 1 and 3.
3434 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3435 Mpi2SCSIIORequest_t *mpi_request)
3438 unsigned char prot_op = scsi_get_prot_op(scmd);
3439 unsigned char prot_type = scsi_get_prot_type(scmd);
3440 Mpi25SCSIIORequest_t *mpi_request_3v =
3441 (Mpi25SCSIIORequest_t *)mpi_request;
3443 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3446 if (prot_op == SCSI_PROT_READ_STRIP)
3447 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3448 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3449 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3453 switch (prot_type) {
3454 case SCSI_PROT_DIF_TYPE1:
3455 case SCSI_PROT_DIF_TYPE2:
3458 * enable ref/guard checking
3459 * auto increment ref tag
3461 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3462 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3463 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3464 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3465 cpu_to_be32(scsi_get_lba(scmd));
3468 case SCSI_PROT_DIF_TYPE3:
3471 * enable guard checking
3473 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3478 mpi_request_3v->EEDPBlockSize =
3479 cpu_to_le16(scmd->device->sector_size);
3480 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3484 * _scsih_eedp_error_handling - return sense code for EEDP errors
3485 * @scmd: pointer to scsi command object
3486 * @ioc_status: ioc status
3491 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3495 switch (ioc_status) {
3496 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3499 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3502 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3509 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3511 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3512 SAM_STAT_CHECK_CONDITION;
3517 * _scsih_qcmd - main scsi request entry point
3518 * @scmd: pointer to scsi command object
3519 * @done: function pointer to be invoked on completion
3521 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3523 * Returns 0 on success. If there's a failure, return either:
3524 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3525 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3528 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3530 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3531 struct MPT3SAS_DEVICE *sas_device_priv_data;
3532 struct MPT3SAS_TARGET *sas_target_priv_data;
3533 Mpi2SCSIIORequest_t *mpi_request;
3538 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3539 if (ioc->logging_level & MPT_DEBUG_SCSI)
3540 scsi_print_command(scmd);
3543 sas_device_priv_data = scmd->device->hostdata;
3544 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3545 scmd->result = DID_NO_CONNECT << 16;
3546 scmd->scsi_done(scmd);
3550 if (ioc->pci_error_recovery || ioc->remove_host) {
3551 scmd->result = DID_NO_CONNECT << 16;
3552 scmd->scsi_done(scmd);
3556 sas_target_priv_data = sas_device_priv_data->sas_target;
3558 /* invalid device handle */
3559 handle = sas_target_priv_data->handle;
3560 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3561 scmd->result = DID_NO_CONNECT << 16;
3562 scmd->scsi_done(scmd);
3567 /* host recovery or link resets sent via IOCTLs */
3568 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3569 return SCSI_MLQUEUE_HOST_BUSY;
3571 /* device has been deleted */
3572 else if (sas_target_priv_data->deleted) {
3573 scmd->result = DID_NO_CONNECT << 16;
3574 scmd->scsi_done(scmd);
3576 /* device busy with task managment */
3577 } else if (sas_target_priv_data->tm_busy ||
3578 sas_device_priv_data->block)
3579 return SCSI_MLQUEUE_DEVICE_BUSY;
3581 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3582 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3583 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3584 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3586 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3589 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3590 if (scmd->device->tagged_supported) {
3591 if (scmd->device->ordered_tags)
3592 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3594 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3596 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3598 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3600 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3601 scmd->cmd_len != 32)
3602 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3604 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3606 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3607 ioc->name, __func__);
3610 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3611 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3612 _scsih_setup_eedp(ioc, scmd, mpi_request);
3614 if (scmd->cmd_len == 32)
3615 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3616 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3617 if (sas_device_priv_data->sas_target->flags &
3618 MPT_TARGET_FLAGS_RAID_COMPONENT)
3619 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3621 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3622 mpi_request->DevHandle = cpu_to_le16(handle);
3623 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3624 mpi_request->Control = cpu_to_le32(mpi_control);
3625 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3626 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3627 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3628 mpi_request->SenseBufferLowAddress =
3629 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3630 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3631 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3633 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3635 if (mpi_request->DataLength) {
3636 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3637 mpt3sas_base_free_smid(ioc, smid);
3641 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3643 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3644 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3645 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3646 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3647 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3649 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3651 mpt3sas_base_put_smid_default(ioc, smid);
3655 return SCSI_MLQUEUE_HOST_BUSY;
3659 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3660 * @sense_buffer: sense data returned by target
3661 * @data: normalized skey/asc/ascq
3666 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3668 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3669 /* descriptor format */
3670 data->skey = sense_buffer[1] & 0x0F;
3671 data->asc = sense_buffer[2];
3672 data->ascq = sense_buffer[3];
3675 data->skey = sense_buffer[2] & 0x0F;
3676 data->asc = sense_buffer[12];
3677 data->ascq = sense_buffer[13];
3681 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3683 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3684 * @ioc: per adapter object
3685 * @scmd: pointer to scsi command object
3686 * @mpi_reply: reply mf payload returned from firmware
3688 * scsi_status - SCSI Status code returned from target device
3689 * scsi_state - state info associated with SCSI_IO determined by ioc
3690 * ioc_status - ioc supplied status info
3695 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3696 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3700 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3701 MPI2_IOCSTATUS_MASK;
3702 u8 scsi_state = mpi_reply->SCSIState;
3703 u8 scsi_status = mpi_reply->SCSIStatus;
3704 char *desc_ioc_state = NULL;
3705 char *desc_scsi_status = NULL;
3706 char *desc_scsi_state = ioc->tmp_string;
3707 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3708 struct _sas_device *sas_device = NULL;
3709 unsigned long flags;
3710 struct scsi_target *starget = scmd->device->sdev_target;
3711 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3712 char *device_str = NULL;
3716 device_str = "volume";
3718 if (log_info == 0x31170000)
3721 switch (ioc_status) {
3722 case MPI2_IOCSTATUS_SUCCESS:
3723 desc_ioc_state = "success";
3725 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3726 desc_ioc_state = "invalid function";
3728 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3729 desc_ioc_state = "scsi recovered error";
3731 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3732 desc_ioc_state = "scsi invalid dev handle";
3734 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3735 desc_ioc_state = "scsi device not there";
3737 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3738 desc_ioc_state = "scsi data overrun";
3740 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3741 desc_ioc_state = "scsi data underrun";
3743 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3744 desc_ioc_state = "scsi io data error";
3746 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3747 desc_ioc_state = "scsi protocol error";
3749 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3750 desc_ioc_state = "scsi task terminated";
3752 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3753 desc_ioc_state = "scsi residual mismatch";
3755 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3756 desc_ioc_state = "scsi task mgmt failed";
3758 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3759 desc_ioc_state = "scsi ioc terminated";
3761 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3762 desc_ioc_state = "scsi ext terminated";
3764 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3765 desc_ioc_state = "eedp guard error";
3767 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3768 desc_ioc_state = "eedp ref tag error";
3770 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3771 desc_ioc_state = "eedp app tag error";
3774 desc_ioc_state = "unknown";
3778 switch (scsi_status) {
3779 case MPI2_SCSI_STATUS_GOOD:
3780 desc_scsi_status = "good";
3782 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3783 desc_scsi_status = "check condition";
3785 case MPI2_SCSI_STATUS_CONDITION_MET:
3786 desc_scsi_status = "condition met";
3788 case MPI2_SCSI_STATUS_BUSY:
3789 desc_scsi_status = "busy";
3791 case MPI2_SCSI_STATUS_INTERMEDIATE:
3792 desc_scsi_status = "intermediate";
3794 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3795 desc_scsi_status = "intermediate condmet";
3797 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3798 desc_scsi_status = "reservation conflict";
3800 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3801 desc_scsi_status = "command terminated";
3803 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3804 desc_scsi_status = "task set full";
3806 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3807 desc_scsi_status = "aca active";
3809 case MPI2_SCSI_STATUS_TASK_ABORTED:
3810 desc_scsi_status = "task aborted";
3813 desc_scsi_status = "unknown";
3817 desc_scsi_state[0] = '\0';
3819 desc_scsi_state = " ";
3820 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3821 strcat(desc_scsi_state, "response info ");
3822 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3823 strcat(desc_scsi_state, "state terminated ");
3824 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3825 strcat(desc_scsi_state, "no status ");
3826 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3827 strcat(desc_scsi_state, "autosense failed ");
3828 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3829 strcat(desc_scsi_state, "autosense valid ");
3831 scsi_print_command(scmd);
3833 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3834 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3835 device_str, (unsigned long long)priv_target->sas_address);
3837 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3838 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3839 priv_target->sas_address);
3842 "\tsas_address(0x%016llx), phy(%d)\n",
3843 ioc->name, (unsigned long long)
3844 sas_device->sas_address, sas_device->phy);
3846 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3847 ioc->name, (unsigned long long)
3848 sas_device->enclosure_logical_id, sas_device->slot);
3850 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3854 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3855 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3856 desc_ioc_state, ioc_status, smid);
3858 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3859 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3860 scsi_get_resid(scmd));
3862 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3863 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3864 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3866 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3867 ioc->name, desc_scsi_status,
3868 scsi_status, desc_scsi_state, scsi_state);
3870 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3871 struct sense_info data;
3872 _scsih_normalize_sense(scmd->sense_buffer, &data);
3874 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3875 ioc->name, data.skey,
3876 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3879 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3880 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3881 response_bytes = (u8 *)&response_info;
3882 _scsih_response_code(ioc, response_bytes[0]);
3888 * _scsih_turn_on_pfa_led - illuminate PFA LED
3889 * @ioc: per adapter object
3890 * @handle: device handle
3896 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3898 Mpi2SepReply_t mpi_reply;
3899 Mpi2SepRequest_t mpi_request;
3900 struct _sas_device *sas_device;
3902 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3906 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3907 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3908 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3909 mpi_request.SlotStatus =
3910 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3911 mpi_request.DevHandle = cpu_to_le16(handle);
3912 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3913 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3914 &mpi_request)) != 0) {
3915 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3916 __FILE__, __LINE__, __func__);
3919 sas_device->pfa_led_on = 1;
3921 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3922 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3923 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3924 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3925 le32_to_cpu(mpi_reply.IOCLogInfo)));
3930 * _scsih_turn_off_pfa_led - turn off Fault LED
3931 * @ioc: per adapter object
3932 * @sas_device: sas device whose PFA LED has to turned off
3938 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
3939 struct _sas_device *sas_device)
3941 Mpi2SepReply_t mpi_reply;
3942 Mpi2SepRequest_t mpi_request;
3944 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3945 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3946 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3947 mpi_request.SlotStatus = 0;
3948 mpi_request.Slot = cpu_to_le16(sas_device->slot);
3949 mpi_request.DevHandle = 0;
3950 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
3951 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
3952 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3953 &mpi_request)) != 0) {
3954 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3955 __FILE__, __LINE__, __func__);
3959 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3960 dewtprintk(ioc, printk(MPT3SAS_FMT
3961 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3962 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3963 le32_to_cpu(mpi_reply.IOCLogInfo)));
3968 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
3969 * @ioc: per adapter object
3970 * @handle: device handle
3971 * Context: interrupt.
3976 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3978 struct fw_event_work *fw_event;
3980 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
3983 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
3984 fw_event->device_handle = handle;
3985 fw_event->ioc = ioc;
3986 _scsih_fw_event_add(ioc, fw_event);
3990 * _scsih_smart_predicted_fault - process smart errors
3991 * @ioc: per adapter object
3992 * @handle: device handle
3993 * Context: interrupt.
3998 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4000 struct scsi_target *starget;
4001 struct MPT3SAS_TARGET *sas_target_priv_data;
4002 Mpi2EventNotificationReply_t *event_reply;
4003 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4004 struct _sas_device *sas_device;
4006 unsigned long flags;
4008 /* only handle non-raid devices */
4009 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4010 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4012 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4015 starget = sas_device->starget;
4016 sas_target_priv_data = starget->hostdata;
4018 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4019 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4020 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4023 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4024 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4026 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4027 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4029 /* insert into event log */
4030 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4031 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4032 event_reply = kzalloc(sz, GFP_KERNEL);
4034 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4035 ioc->name, __FILE__, __LINE__, __func__);
4039 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4040 event_reply->Event =
4041 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4042 event_reply->MsgLength = sz/4;
4043 event_reply->EventDataLength =
4044 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4045 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4046 event_reply->EventData;
4047 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4048 event_data->ASC = 0x5D;
4049 event_data->DevHandle = cpu_to_le16(handle);
4050 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4051 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4056 * _scsih_io_done - scsi request callback
4057 * @ioc: per adapter object
4058 * @smid: system request message index
4059 * @msix_index: MSIX table index supplied by the OS
4060 * @reply: reply message frame(lower 32bit addr)
4062 * Callback handler when using _scsih_qcmd.
4064 * Return 1 meaning mf should be freed from _base_interrupt
4065 * 0 means the mf is freed from this function.
4068 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4070 Mpi2SCSIIORequest_t *mpi_request;
4071 Mpi2SCSIIOReply_t *mpi_reply;
4072 struct scsi_cmnd *scmd;
4078 struct MPT3SAS_DEVICE *sas_device_priv_data;
4079 u32 response_code = 0;
4081 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4082 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4086 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4088 if (mpi_reply == NULL) {
4089 scmd->result = DID_OK << 16;
4093 sas_device_priv_data = scmd->device->hostdata;
4094 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4095 sas_device_priv_data->sas_target->deleted) {
4096 scmd->result = DID_NO_CONNECT << 16;
4099 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4101 /* turning off TLR */
4102 scsi_state = mpi_reply->SCSIState;
4103 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4105 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4106 if (!sas_device_priv_data->tlr_snoop_check) {
4107 sas_device_priv_data->tlr_snoop_check++;
4108 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4109 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4110 sas_device_priv_data->flags &=
4114 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4115 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4116 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4117 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4120 ioc_status &= MPI2_IOCSTATUS_MASK;
4121 scsi_status = mpi_reply->SCSIStatus;
4123 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4124 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4125 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4126 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4127 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4130 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4131 struct sense_info data;
4132 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4134 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4135 le32_to_cpu(mpi_reply->SenseCount));
4136 memcpy(scmd->sense_buffer, sense_data, sz);
4137 _scsih_normalize_sense(scmd->sense_buffer, &data);
4138 /* failure prediction threshold exceeded */
4139 if (data.asc == 0x5D)
4140 _scsih_smart_predicted_fault(ioc,
4141 le16_to_cpu(mpi_reply->DevHandle));
4142 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4145 switch (ioc_status) {
4146 case MPI2_IOCSTATUS_BUSY:
4147 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4148 scmd->result = SAM_STAT_BUSY;
4151 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4152 scmd->result = DID_NO_CONNECT << 16;
4155 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4156 if (sas_device_priv_data->block) {
4157 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4160 if (log_info == 0x31110630) {
4161 if (scmd->retries > 2) {
4162 scmd->result = DID_NO_CONNECT << 16;
4163 scsi_device_set_state(scmd->device,
4166 scmd->result = DID_SOFT_ERROR << 16;
4167 scmd->device->expecting_cc_ua = 1;
4171 scmd->result = DID_SOFT_ERROR << 16;
4173 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4174 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4175 scmd->result = DID_RESET << 16;
4178 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4179 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4180 scmd->result = DID_SOFT_ERROR << 16;
4182 scmd->result = (DID_OK << 16) | scsi_status;
4185 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4186 scmd->result = (DID_OK << 16) | scsi_status;
4188 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4191 if (xfer_cnt < scmd->underflow) {
4192 if (scsi_status == SAM_STAT_BUSY)
4193 scmd->result = SAM_STAT_BUSY;
4195 scmd->result = DID_SOFT_ERROR << 16;
4196 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4197 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4198 scmd->result = DID_SOFT_ERROR << 16;
4199 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4200 scmd->result = DID_RESET << 16;
4201 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4202 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4203 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4204 scmd->result = (DRIVER_SENSE << 24) |
4205 SAM_STAT_CHECK_CONDITION;
4206 scmd->sense_buffer[0] = 0x70;
4207 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4208 scmd->sense_buffer[12] = 0x20;
4209 scmd->sense_buffer[13] = 0;
4213 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4214 scsi_set_resid(scmd, 0);
4215 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4216 case MPI2_IOCSTATUS_SUCCESS:
4217 scmd->result = (DID_OK << 16) | scsi_status;
4218 if (response_code ==
4219 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4220 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4221 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4222 scmd->result = DID_SOFT_ERROR << 16;
4223 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4224 scmd->result = DID_RESET << 16;
4227 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4228 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4229 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4230 _scsih_eedp_error_handling(scmd, ioc_status);
4233 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4234 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4235 case MPI2_IOCSTATUS_INVALID_SGL:
4236 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4237 case MPI2_IOCSTATUS_INVALID_FIELD:
4238 case MPI2_IOCSTATUS_INVALID_STATE:
4239 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4240 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4242 scmd->result = DID_SOFT_ERROR << 16;
4247 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4248 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4249 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4254 scsi_dma_unmap(scmd);
4256 scmd->scsi_done(scmd);
4261 * _scsih_sas_host_refresh - refreshing sas host object contents
4262 * @ioc: per adapter object
4265 * During port enable, fw will send topology events for every device. Its
4266 * possible that the handles may change from the previous setting, so this
4267 * code keeping handles updating if changed.
4272 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4277 Mpi2ConfigReply_t mpi_reply;
4278 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4279 u16 attached_handle;
4282 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4283 "updating handles for sas_host(0x%016llx)\n",
4284 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4286 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4287 * sizeof(Mpi2SasIOUnit0PhyData_t));
4288 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4289 if (!sas_iounit_pg0) {
4290 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4291 ioc->name, __FILE__, __LINE__, __func__);
4295 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4296 sas_iounit_pg0, sz)) != 0)
4298 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4299 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4301 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4302 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4304 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4305 PhyData[0].ControllerDevHandle);
4306 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4307 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4309 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4310 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4311 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4312 attached_handle, i, link_rate);
4315 kfree(sas_iounit_pg0);
4319 * _scsih_sas_host_add - create sas host object
4320 * @ioc: per adapter object
4322 * Creating host side data object, stored in ioc->sas_hba
4327 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4330 Mpi2ConfigReply_t mpi_reply;
4331 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4332 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4333 Mpi2SasPhyPage0_t phy_pg0;
4334 Mpi2SasDevicePage0_t sas_device_pg0;
4335 Mpi2SasEnclosurePage0_t enclosure_pg0;
4338 u8 device_missing_delay;
4340 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4341 if (!ioc->sas_hba.num_phys) {
4342 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4343 ioc->name, __FILE__, __LINE__, __func__);
4347 /* sas_iounit page 0 */
4348 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4349 sizeof(Mpi2SasIOUnit0PhyData_t));
4350 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4351 if (!sas_iounit_pg0) {
4352 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4353 ioc->name, __FILE__, __LINE__, __func__);
4356 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4357 sas_iounit_pg0, sz))) {
4358 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4359 ioc->name, __FILE__, __LINE__, __func__);
4362 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4363 MPI2_IOCSTATUS_MASK;
4364 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4365 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4366 ioc->name, __FILE__, __LINE__, __func__);
4370 /* sas_iounit page 1 */
4371 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4372 sizeof(Mpi2SasIOUnit1PhyData_t));
4373 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4374 if (!sas_iounit_pg1) {
4375 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4376 ioc->name, __FILE__, __LINE__, __func__);
4379 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4380 sas_iounit_pg1, sz))) {
4381 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4382 ioc->name, __FILE__, __LINE__, __func__);
4385 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4386 MPI2_IOCSTATUS_MASK;
4387 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4388 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4389 ioc->name, __FILE__, __LINE__, __func__);
4393 ioc->io_missing_delay =
4394 sas_iounit_pg1->IODeviceMissingDelay;
4395 device_missing_delay =
4396 sas_iounit_pg1->ReportDeviceMissingDelay;
4397 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4398 ioc->device_missing_delay = (device_missing_delay &
4399 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4401 ioc->device_missing_delay = device_missing_delay &
4402 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4404 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4405 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4406 sizeof(struct _sas_phy), GFP_KERNEL);
4407 if (!ioc->sas_hba.phy) {
4408 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4409 ioc->name, __FILE__, __LINE__, __func__);
4412 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4413 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4415 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4416 ioc->name, __FILE__, __LINE__, __func__);
4419 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4420 MPI2_IOCSTATUS_MASK;
4421 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4422 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4423 ioc->name, __FILE__, __LINE__, __func__);
4428 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4429 PhyData[0].ControllerDevHandle);
4430 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4431 ioc->sas_hba.phy[i].phy_id = i;
4432 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4433 phy_pg0, ioc->sas_hba.parent_dev);
4435 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4436 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4437 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4438 ioc->name, __FILE__, __LINE__, __func__);
4441 ioc->sas_hba.enclosure_handle =
4442 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4443 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4445 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4446 ioc->name, ioc->sas_hba.handle,
4447 (unsigned long long) ioc->sas_hba.sas_address,
4448 ioc->sas_hba.num_phys) ;
4450 if (ioc->sas_hba.enclosure_handle) {
4451 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4452 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4453 ioc->sas_hba.enclosure_handle)))
4454 ioc->sas_hba.enclosure_logical_id =
4455 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4459 kfree(sas_iounit_pg1);
4460 kfree(sas_iounit_pg0);
4464 * _scsih_expander_add - creating expander object
4465 * @ioc: per adapter object
4466 * @handle: expander handle
4468 * Creating expander object, stored in ioc->sas_expander_list.
4470 * Return 0 for success, else error.
4473 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4475 struct _sas_node *sas_expander;
4476 Mpi2ConfigReply_t mpi_reply;
4477 Mpi2ExpanderPage0_t expander_pg0;
4478 Mpi2ExpanderPage1_t expander_pg1;
4479 Mpi2SasEnclosurePage0_t enclosure_pg0;
4482 u64 sas_address, sas_address_parent = 0;
4484 unsigned long flags;
4485 struct _sas_port *mpt3sas_port = NULL;
4492 if (ioc->shost_recovery || ioc->pci_error_recovery)
4495 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4496 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4497 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4498 ioc->name, __FILE__, __LINE__, __func__);
4502 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4503 MPI2_IOCSTATUS_MASK;
4504 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4505 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4506 ioc->name, __FILE__, __LINE__, __func__);
4510 /* handle out of order topology events */
4511 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4512 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4514 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4515 ioc->name, __FILE__, __LINE__, __func__);
4518 if (sas_address_parent != ioc->sas_hba.sas_address) {
4519 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4520 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4521 sas_address_parent);
4522 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4523 if (!sas_expander) {
4524 rc = _scsih_expander_add(ioc, parent_handle);
4530 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4531 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4532 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4534 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4539 sas_expander = kzalloc(sizeof(struct _sas_node),
4541 if (!sas_expander) {
4542 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4543 ioc->name, __FILE__, __LINE__, __func__);
4547 sas_expander->handle = handle;
4548 sas_expander->num_phys = expander_pg0.NumPhys;
4549 sas_expander->sas_address_parent = sas_address_parent;
4550 sas_expander->sas_address = sas_address;
4552 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4553 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4554 handle, parent_handle, (unsigned long long)
4555 sas_expander->sas_address, sas_expander->num_phys);
4557 if (!sas_expander->num_phys)
4559 sas_expander->phy = kcalloc(sas_expander->num_phys,
4560 sizeof(struct _sas_phy), GFP_KERNEL);
4561 if (!sas_expander->phy) {
4562 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4563 ioc->name, __FILE__, __LINE__, __func__);
4568 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4569 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4570 sas_address_parent);
4571 if (!mpt3sas_port) {
4572 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4573 ioc->name, __FILE__, __LINE__, __func__);
4577 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4579 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4580 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4581 &expander_pg1, i, handle))) {
4582 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4583 ioc->name, __FILE__, __LINE__, __func__);
4587 sas_expander->phy[i].handle = handle;
4588 sas_expander->phy[i].phy_id = i;
4590 if ((mpt3sas_transport_add_expander_phy(ioc,
4591 &sas_expander->phy[i], expander_pg1,
4592 sas_expander->parent_dev))) {
4593 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4594 ioc->name, __FILE__, __LINE__, __func__);
4600 if (sas_expander->enclosure_handle) {
4601 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4602 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4603 sas_expander->enclosure_handle)))
4604 sas_expander->enclosure_logical_id =
4605 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4608 _scsih_expander_node_add(ioc, sas_expander);
4614 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4615 sas_address_parent);
4616 kfree(sas_expander);
4621 * mpt3sas_expander_remove - removing expander object
4622 * @ioc: per adapter object
4623 * @sas_address: expander sas_address
4628 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4630 struct _sas_node *sas_expander;
4631 unsigned long flags;
4633 if (ioc->shost_recovery)
4636 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4637 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4640 list_del(&sas_expander->list);
4641 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4643 _scsih_expander_node_remove(ioc, sas_expander);
4647 * _scsih_done - internal SCSI_IO callback handler.
4648 * @ioc: per adapter object
4649 * @smid: system request message index
4650 * @msix_index: MSIX table index supplied by the OS
4651 * @reply: reply message frame(lower 32bit addr)
4653 * Callback handler when sending internal generated SCSI_IO.
4654 * The callback index passed is `ioc->scsih_cb_idx`
4656 * Return 1 meaning mf should be freed from _base_interrupt
4657 * 0 means the mf is freed from this function.
4660 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4662 MPI2DefaultReply_t *mpi_reply;
4664 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4665 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4667 if (ioc->scsih_cmds.smid != smid)
4669 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4671 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4672 mpi_reply->MsgLength*4);
4673 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4675 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4676 complete(&ioc->scsih_cmds.done);
4683 #define MPT3_MAX_LUNS (255)
4687 * _scsih_check_access_status - check access flags
4688 * @ioc: per adapter object
4689 * @sas_address: sas address
4690 * @handle: sas device handle
4691 * @access_flags: errors returned during discovery of the device
4693 * Return 0 for success, else failure
4696 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4697 u16 handle, u8 access_status)
4702 switch (access_status) {
4703 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4704 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4707 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4708 desc = "sata capability failed";
4710 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4711 desc = "sata affiliation conflict";
4713 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4714 desc = "route not addressable";
4716 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4717 desc = "smp error not addressable";
4719 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4720 desc = "device blocked";
4722 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4723 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4724 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4725 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4726 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4727 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4728 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4729 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4730 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4731 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4732 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4733 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4734 desc = "sata initialization failed";
4745 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4746 ioc->name, desc, (unsigned long long)sas_address, handle);
4751 * _scsih_check_device - checking device responsiveness
4752 * @ioc: per adapter object
4753 * @parent_sas_address: sas address of parent expander or sas host
4754 * @handle: attached device handle
4755 * @phy_numberv: phy number
4756 * @link_rate: new link rate
4761 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4762 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4764 Mpi2ConfigReply_t mpi_reply;
4765 Mpi2SasDevicePage0_t sas_device_pg0;
4766 struct _sas_device *sas_device;
4768 unsigned long flags;
4770 struct scsi_target *starget;
4771 struct MPT3SAS_TARGET *sas_target_priv_data;
4775 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4776 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4779 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4780 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4783 /* wide port handling ~ we need only handle device once for the phy that
4784 * is matched in sas device page zero
4786 if (phy_number != sas_device_pg0.PhyNum)
4789 /* check if this is end device */
4790 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4791 if (!(_scsih_is_end_device(device_info)))
4794 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4795 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4796 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4800 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4804 if (unlikely(sas_device->handle != handle)) {
4805 starget = sas_device->starget;
4806 sas_target_priv_data = starget->hostdata;
4807 starget_printk(KERN_INFO, starget,
4808 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4809 sas_device->handle, handle);
4810 sas_target_priv_data->handle = handle;
4811 sas_device->handle = handle;
4814 /* check if device is present */
4815 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4816 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4818 "device is not present handle(0x%04x), flags!!!\n",
4820 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4824 /* check if there were any issues with discovery */
4825 if (_scsih_check_access_status(ioc, sas_address, handle,
4826 sas_device_pg0.AccessStatus)) {
4827 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4831 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4832 _scsih_ublock_io_device(ioc, sas_address);
4837 * _scsih_add_device - creating sas device object
4838 * @ioc: per adapter object
4839 * @handle: sas device handle
4840 * @phy_num: phy number end device attached to
4841 * @is_pd: is this hidden raid component
4843 * Creating end device object, stored in ioc->sas_device_list.
4845 * Returns 0 for success, non-zero for failure.
4848 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4851 Mpi2ConfigReply_t mpi_reply;
4852 Mpi2SasDevicePage0_t sas_device_pg0;
4853 Mpi2SasEnclosurePage0_t enclosure_pg0;
4854 struct _sas_device *sas_device;
4858 unsigned long flags;
4860 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4861 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4862 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4863 ioc->name, __FILE__, __LINE__, __func__);
4867 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4868 MPI2_IOCSTATUS_MASK;
4869 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4870 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4871 ioc->name, __FILE__, __LINE__, __func__);
4875 /* check if this is end device */
4876 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4877 if (!(_scsih_is_end_device(device_info)))
4879 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4881 /* check if device is present */
4882 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4883 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4884 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4889 /* check if there were any issues with discovery */
4890 if (_scsih_check_access_status(ioc, sas_address, handle,
4891 sas_device_pg0.AccessStatus))
4894 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4895 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4897 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4902 sas_device = kzalloc(sizeof(struct _sas_device),
4905 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4906 ioc->name, __FILE__, __LINE__, __func__);
4910 sas_device->handle = handle;
4911 if (_scsih_get_sas_address(ioc,
4912 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4913 &sas_device->sas_address_parent) != 0)
4914 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4915 ioc->name, __FILE__, __LINE__, __func__);
4916 sas_device->enclosure_handle =
4917 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4919 le16_to_cpu(sas_device_pg0.Slot);
4920 sas_device->device_info = device_info;
4921 sas_device->sas_address = sas_address;
4922 sas_device->phy = sas_device_pg0.PhyNum;
4923 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
4924 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
4926 /* get enclosure_logical_id */
4927 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
4928 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4929 sas_device->enclosure_handle)))
4930 sas_device->enclosure_logical_id =
4931 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4933 /* get device name */
4934 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
4936 if (ioc->wait_for_discovery_to_complete)
4937 _scsih_sas_device_init_add(ioc, sas_device);
4939 _scsih_sas_device_add(ioc, sas_device);
4945 * _scsih_remove_device - removing sas device object
4946 * @ioc: per adapter object
4947 * @sas_device_delete: the sas_device object
4952 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
4953 struct _sas_device *sas_device)
4955 struct MPT3SAS_TARGET *sas_target_priv_data;
4957 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
4958 (sas_device->pfa_led_on)) {
4959 _scsih_turn_off_pfa_led(ioc, sas_device);
4960 sas_device->pfa_led_on = 0;
4962 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4963 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4964 ioc->name, __func__,
4965 sas_device->handle, (unsigned long long)
4966 sas_device->sas_address));
4968 if (sas_device->starget && sas_device->starget->hostdata) {
4969 sas_target_priv_data = sas_device->starget->hostdata;
4970 sas_target_priv_data->deleted = 1;
4971 _scsih_ublock_io_device(ioc, sas_device->sas_address);
4972 sas_target_priv_data->handle =
4973 MPT3SAS_INVALID_DEVICE_HANDLE;
4975 mpt3sas_transport_port_remove(ioc,
4976 sas_device->sas_address,
4977 sas_device->sas_address_parent);
4980 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4981 ioc->name, sas_device->handle,
4982 (unsigned long long) sas_device->sas_address);
4984 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4985 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4986 ioc->name, __func__,
4987 sas_device->handle, (unsigned long long)
4988 sas_device->sas_address));
4993 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4995 * _scsih_sas_topology_change_event_debug - debug for topology event
4996 * @ioc: per adapter object
4997 * @event_data: event data payload
5001 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5002 Mpi2EventDataSasTopologyChangeList_t *event_data)
5008 char *status_str = NULL;
5009 u8 link_rate, prev_link_rate;
5011 switch (event_data->ExpStatus) {
5012 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5015 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5016 status_str = "remove";
5018 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5020 status_str = "responding";
5022 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5023 status_str = "remove delay";
5026 status_str = "unknown status";
5029 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5030 ioc->name, status_str);
5031 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5032 "start_phy(%02d), count(%d)\n",
5033 le16_to_cpu(event_data->ExpanderDevHandle),
5034 le16_to_cpu(event_data->EnclosureHandle),
5035 event_data->StartPhyNum, event_data->NumEntries);
5036 for (i = 0; i < event_data->NumEntries; i++) {
5037 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5040 phy_number = event_data->StartPhyNum + i;
5041 reason_code = event_data->PHY[i].PhyStatus &
5042 MPI2_EVENT_SAS_TOPO_RC_MASK;
5043 switch (reason_code) {
5044 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5045 status_str = "target add";
5047 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5048 status_str = "target remove";
5050 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5051 status_str = "delay target remove";
5053 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5054 status_str = "link rate change";
5056 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5057 status_str = "target responding";
5060 status_str = "unknown";
5063 link_rate = event_data->PHY[i].LinkRate >> 4;
5064 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5065 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5066 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5067 handle, status_str, link_rate, prev_link_rate);
5074 * _scsih_sas_topology_change_event - handle topology changes
5075 * @ioc: per adapter object
5076 * @fw_event: The fw_event_work object
5081 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5082 struct fw_event_work *fw_event)
5085 u16 parent_handle, handle;
5087 u8 phy_number, max_phys;
5088 struct _sas_node *sas_expander;
5090 unsigned long flags;
5091 u8 link_rate, prev_link_rate;
5092 Mpi2EventDataSasTopologyChangeList_t *event_data =
5093 (Mpi2EventDataSasTopologyChangeList_t *)
5094 fw_event->event_data;
5096 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5097 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5098 _scsih_sas_topology_change_event_debug(ioc, event_data);
5101 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5104 if (!ioc->sas_hba.num_phys)
5105 _scsih_sas_host_add(ioc);
5107 _scsih_sas_host_refresh(ioc);
5109 if (fw_event->ignore) {
5110 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5111 "ignoring expander event\n", ioc->name));
5115 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5117 /* handle expander add */
5118 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5119 if (_scsih_expander_add(ioc, parent_handle) != 0)
5122 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5123 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5126 sas_address = sas_expander->sas_address;
5127 max_phys = sas_expander->num_phys;
5128 } else if (parent_handle < ioc->sas_hba.num_phys) {
5129 sas_address = ioc->sas_hba.sas_address;
5130 max_phys = ioc->sas_hba.num_phys;
5132 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5135 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5137 /* handle siblings events */
5138 for (i = 0; i < event_data->NumEntries; i++) {
5139 if (fw_event->ignore) {
5140 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5141 "ignoring expander event\n", ioc->name));
5144 if (ioc->remove_host || ioc->pci_error_recovery)
5146 phy_number = event_data->StartPhyNum + i;
5147 if (phy_number >= max_phys)
5149 reason_code = event_data->PHY[i].PhyStatus &
5150 MPI2_EVENT_SAS_TOPO_RC_MASK;
5151 if ((event_data->PHY[i].PhyStatus &
5152 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5153 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5155 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5158 link_rate = event_data->PHY[i].LinkRate >> 4;
5159 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5160 switch (reason_code) {
5161 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5163 if (ioc->shost_recovery)
5166 if (link_rate == prev_link_rate)
5169 mpt3sas_transport_update_links(ioc, sas_address,
5170 handle, phy_number, link_rate);
5172 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5175 _scsih_check_device(ioc, sas_address, handle,
5176 phy_number, link_rate);
5179 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5181 if (ioc->shost_recovery)
5184 mpt3sas_transport_update_links(ioc, sas_address,
5185 handle, phy_number, link_rate);
5187 _scsih_add_device(ioc, handle, phy_number, 0);
5190 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5192 _scsih_device_remove_by_handle(ioc, handle);
5197 /* handle expander removal */
5198 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5200 mpt3sas_expander_remove(ioc, sas_address);
5205 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5207 * _scsih_sas_device_status_change_event_debug - debug for device event
5208 * @event_data: event data payload
5214 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5215 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5217 char *reason_str = NULL;
5219 switch (event_data->ReasonCode) {
5220 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5221 reason_str = "smart data";
5223 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5224 reason_str = "unsupported device discovered";
5226 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5227 reason_str = "internal device reset";
5229 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5230 reason_str = "internal task abort";
5232 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5233 reason_str = "internal task abort set";
5235 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5236 reason_str = "internal clear task set";
5238 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5239 reason_str = "internal query task";
5241 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5242 reason_str = "sata init failure";
5244 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5245 reason_str = "internal device reset complete";
5247 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5248 reason_str = "internal task abort complete";
5250 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5251 reason_str = "internal async notification";
5253 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5254 reason_str = "expander reduced functionality";
5256 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5257 reason_str = "expander reduced functionality complete";
5260 reason_str = "unknown reason";
5263 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5264 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5265 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5266 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5267 le16_to_cpu(event_data->TaskTag));
5268 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5269 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5270 event_data->ASC, event_data->ASCQ);
5276 * _scsih_sas_device_status_change_event - handle device status change
5277 * @ioc: per adapter object
5278 * @fw_event: The fw_event_work object
5284 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5285 struct fw_event_work *fw_event)
5287 struct MPT3SAS_TARGET *target_priv_data;
5288 struct _sas_device *sas_device;
5290 unsigned long flags;
5291 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5292 (Mpi2EventDataSasDeviceStatusChange_t *)
5293 fw_event->event_data;
5295 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5296 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5297 _scsih_sas_device_status_change_event_debug(ioc,
5301 /* In MPI Revision K (0xC), the internal device reset complete was
5302 * implemented, so avoid setting tm_busy flag for older firmware.
5304 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5307 if (event_data->ReasonCode !=
5308 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5309 event_data->ReasonCode !=
5310 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5313 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5314 sas_address = le64_to_cpu(event_data->SASAddress);
5315 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5318 if (!sas_device || !sas_device->starget) {
5319 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5323 target_priv_data = sas_device->starget->hostdata;
5324 if (!target_priv_data) {
5325 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5329 if (event_data->ReasonCode ==
5330 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5331 target_priv_data->tm_busy = 1;
5333 target_priv_data->tm_busy = 0;
5334 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5337 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5339 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5341 * @ioc: per adapter object
5342 * @event_data: event data payload
5348 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5349 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5351 char *reason_str = NULL;
5353 switch (event_data->ReasonCode) {
5354 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5355 reason_str = "enclosure add";
5357 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5358 reason_str = "enclosure remove";
5361 reason_str = "unknown reason";
5365 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5366 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5367 " number slots(%d)\n", ioc->name, reason_str,
5368 le16_to_cpu(event_data->EnclosureHandle),
5369 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5370 le16_to_cpu(event_data->StartSlot));
5375 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5376 * @ioc: per adapter object
5377 * @fw_event: The fw_event_work object
5383 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5384 struct fw_event_work *fw_event)
5386 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5387 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5388 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5389 (Mpi2EventDataSasEnclDevStatusChange_t *)
5390 fw_event->event_data);
5395 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5396 * @ioc: per adapter object
5397 * @fw_event: The fw_event_work object
5403 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5404 struct fw_event_work *fw_event)
5406 struct scsi_cmnd *scmd;
5407 struct scsi_device *sdev;
5410 struct MPT3SAS_DEVICE *sas_device_priv_data;
5411 u32 termination_count;
5413 Mpi2SCSITaskManagementReply_t *mpi_reply;
5414 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5415 (Mpi2EventDataSasBroadcastPrimitive_t *)
5416 fw_event->event_data;
5418 unsigned long flags;
5421 u8 task_abort_retries;
5423 mutex_lock(&ioc->tm_cmds.mutex);
5425 "%s: enter: phy number(%d), width(%d)\n",
5426 ioc->name, __func__, event_data->PhyNum,
5427 event_data->PortWidth);
5429 _scsih_block_io_all_device(ioc);
5431 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5432 mpi_reply = ioc->tm_cmds.reply;
5433 broadcast_aen_retry:
5435 /* sanity checks for retrying this loop */
5436 if (max_retries++ == 5) {
5437 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5438 ioc->name, __func__));
5440 } else if (max_retries > 1)
5441 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5442 ioc->name, __func__, max_retries - 1));
5444 termination_count = 0;
5446 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5447 if (ioc->shost_recovery)
5449 scmd = _scsih_scsi_lookup_get(ioc, smid);
5452 sdev = scmd->device;
5453 sas_device_priv_data = sdev->hostdata;
5454 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5456 /* skip hidden raid components */
5457 if (sas_device_priv_data->sas_target->flags &
5458 MPT_TARGET_FLAGS_RAID_COMPONENT)
5461 if (sas_device_priv_data->sas_target->flags &
5462 MPT_TARGET_FLAGS_VOLUME)
5465 handle = sas_device_priv_data->sas_target->handle;
5466 lun = sas_device_priv_data->lun;
5469 if (ioc->shost_recovery)
5472 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5473 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5474 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5477 sdev_printk(KERN_WARNING, sdev,
5478 "mpt3sas_scsih_issue_tm: FAILED when sending "
5479 "QUERY_TASK: scmd(%p)\n", scmd);
5480 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5481 goto broadcast_aen_retry;
5483 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5484 & MPI2_IOCSTATUS_MASK;
5485 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5486 sdev_printk(KERN_WARNING, sdev,
5487 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5489 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5490 goto broadcast_aen_retry;
5493 /* see if IO is still owned by IOC and target */
5494 if (mpi_reply->ResponseCode ==
5495 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5496 mpi_reply->ResponseCode ==
5497 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5498 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5501 task_abort_retries = 0;
5503 if (task_abort_retries++ == 60) {
5504 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5505 "%s: ABORT_TASK: giving up\n", ioc->name,
5507 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5508 goto broadcast_aen_retry;
5511 if (ioc->shost_recovery)
5514 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5515 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5518 sdev_printk(KERN_WARNING, sdev,
5519 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5520 "scmd(%p)\n", scmd);
5524 if (task_abort_retries > 1)
5525 sdev_printk(KERN_WARNING, sdev,
5526 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5528 task_abort_retries - 1, scmd);
5530 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5531 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5534 if (ioc->broadcast_aen_pending) {
5535 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5536 "%s: loop back due to pending AEN\n",
5537 ioc->name, __func__));
5538 ioc->broadcast_aen_pending = 0;
5539 goto broadcast_aen_retry;
5543 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5546 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5547 "%s - exit, query_count = %d termination_count = %d\n",
5548 ioc->name, __func__, query_count, termination_count));
5550 ioc->broadcast_aen_busy = 0;
5551 if (!ioc->shost_recovery)
5552 _scsih_ublock_io_all_device(ioc);
5553 mutex_unlock(&ioc->tm_cmds.mutex);
5557 * _scsih_sas_discovery_event - handle discovery events
5558 * @ioc: per adapter object
5559 * @fw_event: The fw_event_work object
5565 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5566 struct fw_event_work *fw_event)
5568 Mpi2EventDataSasDiscovery_t *event_data =
5569 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5571 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5572 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5573 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5574 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5576 if (event_data->DiscoveryStatus)
5577 pr_info("discovery_status(0x%08x)",
5578 le32_to_cpu(event_data->DiscoveryStatus));
5583 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5584 !ioc->sas_hba.num_phys) {
5585 if (disable_discovery > 0 && ioc->shost_recovery) {
5586 /* Wait for the reset to complete */
5587 while (ioc->shost_recovery)
5590 _scsih_sas_host_add(ioc);
5595 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5596 * @ioc: per adapter object
5597 * @handle: device handle for physical disk
5598 * @phys_disk_num: physical disk number
5600 * Return 0 for success, else failure.
5603 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5605 Mpi2RaidActionRequest_t *mpi_request;
5606 Mpi2RaidActionReply_t *mpi_reply;
5614 mutex_lock(&ioc->scsih_cmds.mutex);
5616 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5617 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5618 ioc->name, __func__);
5622 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5624 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5626 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5627 ioc->name, __func__);
5628 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5633 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5634 ioc->scsih_cmds.smid = smid;
5635 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5637 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5638 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5639 mpi_request->PhysDiskNum = phys_disk_num;
5641 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5642 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5643 handle, phys_disk_num));
5645 init_completion(&ioc->scsih_cmds.done);
5646 mpt3sas_base_put_smid_default(ioc, smid);
5647 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5649 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5650 pr_err(MPT3SAS_FMT "%s: timeout\n",
5651 ioc->name, __func__);
5652 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5658 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5660 mpi_reply = ioc->scsih_cmds.reply;
5661 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5662 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5663 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5666 ioc_status &= MPI2_IOCSTATUS_MASK;
5667 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5668 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5669 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5670 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5674 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5675 "IR RAID_ACTION: completed successfully\n",
5680 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5681 mutex_unlock(&ioc->scsih_cmds.mutex);
5684 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5690 * _scsih_reprobe_lun - reprobing lun
5691 * @sdev: scsi device struct
5692 * @no_uld_attach: sdev->no_uld_attach flag setting
5696 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5699 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5700 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5701 sdev->no_uld_attach ? "hidding" : "exposing");
5702 rc = scsi_device_reprobe(sdev);
5706 * _scsih_sas_volume_add - add new volume
5707 * @ioc: per adapter object
5708 * @element: IR config element data
5714 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5715 Mpi2EventIrConfigElement_t *element)
5717 struct _raid_device *raid_device;
5718 unsigned long flags;
5720 u16 handle = le16_to_cpu(element->VolDevHandle);
5723 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5726 "failure at %s:%d/%s()!\n", ioc->name,
5727 __FILE__, __LINE__, __func__);
5731 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5732 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5733 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5738 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5741 "failure at %s:%d/%s()!\n", ioc->name,
5742 __FILE__, __LINE__, __func__);
5746 raid_device->id = ioc->sas_id++;
5747 raid_device->channel = RAID_CHANNEL;
5748 raid_device->handle = handle;
5749 raid_device->wwid = wwid;
5750 _scsih_raid_device_add(ioc, raid_device);
5751 if (!ioc->wait_for_discovery_to_complete) {
5752 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5753 raid_device->id, 0);
5755 _scsih_raid_device_remove(ioc, raid_device);
5757 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5758 _scsih_determine_boot_device(ioc, raid_device, 1);
5759 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5764 * _scsih_sas_volume_delete - delete volume
5765 * @ioc: per adapter object
5766 * @handle: volume device handle
5772 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5774 struct _raid_device *raid_device;
5775 unsigned long flags;
5776 struct MPT3SAS_TARGET *sas_target_priv_data;
5777 struct scsi_target *starget = NULL;
5779 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5780 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5782 if (raid_device->starget) {
5783 starget = raid_device->starget;
5784 sas_target_priv_data = starget->hostdata;
5785 sas_target_priv_data->deleted = 1;
5787 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5788 ioc->name, raid_device->handle,
5789 (unsigned long long) raid_device->wwid);
5790 list_del(&raid_device->list);
5793 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5795 scsi_remove_target(&starget->dev);
5799 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5800 * @ioc: per adapter object
5801 * @element: IR config element data
5807 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5808 Mpi2EventIrConfigElement_t *element)
5810 struct _sas_device *sas_device;
5811 struct scsi_target *starget = NULL;
5812 struct MPT3SAS_TARGET *sas_target_priv_data;
5813 unsigned long flags;
5814 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5816 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5817 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5819 sas_device->volume_handle = 0;
5820 sas_device->volume_wwid = 0;
5821 clear_bit(handle, ioc->pd_handles);
5822 if (sas_device->starget && sas_device->starget->hostdata) {
5823 starget = sas_device->starget;
5824 sas_target_priv_data = starget->hostdata;
5825 sas_target_priv_data->flags &=
5826 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5829 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5833 /* exposing raid component */
5835 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5839 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5840 * @ioc: per adapter object
5841 * @element: IR config element data
5847 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5848 Mpi2EventIrConfigElement_t *element)
5850 struct _sas_device *sas_device;
5851 struct scsi_target *starget = NULL;
5852 struct MPT3SAS_TARGET *sas_target_priv_data;
5853 unsigned long flags;
5854 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5855 u16 volume_handle = 0;
5856 u64 volume_wwid = 0;
5858 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
5860 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
5863 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5864 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5866 set_bit(handle, ioc->pd_handles);
5867 if (sas_device->starget && sas_device->starget->hostdata) {
5868 starget = sas_device->starget;
5869 sas_target_priv_data = starget->hostdata;
5870 sas_target_priv_data->flags |=
5871 MPT_TARGET_FLAGS_RAID_COMPONENT;
5872 sas_device->volume_handle = volume_handle;
5873 sas_device->volume_wwid = volume_wwid;
5876 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5880 /* hiding raid component */
5881 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5883 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
5887 * _scsih_sas_pd_delete - delete pd component
5888 * @ioc: per adapter object
5889 * @element: IR config element data
5895 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
5896 Mpi2EventIrConfigElement_t *element)
5898 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5900 _scsih_device_remove_by_handle(ioc, handle);
5904 * _scsih_sas_pd_add - remove pd component
5905 * @ioc: per adapter object
5906 * @element: IR config element data
5912 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
5913 Mpi2EventIrConfigElement_t *element)
5915 struct _sas_device *sas_device;
5916 unsigned long flags;
5917 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5918 Mpi2ConfigReply_t mpi_reply;
5919 Mpi2SasDevicePage0_t sas_device_pg0;
5924 set_bit(handle, ioc->pd_handles);
5926 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5927 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5928 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5930 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5934 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5935 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5936 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5937 ioc->name, __FILE__, __LINE__, __func__);
5941 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5942 MPI2_IOCSTATUS_MASK;
5943 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5944 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5945 ioc->name, __FILE__, __LINE__, __func__);
5949 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5950 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5951 mpt3sas_transport_update_links(ioc, sas_address, handle,
5952 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5954 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5955 _scsih_add_device(ioc, handle, 0, 1);
5958 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5960 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5961 * @ioc: per adapter object
5962 * @event_data: event data payload
5968 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5969 Mpi2EventDataIrConfigChangeList_t *event_data)
5971 Mpi2EventIrConfigElement_t *element;
5974 char *reason_str = NULL, *element_str = NULL;
5976 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5978 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
5979 ioc->name, (le32_to_cpu(event_data->Flags) &
5980 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5981 "foreign" : "native", event_data->NumElements);
5982 for (i = 0; i < event_data->NumElements; i++, element++) {
5983 switch (element->ReasonCode) {
5984 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5987 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5988 reason_str = "remove";
5990 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5991 reason_str = "no change";
5993 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5994 reason_str = "hide";
5996 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5997 reason_str = "unhide";
5999 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6000 reason_str = "volume_created";
6002 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6003 reason_str = "volume_deleted";
6005 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6006 reason_str = "pd_created";
6008 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6009 reason_str = "pd_deleted";
6012 reason_str = "unknown reason";
6015 element_type = le16_to_cpu(element->ElementFlags) &
6016 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6017 switch (element_type) {
6018 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6019 element_str = "volume";
6021 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6022 element_str = "phys disk";
6024 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6025 element_str = "hot spare";
6028 element_str = "unknown element";
6031 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6032 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6033 reason_str, le16_to_cpu(element->VolDevHandle),
6034 le16_to_cpu(element->PhysDiskDevHandle),
6035 element->PhysDiskNum);
6041 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6042 * @ioc: per adapter object
6043 * @fw_event: The fw_event_work object
6049 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6050 struct fw_event_work *fw_event)
6052 Mpi2EventIrConfigElement_t *element;
6055 Mpi2EventDataIrConfigChangeList_t *event_data =
6056 (Mpi2EventDataIrConfigChangeList_t *)
6057 fw_event->event_data;
6059 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6060 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6061 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6065 foreign_config = (le32_to_cpu(event_data->Flags) &
6066 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6068 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6069 if (ioc->shost_recovery) {
6071 for (i = 0; i < event_data->NumElements; i++, element++) {
6072 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6073 _scsih_ir_fastpath(ioc,
6074 le16_to_cpu(element->PhysDiskDevHandle),
6075 element->PhysDiskNum);
6079 for (i = 0; i < event_data->NumElements; i++, element++) {
6081 switch (element->ReasonCode) {
6082 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6083 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6084 if (!foreign_config)
6085 _scsih_sas_volume_add(ioc, element);
6087 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6088 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6089 if (!foreign_config)
6090 _scsih_sas_volume_delete(ioc,
6091 le16_to_cpu(element->VolDevHandle));
6093 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6094 _scsih_sas_pd_hide(ioc, element);
6096 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6097 _scsih_sas_pd_expose(ioc, element);
6099 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6100 _scsih_sas_pd_add(ioc, element);
6102 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6103 _scsih_sas_pd_delete(ioc, element);
6110 * _scsih_sas_ir_volume_event - IR volume event
6111 * @ioc: per adapter object
6112 * @fw_event: The fw_event_work object
6118 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6119 struct fw_event_work *fw_event)
6122 unsigned long flags;
6123 struct _raid_device *raid_device;
6127 Mpi2EventDataIrVolume_t *event_data =
6128 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6130 if (ioc->shost_recovery)
6133 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6136 handle = le16_to_cpu(event_data->VolDevHandle);
6137 state = le32_to_cpu(event_data->NewValue);
6138 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6139 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6140 ioc->name, __func__, handle,
6141 le32_to_cpu(event_data->PreviousValue), state));
6143 case MPI2_RAID_VOL_STATE_MISSING:
6144 case MPI2_RAID_VOL_STATE_FAILED:
6145 _scsih_sas_volume_delete(ioc, handle);
6148 case MPI2_RAID_VOL_STATE_ONLINE:
6149 case MPI2_RAID_VOL_STATE_DEGRADED:
6150 case MPI2_RAID_VOL_STATE_OPTIMAL:
6152 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6153 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6154 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6159 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6162 "failure at %s:%d/%s()!\n", ioc->name,
6163 __FILE__, __LINE__, __func__);
6167 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6170 "failure at %s:%d/%s()!\n", ioc->name,
6171 __FILE__, __LINE__, __func__);
6175 raid_device->id = ioc->sas_id++;
6176 raid_device->channel = RAID_CHANNEL;
6177 raid_device->handle = handle;
6178 raid_device->wwid = wwid;
6179 _scsih_raid_device_add(ioc, raid_device);
6180 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6181 raid_device->id, 0);
6183 _scsih_raid_device_remove(ioc, raid_device);
6186 case MPI2_RAID_VOL_STATE_INITIALIZING:
6193 * _scsih_sas_ir_physical_disk_event - PD event
6194 * @ioc: per adapter object
6195 * @fw_event: The fw_event_work object
6201 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6202 struct fw_event_work *fw_event)
6204 u16 handle, parent_handle;
6206 struct _sas_device *sas_device;
6207 unsigned long flags;
6208 Mpi2ConfigReply_t mpi_reply;
6209 Mpi2SasDevicePage0_t sas_device_pg0;
6211 Mpi2EventDataIrPhysicalDisk_t *event_data =
6212 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6215 if (ioc->shost_recovery)
6218 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6221 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6222 state = le32_to_cpu(event_data->NewValue);
6224 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6225 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6226 ioc->name, __func__, handle,
6227 le32_to_cpu(event_data->PreviousValue), state));
6229 case MPI2_RAID_PD_STATE_ONLINE:
6230 case MPI2_RAID_PD_STATE_DEGRADED:
6231 case MPI2_RAID_PD_STATE_REBUILDING:
6232 case MPI2_RAID_PD_STATE_OPTIMAL:
6233 case MPI2_RAID_PD_STATE_HOT_SPARE:
6235 set_bit(handle, ioc->pd_handles);
6236 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6237 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6238 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6243 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6244 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6246 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6247 ioc->name, __FILE__, __LINE__, __func__);
6251 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6252 MPI2_IOCSTATUS_MASK;
6253 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6254 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6255 ioc->name, __FILE__, __LINE__, __func__);
6259 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6260 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6261 mpt3sas_transport_update_links(ioc, sas_address, handle,
6262 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6264 _scsih_add_device(ioc, handle, 0, 1);
6268 case MPI2_RAID_PD_STATE_OFFLINE:
6269 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6270 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6276 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6278 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6279 * @ioc: per adapter object
6280 * @event_data: event data payload
6286 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6287 Mpi2EventDataIrOperationStatus_t *event_data)
6289 char *reason_str = NULL;
6291 switch (event_data->RAIDOperation) {
6292 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6293 reason_str = "resync";
6295 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6296 reason_str = "online capacity expansion";
6298 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6299 reason_str = "consistency check";
6301 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6302 reason_str = "background init";
6304 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6305 reason_str = "make data consistent";
6312 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6313 "\thandle(0x%04x), percent complete(%d)\n",
6314 ioc->name, reason_str,
6315 le16_to_cpu(event_data->VolDevHandle),
6316 event_data->PercentComplete);
6321 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6322 * @ioc: per adapter object
6323 * @fw_event: The fw_event_work object
6329 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6330 struct fw_event_work *fw_event)
6332 Mpi2EventDataIrOperationStatus_t *event_data =
6333 (Mpi2EventDataIrOperationStatus_t *)
6334 fw_event->event_data;
6335 static struct _raid_device *raid_device;
6336 unsigned long flags;
6339 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6340 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6341 _scsih_sas_ir_operation_status_event_debug(ioc,
6345 /* code added for raid transport support */
6346 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6348 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6349 handle = le16_to_cpu(event_data->VolDevHandle);
6350 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6352 raid_device->percent_complete =
6353 event_data->PercentComplete;
6354 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6359 * _scsih_prep_device_scan - initialize parameters prior to device scan
6360 * @ioc: per adapter object
6362 * Set the deleted flag prior to device scan. If the device is found during
6363 * the scan, then we clear the deleted flag.
6366 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6368 struct MPT3SAS_DEVICE *sas_device_priv_data;
6369 struct scsi_device *sdev;
6371 shost_for_each_device(sdev, ioc->shost) {
6372 sas_device_priv_data = sdev->hostdata;
6373 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6374 sas_device_priv_data->sas_target->deleted = 1;
6379 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6380 * @ioc: per adapter object
6381 * @sas_address: sas address
6382 * @slot: enclosure slot id
6383 * @handle: device handle
6385 * After host reset, find out whether devices are still responding.
6386 * Used in _scsih_remove_unresponsive_sas_devices.
6391 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6392 u16 slot, u16 handle)
6394 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6395 struct scsi_target *starget;
6396 struct _sas_device *sas_device;
6397 unsigned long flags;
6399 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6400 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6401 if (sas_device->sas_address == sas_address &&
6402 sas_device->slot == slot) {
6403 sas_device->responding = 1;
6404 starget = sas_device->starget;
6405 if (starget && starget->hostdata) {
6406 sas_target_priv_data = starget->hostdata;
6407 sas_target_priv_data->tm_busy = 0;
6408 sas_target_priv_data->deleted = 0;
6410 sas_target_priv_data = NULL;
6412 starget_printk(KERN_INFO, starget,
6413 "handle(0x%04x), sas_addr(0x%016llx), "
6414 "enclosure logical id(0x%016llx), "
6415 "slot(%d)\n", handle,
6416 (unsigned long long)sas_device->sas_address,
6417 (unsigned long long)
6418 sas_device->enclosure_logical_id,
6420 if (sas_device->handle == handle)
6422 pr_info("\thandle changed from(0x%04x)!!!\n",
6423 sas_device->handle);
6424 sas_device->handle = handle;
6425 if (sas_target_priv_data)
6426 sas_target_priv_data->handle = handle;
6431 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6435 * _scsih_search_responding_sas_devices -
6436 * @ioc: per adapter object
6438 * After host reset, find out whether devices are still responding.
6444 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6446 Mpi2SasDevicePage0_t sas_device_pg0;
6447 Mpi2ConfigReply_t mpi_reply;
6452 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6454 if (list_empty(&ioc->sas_device_list))
6458 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6459 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6461 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6462 MPI2_IOCSTATUS_MASK;
6463 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6465 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6466 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6467 if (!(_scsih_is_end_device(device_info)))
6469 _scsih_mark_responding_sas_device(ioc,
6470 le64_to_cpu(sas_device_pg0.SASAddress),
6471 le16_to_cpu(sas_device_pg0.Slot), handle);
6475 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6480 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6481 * @ioc: per adapter object
6482 * @wwid: world wide identifier for raid volume
6483 * @handle: device handle
6485 * After host reset, find out whether devices are still responding.
6486 * Used in _scsih_remove_unresponsive_raid_devices.
6491 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6494 struct MPT3SAS_TARGET *sas_target_priv_data;
6495 struct scsi_target *starget;
6496 struct _raid_device *raid_device;
6497 unsigned long flags;
6499 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6500 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6501 if (raid_device->wwid == wwid && raid_device->starget) {
6502 starget = raid_device->starget;
6503 if (starget && starget->hostdata) {
6504 sas_target_priv_data = starget->hostdata;
6505 sas_target_priv_data->deleted = 0;
6507 sas_target_priv_data = NULL;
6508 raid_device->responding = 1;
6509 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6510 starget_printk(KERN_INFO, raid_device->starget,
6511 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6512 (unsigned long long)raid_device->wwid);
6513 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6514 if (raid_device->handle == handle) {
6515 spin_unlock_irqrestore(&ioc->raid_device_lock,
6519 pr_info("\thandle changed from(0x%04x)!!!\n",
6520 raid_device->handle);
6521 raid_device->handle = handle;
6522 if (sas_target_priv_data)
6523 sas_target_priv_data->handle = handle;
6524 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6528 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6532 * _scsih_search_responding_raid_devices -
6533 * @ioc: per adapter object
6535 * After host reset, find out whether devices are still responding.
6541 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6543 Mpi2RaidVolPage1_t volume_pg1;
6544 Mpi2RaidVolPage0_t volume_pg0;
6545 Mpi2RaidPhysDiskPage0_t pd_pg0;
6546 Mpi2ConfigReply_t mpi_reply;
6551 if (!ioc->ir_firmware)
6554 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6557 if (list_empty(&ioc->raid_device_list))
6561 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6562 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6563 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6564 MPI2_IOCSTATUS_MASK;
6565 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6567 handle = le16_to_cpu(volume_pg1.DevHandle);
6569 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6570 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6571 sizeof(Mpi2RaidVolPage0_t)))
6574 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6575 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6576 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6577 _scsih_mark_responding_raid_device(ioc,
6578 le64_to_cpu(volume_pg1.WWID), handle);
6581 /* refresh the pd_handles */
6582 phys_disk_num = 0xFF;
6583 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6584 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6585 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6587 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6588 MPI2_IOCSTATUS_MASK;
6589 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6591 phys_disk_num = pd_pg0.PhysDiskNum;
6592 handle = le16_to_cpu(pd_pg0.DevHandle);
6593 set_bit(handle, ioc->pd_handles);
6596 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6601 * _scsih_mark_responding_expander - mark a expander as responding
6602 * @ioc: per adapter object
6603 * @sas_address: sas address
6606 * After host reset, find out whether devices are still responding.
6607 * Used in _scsih_remove_unresponsive_expanders.
6612 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6615 struct _sas_node *sas_expander;
6616 unsigned long flags;
6619 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6620 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6621 if (sas_expander->sas_address != sas_address)
6623 sas_expander->responding = 1;
6624 if (sas_expander->handle == handle)
6626 pr_info("\texpander(0x%016llx): handle changed" \
6627 " from(0x%04x) to (0x%04x)!!!\n",
6628 (unsigned long long)sas_expander->sas_address,
6629 sas_expander->handle, handle);
6630 sas_expander->handle = handle;
6631 for (i = 0 ; i < sas_expander->num_phys ; i++)
6632 sas_expander->phy[i].handle = handle;
6636 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6640 * _scsih_search_responding_expanders -
6641 * @ioc: per adapter object
6643 * After host reset, find out whether devices are still responding.
6649 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6651 Mpi2ExpanderPage0_t expander_pg0;
6652 Mpi2ConfigReply_t mpi_reply;
6657 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6659 if (list_empty(&ioc->sas_expander_list))
6663 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6664 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6666 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6667 MPI2_IOCSTATUS_MASK;
6668 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6671 handle = le16_to_cpu(expander_pg0.DevHandle);
6672 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6673 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6675 (unsigned long long)sas_address);
6676 _scsih_mark_responding_expander(ioc, sas_address, handle);
6680 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6684 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6685 * @ioc: per adapter object
6690 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6692 struct _sas_device *sas_device, *sas_device_next;
6693 struct _sas_node *sas_expander, *sas_expander_next;
6694 struct _raid_device *raid_device, *raid_device_next;
6695 struct list_head tmp_list;
6696 unsigned long flags;
6698 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6701 /* removing unresponding end devices */
6702 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6704 list_for_each_entry_safe(sas_device, sas_device_next,
6705 &ioc->sas_device_list, list) {
6706 if (!sas_device->responding)
6707 mpt3sas_device_remove_by_sas_address(ioc,
6708 sas_device->sas_address);
6710 sas_device->responding = 0;
6713 /* removing unresponding volumes */
6714 if (ioc->ir_firmware) {
6715 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6717 list_for_each_entry_safe(raid_device, raid_device_next,
6718 &ioc->raid_device_list, list) {
6719 if (!raid_device->responding)
6720 _scsih_sas_volume_delete(ioc,
6721 raid_device->handle);
6723 raid_device->responding = 0;
6727 /* removing unresponding expanders */
6728 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6730 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6731 INIT_LIST_HEAD(&tmp_list);
6732 list_for_each_entry_safe(sas_expander, sas_expander_next,
6733 &ioc->sas_expander_list, list) {
6734 if (!sas_expander->responding)
6735 list_move_tail(&sas_expander->list, &tmp_list);
6737 sas_expander->responding = 0;
6739 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6740 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6742 list_del(&sas_expander->list);
6743 _scsih_expander_node_remove(ioc, sas_expander);
6746 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6749 /* unblock devices */
6750 _scsih_ublock_io_all_device(ioc);
6754 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6755 struct _sas_node *sas_expander, u16 handle)
6757 Mpi2ExpanderPage1_t expander_pg1;
6758 Mpi2ConfigReply_t mpi_reply;
6761 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6762 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6763 &expander_pg1, i, handle))) {
6764 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6765 ioc->name, __FILE__, __LINE__, __func__);
6769 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6770 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6771 expander_pg1.NegotiatedLinkRate >> 4);
6776 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6777 * @ioc: per adapter object
6782 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6784 Mpi2ExpanderPage0_t expander_pg0;
6785 Mpi2SasDevicePage0_t sas_device_pg0;
6786 Mpi2RaidVolPage1_t volume_pg1;
6787 Mpi2RaidVolPage0_t volume_pg0;
6788 Mpi2RaidPhysDiskPage0_t pd_pg0;
6789 Mpi2EventIrConfigElement_t element;
6790 Mpi2ConfigReply_t mpi_reply;
6793 u16 handle, parent_handle;
6795 struct _sas_device *sas_device;
6796 struct _sas_node *expander_device;
6797 static struct _raid_device *raid_device;
6799 unsigned long flags;
6801 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6803 _scsih_sas_host_refresh(ioc);
6805 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6809 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6810 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6811 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6812 MPI2_IOCSTATUS_MASK;
6813 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6814 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6815 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6816 ioc->name, ioc_status,
6817 le32_to_cpu(mpi_reply.IOCLogInfo));
6820 handle = le16_to_cpu(expander_pg0.DevHandle);
6821 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6822 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6823 ioc, le64_to_cpu(expander_pg0.SASAddress));
6824 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6825 if (expander_device)
6826 _scsih_refresh_expander_links(ioc, expander_device,
6829 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6830 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6831 handle, (unsigned long long)
6832 le64_to_cpu(expander_pg0.SASAddress));
6833 _scsih_expander_add(ioc, handle);
6834 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6835 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6836 handle, (unsigned long long)
6837 le64_to_cpu(expander_pg0.SASAddress));
6841 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6844 if (!ioc->ir_firmware)
6847 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6850 phys_disk_num = 0xFF;
6851 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6852 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6854 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6855 MPI2_IOCSTATUS_MASK;
6856 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6857 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
6858 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6859 ioc->name, ioc_status,
6860 le32_to_cpu(mpi_reply.IOCLogInfo));
6863 phys_disk_num = pd_pg0.PhysDiskNum;
6864 handle = le16_to_cpu(pd_pg0.DevHandle);
6865 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6866 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6867 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6870 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6871 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6874 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6875 MPI2_IOCSTATUS_MASK;
6876 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6877 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
6878 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6879 ioc->name, ioc_status,
6880 le32_to_cpu(mpi_reply.IOCLogInfo));
6883 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6884 if (!_scsih_get_sas_address(ioc, parent_handle,
6886 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
6887 " handle (0x%04x), sas_addr(0x%016llx)\n",
6888 ioc->name, handle, (unsigned long long)
6889 le64_to_cpu(sas_device_pg0.SASAddress));
6890 mpt3sas_transport_update_links(ioc, sas_address,
6891 handle, sas_device_pg0.PhyNum,
6892 MPI2_SAS_NEG_LINK_RATE_1_5);
6893 set_bit(handle, ioc->pd_handles);
6895 /* This will retry adding the end device.
6896 * _scsih_add_device() will decide on retries and
6897 * return "1" when it should be retried
6899 while (_scsih_add_device(ioc, handle, retry_count++,
6903 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
6904 " handle (0x%04x), sas_addr(0x%016llx)\n",
6905 ioc->name, handle, (unsigned long long)
6906 le64_to_cpu(sas_device_pg0.SASAddress));
6910 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
6913 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
6917 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6918 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6919 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6920 MPI2_IOCSTATUS_MASK;
6921 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6922 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6923 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6924 ioc->name, ioc_status,
6925 le32_to_cpu(mpi_reply.IOCLogInfo));
6928 handle = le16_to_cpu(volume_pg1.DevHandle);
6929 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6930 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6931 le64_to_cpu(volume_pg1.WWID));
6932 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6935 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6936 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6937 sizeof(Mpi2RaidVolPage0_t)))
6939 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6940 MPI2_IOCSTATUS_MASK;
6941 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6942 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6943 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6944 ioc->name, ioc_status,
6945 le32_to_cpu(mpi_reply.IOCLogInfo));
6948 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6949 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6950 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6951 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6952 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6953 element.VolDevHandle = volume_pg1.DevHandle;
6955 "\tBEFORE adding volume: handle (0x%04x)\n",
6956 ioc->name, volume_pg1.DevHandle);
6957 _scsih_sas_volume_add(ioc, &element);
6959 "\tAFTER adding volume: handle (0x%04x)\n",
6960 ioc->name, volume_pg1.DevHandle);
6964 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
6969 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
6974 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6975 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6977 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6978 MPI2_IOCSTATUS_MASK;
6979 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6980 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
6981 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6982 ioc->name, ioc_status,
6983 le32_to_cpu(mpi_reply.IOCLogInfo));
6986 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6987 if (!(_scsih_is_end_device(
6988 le32_to_cpu(sas_device_pg0.DeviceInfo))))
6990 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6991 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
6992 le64_to_cpu(sas_device_pg0.SASAddress));
6993 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6996 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6997 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
6998 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
6999 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7000 handle, (unsigned long long)
7001 le64_to_cpu(sas_device_pg0.SASAddress));
7002 mpt3sas_transport_update_links(ioc, sas_address, handle,
7003 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7005 /* This will retry adding the end device.
7006 * _scsih_add_device() will decide on retries and
7007 * return "1" when it should be retried
7009 while (_scsih_add_device(ioc, handle, retry_count++,
7013 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7014 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7015 handle, (unsigned long long)
7016 le64_to_cpu(sas_device_pg0.SASAddress));
7019 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7022 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7025 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7026 * @ioc: per adapter object
7027 * @reset_phase: phase
7029 * The handler for doing any required cleanup or initialization.
7031 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7032 * MPT3_IOC_DONE_RESET
7037 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7039 switch (reset_phase) {
7040 case MPT3_IOC_PRE_RESET:
7041 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7042 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7044 case MPT3_IOC_AFTER_RESET:
7045 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7046 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7047 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7048 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7049 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7050 complete(&ioc->scsih_cmds.done);
7052 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7053 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7054 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7055 complete(&ioc->tm_cmds.done);
7058 _scsih_fw_event_cleanup_queue(ioc);
7059 _scsih_flush_running_cmds(ioc);
7061 case MPT3_IOC_DONE_RESET:
7062 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7063 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7064 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7065 !ioc->sas_hba.num_phys)) {
7066 _scsih_prep_device_scan(ioc);
7067 _scsih_search_responding_sas_devices(ioc);
7068 _scsih_search_responding_raid_devices(ioc);
7069 _scsih_search_responding_expanders(ioc);
7070 _scsih_error_recovery_delete_devices(ioc);
7077 * _mpt3sas_fw_work - delayed task for processing firmware events
7078 * @ioc: per adapter object
7079 * @fw_event: The fw_event_work object
7085 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7087 /* the queue is being flushed so ignore this event */
7088 if (ioc->remove_host ||
7089 ioc->pci_error_recovery) {
7090 _scsih_fw_event_free(ioc, fw_event);
7094 switch (fw_event->event) {
7095 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7096 mpt3sas_process_trigger_data(ioc,
7097 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7098 fw_event->event_data);
7100 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7101 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7103 _scsih_remove_unresponding_sas_devices(ioc);
7104 _scsih_scan_for_devices_after_reset(ioc);
7106 case MPT3SAS_PORT_ENABLE_COMPLETE:
7107 ioc->start_scan = 0;
7108 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7109 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7111 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7112 "port enable: complete from worker thread\n",
7115 case MPT3SAS_TURN_ON_PFA_LED:
7116 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7118 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7119 _scsih_sas_topology_change_event(ioc, fw_event);
7121 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7122 _scsih_sas_device_status_change_event(ioc, fw_event);
7124 case MPI2_EVENT_SAS_DISCOVERY:
7125 _scsih_sas_discovery_event(ioc, fw_event);
7127 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7128 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7130 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7131 _scsih_sas_enclosure_dev_status_change_event(ioc,
7134 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7135 _scsih_sas_ir_config_change_event(ioc, fw_event);
7137 case MPI2_EVENT_IR_VOLUME:
7138 _scsih_sas_ir_volume_event(ioc, fw_event);
7140 case MPI2_EVENT_IR_PHYSICAL_DISK:
7141 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7143 case MPI2_EVENT_IR_OPERATION_STATUS:
7144 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7147 _scsih_fw_event_free(ioc, fw_event);
7151 * _firmware_event_work
7152 * @ioc: per adapter object
7153 * @work: The fw_event_work object
7156 * wrappers for the work thread handling firmware events
7162 _firmware_event_work(struct work_struct *work)
7164 struct fw_event_work *fw_event = container_of(work,
7165 struct fw_event_work, work);
7167 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7171 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7172 * @ioc: per adapter object
7173 * @msix_index: MSIX table index supplied by the OS
7174 * @reply: reply message frame(lower 32bit addr)
7175 * Context: interrupt.
7177 * This function merely adds a new work task into ioc->firmware_event_thread.
7178 * The tasks are worked from _firmware_event_work in user context.
7180 * Return 1 meaning mf should be freed from _base_interrupt
7181 * 0 means the mf is freed from this function.
7184 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7187 struct fw_event_work *fw_event;
7188 Mpi2EventNotificationReply_t *mpi_reply;
7192 /* events turned off due to host reset or driver unloading */
7193 if (ioc->remove_host || ioc->pci_error_recovery)
7196 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7198 if (unlikely(!mpi_reply)) {
7199 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7200 ioc->name, __FILE__, __LINE__, __func__);
7204 event = le16_to_cpu(mpi_reply->Event);
7206 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7207 mpt3sas_trigger_event(ioc, event, 0);
7211 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7213 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7214 (Mpi2EventDataSasBroadcastPrimitive_t *)
7215 mpi_reply->EventData;
7217 if (baen_data->Primitive !=
7218 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7221 if (ioc->broadcast_aen_busy) {
7222 ioc->broadcast_aen_pending++;
7225 ioc->broadcast_aen_busy = 1;
7229 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7230 _scsih_check_topo_delete_events(ioc,
7231 (Mpi2EventDataSasTopologyChangeList_t *)
7232 mpi_reply->EventData);
7234 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7235 _scsih_check_ir_config_unhide_events(ioc,
7236 (Mpi2EventDataIrConfigChangeList_t *)
7237 mpi_reply->EventData);
7239 case MPI2_EVENT_IR_VOLUME:
7240 _scsih_check_volume_delete_events(ioc,
7241 (Mpi2EventDataIrVolume_t *)
7242 mpi_reply->EventData);
7245 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7246 case MPI2_EVENT_IR_OPERATION_STATUS:
7247 case MPI2_EVENT_SAS_DISCOVERY:
7248 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7249 case MPI2_EVENT_IR_PHYSICAL_DISK:
7252 default: /* ignore the rest */
7256 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7257 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7259 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7260 ioc->name, __FILE__, __LINE__, __func__);
7264 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7265 fw_event->ioc = ioc;
7266 fw_event->VF_ID = mpi_reply->VF_ID;
7267 fw_event->VP_ID = mpi_reply->VP_ID;
7268 fw_event->event = event;
7269 _scsih_fw_event_add(ioc, fw_event);
7273 /* shost template */
7274 static struct scsi_host_template scsih_driver_template = {
7275 .module = THIS_MODULE,
7276 .name = "Fusion MPT SAS Host",
7277 .proc_name = MPT3SAS_DRIVER_NAME,
7278 .queuecommand = _scsih_qcmd,
7279 .target_alloc = _scsih_target_alloc,
7280 .slave_alloc = _scsih_slave_alloc,
7281 .slave_configure = _scsih_slave_configure,
7282 .target_destroy = _scsih_target_destroy,
7283 .slave_destroy = _scsih_slave_destroy,
7284 .scan_finished = _scsih_scan_finished,
7285 .scan_start = _scsih_scan_start,
7286 .change_queue_depth = _scsih_change_queue_depth,
7287 .change_queue_type = _scsih_change_queue_type,
7288 .eh_abort_handler = _scsih_abort,
7289 .eh_device_reset_handler = _scsih_dev_reset,
7290 .eh_target_reset_handler = _scsih_target_reset,
7291 .eh_host_reset_handler = _scsih_host_reset,
7292 .bios_param = _scsih_bios_param,
7295 .sg_tablesize = MPT3SAS_SG_DEPTH,
7296 .max_sectors = 32767,
7298 .use_clustering = ENABLE_CLUSTERING,
7299 .shost_attrs = mpt3sas_host_attrs,
7300 .sdev_attrs = mpt3sas_dev_attrs,
7304 * _scsih_expander_node_remove - removing expander device from list.
7305 * @ioc: per adapter object
7306 * @sas_expander: the sas_device object
7307 * Context: Calling function should acquire ioc->sas_node_lock.
7309 * Removing object and freeing associated memory from the
7310 * ioc->sas_expander_list.
7315 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7316 struct _sas_node *sas_expander)
7318 struct _sas_port *mpt3sas_port, *next;
7320 /* remove sibling ports attached to this expander */
7321 list_for_each_entry_safe(mpt3sas_port, next,
7322 &sas_expander->sas_port_list, port_list) {
7323 if (ioc->shost_recovery)
7325 if (mpt3sas_port->remote_identify.device_type ==
7327 mpt3sas_device_remove_by_sas_address(ioc,
7328 mpt3sas_port->remote_identify.sas_address);
7329 else if (mpt3sas_port->remote_identify.device_type ==
7330 SAS_EDGE_EXPANDER_DEVICE ||
7331 mpt3sas_port->remote_identify.device_type ==
7332 SAS_FANOUT_EXPANDER_DEVICE)
7333 mpt3sas_expander_remove(ioc,
7334 mpt3sas_port->remote_identify.sas_address);
7337 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7338 sas_expander->sas_address_parent);
7341 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7343 sas_expander->handle, (unsigned long long)
7344 sas_expander->sas_address);
7346 kfree(sas_expander->phy);
7347 kfree(sas_expander);
7351 * _scsih_ir_shutdown - IR shutdown notification
7352 * @ioc: per adapter object
7354 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7355 * the host system is shutting down.
7360 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7362 Mpi2RaidActionRequest_t *mpi_request;
7363 Mpi2RaidActionReply_t *mpi_reply;
7366 /* is IR firmware build loaded ? */
7367 if (!ioc->ir_firmware)
7370 /* are there any volumes ? */
7371 if (list_empty(&ioc->raid_device_list))
7374 mutex_lock(&ioc->scsih_cmds.mutex);
7376 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7377 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7378 ioc->name, __func__);
7381 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7383 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7385 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7386 ioc->name, __func__);
7387 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7391 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7392 ioc->scsih_cmds.smid = smid;
7393 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7395 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7396 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7398 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7399 init_completion(&ioc->scsih_cmds.done);
7400 mpt3sas_base_put_smid_default(ioc, smid);
7401 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7403 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7404 pr_err(MPT3SAS_FMT "%s: timeout\n",
7405 ioc->name, __func__);
7409 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7410 mpi_reply = ioc->scsih_cmds.reply;
7412 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7413 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7414 le32_to_cpu(mpi_reply->IOCLogInfo));
7418 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7419 mutex_unlock(&ioc->scsih_cmds.mutex);
7423 * _scsih_remove - detach and remove add host
7424 * @pdev: PCI device struct
7426 * Routine called when unloading the driver.
7429 static void _scsih_remove(struct pci_dev *pdev)
7431 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7432 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7433 struct _sas_port *mpt3sas_port, *next_port;
7434 struct _raid_device *raid_device, *next;
7435 struct MPT3SAS_TARGET *sas_target_priv_data;
7436 struct workqueue_struct *wq;
7437 unsigned long flags;
7439 ioc->remove_host = 1;
7440 _scsih_fw_event_cleanup_queue(ioc);
7442 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7443 wq = ioc->firmware_event_thread;
7444 ioc->firmware_event_thread = NULL;
7445 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7447 destroy_workqueue(wq);
7449 /* release all the volumes */
7450 _scsih_ir_shutdown(ioc);
7451 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7453 if (raid_device->starget) {
7454 sas_target_priv_data =
7455 raid_device->starget->hostdata;
7456 sas_target_priv_data->deleted = 1;
7457 scsi_remove_target(&raid_device->starget->dev);
7459 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7460 ioc->name, raid_device->handle,
7461 (unsigned long long) raid_device->wwid);
7462 _scsih_raid_device_remove(ioc, raid_device);
7465 /* free ports attached to the sas_host */
7466 list_for_each_entry_safe(mpt3sas_port, next_port,
7467 &ioc->sas_hba.sas_port_list, port_list) {
7468 if (mpt3sas_port->remote_identify.device_type ==
7470 mpt3sas_device_remove_by_sas_address(ioc,
7471 mpt3sas_port->remote_identify.sas_address);
7472 else if (mpt3sas_port->remote_identify.device_type ==
7473 SAS_EDGE_EXPANDER_DEVICE ||
7474 mpt3sas_port->remote_identify.device_type ==
7475 SAS_FANOUT_EXPANDER_DEVICE)
7476 mpt3sas_expander_remove(ioc,
7477 mpt3sas_port->remote_identify.sas_address);
7480 /* free phys attached to the sas_host */
7481 if (ioc->sas_hba.num_phys) {
7482 kfree(ioc->sas_hba.phy);
7483 ioc->sas_hba.phy = NULL;
7484 ioc->sas_hba.num_phys = 0;
7487 sas_remove_host(shost);
7488 scsi_remove_host(shost);
7489 mpt3sas_base_detach(ioc);
7490 list_del(&ioc->list);
7491 scsi_host_put(shost);
7495 * _scsih_shutdown - routine call during system shutdown
7496 * @pdev: PCI device struct
7501 _scsih_shutdown(struct pci_dev *pdev)
7503 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7504 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7505 struct workqueue_struct *wq;
7506 unsigned long flags;
7508 ioc->remove_host = 1;
7509 _scsih_fw_event_cleanup_queue(ioc);
7511 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7512 wq = ioc->firmware_event_thread;
7513 ioc->firmware_event_thread = NULL;
7514 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7516 destroy_workqueue(wq);
7518 _scsih_ir_shutdown(ioc);
7519 mpt3sas_base_detach(ioc);
7524 * _scsih_probe_boot_devices - reports 1st device
7525 * @ioc: per adapter object
7527 * If specified in bios page 2, this routine reports the 1st
7528 * device scsi-ml or sas transport for persistent boot device
7529 * purposes. Please refer to function _scsih_determine_boot_device()
7532 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7536 struct _sas_device *sas_device;
7537 struct _raid_device *raid_device;
7539 u64 sas_address_parent;
7541 unsigned long flags;
7544 /* no Bios, return immediately */
7545 if (!ioc->bios_pg3.BiosVersion)
7550 if (ioc->req_boot_device.device) {
7551 device = ioc->req_boot_device.device;
7552 is_raid = ioc->req_boot_device.is_raid;
7553 } else if (ioc->req_alt_boot_device.device) {
7554 device = ioc->req_alt_boot_device.device;
7555 is_raid = ioc->req_alt_boot_device.is_raid;
7556 } else if (ioc->current_boot_device.device) {
7557 device = ioc->current_boot_device.device;
7558 is_raid = ioc->current_boot_device.is_raid;
7565 raid_device = device;
7566 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7567 raid_device->id, 0);
7569 _scsih_raid_device_remove(ioc, raid_device);
7571 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7572 sas_device = device;
7573 handle = sas_device->handle;
7574 sas_address_parent = sas_device->sas_address_parent;
7575 sas_address = sas_device->sas_address;
7576 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7577 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7579 if (!mpt3sas_transport_port_add(ioc, handle,
7580 sas_address_parent)) {
7581 _scsih_sas_device_remove(ioc, sas_device);
7582 } else if (!sas_device->starget) {
7583 if (!ioc->is_driver_loading) {
7584 mpt3sas_transport_port_remove(ioc,
7586 sas_address_parent);
7587 _scsih_sas_device_remove(ioc, sas_device);
7594 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7595 * @ioc: per adapter object
7597 * Called during initial loading of the driver.
7600 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7602 struct _raid_device *raid_device, *raid_next;
7605 list_for_each_entry_safe(raid_device, raid_next,
7606 &ioc->raid_device_list, list) {
7607 if (raid_device->starget)
7609 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7610 raid_device->id, 0);
7612 _scsih_raid_device_remove(ioc, raid_device);
7617 * _scsih_probe_sas - reporting sas devices to sas transport
7618 * @ioc: per adapter object
7620 * Called during initial loading of the driver.
7623 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7625 struct _sas_device *sas_device, *next;
7626 unsigned long flags;
7628 /* SAS Device List */
7629 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7632 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7633 sas_device->sas_address_parent)) {
7634 list_del(&sas_device->list);
7637 } else if (!sas_device->starget) {
7639 * When asyn scanning is enabled, its not possible to
7640 * remove devices while scanning is turned on due to an
7641 * oops in scsi_sysfs_add_sdev()->add_device()->
7642 * sysfs_addrm_start()
7644 if (!ioc->is_driver_loading) {
7645 mpt3sas_transport_port_remove(ioc,
7646 sas_device->sas_address,
7647 sas_device->sas_address_parent);
7648 list_del(&sas_device->list);
7654 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7655 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7656 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7661 * _scsih_probe_devices - probing for devices
7662 * @ioc: per adapter object
7664 * Called during initial loading of the driver.
7667 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7669 u16 volume_mapping_flags;
7671 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7672 return; /* return when IOC doesn't support initiator mode */
7674 _scsih_probe_boot_devices(ioc);
7676 if (ioc->ir_firmware) {
7677 volume_mapping_flags =
7678 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7679 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7680 if (volume_mapping_flags ==
7681 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7682 _scsih_probe_raid(ioc);
7683 _scsih_probe_sas(ioc);
7685 _scsih_probe_sas(ioc);
7686 _scsih_probe_raid(ioc);
7689 _scsih_probe_sas(ioc);
7693 * _scsih_scan_start - scsi lld callback for .scan_start
7694 * @shost: SCSI host pointer
7696 * The shost has the ability to discover targets on its own instead
7697 * of scanning the entire bus. In our implemention, we will kick off
7698 * firmware discovery.
7701 _scsih_scan_start(struct Scsi_Host *shost)
7703 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7705 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7706 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7708 if (disable_discovery > 0)
7711 ioc->start_scan = 1;
7712 rc = mpt3sas_port_enable(ioc);
7715 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7719 * _scsih_scan_finished - scsi lld callback for .scan_finished
7720 * @shost: SCSI host pointer
7721 * @time: elapsed time of the scan in jiffies
7723 * This function will be called periodicallyn until it returns 1 with the
7724 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7725 * we wait for firmware discovery to complete, then return 1.
7728 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7730 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7732 if (disable_discovery > 0) {
7733 ioc->is_driver_loading = 0;
7734 ioc->wait_for_discovery_to_complete = 0;
7738 if (time >= (300 * HZ)) {
7739 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7741 "port enable: FAILED with timeout (timeout=300s)\n",
7743 ioc->is_driver_loading = 0;
7747 if (ioc->start_scan)
7750 if (ioc->start_scan_failed) {
7752 "port enable: FAILED with (ioc_status=0x%08x)\n",
7753 ioc->name, ioc->start_scan_failed);
7754 ioc->is_driver_loading = 0;
7755 ioc->wait_for_discovery_to_complete = 0;
7756 ioc->remove_host = 1;
7760 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7761 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7763 if (ioc->wait_for_discovery_to_complete) {
7764 ioc->wait_for_discovery_to_complete = 0;
7765 _scsih_probe_devices(ioc);
7767 mpt3sas_base_start_watchdog(ioc);
7768 ioc->is_driver_loading = 0;
7773 * _scsih_probe - attach and add scsi host
7774 * @pdev: PCI device struct
7775 * @id: pci device id
7777 * Returns 0 success, anything else error.
7780 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7782 struct MPT3SAS_ADAPTER *ioc;
7783 struct Scsi_Host *shost;
7786 shost = scsi_host_alloc(&scsih_driver_template,
7787 sizeof(struct MPT3SAS_ADAPTER));
7791 /* init local params */
7792 ioc = shost_priv(shost);
7793 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7794 INIT_LIST_HEAD(&ioc->list);
7795 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7797 ioc->id = mpt_ids++;
7798 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
7800 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7801 ioc->tm_cb_idx = tm_cb_idx;
7802 ioc->ctl_cb_idx = ctl_cb_idx;
7803 ioc->base_cb_idx = base_cb_idx;
7804 ioc->port_enable_cb_idx = port_enable_cb_idx;
7805 ioc->transport_cb_idx = transport_cb_idx;
7806 ioc->scsih_cb_idx = scsih_cb_idx;
7807 ioc->config_cb_idx = config_cb_idx;
7808 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7809 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7810 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7811 ioc->logging_level = logging_level;
7812 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7813 /* misc semaphores and spin locks */
7814 mutex_init(&ioc->reset_in_progress_mutex);
7815 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7816 spin_lock_init(&ioc->scsi_lookup_lock);
7817 spin_lock_init(&ioc->sas_device_lock);
7818 spin_lock_init(&ioc->sas_node_lock);
7819 spin_lock_init(&ioc->fw_event_lock);
7820 spin_lock_init(&ioc->raid_device_lock);
7821 spin_lock_init(&ioc->diag_trigger_lock);
7823 INIT_LIST_HEAD(&ioc->sas_device_list);
7824 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7825 INIT_LIST_HEAD(&ioc->sas_expander_list);
7826 INIT_LIST_HEAD(&ioc->fw_event_list);
7827 INIT_LIST_HEAD(&ioc->raid_device_list);
7828 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7829 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7830 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7831 INIT_LIST_HEAD(&ioc->reply_queue_list);
7833 /* init shost parameters */
7834 shost->max_cmd_len = 32;
7835 shost->max_lun = max_lun;
7836 shost->transportt = mpt3sas_transport_template;
7837 shost->unique_id = ioc->id;
7839 if (max_sectors != 0xFFFF) {
7840 if (max_sectors < 64) {
7841 shost->max_sectors = 64;
7842 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7843 "for max_sectors, range is 64 to 32767. Assigning "
7844 "value of 64.\n", ioc->name, max_sectors);
7845 } else if (max_sectors > 32767) {
7846 shost->max_sectors = 32767;
7847 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7848 "for max_sectors, range is 64 to 32767. Assigning "
7849 "default value of 32767.\n", ioc->name,
7852 shost->max_sectors = max_sectors & 0xFFFE;
7854 "The max_sectors value is set to %d\n",
7855 ioc->name, shost->max_sectors);
7859 /* register EEDP capabilities with SCSI layer */
7861 scsi_host_set_prot(shost, prot_mask);
7863 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7864 | SHOST_DIF_TYPE2_PROTECTION
7865 | SHOST_DIF_TYPE3_PROTECTION);
7867 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7870 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7871 "fw_event%d", ioc->id);
7872 ioc->firmware_event_thread = create_singlethread_workqueue(
7873 ioc->firmware_event_name);
7874 if (!ioc->firmware_event_thread) {
7875 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7876 ioc->name, __FILE__, __LINE__, __func__);
7878 goto out_thread_fail;
7881 ioc->is_driver_loading = 1;
7882 if ((mpt3sas_base_attach(ioc))) {
7883 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7884 ioc->name, __FILE__, __LINE__, __func__);
7886 goto out_attach_fail;
7888 rv = scsi_add_host(shost, &pdev->dev);
7890 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7891 ioc->name, __FILE__, __LINE__, __func__);
7892 goto out_add_shost_fail;
7895 scsi_scan_host(shost);
7898 mpt3sas_base_detach(ioc);
7900 destroy_workqueue(ioc->firmware_event_thread);
7902 list_del(&ioc->list);
7903 scsi_host_put(shost);
7909 * _scsih_suspend - power management suspend main entry point
7910 * @pdev: PCI device struct
7911 * @state: PM state change to (usually PCI_D3)
7913 * Returns 0 success, anything else error.
7916 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7918 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7919 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7920 pci_power_t device_state;
7922 mpt3sas_base_stop_watchdog(ioc);
7923 flush_scheduled_work();
7924 scsi_block_requests(shost);
7925 device_state = pci_choose_state(pdev, state);
7927 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7928 ioc->name, pdev, pci_name(pdev), device_state);
7930 pci_save_state(pdev);
7931 mpt3sas_base_free_resources(ioc);
7932 pci_set_power_state(pdev, device_state);
7937 * _scsih_resume - power management resume main entry point
7938 * @pdev: PCI device struct
7940 * Returns 0 success, anything else error.
7943 _scsih_resume(struct pci_dev *pdev)
7945 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7946 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7947 pci_power_t device_state = pdev->current_state;
7951 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7952 ioc->name, pdev, pci_name(pdev), device_state);
7954 pci_set_power_state(pdev, PCI_D0);
7955 pci_enable_wake(pdev, PCI_D0, 0);
7956 pci_restore_state(pdev);
7958 r = mpt3sas_base_map_resources(ioc);
7962 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7963 scsi_unblock_requests(shost);
7964 mpt3sas_base_start_watchdog(ioc);
7967 #endif /* CONFIG_PM */
7970 * _scsih_pci_error_detected - Called when a PCI error is detected.
7971 * @pdev: PCI device struct
7972 * @state: PCI channel state
7974 * Description: Called when a PCI error is detected.
7977 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7979 static pci_ers_result_t
7980 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7982 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7983 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7985 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
7989 case pci_channel_io_normal:
7990 return PCI_ERS_RESULT_CAN_RECOVER;
7991 case pci_channel_io_frozen:
7992 /* Fatal error, prepare for slot reset */
7993 ioc->pci_error_recovery = 1;
7994 scsi_block_requests(ioc->shost);
7995 mpt3sas_base_stop_watchdog(ioc);
7996 mpt3sas_base_free_resources(ioc);
7997 return PCI_ERS_RESULT_NEED_RESET;
7998 case pci_channel_io_perm_failure:
7999 /* Permanent error, prepare for device removal */
8000 ioc->pci_error_recovery = 1;
8001 mpt3sas_base_stop_watchdog(ioc);
8002 _scsih_flush_running_cmds(ioc);
8003 return PCI_ERS_RESULT_DISCONNECT;
8005 return PCI_ERS_RESULT_NEED_RESET;
8009 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8010 * @pdev: PCI device struct
8012 * Description: This routine is called by the pci error recovery
8013 * code after the PCI slot has been reset, just before we
8014 * should resume normal operations.
8016 static pci_ers_result_t
8017 _scsih_pci_slot_reset(struct pci_dev *pdev)
8019 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8020 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8023 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8026 ioc->pci_error_recovery = 0;
8028 pci_restore_state(pdev);
8029 rc = mpt3sas_base_map_resources(ioc);
8031 return PCI_ERS_RESULT_DISCONNECT;
8033 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8036 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8037 (rc == 0) ? "success" : "failed");
8040 return PCI_ERS_RESULT_RECOVERED;
8042 return PCI_ERS_RESULT_DISCONNECT;
8046 * _scsih_pci_resume() - resume normal ops after PCI reset
8047 * @pdev: pointer to PCI device
8049 * Called when the error recovery driver tells us that its
8050 * OK to resume normal operation. Use completion to allow
8051 * halted scsi ops to resume.
8054 _scsih_pci_resume(struct pci_dev *pdev)
8056 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8057 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8059 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8061 pci_cleanup_aer_uncorrect_error_status(pdev);
8062 mpt3sas_base_start_watchdog(ioc);
8063 scsi_unblock_requests(ioc->shost);
8067 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8068 * @pdev: pointer to PCI device
8070 static pci_ers_result_t
8071 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8073 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8074 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8076 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8079 /* TODO - dump whatever for debugging purposes */
8081 /* Request a slot reset. */
8082 return PCI_ERS_RESULT_NEED_RESET;
8085 /* raid transport support */
8086 static struct raid_function_template mpt3sas_raid_functions = {
8087 .cookie = &scsih_driver_template,
8088 .is_raid = _scsih_is_raid,
8089 .get_resync = _scsih_get_resync,
8090 .get_state = _scsih_get_state,
8093 static struct pci_error_handlers _scsih_err_handler = {
8094 .error_detected = _scsih_pci_error_detected,
8095 .mmio_enabled = _scsih_pci_mmio_enabled,
8096 .slot_reset = _scsih_pci_slot_reset,
8097 .resume = _scsih_pci_resume,
8100 static struct pci_driver scsih_driver = {
8101 .name = MPT3SAS_DRIVER_NAME,
8102 .id_table = scsih_pci_table,
8103 .probe = _scsih_probe,
8104 .remove = _scsih_remove,
8105 .shutdown = _scsih_shutdown,
8106 .err_handler = &_scsih_err_handler,
8108 .suspend = _scsih_suspend,
8109 .resume = _scsih_resume,
8115 * _scsih_init - main entry point for this driver.
8117 * Returns 0 success, anything else error.
8126 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8127 MPT3SAS_DRIVER_VERSION);
8129 mpt3sas_transport_template =
8130 sas_attach_transport(&mpt3sas_transport_functions);
8131 if (!mpt3sas_transport_template)
8134 /* raid transport support */
8135 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8136 if (!mpt3sas_raid_template) {
8137 sas_release_transport(mpt3sas_transport_template);
8141 mpt3sas_base_initialize_callback_handler();
8143 /* queuecommand callback hander */
8144 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8146 /* task managment callback handler */
8147 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8149 /* base internal commands callback handler */
8150 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8151 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8152 mpt3sas_port_enable_done);
8154 /* transport internal commands callback handler */
8155 transport_cb_idx = mpt3sas_base_register_callback_handler(
8156 mpt3sas_transport_done);
8158 /* scsih internal commands callback handler */
8159 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8161 /* configuration page API internal commands callback handler */
8162 config_cb_idx = mpt3sas_base_register_callback_handler(
8163 mpt3sas_config_done);
8165 /* ctl module callback handler */
8166 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8168 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8169 _scsih_tm_tr_complete);
8171 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8172 _scsih_tm_volume_tr_complete);
8174 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8175 _scsih_sas_control_complete);
8179 error = pci_register_driver(&scsih_driver);
8181 /* raid transport support */
8182 raid_class_release(mpt3sas_raid_template);
8183 sas_release_transport(mpt3sas_transport_template);
8190 * _scsih_exit - exit point for this driver (when it is a module).
8192 * Returns 0 success, anything else error.
8197 pr_info("mpt3sas version %s unloading\n",
8198 MPT3SAS_DRIVER_VERSION);
8202 pci_unregister_driver(&scsih_driver);
8205 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8206 mpt3sas_base_release_callback_handler(tm_cb_idx);
8207 mpt3sas_base_release_callback_handler(base_cb_idx);
8208 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8209 mpt3sas_base_release_callback_handler(transport_cb_idx);
8210 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8211 mpt3sas_base_release_callback_handler(config_cb_idx);
8212 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8214 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8215 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8216 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8218 /* raid transport support */
8219 raid_class_release(mpt3sas_raid_template);
8220 sas_release_transport(mpt3sas_transport_template);
8223 module_init(_scsih_init);
8224 module_exit(_scsih_exit);