2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
57 #include "mpt3sas_base.h"
59 MODULE_AUTHOR(MPT3SAS_AUTHOR);
60 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
61 MODULE_LICENSE("GPL");
62 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
64 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
67 struct _sas_node *sas_expander);
68 static void _firmware_event_work(struct work_struct *work);
70 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
71 struct _sas_device *sas_device);
72 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
73 u8 retry_count, u8 is_pd);
75 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
77 static void _scsih_scan_start(struct Scsi_Host *shost);
78 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
80 /* global parameters */
81 LIST_HEAD(mpt3sas_ioc_list);
83 /* local parameters */
84 static u8 scsi_io_cb_idx = -1;
85 static u8 tm_cb_idx = -1;
86 static u8 ctl_cb_idx = -1;
87 static u8 base_cb_idx = -1;
88 static u8 port_enable_cb_idx = -1;
89 static u8 transport_cb_idx = -1;
90 static u8 scsih_cb_idx = -1;
91 static u8 config_cb_idx = -1;
94 static u8 tm_tr_cb_idx = -1 ;
95 static u8 tm_tr_volume_cb_idx = -1 ;
96 static u8 tm_sas_control_cb_idx = -1;
98 /* command line options */
99 static u32 logging_level;
100 MODULE_PARM_DESC(logging_level,
101 " bits for enabling additional logging info (default=0)");
104 static ushort max_sectors = 0xFFFF;
105 module_param(max_sectors, ushort, 0);
106 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
109 static int missing_delay[2] = {-1, -1};
110 module_param_array(missing_delay, int, NULL, 0);
111 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
113 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
114 #define MPT3SAS_MAX_LUN (16895)
115 static u64 max_lun = MPT3SAS_MAX_LUN;
116 module_param(max_lun, ullong, 0);
117 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
122 /* diag_buffer_enable is bitwise
124 * bit 1 set = SNAPSHOT
125 * bit 2 set = EXTENDED
127 * Either bit can be set, or both
129 static int diag_buffer_enable = -1;
130 module_param(diag_buffer_enable, int, 0);
131 MODULE_PARM_DESC(diag_buffer_enable,
132 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
133 static int disable_discovery = -1;
134 module_param(disable_discovery, int, 0);
135 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
138 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
139 static int prot_mask = -1;
140 module_param(prot_mask, int, 0);
141 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
144 /* raid transport support */
146 static struct raid_template *mpt3sas_raid_template;
150 * struct sense_info - common structure for obtaining sense keys
152 * @asc: additional sense code
153 * @ascq: additional sense code qualifier
161 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
162 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
163 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
164 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
165 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
167 * struct fw_event_work - firmware event struct
168 * @list: link list framework
169 * @work: work object (ioc->fault_reset_work_q)
170 * @cancel_pending_work: flag set during reset handling
171 * @ioc: per adapter object
172 * @device_handle: device handle
173 * @VF_ID: virtual function id
174 * @VP_ID: virtual port id
175 * @ignore: flag meaning this event has been marked to ignore
176 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
177 * @event_data: reply event data payload follows
179 * This object stored on ioc->fw_event_list.
181 struct fw_event_work {
182 struct list_head list;
183 struct work_struct work;
184 u8 cancel_pending_work;
185 struct delayed_work delayed_work;
187 struct MPT3SAS_ADAPTER *ioc;
193 char event_data[0] __aligned(4);
196 /* raid transport support */
197 static struct raid_template *mpt3sas_raid_template;
200 * struct _scsi_io_transfer - scsi io transfer
201 * @handle: sas device handle (assigned by firmware)
202 * @is_raid: flag set for hidden raid components
203 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
204 * @data_length: data transfer length
205 * @data_dma: dma pointer to data
208 * @cdb_length: cdb length
210 * @timeout: timeout for this command
211 * @VF_ID: virtual function id
212 * @VP_ID: virtual port id
213 * @valid_reply: flag set for reply message
214 * @sense_length: sense length
215 * @ioc_status: ioc status
216 * @scsi_state: scsi state
217 * @scsi_status: scsi staus
218 * @log_info: log information
219 * @transfer_length: data length transfer when there is a reply message
221 * Used for sending internal scsi commands to devices within this module.
222 * Refer to _scsi_send_scsi_io().
224 struct _scsi_io_transfer {
227 enum dma_data_direction dir;
230 u8 sense[SCSI_SENSE_BUFFERSIZE];
238 /* the following bits are only valid when 'valid_reply = 1' */
248 * The pci device ids are defined in mpi/mpi2_cnfg.h.
250 static const struct pci_device_id scsih_pci_table[] = {
251 /* Fury ~ 3004 and 3008 */
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
253 PCI_ANY_ID, PCI_ANY_ID },
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
255 PCI_ANY_ID, PCI_ANY_ID },
257 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
258 PCI_ANY_ID, PCI_ANY_ID },
259 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
260 PCI_ANY_ID, PCI_ANY_ID },
261 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
262 PCI_ANY_ID, PCI_ANY_ID },
263 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
264 PCI_ANY_ID, PCI_ANY_ID },
265 {0} /* Terminating entry */
267 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
270 * _scsih_set_debug_level - global setting of ioc->logging_level.
272 * Note: The logging levels are defined in mpt3sas_debug.h.
275 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
277 int ret = param_set_int(val, kp);
278 struct MPT3SAS_ADAPTER *ioc;
283 pr_info("setting logging_level(0x%08x)\n", logging_level);
284 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
285 ioc->logging_level = logging_level;
288 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
289 &logging_level, 0644);
292 * _scsih_srch_boot_sas_address - search based on sas_address
293 * @sas_address: sas address
294 * @boot_device: boot device object from bios page 2
296 * Returns 1 when there's a match, 0 means no match.
299 _scsih_srch_boot_sas_address(u64 sas_address,
300 Mpi2BootDeviceSasWwid_t *boot_device)
302 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
306 * _scsih_srch_boot_device_name - search based on device name
307 * @device_name: device name specified in INDENTIFY fram
308 * @boot_device: boot device object from bios page 2
310 * Returns 1 when there's a match, 0 means no match.
313 _scsih_srch_boot_device_name(u64 device_name,
314 Mpi2BootDeviceDeviceName_t *boot_device)
316 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
320 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
321 * @enclosure_logical_id: enclosure logical id
322 * @slot_number: slot number
323 * @boot_device: boot device object from bios page 2
325 * Returns 1 when there's a match, 0 means no match.
328 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
329 Mpi2BootDeviceEnclosureSlot_t *boot_device)
331 return (enclosure_logical_id == le64_to_cpu(boot_device->
332 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
333 SlotNumber)) ? 1 : 0;
337 * _scsih_is_boot_device - search for matching boot device.
338 * @sas_address: sas address
339 * @device_name: device name specified in INDENTIFY fram
340 * @enclosure_logical_id: enclosure logical id
341 * @slot_number: slot number
342 * @form: specifies boot device form
343 * @boot_device: boot device object from bios page 2
345 * Returns 1 when there's a match, 0 means no match.
348 _scsih_is_boot_device(u64 sas_address, u64 device_name,
349 u64 enclosure_logical_id, u16 slot, u8 form,
350 Mpi2BiosPage2BootDevice_t *boot_device)
355 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
358 rc = _scsih_srch_boot_sas_address(
359 sas_address, &boot_device->SasWwid);
361 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
362 if (!enclosure_logical_id)
364 rc = _scsih_srch_boot_encl_slot(
365 enclosure_logical_id,
366 slot, &boot_device->EnclosureSlot);
368 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
371 rc = _scsih_srch_boot_device_name(
372 device_name, &boot_device->DeviceName);
374 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
382 * _scsih_get_sas_address - set the sas_address for given device handle
383 * @handle: device handle
384 * @sas_address: sas address
386 * Returns 0 success, non-zero when failure
389 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
392 Mpi2SasDevicePage0_t sas_device_pg0;
393 Mpi2ConfigReply_t mpi_reply;
398 if (handle <= ioc->sas_hba.num_phys) {
399 *sas_address = ioc->sas_hba.sas_address;
403 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
404 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
405 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
406 __FILE__, __LINE__, __func__);
410 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
411 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
412 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
416 /* we hit this becuase the given parent handle doesn't exist */
417 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
420 /* else error case */
422 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
423 ioc->name, handle, ioc_status,
424 __FILE__, __LINE__, __func__);
429 * _scsih_determine_boot_device - determine boot device.
430 * @ioc: per adapter object
431 * @device: either sas_device or raid_device object
432 * @is_raid: [flag] 1 = raid object, 0 = sas object
434 * Determines whether this device should be first reported device to
435 * to scsi-ml or sas transport, this purpose is for persistent boot device.
436 * There are primary, alternate, and current entries in bios page 2. The order
437 * priority is primary, alternate, then current. This routine saves
438 * the corresponding device object and is_raid flag in the ioc object.
439 * The saved data to be used later in _scsih_probe_boot_devices().
442 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
443 void *device, u8 is_raid)
445 struct _sas_device *sas_device;
446 struct _raid_device *raid_device;
449 u64 enclosure_logical_id;
452 /* only process this function when driver loads */
453 if (!ioc->is_driver_loading)
456 /* no Bios, return immediately */
457 if (!ioc->bios_pg3.BiosVersion)
462 sas_address = sas_device->sas_address;
463 device_name = sas_device->device_name;
464 enclosure_logical_id = sas_device->enclosure_logical_id;
465 slot = sas_device->slot;
467 raid_device = device;
468 sas_address = raid_device->wwid;
470 enclosure_logical_id = 0;
474 if (!ioc->req_boot_device.device) {
475 if (_scsih_is_boot_device(sas_address, device_name,
476 enclosure_logical_id, slot,
477 (ioc->bios_pg2.ReqBootDeviceForm &
478 MPI2_BIOSPAGE2_FORM_MASK),
479 &ioc->bios_pg2.RequestedBootDevice)) {
480 dinitprintk(ioc, pr_info(MPT3SAS_FMT
481 "%s: req_boot_device(0x%016llx)\n",
483 (unsigned long long)sas_address));
484 ioc->req_boot_device.device = device;
485 ioc->req_boot_device.is_raid = is_raid;
489 if (!ioc->req_alt_boot_device.device) {
490 if (_scsih_is_boot_device(sas_address, device_name,
491 enclosure_logical_id, slot,
492 (ioc->bios_pg2.ReqAltBootDeviceForm &
493 MPI2_BIOSPAGE2_FORM_MASK),
494 &ioc->bios_pg2.RequestedAltBootDevice)) {
495 dinitprintk(ioc, pr_info(MPT3SAS_FMT
496 "%s: req_alt_boot_device(0x%016llx)\n",
498 (unsigned long long)sas_address));
499 ioc->req_alt_boot_device.device = device;
500 ioc->req_alt_boot_device.is_raid = is_raid;
504 if (!ioc->current_boot_device.device) {
505 if (_scsih_is_boot_device(sas_address, device_name,
506 enclosure_logical_id, slot,
507 (ioc->bios_pg2.CurrentBootDeviceForm &
508 MPI2_BIOSPAGE2_FORM_MASK),
509 &ioc->bios_pg2.CurrentBootDevice)) {
510 dinitprintk(ioc, pr_info(MPT3SAS_FMT
511 "%s: current_boot_device(0x%016llx)\n",
513 (unsigned long long)sas_address));
514 ioc->current_boot_device.device = device;
515 ioc->current_boot_device.is_raid = is_raid;
521 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
522 * @ioc: per adapter object
523 * @sas_address: sas address
524 * Context: Calling function should acquire ioc->sas_device_lock
526 * This searches for sas_device based on sas_address, then return sas_device
530 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
533 struct _sas_device *sas_device;
535 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
536 if (sas_device->sas_address == sas_address)
539 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
540 if (sas_device->sas_address == sas_address)
547 * _scsih_sas_device_find_by_handle - sas device search
548 * @ioc: per adapter object
549 * @handle: sas device handle (assigned by firmware)
550 * Context: Calling function should acquire ioc->sas_device_lock
552 * This searches for sas_device based on sas_address, then return sas_device
555 static struct _sas_device *
556 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
558 struct _sas_device *sas_device;
560 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
561 if (sas_device->handle == handle)
564 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
565 if (sas_device->handle == handle)
572 * _scsih_sas_device_remove - remove sas_device from list.
573 * @ioc: per adapter object
574 * @sas_device: the sas_device object
575 * Context: This function will acquire ioc->sas_device_lock.
577 * Removing object and freeing associated memory from the ioc->sas_device_list.
580 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
581 struct _sas_device *sas_device)
588 spin_lock_irqsave(&ioc->sas_device_lock, flags);
589 list_del(&sas_device->list);
591 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
595 * _scsih_device_remove_by_handle - removing device object by handle
596 * @ioc: per adapter object
597 * @handle: device handle
602 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
604 struct _sas_device *sas_device;
607 if (ioc->shost_recovery)
610 spin_lock_irqsave(&ioc->sas_device_lock, flags);
611 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
613 list_del(&sas_device->list);
614 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
616 _scsih_remove_device(ioc, sas_device);
620 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
621 * @ioc: per adapter object
622 * @sas_address: device sas_address
627 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
630 struct _sas_device *sas_device;
633 if (ioc->shost_recovery)
636 spin_lock_irqsave(&ioc->sas_device_lock, flags);
637 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
640 list_del(&sas_device->list);
641 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
643 _scsih_remove_device(ioc, sas_device);
647 * _scsih_sas_device_add - insert sas_device to the list.
648 * @ioc: per adapter object
649 * @sas_device: the sas_device object
650 * Context: This function will acquire ioc->sas_device_lock.
652 * Adding new object to the ioc->sas_device_list.
655 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
656 struct _sas_device *sas_device)
660 dewtprintk(ioc, pr_info(MPT3SAS_FMT
661 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
662 ioc->name, __func__, sas_device->handle,
663 (unsigned long long)sas_device->sas_address));
665 spin_lock_irqsave(&ioc->sas_device_lock, flags);
666 list_add_tail(&sas_device->list, &ioc->sas_device_list);
667 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
669 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
670 sas_device->sas_address_parent)) {
671 _scsih_sas_device_remove(ioc, sas_device);
672 } else if (!sas_device->starget) {
674 * When asyn scanning is enabled, its not possible to remove
675 * devices while scanning is turned on due to an oops in
676 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
678 if (!ioc->is_driver_loading) {
679 mpt3sas_transport_port_remove(ioc,
680 sas_device->sas_address,
681 sas_device->sas_address_parent);
682 _scsih_sas_device_remove(ioc, sas_device);
688 * _scsih_sas_device_init_add - insert sas_device to the list.
689 * @ioc: per adapter object
690 * @sas_device: the sas_device object
691 * Context: This function will acquire ioc->sas_device_lock.
693 * Adding new object at driver load time to the ioc->sas_device_init_list.
696 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
697 struct _sas_device *sas_device)
701 dewtprintk(ioc, pr_info(MPT3SAS_FMT
702 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
703 __func__, sas_device->handle,
704 (unsigned long long)sas_device->sas_address));
706 spin_lock_irqsave(&ioc->sas_device_lock, flags);
707 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
708 _scsih_determine_boot_device(ioc, sas_device, 0);
709 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
713 * _scsih_raid_device_find_by_id - raid device search
714 * @ioc: per adapter object
715 * @id: sas device target id
716 * @channel: sas device channel
717 * Context: Calling function should acquire ioc->raid_device_lock
719 * This searches for raid_device based on target id, then return raid_device
722 static struct _raid_device *
723 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
725 struct _raid_device *raid_device, *r;
728 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
729 if (raid_device->id == id && raid_device->channel == channel) {
740 * _scsih_raid_device_find_by_handle - raid device search
741 * @ioc: per adapter object
742 * @handle: sas device handle (assigned by firmware)
743 * Context: Calling function should acquire ioc->raid_device_lock
745 * This searches for raid_device based on handle, then return raid_device
748 static struct _raid_device *
749 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
751 struct _raid_device *raid_device, *r;
754 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
755 if (raid_device->handle != handle)
766 * _scsih_raid_device_find_by_wwid - raid device search
767 * @ioc: per adapter object
768 * @handle: sas device handle (assigned by firmware)
769 * Context: Calling function should acquire ioc->raid_device_lock
771 * This searches for raid_device based on wwid, then return raid_device
774 static struct _raid_device *
775 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
777 struct _raid_device *raid_device, *r;
780 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
781 if (raid_device->wwid != wwid)
792 * _scsih_raid_device_add - add raid_device object
793 * @ioc: per adapter object
794 * @raid_device: raid_device object
796 * This is added to the raid_device_list link list.
799 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
800 struct _raid_device *raid_device)
804 dewtprintk(ioc, pr_info(MPT3SAS_FMT
805 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
806 raid_device->handle, (unsigned long long)raid_device->wwid));
808 spin_lock_irqsave(&ioc->raid_device_lock, flags);
809 list_add_tail(&raid_device->list, &ioc->raid_device_list);
810 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
814 * _scsih_raid_device_remove - delete raid_device object
815 * @ioc: per adapter object
816 * @raid_device: raid_device object
820 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
821 struct _raid_device *raid_device)
825 spin_lock_irqsave(&ioc->raid_device_lock, flags);
826 list_del(&raid_device->list);
828 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
832 * mpt3sas_scsih_expander_find_by_handle - expander device search
833 * @ioc: per adapter object
834 * @handle: expander handle (assigned by firmware)
835 * Context: Calling function should acquire ioc->sas_device_lock
837 * This searches for expander device based on handle, then returns the
841 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
843 struct _sas_node *sas_expander, *r;
846 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
847 if (sas_expander->handle != handle)
857 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
858 * @ioc: per adapter object
859 * @sas_address: sas address
860 * Context: Calling function should acquire ioc->sas_node_lock.
862 * This searches for expander device based on sas_address, then returns the
866 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
869 struct _sas_node *sas_expander, *r;
872 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
873 if (sas_expander->sas_address != sas_address)
883 * _scsih_expander_node_add - insert expander device to the list.
884 * @ioc: per adapter object
885 * @sas_expander: the sas_device object
886 * Context: This function will acquire ioc->sas_node_lock.
888 * Adding new object to the ioc->sas_expander_list.
893 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
894 struct _sas_node *sas_expander)
898 spin_lock_irqsave(&ioc->sas_node_lock, flags);
899 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
900 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
904 * _scsih_is_end_device - determines if device is an end device
905 * @device_info: bitfield providing information about the device.
908 * Returns 1 if end device.
911 _scsih_is_end_device(u32 device_info)
913 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
914 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
915 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
916 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
923 * _scsih_scsi_lookup_get - returns scmd entry
924 * @ioc: per adapter object
925 * @smid: system request message index
927 * Returns the smid stored scmd pointer.
929 static struct scsi_cmnd *
930 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
932 return ioc->scsi_lookup[smid - 1].scmd;
936 * _scsih_scsi_lookup_get_clear - returns scmd entry
937 * @ioc: per adapter object
938 * @smid: system request message index
940 * Returns the smid stored scmd pointer.
941 * Then will derefrence the stored scmd pointer.
943 static inline struct scsi_cmnd *
944 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
947 struct scsi_cmnd *scmd;
949 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
950 scmd = ioc->scsi_lookup[smid - 1].scmd;
951 ioc->scsi_lookup[smid - 1].scmd = NULL;
952 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
958 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
959 * @ioc: per adapter object
960 * @smid: system request message index
961 * @scmd: pointer to scsi command object
962 * Context: This function will acquire ioc->scsi_lookup_lock.
964 * This will search for a scmd pointer in the scsi_lookup array,
965 * returning the revelent smid. A returned value of zero means invalid.
968 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
975 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
977 for (i = 0; i < ioc->scsiio_depth; i++) {
978 if (ioc->scsi_lookup[i].scmd == scmd) {
979 smid = ioc->scsi_lookup[i].smid;
984 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
989 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
990 * @ioc: per adapter object
993 * Context: This function will acquire ioc->scsi_lookup_lock.
995 * This will search for a matching channel:id in the scsi_lookup array,
996 * returning 1 if found.
999 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1003 unsigned long flags;
1006 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1008 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1009 if (ioc->scsi_lookup[i].scmd &&
1010 (ioc->scsi_lookup[i].scmd->device->id == id &&
1011 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1017 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1022 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1023 * @ioc: per adapter object
1027 * Context: This function will acquire ioc->scsi_lookup_lock.
1029 * This will search for a matching channel:id:lun in the scsi_lookup array,
1030 * returning 1 if found.
1033 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1034 unsigned int lun, int channel)
1037 unsigned long flags;
1040 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1042 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1043 if (ioc->scsi_lookup[i].scmd &&
1044 (ioc->scsi_lookup[i].scmd->device->id == id &&
1045 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1046 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1052 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1058 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1060 struct Scsi_Host *shost = sdev->host;
1062 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1063 struct MPT3SAS_DEVICE *sas_device_priv_data;
1064 struct MPT3SAS_TARGET *sas_target_priv_data;
1065 struct _sas_device *sas_device;
1066 unsigned long flags;
1068 max_depth = shost->can_queue;
1070 /* limit max device queue for SATA to 32 */
1071 sas_device_priv_data = sdev->hostdata;
1072 if (!sas_device_priv_data)
1074 sas_target_priv_data = sas_device_priv_data->sas_target;
1075 if (!sas_target_priv_data)
1077 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1079 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1080 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1081 sas_device_priv_data->sas_target->sas_address);
1082 if (sas_device && sas_device->device_info &
1083 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1084 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1085 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1089 if (!sdev->tagged_supported)
1091 if (qdepth > max_depth)
1093 scsi_adjust_queue_depth(sdev, 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_target_alloc - target add routine
1127 * @starget: scsi target struct
1129 * Returns 0 if ok. Any other return is assumed to be an error and
1130 * the device is ignored.
1133 _scsih_target_alloc(struct scsi_target *starget)
1135 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1136 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1137 struct MPT3SAS_TARGET *sas_target_priv_data;
1138 struct _sas_device *sas_device;
1139 struct _raid_device *raid_device;
1140 unsigned long flags;
1141 struct sas_rphy *rphy;
1143 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1145 if (!sas_target_priv_data)
1148 starget->hostdata = sas_target_priv_data;
1149 sas_target_priv_data->starget = starget;
1150 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1153 if (starget->channel == RAID_CHANNEL) {
1154 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1155 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1158 sas_target_priv_data->handle = raid_device->handle;
1159 sas_target_priv_data->sas_address = raid_device->wwid;
1160 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1161 raid_device->starget = starget;
1163 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1167 /* sas/sata devices */
1168 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1169 rphy = dev_to_rphy(starget->dev.parent);
1170 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1171 rphy->identify.sas_address);
1174 sas_target_priv_data->handle = sas_device->handle;
1175 sas_target_priv_data->sas_address = sas_device->sas_address;
1176 sas_device->starget = starget;
1177 sas_device->id = starget->id;
1178 sas_device->channel = starget->channel;
1179 if (test_bit(sas_device->handle, ioc->pd_handles))
1180 sas_target_priv_data->flags |=
1181 MPT_TARGET_FLAGS_RAID_COMPONENT;
1182 if (sas_device->fast_path)
1183 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1191 * _scsih_target_destroy - target destroy routine
1192 * @starget: scsi target struct
1197 _scsih_target_destroy(struct scsi_target *starget)
1199 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1200 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1201 struct MPT3SAS_TARGET *sas_target_priv_data;
1202 struct _sas_device *sas_device;
1203 struct _raid_device *raid_device;
1204 unsigned long flags;
1205 struct sas_rphy *rphy;
1207 sas_target_priv_data = starget->hostdata;
1208 if (!sas_target_priv_data)
1211 if (starget->channel == RAID_CHANNEL) {
1212 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1213 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1216 raid_device->starget = NULL;
1217 raid_device->sdev = NULL;
1219 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1223 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1224 rphy = dev_to_rphy(starget->dev.parent);
1225 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1226 rphy->identify.sas_address);
1227 if (sas_device && (sas_device->starget == starget) &&
1228 (sas_device->id == starget->id) &&
1229 (sas_device->channel == starget->channel))
1230 sas_device->starget = NULL;
1232 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1235 kfree(sas_target_priv_data);
1236 starget->hostdata = NULL;
1240 * _scsih_slave_alloc - device add routine
1241 * @sdev: scsi device struct
1243 * Returns 0 if ok. Any other return is assumed to be an error and
1244 * the device is ignored.
1247 _scsih_slave_alloc(struct scsi_device *sdev)
1249 struct Scsi_Host *shost;
1250 struct MPT3SAS_ADAPTER *ioc;
1251 struct MPT3SAS_TARGET *sas_target_priv_data;
1252 struct MPT3SAS_DEVICE *sas_device_priv_data;
1253 struct scsi_target *starget;
1254 struct _raid_device *raid_device;
1255 struct _sas_device *sas_device;
1256 unsigned long flags;
1258 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1260 if (!sas_device_priv_data)
1263 sas_device_priv_data->lun = sdev->lun;
1264 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1266 starget = scsi_target(sdev);
1267 sas_target_priv_data = starget->hostdata;
1268 sas_target_priv_data->num_luns++;
1269 sas_device_priv_data->sas_target = sas_target_priv_data;
1270 sdev->hostdata = sas_device_priv_data;
1271 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1272 sdev->no_uld_attach = 1;
1274 shost = dev_to_shost(&starget->dev);
1275 ioc = shost_priv(shost);
1276 if (starget->channel == RAID_CHANNEL) {
1277 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1278 raid_device = _scsih_raid_device_find_by_id(ioc,
1279 starget->id, starget->channel);
1281 raid_device->sdev = sdev; /* raid is single lun */
1282 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1285 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1286 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1287 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1288 sas_target_priv_data->sas_address);
1289 if (sas_device && (sas_device->starget == NULL)) {
1290 sdev_printk(KERN_INFO, sdev,
1291 "%s : sas_device->starget set to starget @ %d\n",
1292 __func__, __LINE__);
1293 sas_device->starget = starget;
1295 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1302 * _scsih_slave_destroy - device destroy routine
1303 * @sdev: scsi device struct
1308 _scsih_slave_destroy(struct scsi_device *sdev)
1310 struct MPT3SAS_TARGET *sas_target_priv_data;
1311 struct scsi_target *starget;
1312 struct Scsi_Host *shost;
1313 struct MPT3SAS_ADAPTER *ioc;
1314 struct _sas_device *sas_device;
1315 unsigned long flags;
1317 if (!sdev->hostdata)
1320 starget = scsi_target(sdev);
1321 sas_target_priv_data = starget->hostdata;
1322 sas_target_priv_data->num_luns--;
1324 shost = dev_to_shost(&starget->dev);
1325 ioc = shost_priv(shost);
1327 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1328 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1329 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1330 sas_target_priv_data->sas_address);
1331 if (sas_device && !sas_target_priv_data->num_luns)
1332 sas_device->starget = NULL;
1333 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1336 kfree(sdev->hostdata);
1337 sdev->hostdata = NULL;
1341 * _scsih_display_sata_capabilities - sata capabilities
1342 * @ioc: per adapter object
1343 * @handle: device handle
1344 * @sdev: scsi device struct
1347 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1348 u16 handle, struct scsi_device *sdev)
1350 Mpi2ConfigReply_t mpi_reply;
1351 Mpi2SasDevicePage0_t sas_device_pg0;
1356 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1357 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1358 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1359 ioc->name, __FILE__, __LINE__, __func__);
1363 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1364 MPI2_IOCSTATUS_MASK;
1365 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1366 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1367 ioc->name, __FILE__, __LINE__, __func__);
1371 flags = le16_to_cpu(sas_device_pg0.Flags);
1372 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1374 sdev_printk(KERN_INFO, sdev,
1375 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1376 "sw_preserve(%s)\n",
1377 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1378 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1379 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1381 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1382 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1383 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1387 * raid transport support -
1388 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1389 * unloading the driver followed by a load - I beleive that the subroutine
1390 * raid_class_release() is not cleaning up properly.
1394 * _scsih_is_raid - return boolean indicating device is raid volume
1395 * @dev the device struct object
1398 _scsih_is_raid(struct device *dev)
1400 struct scsi_device *sdev = to_scsi_device(dev);
1402 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1406 * _scsih_get_resync - get raid volume resync percent complete
1407 * @dev the device struct object
1410 _scsih_get_resync(struct device *dev)
1412 struct scsi_device *sdev = to_scsi_device(dev);
1413 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1414 static struct _raid_device *raid_device;
1415 unsigned long flags;
1416 Mpi2RaidVolPage0_t vol_pg0;
1417 Mpi2ConfigReply_t mpi_reply;
1418 u32 volume_status_flags;
1419 u8 percent_complete;
1422 percent_complete = 0;
1424 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1425 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1428 handle = raid_device->handle;
1429 percent_complete = raid_device->percent_complete;
1431 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1436 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1437 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1438 sizeof(Mpi2RaidVolPage0_t))) {
1439 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1440 ioc->name, __FILE__, __LINE__, __func__);
1441 percent_complete = 0;
1445 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1446 if (!(volume_status_flags &
1447 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1448 percent_complete = 0;
1451 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1455 * _scsih_get_state - get raid volume level
1456 * @dev the device struct object
1459 _scsih_get_state(struct device *dev)
1461 struct scsi_device *sdev = to_scsi_device(dev);
1462 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1463 static struct _raid_device *raid_device;
1464 unsigned long flags;
1465 Mpi2RaidVolPage0_t vol_pg0;
1466 Mpi2ConfigReply_t mpi_reply;
1468 enum raid_state state = RAID_STATE_UNKNOWN;
1471 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1472 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1475 handle = raid_device->handle;
1476 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1481 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1482 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1483 sizeof(Mpi2RaidVolPage0_t))) {
1484 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1485 ioc->name, __FILE__, __LINE__, __func__);
1489 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1490 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1491 state = RAID_STATE_RESYNCING;
1495 switch (vol_pg0.VolumeState) {
1496 case MPI2_RAID_VOL_STATE_OPTIMAL:
1497 case MPI2_RAID_VOL_STATE_ONLINE:
1498 state = RAID_STATE_ACTIVE;
1500 case MPI2_RAID_VOL_STATE_DEGRADED:
1501 state = RAID_STATE_DEGRADED;
1503 case MPI2_RAID_VOL_STATE_FAILED:
1504 case MPI2_RAID_VOL_STATE_MISSING:
1505 state = RAID_STATE_OFFLINE;
1509 raid_set_state(mpt3sas_raid_template, dev, state);
1513 * _scsih_set_level - set raid level
1514 * @sdev: scsi device struct
1515 * @volume_type: volume type
1518 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1520 enum raid_level level = RAID_LEVEL_UNKNOWN;
1522 switch (volume_type) {
1523 case MPI2_RAID_VOL_TYPE_RAID0:
1524 level = RAID_LEVEL_0;
1526 case MPI2_RAID_VOL_TYPE_RAID10:
1527 level = RAID_LEVEL_10;
1529 case MPI2_RAID_VOL_TYPE_RAID1E:
1530 level = RAID_LEVEL_1E;
1532 case MPI2_RAID_VOL_TYPE_RAID1:
1533 level = RAID_LEVEL_1;
1537 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1542 * _scsih_get_volume_capabilities - volume capabilities
1543 * @ioc: per adapter object
1544 * @sas_device: the raid_device object
1546 * Returns 0 for success, else 1
1549 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1550 struct _raid_device *raid_device)
1552 Mpi2RaidVolPage0_t *vol_pg0;
1553 Mpi2RaidPhysDiskPage0_t pd_pg0;
1554 Mpi2SasDevicePage0_t sas_device_pg0;
1555 Mpi2ConfigReply_t mpi_reply;
1559 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1560 &num_pds)) || !num_pds) {
1561 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1562 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1567 raid_device->num_pds = num_pds;
1568 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1569 sizeof(Mpi2RaidVol0PhysDisk_t));
1570 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1572 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1573 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1578 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1579 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1580 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1581 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1587 raid_device->volume_type = vol_pg0->VolumeType;
1589 /* figure out what the underlying devices are by
1590 * obtaining the device_info bits for the 1st device
1592 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1593 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1594 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1595 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1596 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1597 le16_to_cpu(pd_pg0.DevHandle)))) {
1598 raid_device->device_info =
1599 le32_to_cpu(sas_device_pg0.DeviceInfo);
1610 * _scsih_enable_tlr - setting TLR flags
1611 * @ioc: per adapter object
1612 * @sdev: scsi device struct
1614 * Enabling Transaction Layer Retries for tape devices when
1615 * vpd page 0x90 is present
1619 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1623 if (sdev->type != TYPE_TAPE)
1626 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1629 sas_enable_tlr(sdev);
1630 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1631 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1637 * _scsih_slave_configure - device configure routine.
1638 * @sdev: scsi device struct
1640 * Returns 0 if ok. Any other return is assumed to be an error and
1641 * the device is ignored.
1644 _scsih_slave_configure(struct scsi_device *sdev)
1646 struct Scsi_Host *shost = sdev->host;
1647 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1648 struct MPT3SAS_DEVICE *sas_device_priv_data;
1649 struct MPT3SAS_TARGET *sas_target_priv_data;
1650 struct _sas_device *sas_device;
1651 struct _raid_device *raid_device;
1652 unsigned long flags;
1657 u16 handle, volume_handle = 0;
1658 u64 volume_wwid = 0;
1661 sas_device_priv_data = sdev->hostdata;
1662 sas_device_priv_data->configured_lun = 1;
1663 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1664 sas_target_priv_data = sas_device_priv_data->sas_target;
1665 handle = sas_target_priv_data->handle;
1667 /* raid volume handling */
1668 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1670 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1671 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1672 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1674 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1675 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1676 __LINE__, __func__));
1680 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1681 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1682 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1683 __LINE__, __func__));
1688 /* RAID Queue Depth Support
1689 * IS volume = underlying qdepth of drive type, either
1690 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1691 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1693 if (raid_device->device_info &
1694 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1695 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1698 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1699 if (raid_device->device_info &
1700 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1706 switch (raid_device->volume_type) {
1707 case MPI2_RAID_VOL_TYPE_RAID0:
1710 case MPI2_RAID_VOL_TYPE_RAID1E:
1711 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1712 if (ioc->manu_pg10.OEMIdentifier &&
1713 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1714 MFG10_GF0_R10_DISPLAY) &&
1715 !(raid_device->num_pds % 2))
1720 case MPI2_RAID_VOL_TYPE_RAID1:
1721 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1724 case MPI2_RAID_VOL_TYPE_RAID10:
1725 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1728 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1730 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1735 sdev_printk(KERN_INFO, sdev,
1736 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1737 r_level, raid_device->handle,
1738 (unsigned long long)raid_device->wwid,
1739 raid_device->num_pds, ds);
1742 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1744 /* raid transport support */
1745 _scsih_set_level(sdev, raid_device->volume_type);
1749 /* non-raid handling */
1750 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1751 if (mpt3sas_config_get_volume_handle(ioc, handle,
1753 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1754 "failure at %s:%d/%s()!\n", ioc->name,
1755 __FILE__, __LINE__, __func__));
1758 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1759 volume_handle, &volume_wwid)) {
1760 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1761 "failure at %s:%d/%s()!\n", ioc->name,
1762 __FILE__, __LINE__, __func__));
1767 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1768 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1769 sas_device_priv_data->sas_target->sas_address);
1771 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1772 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1773 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1778 sas_device->volume_handle = volume_handle;
1779 sas_device->volume_wwid = volume_wwid;
1780 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1781 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1785 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1786 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1788 else if (sas_device->device_info &
1789 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1793 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1794 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1795 ds, handle, (unsigned long long)sas_device->sas_address,
1796 sas_device->phy, (unsigned long long)sas_device->device_name);
1797 sdev_printk(KERN_INFO, sdev,
1798 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1799 ds, (unsigned long long)
1800 sas_device->enclosure_logical_id, sas_device->slot);
1802 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1805 _scsih_display_sata_capabilities(ioc, handle, sdev);
1808 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1811 sas_read_port_mode_page(sdev);
1812 _scsih_enable_tlr(ioc, sdev);
1819 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1820 * @sdev: scsi device struct
1821 * @bdev: pointer to block device context
1822 * @capacity: device size (in 512 byte sectors)
1823 * @params: three element array to place output:
1824 * params[0] number of heads (max 255)
1825 * params[1] number of sectors (max 63)
1826 * params[2] number of cylinders
1831 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1832 sector_t capacity, int params[])
1842 dummy = heads * sectors;
1843 cylinders = capacity;
1844 sector_div(cylinders, dummy);
1847 * Handle extended translation size for logical drives
1850 if ((ulong)capacity >= 0x200000) {
1853 dummy = heads * sectors;
1854 cylinders = capacity;
1855 sector_div(cylinders, dummy);
1860 params[1] = sectors;
1861 params[2] = cylinders;
1867 * _scsih_response_code - translation of device response code
1868 * @ioc: per adapter object
1869 * @response_code: response code returned by the device
1874 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1878 switch (response_code) {
1879 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1880 desc = "task management request completed";
1882 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1883 desc = "invalid frame";
1885 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1886 desc = "task management request not supported";
1888 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1889 desc = "task management request failed";
1891 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1892 desc = "task management request succeeded";
1894 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1895 desc = "invalid lun";
1898 desc = "overlapped tag attempted";
1900 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1901 desc = "task queued, however not sent to target";
1907 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1908 ioc->name, response_code, desc);
1912 * _scsih_tm_done - tm completion routine
1913 * @ioc: per adapter object
1914 * @smid: system request message index
1915 * @msix_index: MSIX table index supplied by the OS
1916 * @reply: reply message frame(lower 32bit addr)
1919 * The callback handler when using scsih_issue_tm.
1921 * Return 1 meaning mf should be freed from _base_interrupt
1922 * 0 means the mf is freed from this function.
1925 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1927 MPI2DefaultReply_t *mpi_reply;
1929 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1931 if (ioc->tm_cmds.smid != smid)
1933 mpt3sas_base_flush_reply_queues(ioc);
1934 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1935 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1937 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1938 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1940 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1941 complete(&ioc->tm_cmds.done);
1946 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1947 * @ioc: per adapter object
1948 * @handle: device handle
1950 * During taskmangement request, we need to freeze the device queue.
1953 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1955 struct MPT3SAS_DEVICE *sas_device_priv_data;
1956 struct scsi_device *sdev;
1959 shost_for_each_device(sdev, ioc->shost) {
1962 sas_device_priv_data = sdev->hostdata;
1963 if (!sas_device_priv_data)
1965 if (sas_device_priv_data->sas_target->handle == handle) {
1966 sas_device_priv_data->sas_target->tm_busy = 1;
1968 ioc->ignore_loginfos = 1;
1974 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1975 * @ioc: per adapter object
1976 * @handle: device handle
1978 * During taskmangement request, we need to freeze the device queue.
1981 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1983 struct MPT3SAS_DEVICE *sas_device_priv_data;
1984 struct scsi_device *sdev;
1987 shost_for_each_device(sdev, ioc->shost) {
1990 sas_device_priv_data = sdev->hostdata;
1991 if (!sas_device_priv_data)
1993 if (sas_device_priv_data->sas_target->handle == handle) {
1994 sas_device_priv_data->sas_target->tm_busy = 0;
1996 ioc->ignore_loginfos = 0;
2002 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2003 * @ioc: per adapter struct
2004 * @device_handle: device handle
2005 * @channel: the channel assigned by the OS
2006 * @id: the id assigned by the OS
2008 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2009 * @smid_task: smid assigned to the task
2010 * @timeout: timeout in seconds
2011 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2014 * A generic API for sending task management requests to firmware.
2016 * The callback index is set inside `ioc->tm_cb_idx`.
2018 * Return SUCCESS or FAILED.
2021 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2022 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2023 enum mutex_type m_type)
2025 Mpi2SCSITaskManagementRequest_t *mpi_request;
2026 Mpi2SCSITaskManagementReply_t *mpi_reply;
2029 unsigned long timeleft;
2030 struct scsiio_tracker *scsi_lookup = NULL;
2033 if (m_type == TM_MUTEX_ON)
2034 mutex_lock(&ioc->tm_cmds.mutex);
2035 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2036 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2037 __func__, ioc->name);
2042 if (ioc->shost_recovery || ioc->remove_host ||
2043 ioc->pci_error_recovery) {
2044 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2045 __func__, ioc->name);
2050 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2051 if (ioc_state & MPI2_DOORBELL_USED) {
2052 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2053 "unexpected doorbell active!\n", ioc->name));
2054 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2056 rc = (!rc) ? SUCCESS : FAILED;
2060 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2061 mpt3sas_base_fault_info(ioc, ioc_state &
2062 MPI2_DOORBELL_DATA_MASK);
2063 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2065 rc = (!rc) ? SUCCESS : FAILED;
2069 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2071 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2072 ioc->name, __func__);
2077 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2078 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2080 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2081 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2082 ioc->name, handle, type, smid_task));
2083 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2084 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2085 ioc->tm_cmds.smid = smid;
2086 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2087 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2088 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2089 mpi_request->DevHandle = cpu_to_le16(handle);
2090 mpi_request->TaskType = type;
2091 mpi_request->TaskMID = cpu_to_le16(smid_task);
2092 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2093 mpt3sas_scsih_set_tm_flag(ioc, handle);
2094 init_completion(&ioc->tm_cmds.done);
2095 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2096 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2097 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2098 pr_err(MPT3SAS_FMT "%s: timeout\n",
2099 ioc->name, __func__);
2100 _debug_dump_mf(mpi_request,
2101 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2102 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2103 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2105 rc = (!rc) ? SUCCESS : FAILED;
2106 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2107 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2112 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2113 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2114 mpi_reply = ioc->tm_cmds.reply;
2115 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2116 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2117 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2118 le32_to_cpu(mpi_reply->IOCLogInfo),
2119 le32_to_cpu(mpi_reply->TerminationCount)));
2120 if (ioc->logging_level & MPT_DEBUG_TM) {
2121 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2122 if (mpi_reply->IOCStatus)
2123 _debug_dump_mf(mpi_request,
2124 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2129 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2131 if (scsi_lookup->scmd == NULL)
2136 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2137 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2142 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2143 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2144 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2149 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2157 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2158 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2159 if (m_type == TM_MUTEX_ON)
2160 mutex_unlock(&ioc->tm_cmds.mutex);
2165 if (m_type == TM_MUTEX_ON)
2166 mutex_unlock(&ioc->tm_cmds.mutex);
2171 * _scsih_tm_display_info - displays info about the device
2172 * @ioc: per adapter struct
2173 * @scmd: pointer to scsi command object
2175 * Called by task management callback handlers.
2178 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2180 struct scsi_target *starget = scmd->device->sdev_target;
2181 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2182 struct _sas_device *sas_device = NULL;
2183 unsigned long flags;
2184 char *device_str = NULL;
2188 device_str = "volume";
2190 scsi_print_command(scmd);
2191 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2192 starget_printk(KERN_INFO, starget,
2193 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2194 device_str, priv_target->handle,
2195 device_str, (unsigned long long)priv_target->sas_address);
2197 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2198 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2199 priv_target->sas_address);
2201 if (priv_target->flags &
2202 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2203 starget_printk(KERN_INFO, starget,
2204 "volume handle(0x%04x), "
2205 "volume wwid(0x%016llx)\n",
2206 sas_device->volume_handle,
2207 (unsigned long long)sas_device->volume_wwid);
2209 starget_printk(KERN_INFO, starget,
2210 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2212 (unsigned long long)sas_device->sas_address,
2214 starget_printk(KERN_INFO, starget,
2215 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2216 (unsigned long long)sas_device->enclosure_logical_id,
2219 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2224 * _scsih_abort - eh threads main abort routine
2225 * @scmd: pointer to scsi command object
2227 * Returns SUCCESS if command aborted else FAILED
2230 _scsih_abort(struct scsi_cmnd *scmd)
2232 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2233 struct MPT3SAS_DEVICE *sas_device_priv_data;
2238 sdev_printk(KERN_INFO, scmd->device,
2239 "attempting task abort! scmd(%p)\n", scmd);
2240 _scsih_tm_display_info(ioc, scmd);
2242 sas_device_priv_data = scmd->device->hostdata;
2243 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2244 sdev_printk(KERN_INFO, scmd->device,
2245 "device been deleted! scmd(%p)\n", scmd);
2246 scmd->result = DID_NO_CONNECT << 16;
2247 scmd->scsi_done(scmd);
2252 /* search for the command */
2253 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2255 scmd->result = DID_RESET << 16;
2260 /* for hidden raid components and volumes this is not supported */
2261 if (sas_device_priv_data->sas_target->flags &
2262 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2263 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2264 scmd->result = DID_RESET << 16;
2269 mpt3sas_halt_firmware(ioc);
2271 handle = sas_device_priv_data->sas_target->handle;
2272 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2273 scmd->device->id, scmd->device->lun,
2274 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2277 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2278 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2283 * _scsih_dev_reset - eh threads main device reset routine
2284 * @scmd: pointer to scsi command object
2286 * Returns SUCCESS if command aborted else FAILED
2289 _scsih_dev_reset(struct scsi_cmnd *scmd)
2291 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2292 struct MPT3SAS_DEVICE *sas_device_priv_data;
2293 struct _sas_device *sas_device;
2294 unsigned long flags;
2298 sdev_printk(KERN_INFO, scmd->device,
2299 "attempting device reset! scmd(%p)\n", scmd);
2300 _scsih_tm_display_info(ioc, scmd);
2302 sas_device_priv_data = scmd->device->hostdata;
2303 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2304 sdev_printk(KERN_INFO, scmd->device,
2305 "device been deleted! scmd(%p)\n", scmd);
2306 scmd->result = DID_NO_CONNECT << 16;
2307 scmd->scsi_done(scmd);
2312 /* for hidden raid components obtain the volume_handle */
2314 if (sas_device_priv_data->sas_target->flags &
2315 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2316 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2317 sas_device = _scsih_sas_device_find_by_handle(ioc,
2318 sas_device_priv_data->sas_target->handle);
2320 handle = sas_device->volume_handle;
2321 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2323 handle = sas_device_priv_data->sas_target->handle;
2326 scmd->result = DID_RESET << 16;
2331 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2332 scmd->device->id, scmd->device->lun,
2333 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2336 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2337 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2342 * _scsih_target_reset - eh threads main target reset routine
2343 * @scmd: pointer to scsi command object
2345 * Returns SUCCESS if command aborted else FAILED
2348 _scsih_target_reset(struct scsi_cmnd *scmd)
2350 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2351 struct MPT3SAS_DEVICE *sas_device_priv_data;
2352 struct _sas_device *sas_device;
2353 unsigned long flags;
2356 struct scsi_target *starget = scmd->device->sdev_target;
2358 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2360 _scsih_tm_display_info(ioc, scmd);
2362 sas_device_priv_data = scmd->device->hostdata;
2363 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2364 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2366 scmd->result = DID_NO_CONNECT << 16;
2367 scmd->scsi_done(scmd);
2372 /* for hidden raid components obtain the volume_handle */
2374 if (sas_device_priv_data->sas_target->flags &
2375 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2376 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2377 sas_device = _scsih_sas_device_find_by_handle(ioc,
2378 sas_device_priv_data->sas_target->handle);
2380 handle = sas_device->volume_handle;
2381 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2383 handle = sas_device_priv_data->sas_target->handle;
2386 scmd->result = DID_RESET << 16;
2391 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2392 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2396 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2397 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2403 * _scsih_host_reset - eh threads main host reset routine
2404 * @scmd: pointer to scsi command object
2406 * Returns SUCCESS if command aborted else FAILED
2409 _scsih_host_reset(struct scsi_cmnd *scmd)
2411 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2414 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2416 scsi_print_command(scmd);
2418 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2420 r = (retval < 0) ? FAILED : SUCCESS;
2421 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2422 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2428 * _scsih_fw_event_add - insert and queue up fw_event
2429 * @ioc: per adapter object
2430 * @fw_event: object describing the event
2431 * Context: This function will acquire ioc->fw_event_lock.
2433 * This adds the firmware event object into link list, then queues it up to
2434 * be processed from user context.
2439 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2441 unsigned long flags;
2443 if (ioc->firmware_event_thread == NULL)
2446 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2447 INIT_LIST_HEAD(&fw_event->list);
2448 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2449 INIT_WORK(&fw_event->work, _firmware_event_work);
2450 queue_work(ioc->firmware_event_thread, &fw_event->work);
2451 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2455 * _scsih_fw_event_free - delete fw_event
2456 * @ioc: per adapter object
2457 * @fw_event: object describing the event
2458 * Context: This function will acquire ioc->fw_event_lock.
2460 * This removes firmware event object from link list, frees associated memory.
2465 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2468 unsigned long flags;
2470 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2471 list_del(&fw_event->list);
2473 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2478 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2479 * @ioc: per adapter object
2480 * @event_data: trigger event data
2485 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2486 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2488 struct fw_event_work *fw_event;
2490 if (ioc->is_driver_loading)
2492 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2496 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2497 fw_event->ioc = ioc;
2498 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2499 _scsih_fw_event_add(ioc, fw_event);
2503 * _scsih_error_recovery_delete_devices - remove devices not responding
2504 * @ioc: per adapter object
2509 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2511 struct fw_event_work *fw_event;
2513 if (ioc->is_driver_loading)
2515 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2518 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2519 fw_event->ioc = ioc;
2520 _scsih_fw_event_add(ioc, fw_event);
2524 * mpt3sas_port_enable_complete - port enable completed (fake event)
2525 * @ioc: per adapter object
2530 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2532 struct fw_event_work *fw_event;
2534 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2537 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2538 fw_event->ioc = ioc;
2539 _scsih_fw_event_add(ioc, fw_event);
2543 * _scsih_fw_event_cleanup_queue - cleanup event queue
2544 * @ioc: per adapter object
2546 * Walk the firmware event queue, either killing timers, or waiting
2547 * for outstanding events to complete
2552 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2554 struct fw_event_work *fw_event, *next;
2556 if (list_empty(&ioc->fw_event_list) ||
2557 !ioc->firmware_event_thread || in_interrupt())
2560 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2561 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2562 _scsih_fw_event_free(ioc, fw_event);
2569 * _scsih_ublock_io_all_device - unblock every device
2570 * @ioc: per adapter object
2572 * change the device state from block to running
2575 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2577 struct MPT3SAS_DEVICE *sas_device_priv_data;
2578 struct scsi_device *sdev;
2580 shost_for_each_device(sdev, ioc->shost) {
2581 sas_device_priv_data = sdev->hostdata;
2582 if (!sas_device_priv_data)
2584 if (!sas_device_priv_data->block)
2587 sas_device_priv_data->block = 0;
2588 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2589 "device_running, handle(0x%04x)\n",
2590 sas_device_priv_data->sas_target->handle));
2591 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2597 * _scsih_ublock_io_device - prepare device to be deleted
2598 * @ioc: per adapter object
2599 * @sas_addr: sas address
2601 * unblock then put device in offline state
2604 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2606 struct MPT3SAS_DEVICE *sas_device_priv_data;
2607 struct scsi_device *sdev;
2609 shost_for_each_device(sdev, ioc->shost) {
2610 sas_device_priv_data = sdev->hostdata;
2611 if (!sas_device_priv_data)
2613 if (sas_device_priv_data->sas_target->sas_address
2616 if (sas_device_priv_data->block) {
2617 sas_device_priv_data->block = 0;
2618 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2624 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2625 * @ioc: per adapter object
2626 * @handle: device handle
2628 * During device pull we need to appropiately set the sdev state.
2631 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2633 struct MPT3SAS_DEVICE *sas_device_priv_data;
2634 struct scsi_device *sdev;
2636 shost_for_each_device(sdev, ioc->shost) {
2637 sas_device_priv_data = sdev->hostdata;
2638 if (!sas_device_priv_data)
2640 if (sas_device_priv_data->block)
2642 sas_device_priv_data->block = 1;
2643 scsi_internal_device_block(sdev);
2644 sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n",
2645 sas_device_priv_data->sas_target->handle);
2650 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2651 * @ioc: per adapter object
2652 * @handle: device handle
2654 * During device pull we need to appropiately set the sdev state.
2657 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2659 struct MPT3SAS_DEVICE *sas_device_priv_data;
2660 struct scsi_device *sdev;
2662 shost_for_each_device(sdev, ioc->shost) {
2663 sas_device_priv_data = sdev->hostdata;
2664 if (!sas_device_priv_data)
2666 if (sas_device_priv_data->sas_target->handle != handle)
2668 if (sas_device_priv_data->block)
2670 sas_device_priv_data->block = 1;
2671 scsi_internal_device_block(sdev);
2672 sdev_printk(KERN_INFO, sdev,
2673 "device_blocked, handle(0x%04x)\n", handle);
2678 * _scsih_block_io_to_children_attached_to_ex
2679 * @ioc: per adapter object
2680 * @sas_expander: the sas_device object
2682 * This routine set sdev state to SDEV_BLOCK for all devices
2683 * attached to this expander. This function called when expander is
2687 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2688 struct _sas_node *sas_expander)
2690 struct _sas_port *mpt3sas_port;
2691 struct _sas_device *sas_device;
2692 struct _sas_node *expander_sibling;
2693 unsigned long flags;
2698 list_for_each_entry(mpt3sas_port,
2699 &sas_expander->sas_port_list, port_list) {
2700 if (mpt3sas_port->remote_identify.device_type ==
2702 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2704 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2705 mpt3sas_port->remote_identify.sas_address);
2707 set_bit(sas_device->handle,
2708 ioc->blocking_handles);
2709 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2713 list_for_each_entry(mpt3sas_port,
2714 &sas_expander->sas_port_list, port_list) {
2716 if (mpt3sas_port->remote_identify.device_type ==
2717 SAS_EDGE_EXPANDER_DEVICE ||
2718 mpt3sas_port->remote_identify.device_type ==
2719 SAS_FANOUT_EXPANDER_DEVICE) {
2721 mpt3sas_scsih_expander_find_by_sas_address(
2722 ioc, mpt3sas_port->remote_identify.sas_address);
2723 _scsih_block_io_to_children_attached_to_ex(ioc,
2730 * _scsih_block_io_to_children_attached_directly
2731 * @ioc: per adapter object
2732 * @event_data: topology change event data
2734 * This routine set sdev state to SDEV_BLOCK for all devices
2735 * direct attached during device pull.
2738 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2739 Mpi2EventDataSasTopologyChangeList_t *event_data)
2745 for (i = 0; i < event_data->NumEntries; i++) {
2746 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2749 reason_code = event_data->PHY[i].PhyStatus &
2750 MPI2_EVENT_SAS_TOPO_RC_MASK;
2751 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2752 _scsih_block_io_device(ioc, handle);
2757 * _scsih_tm_tr_send - send task management request
2758 * @ioc: per adapter object
2759 * @handle: device handle
2760 * Context: interrupt time.
2762 * This code is to initiate the device removal handshake protocol
2763 * with controller firmware. This function will issue target reset
2764 * using high priority request queue. It will send a sas iounit
2765 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2767 * This is designed to send muliple task management request at the same
2768 * time to the fifo. If the fifo is full, we will append the request,
2769 * and process it in a future completion.
2772 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2774 Mpi2SCSITaskManagementRequest_t *mpi_request;
2776 struct _sas_device *sas_device;
2777 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2778 u64 sas_address = 0;
2779 unsigned long flags;
2780 struct _tr_list *delayed_tr;
2783 if (ioc->remove_host) {
2784 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2785 "%s: host has been removed: handle(0x%04x)\n",
2786 __func__, ioc->name, handle));
2788 } else if (ioc->pci_error_recovery) {
2789 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2790 "%s: host in pci error recovery: handle(0x%04x)\n",
2791 __func__, ioc->name,
2795 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2796 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2797 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2798 "%s: host is not operational: handle(0x%04x)\n",
2799 __func__, ioc->name,
2804 /* if PD, then return */
2805 if (test_bit(handle, ioc->pd_handles))
2808 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2809 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2810 if (sas_device && sas_device->starget &&
2811 sas_device->starget->hostdata) {
2812 sas_target_priv_data = sas_device->starget->hostdata;
2813 sas_target_priv_data->deleted = 1;
2814 sas_address = sas_device->sas_address;
2816 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2818 if (sas_target_priv_data) {
2819 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2820 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2822 (unsigned long long)sas_address));
2823 _scsih_ublock_io_device(ioc, sas_address);
2824 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2827 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2829 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2832 INIT_LIST_HEAD(&delayed_tr->list);
2833 delayed_tr->handle = handle;
2834 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2835 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2836 "DELAYED:tr:handle(0x%04x), (open)\n",
2837 ioc->name, handle));
2841 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2842 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2843 ioc->name, handle, smid,
2844 ioc->tm_tr_cb_idx));
2845 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2846 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2847 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2848 mpi_request->DevHandle = cpu_to_le16(handle);
2849 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2850 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2851 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2855 * _scsih_tm_tr_complete -
2856 * @ioc: per adapter object
2857 * @smid: system request message index
2858 * @msix_index: MSIX table index supplied by the OS
2859 * @reply: reply message frame(lower 32bit addr)
2860 * Context: interrupt time.
2862 * This is the target reset completion routine.
2863 * This code is part of the code to initiate the device removal
2864 * handshake protocol with controller firmware.
2865 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2867 * Return 1 meaning mf should be freed from _base_interrupt
2868 * 0 means the mf is freed from this function.
2871 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2875 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2876 Mpi2SCSITaskManagementReply_t *mpi_reply =
2877 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2878 Mpi2SasIoUnitControlRequest_t *mpi_request;
2882 if (ioc->remove_host) {
2883 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2884 "%s: host has been removed\n", __func__, ioc->name));
2886 } else if (ioc->pci_error_recovery) {
2887 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2888 "%s: host in pci error recovery\n", __func__,
2892 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2893 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2894 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2895 "%s: host is not operational\n", __func__, ioc->name));
2898 if (unlikely(!mpi_reply)) {
2899 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2900 ioc->name, __FILE__, __LINE__, __func__);
2903 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2904 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2905 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2906 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2907 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2909 le16_to_cpu(mpi_reply->DevHandle), smid));
2913 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2914 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2915 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2916 "loginfo(0x%08x), completed(%d)\n", ioc->name,
2917 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
2918 le32_to_cpu(mpi_reply->IOCLogInfo),
2919 le32_to_cpu(mpi_reply->TerminationCount)));
2921 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2922 if (!smid_sas_ctrl) {
2923 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2924 ioc->name, __func__);
2928 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2929 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2930 ioc->name, handle, smid_sas_ctrl,
2931 ioc->tm_sas_control_cb_idx));
2932 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2933 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2934 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2935 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2936 mpi_request->DevHandle = mpi_request_tm->DevHandle;
2937 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
2939 return _scsih_check_for_pending_tm(ioc, smid);
2944 * _scsih_sas_control_complete - completion routine
2945 * @ioc: per adapter object
2946 * @smid: system request message index
2947 * @msix_index: MSIX table index supplied by the OS
2948 * @reply: reply message frame(lower 32bit addr)
2949 * Context: interrupt time.
2951 * This is the sas iounit control completion routine.
2952 * This code is part of the code to initiate the device removal
2953 * handshake protocol with controller firmware.
2955 * Return 1 meaning mf should be freed from _base_interrupt
2956 * 0 means the mf is freed from this function.
2959 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
2960 u8 msix_index, u32 reply)
2962 Mpi2SasIoUnitControlReply_t *mpi_reply =
2963 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2965 if (likely(mpi_reply)) {
2966 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2967 "sc_complete:handle(0x%04x), (open) "
2968 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2969 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2970 le16_to_cpu(mpi_reply->IOCStatus),
2971 le32_to_cpu(mpi_reply->IOCLogInfo)));
2973 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2974 ioc->name, __FILE__, __LINE__, __func__);
2980 * _scsih_tm_tr_volume_send - send target reset request for volumes
2981 * @ioc: per adapter object
2982 * @handle: device handle
2983 * Context: interrupt time.
2985 * This is designed to send muliple task management request at the same
2986 * time to the fifo. If the fifo is full, we will append the request,
2987 * and process it in a future completion.
2990 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2992 Mpi2SCSITaskManagementRequest_t *mpi_request;
2994 struct _tr_list *delayed_tr;
2996 if (ioc->shost_recovery || ioc->remove_host ||
2997 ioc->pci_error_recovery) {
2998 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2999 "%s: host reset in progress!\n",
3000 __func__, ioc->name));
3004 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3006 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3009 INIT_LIST_HEAD(&delayed_tr->list);
3010 delayed_tr->handle = handle;
3011 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3012 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3013 "DELAYED:tr:handle(0x%04x), (open)\n",
3014 ioc->name, handle));
3018 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3019 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3020 ioc->name, handle, smid,
3021 ioc->tm_tr_volume_cb_idx));
3022 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3023 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3024 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3025 mpi_request->DevHandle = cpu_to_le16(handle);
3026 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3027 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3031 * _scsih_tm_volume_tr_complete - target reset completion
3032 * @ioc: per adapter object
3033 * @smid: system request message index
3034 * @msix_index: MSIX table index supplied by the OS
3035 * @reply: reply message frame(lower 32bit addr)
3036 * Context: interrupt time.
3038 * Return 1 meaning mf should be freed from _base_interrupt
3039 * 0 means the mf is freed from this function.
3042 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3043 u8 msix_index, u32 reply)
3046 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3047 Mpi2SCSITaskManagementReply_t *mpi_reply =
3048 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3050 if (ioc->shost_recovery || ioc->remove_host ||
3051 ioc->pci_error_recovery) {
3052 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3053 "%s: host reset in progress!\n",
3054 __func__, ioc->name));
3057 if (unlikely(!mpi_reply)) {
3058 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3059 ioc->name, __FILE__, __LINE__, __func__);
3063 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3064 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3065 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3066 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3067 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3069 le16_to_cpu(mpi_reply->DevHandle), smid));
3073 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3074 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3075 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3076 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3077 le32_to_cpu(mpi_reply->IOCLogInfo),
3078 le32_to_cpu(mpi_reply->TerminationCount)));
3080 return _scsih_check_for_pending_tm(ioc, smid);
3085 * _scsih_check_for_pending_tm - check for pending task management
3086 * @ioc: per adapter object
3087 * @smid: system request message index
3089 * This will check delayed target reset list, and feed the
3092 * Return 1 meaning mf should be freed from _base_interrupt
3093 * 0 means the mf is freed from this function.
3096 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3098 struct _tr_list *delayed_tr;
3100 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3101 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3102 struct _tr_list, list);
3103 mpt3sas_base_free_smid(ioc, smid);
3104 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3105 list_del(&delayed_tr->list);
3110 if (!list_empty(&ioc->delayed_tr_list)) {
3111 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3112 struct _tr_list, list);
3113 mpt3sas_base_free_smid(ioc, smid);
3114 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3115 list_del(&delayed_tr->list);
3124 * _scsih_check_topo_delete_events - sanity check on topo events
3125 * @ioc: per adapter object
3126 * @event_data: the event data payload
3128 * This routine added to better handle cable breaker.
3130 * This handles the case where driver receives multiple expander
3131 * add and delete events in a single shot. When there is a delete event
3132 * the routine will void any pending add events waiting in the event queue.
3137 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3138 Mpi2EventDataSasTopologyChangeList_t *event_data)
3140 struct fw_event_work *fw_event;
3141 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3142 u16 expander_handle;
3143 struct _sas_node *sas_expander;
3144 unsigned long flags;
3148 for (i = 0 ; i < event_data->NumEntries; i++) {
3149 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3152 reason_code = event_data->PHY[i].PhyStatus &
3153 MPI2_EVENT_SAS_TOPO_RC_MASK;
3154 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3155 _scsih_tm_tr_send(ioc, handle);
3158 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3159 if (expander_handle < ioc->sas_hba.num_phys) {
3160 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3163 if (event_data->ExpStatus ==
3164 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3165 /* put expander attached devices into blocking state */
3166 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3167 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3169 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3170 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3172 handle = find_first_bit(ioc->blocking_handles,
3173 ioc->facts.MaxDevHandle);
3174 if (handle < ioc->facts.MaxDevHandle)
3175 _scsih_block_io_device(ioc, handle);
3176 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3177 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3178 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3180 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3183 /* mark ignore flag for pending events */
3184 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3185 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3186 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3189 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3190 fw_event->event_data;
3191 if (local_event_data->ExpStatus ==
3192 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3193 local_event_data->ExpStatus ==
3194 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3195 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3197 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3198 "setting ignoring flag\n", ioc->name));
3199 fw_event->ignore = 1;
3203 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3207 * _scsih_set_volume_delete_flag - setting volume delete flag
3208 * @ioc: per adapter object
3209 * @handle: device handle
3211 * This returns nothing.
3214 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3216 struct _raid_device *raid_device;
3217 struct MPT3SAS_TARGET *sas_target_priv_data;
3218 unsigned long flags;
3220 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3221 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3222 if (raid_device && raid_device->starget &&
3223 raid_device->starget->hostdata) {
3224 sas_target_priv_data =
3225 raid_device->starget->hostdata;
3226 sas_target_priv_data->deleted = 1;
3227 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3228 "setting delete flag: handle(0x%04x), "
3229 "wwid(0x%016llx)\n", ioc->name, handle,
3230 (unsigned long long) raid_device->wwid));
3232 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3236 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3237 * @handle: input handle
3238 * @a: handle for volume a
3239 * @b: handle for volume b
3241 * IR firmware only supports two raid volumes. The purpose of this
3242 * routine is to set the volume handle in either a or b. When the given
3243 * input handle is non-zero, or when a and b have not been set before.
3246 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3248 if (!handle || handle == *a || handle == *b)
3257 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3258 * @ioc: per adapter object
3259 * @event_data: the event data payload
3260 * Context: interrupt time.
3262 * This routine will send target reset to volume, followed by target
3263 * resets to the PDs. This is called when a PD has been removed, or
3264 * volume has been deleted or removed. When the target reset is sent
3265 * to volume, the PD target resets need to be queued to start upon
3266 * completion of the volume target reset.
3271 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3272 Mpi2EventDataIrConfigChangeList_t *event_data)
3274 Mpi2EventIrConfigElement_t *element;
3276 u16 handle, volume_handle, a, b;
3277 struct _tr_list *delayed_tr;
3282 /* Volume Resets for Deleted or Removed */
3283 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3284 for (i = 0; i < event_data->NumElements; i++, element++) {
3285 if (le32_to_cpu(event_data->Flags) &
3286 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3288 if (element->ReasonCode ==
3289 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3290 element->ReasonCode ==
3291 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3292 volume_handle = le16_to_cpu(element->VolDevHandle);
3293 _scsih_set_volume_delete_flag(ioc, volume_handle);
3294 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3298 /* Volume Resets for UNHIDE events */
3299 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3300 for (i = 0; i < event_data->NumElements; i++, element++) {
3301 if (le32_to_cpu(event_data->Flags) &
3302 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3304 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3305 volume_handle = le16_to_cpu(element->VolDevHandle);
3306 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3311 _scsih_tm_tr_volume_send(ioc, a);
3313 _scsih_tm_tr_volume_send(ioc, b);
3315 /* PD target resets */
3316 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3317 for (i = 0; i < event_data->NumElements; i++, element++) {
3318 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3320 handle = le16_to_cpu(element->PhysDiskDevHandle);
3321 volume_handle = le16_to_cpu(element->VolDevHandle);
3322 clear_bit(handle, ioc->pd_handles);
3324 _scsih_tm_tr_send(ioc, handle);
3325 else if (volume_handle == a || volume_handle == b) {
3326 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3327 BUG_ON(!delayed_tr);
3328 INIT_LIST_HEAD(&delayed_tr->list);
3329 delayed_tr->handle = handle;
3330 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3331 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3332 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3335 _scsih_tm_tr_send(ioc, handle);
3341 * _scsih_check_volume_delete_events - set delete flag for volumes
3342 * @ioc: per adapter object
3343 * @event_data: the event data payload
3344 * Context: interrupt time.
3346 * This will handle the case when the cable connected to entire volume is
3347 * pulled. We will take care of setting the deleted flag so normal IO will
3353 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3354 Mpi2EventDataIrVolume_t *event_data)
3358 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3360 state = le32_to_cpu(event_data->NewValue);
3361 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3362 MPI2_RAID_VOL_STATE_FAILED)
3363 _scsih_set_volume_delete_flag(ioc,
3364 le16_to_cpu(event_data->VolDevHandle));
3368 * _scsih_flush_running_cmds - completing outstanding commands.
3369 * @ioc: per adapter object
3371 * The flushing out of all pending scmd commands following host reset,
3372 * where all IO is dropped to the floor.
3377 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3379 struct scsi_cmnd *scmd;
3383 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3384 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3388 mpt3sas_base_free_smid(ioc, smid);
3389 scsi_dma_unmap(scmd);
3390 if (ioc->pci_error_recovery)
3391 scmd->result = DID_NO_CONNECT << 16;
3393 scmd->result = DID_RESET << 16;
3394 scmd->scsi_done(scmd);
3396 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3401 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3402 * @ioc: per adapter object
3403 * @scmd: pointer to scsi command object
3404 * @mpi_request: pointer to the SCSI_IO reqest message frame
3406 * Supporting protection 1 and 3.
3411 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3412 Mpi2SCSIIORequest_t *mpi_request)
3415 unsigned char prot_op = scsi_get_prot_op(scmd);
3416 unsigned char prot_type = scsi_get_prot_type(scmd);
3417 Mpi25SCSIIORequest_t *mpi_request_3v =
3418 (Mpi25SCSIIORequest_t *)mpi_request;
3420 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3423 if (prot_op == SCSI_PROT_READ_STRIP)
3424 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3425 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3426 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3430 switch (prot_type) {
3431 case SCSI_PROT_DIF_TYPE1:
3432 case SCSI_PROT_DIF_TYPE2:
3435 * enable ref/guard checking
3436 * auto increment ref tag
3438 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3439 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3440 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3441 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3442 cpu_to_be32(scsi_get_lba(scmd));
3445 case SCSI_PROT_DIF_TYPE3:
3448 * enable guard checking
3450 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3455 mpi_request_3v->EEDPBlockSize =
3456 cpu_to_le16(scmd->device->sector_size);
3457 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3461 * _scsih_eedp_error_handling - return sense code for EEDP errors
3462 * @scmd: pointer to scsi command object
3463 * @ioc_status: ioc status
3468 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3472 switch (ioc_status) {
3473 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3476 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3479 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3486 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3488 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3489 SAM_STAT_CHECK_CONDITION;
3494 * _scsih_qcmd - main scsi request entry point
3495 * @scmd: pointer to scsi command object
3496 * @done: function pointer to be invoked on completion
3498 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3500 * Returns 0 on success. If there's a failure, return either:
3501 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3502 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3505 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3507 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3508 struct MPT3SAS_DEVICE *sas_device_priv_data;
3509 struct MPT3SAS_TARGET *sas_target_priv_data;
3510 Mpi2SCSIIORequest_t *mpi_request;
3515 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3516 if (ioc->logging_level & MPT_DEBUG_SCSI)
3517 scsi_print_command(scmd);
3520 sas_device_priv_data = scmd->device->hostdata;
3521 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3522 scmd->result = DID_NO_CONNECT << 16;
3523 scmd->scsi_done(scmd);
3527 if (ioc->pci_error_recovery || ioc->remove_host) {
3528 scmd->result = DID_NO_CONNECT << 16;
3529 scmd->scsi_done(scmd);
3533 sas_target_priv_data = sas_device_priv_data->sas_target;
3535 /* invalid device handle */
3536 handle = sas_target_priv_data->handle;
3537 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3538 scmd->result = DID_NO_CONNECT << 16;
3539 scmd->scsi_done(scmd);
3544 /* host recovery or link resets sent via IOCTLs */
3545 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3546 return SCSI_MLQUEUE_HOST_BUSY;
3548 /* device has been deleted */
3549 else if (sas_target_priv_data->deleted) {
3550 scmd->result = DID_NO_CONNECT << 16;
3551 scmd->scsi_done(scmd);
3553 /* device busy with task managment */
3554 } else if (sas_target_priv_data->tm_busy ||
3555 sas_device_priv_data->block)
3556 return SCSI_MLQUEUE_DEVICE_BUSY;
3558 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3559 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3560 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3561 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3563 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3566 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3567 if (scmd->device->tagged_supported) {
3568 if (scmd->device->ordered_tags)
3569 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3571 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3573 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3575 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3577 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3578 scmd->cmd_len != 32)
3579 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3581 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3583 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3584 ioc->name, __func__);
3587 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3588 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3589 _scsih_setup_eedp(ioc, scmd, mpi_request);
3591 if (scmd->cmd_len == 32)
3592 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3593 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3594 if (sas_device_priv_data->sas_target->flags &
3595 MPT_TARGET_FLAGS_RAID_COMPONENT)
3596 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3598 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3599 mpi_request->DevHandle = cpu_to_le16(handle);
3600 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3601 mpi_request->Control = cpu_to_le32(mpi_control);
3602 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3603 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3604 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3605 mpi_request->SenseBufferLowAddress =
3606 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3607 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3608 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3610 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3612 if (mpi_request->DataLength) {
3613 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3614 mpt3sas_base_free_smid(ioc, smid);
3618 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3620 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3621 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3622 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3623 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3624 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3626 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3628 mpt3sas_base_put_smid_default(ioc, smid);
3632 return SCSI_MLQUEUE_HOST_BUSY;
3636 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3637 * @sense_buffer: sense data returned by target
3638 * @data: normalized skey/asc/ascq
3643 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3645 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3646 /* descriptor format */
3647 data->skey = sense_buffer[1] & 0x0F;
3648 data->asc = sense_buffer[2];
3649 data->ascq = sense_buffer[3];
3652 data->skey = sense_buffer[2] & 0x0F;
3653 data->asc = sense_buffer[12];
3654 data->ascq = sense_buffer[13];
3658 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3660 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3661 * @ioc: per adapter object
3662 * @scmd: pointer to scsi command object
3663 * @mpi_reply: reply mf payload returned from firmware
3665 * scsi_status - SCSI Status code returned from target device
3666 * scsi_state - state info associated with SCSI_IO determined by ioc
3667 * ioc_status - ioc supplied status info
3672 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3673 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3677 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3678 MPI2_IOCSTATUS_MASK;
3679 u8 scsi_state = mpi_reply->SCSIState;
3680 u8 scsi_status = mpi_reply->SCSIStatus;
3681 char *desc_ioc_state = NULL;
3682 char *desc_scsi_status = NULL;
3683 char *desc_scsi_state = ioc->tmp_string;
3684 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3685 struct _sas_device *sas_device = NULL;
3686 unsigned long flags;
3687 struct scsi_target *starget = scmd->device->sdev_target;
3688 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3689 char *device_str = NULL;
3693 device_str = "volume";
3695 if (log_info == 0x31170000)
3698 switch (ioc_status) {
3699 case MPI2_IOCSTATUS_SUCCESS:
3700 desc_ioc_state = "success";
3702 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3703 desc_ioc_state = "invalid function";
3705 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3706 desc_ioc_state = "scsi recovered error";
3708 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3709 desc_ioc_state = "scsi invalid dev handle";
3711 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3712 desc_ioc_state = "scsi device not there";
3714 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3715 desc_ioc_state = "scsi data overrun";
3717 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3718 desc_ioc_state = "scsi data underrun";
3720 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3721 desc_ioc_state = "scsi io data error";
3723 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3724 desc_ioc_state = "scsi protocol error";
3726 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3727 desc_ioc_state = "scsi task terminated";
3729 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3730 desc_ioc_state = "scsi residual mismatch";
3732 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3733 desc_ioc_state = "scsi task mgmt failed";
3735 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3736 desc_ioc_state = "scsi ioc terminated";
3738 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3739 desc_ioc_state = "scsi ext terminated";
3741 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3742 desc_ioc_state = "eedp guard error";
3744 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3745 desc_ioc_state = "eedp ref tag error";
3747 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3748 desc_ioc_state = "eedp app tag error";
3751 desc_ioc_state = "unknown";
3755 switch (scsi_status) {
3756 case MPI2_SCSI_STATUS_GOOD:
3757 desc_scsi_status = "good";
3759 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3760 desc_scsi_status = "check condition";
3762 case MPI2_SCSI_STATUS_CONDITION_MET:
3763 desc_scsi_status = "condition met";
3765 case MPI2_SCSI_STATUS_BUSY:
3766 desc_scsi_status = "busy";
3768 case MPI2_SCSI_STATUS_INTERMEDIATE:
3769 desc_scsi_status = "intermediate";
3771 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3772 desc_scsi_status = "intermediate condmet";
3774 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3775 desc_scsi_status = "reservation conflict";
3777 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3778 desc_scsi_status = "command terminated";
3780 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3781 desc_scsi_status = "task set full";
3783 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3784 desc_scsi_status = "aca active";
3786 case MPI2_SCSI_STATUS_TASK_ABORTED:
3787 desc_scsi_status = "task aborted";
3790 desc_scsi_status = "unknown";
3794 desc_scsi_state[0] = '\0';
3796 desc_scsi_state = " ";
3797 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3798 strcat(desc_scsi_state, "response info ");
3799 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3800 strcat(desc_scsi_state, "state terminated ");
3801 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3802 strcat(desc_scsi_state, "no status ");
3803 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3804 strcat(desc_scsi_state, "autosense failed ");
3805 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3806 strcat(desc_scsi_state, "autosense valid ");
3808 scsi_print_command(scmd);
3810 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3811 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3812 device_str, (unsigned long long)priv_target->sas_address);
3814 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3815 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3816 priv_target->sas_address);
3819 "\tsas_address(0x%016llx), phy(%d)\n",
3820 ioc->name, (unsigned long long)
3821 sas_device->sas_address, sas_device->phy);
3823 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3824 ioc->name, (unsigned long long)
3825 sas_device->enclosure_logical_id, sas_device->slot);
3827 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3831 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3832 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3833 desc_ioc_state, ioc_status, smid);
3835 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3836 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3837 scsi_get_resid(scmd));
3839 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3840 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3841 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3843 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3844 ioc->name, desc_scsi_status,
3845 scsi_status, desc_scsi_state, scsi_state);
3847 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3848 struct sense_info data;
3849 _scsih_normalize_sense(scmd->sense_buffer, &data);
3851 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3852 ioc->name, data.skey,
3853 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3856 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3857 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3858 response_bytes = (u8 *)&response_info;
3859 _scsih_response_code(ioc, response_bytes[0]);
3865 * _scsih_turn_on_pfa_led - illuminate PFA LED
3866 * @ioc: per adapter object
3867 * @handle: device handle
3873 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3875 Mpi2SepReply_t mpi_reply;
3876 Mpi2SepRequest_t mpi_request;
3877 struct _sas_device *sas_device;
3879 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3883 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3884 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3885 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3886 mpi_request.SlotStatus =
3887 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3888 mpi_request.DevHandle = cpu_to_le16(handle);
3889 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3890 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3891 &mpi_request)) != 0) {
3892 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3893 __FILE__, __LINE__, __func__);
3896 sas_device->pfa_led_on = 1;
3898 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3899 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3900 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3901 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3902 le32_to_cpu(mpi_reply.IOCLogInfo)));
3907 * _scsih_turn_off_pfa_led - turn off Fault LED
3908 * @ioc: per adapter object
3909 * @sas_device: sas device whose PFA LED has to turned off
3915 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
3916 struct _sas_device *sas_device)
3918 Mpi2SepReply_t mpi_reply;
3919 Mpi2SepRequest_t mpi_request;
3921 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3922 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3923 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3924 mpi_request.SlotStatus = 0;
3925 mpi_request.Slot = cpu_to_le16(sas_device->slot);
3926 mpi_request.DevHandle = 0;
3927 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
3928 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
3929 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3930 &mpi_request)) != 0) {
3931 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3932 __FILE__, __LINE__, __func__);
3936 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3937 dewtprintk(ioc, printk(MPT3SAS_FMT
3938 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3939 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3940 le32_to_cpu(mpi_reply.IOCLogInfo)));
3945 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
3946 * @ioc: per adapter object
3947 * @handle: device handle
3948 * Context: interrupt.
3953 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3955 struct fw_event_work *fw_event;
3957 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
3960 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
3961 fw_event->device_handle = handle;
3962 fw_event->ioc = ioc;
3963 _scsih_fw_event_add(ioc, fw_event);
3967 * _scsih_smart_predicted_fault - process smart errors
3968 * @ioc: per adapter object
3969 * @handle: device handle
3970 * Context: interrupt.
3975 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3977 struct scsi_target *starget;
3978 struct MPT3SAS_TARGET *sas_target_priv_data;
3979 Mpi2EventNotificationReply_t *event_reply;
3980 Mpi2EventDataSasDeviceStatusChange_t *event_data;
3981 struct _sas_device *sas_device;
3983 unsigned long flags;
3985 /* only handle non-raid devices */
3986 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3987 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3989 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3992 starget = sas_device->starget;
3993 sas_target_priv_data = starget->hostdata;
3995 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
3996 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
3997 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4000 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4001 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4003 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4004 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4006 /* insert into event log */
4007 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4008 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4009 event_reply = kzalloc(sz, GFP_KERNEL);
4011 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4012 ioc->name, __FILE__, __LINE__, __func__);
4016 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4017 event_reply->Event =
4018 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4019 event_reply->MsgLength = sz/4;
4020 event_reply->EventDataLength =
4021 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4022 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4023 event_reply->EventData;
4024 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4025 event_data->ASC = 0x5D;
4026 event_data->DevHandle = cpu_to_le16(handle);
4027 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4028 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4033 * _scsih_io_done - scsi request callback
4034 * @ioc: per adapter object
4035 * @smid: system request message index
4036 * @msix_index: MSIX table index supplied by the OS
4037 * @reply: reply message frame(lower 32bit addr)
4039 * Callback handler when using _scsih_qcmd.
4041 * Return 1 meaning mf should be freed from _base_interrupt
4042 * 0 means the mf is freed from this function.
4045 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4047 Mpi2SCSIIORequest_t *mpi_request;
4048 Mpi2SCSIIOReply_t *mpi_reply;
4049 struct scsi_cmnd *scmd;
4055 struct MPT3SAS_DEVICE *sas_device_priv_data;
4056 u32 response_code = 0;
4058 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4059 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4063 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4065 if (mpi_reply == NULL) {
4066 scmd->result = DID_OK << 16;
4070 sas_device_priv_data = scmd->device->hostdata;
4071 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4072 sas_device_priv_data->sas_target->deleted) {
4073 scmd->result = DID_NO_CONNECT << 16;
4076 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4078 /* turning off TLR */
4079 scsi_state = mpi_reply->SCSIState;
4080 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4082 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4083 if (!sas_device_priv_data->tlr_snoop_check) {
4084 sas_device_priv_data->tlr_snoop_check++;
4085 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4086 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4087 sas_device_priv_data->flags &=
4091 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4092 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4093 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4094 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4097 ioc_status &= MPI2_IOCSTATUS_MASK;
4098 scsi_status = mpi_reply->SCSIStatus;
4100 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4101 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4102 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4103 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4104 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4107 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4108 struct sense_info data;
4109 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4111 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4112 le32_to_cpu(mpi_reply->SenseCount));
4113 memcpy(scmd->sense_buffer, sense_data, sz);
4114 _scsih_normalize_sense(scmd->sense_buffer, &data);
4115 /* failure prediction threshold exceeded */
4116 if (data.asc == 0x5D)
4117 _scsih_smart_predicted_fault(ioc,
4118 le16_to_cpu(mpi_reply->DevHandle));
4119 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4122 switch (ioc_status) {
4123 case MPI2_IOCSTATUS_BUSY:
4124 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4125 scmd->result = SAM_STAT_BUSY;
4128 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4129 scmd->result = DID_NO_CONNECT << 16;
4132 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4133 if (sas_device_priv_data->block) {
4134 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4137 if (log_info == 0x31110630) {
4138 if (scmd->retries > 2) {
4139 scmd->result = DID_NO_CONNECT << 16;
4140 scsi_device_set_state(scmd->device,
4143 scmd->result = DID_SOFT_ERROR << 16;
4144 scmd->device->expecting_cc_ua = 1;
4148 scmd->result = DID_SOFT_ERROR << 16;
4150 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4151 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4152 scmd->result = DID_RESET << 16;
4155 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4156 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4157 scmd->result = DID_SOFT_ERROR << 16;
4159 scmd->result = (DID_OK << 16) | scsi_status;
4162 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4163 scmd->result = (DID_OK << 16) | scsi_status;
4165 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4168 if (xfer_cnt < scmd->underflow) {
4169 if (scsi_status == SAM_STAT_BUSY)
4170 scmd->result = SAM_STAT_BUSY;
4172 scmd->result = DID_SOFT_ERROR << 16;
4173 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4174 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4175 scmd->result = DID_SOFT_ERROR << 16;
4176 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4177 scmd->result = DID_RESET << 16;
4178 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4179 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4180 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4181 scmd->result = (DRIVER_SENSE << 24) |
4182 SAM_STAT_CHECK_CONDITION;
4183 scmd->sense_buffer[0] = 0x70;
4184 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4185 scmd->sense_buffer[12] = 0x20;
4186 scmd->sense_buffer[13] = 0;
4190 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4191 scsi_set_resid(scmd, 0);
4192 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4193 case MPI2_IOCSTATUS_SUCCESS:
4194 scmd->result = (DID_OK << 16) | scsi_status;
4195 if (response_code ==
4196 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4197 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4198 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4199 scmd->result = DID_SOFT_ERROR << 16;
4200 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4201 scmd->result = DID_RESET << 16;
4204 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4205 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4206 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4207 _scsih_eedp_error_handling(scmd, ioc_status);
4210 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4211 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4212 case MPI2_IOCSTATUS_INVALID_SGL:
4213 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4214 case MPI2_IOCSTATUS_INVALID_FIELD:
4215 case MPI2_IOCSTATUS_INVALID_STATE:
4216 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4217 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4219 scmd->result = DID_SOFT_ERROR << 16;
4224 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4225 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4226 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4231 scsi_dma_unmap(scmd);
4233 scmd->scsi_done(scmd);
4238 * _scsih_sas_host_refresh - refreshing sas host object contents
4239 * @ioc: per adapter object
4242 * During port enable, fw will send topology events for every device. Its
4243 * possible that the handles may change from the previous setting, so this
4244 * code keeping handles updating if changed.
4249 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4254 Mpi2ConfigReply_t mpi_reply;
4255 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4256 u16 attached_handle;
4259 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4260 "updating handles for sas_host(0x%016llx)\n",
4261 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4263 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4264 * sizeof(Mpi2SasIOUnit0PhyData_t));
4265 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4266 if (!sas_iounit_pg0) {
4267 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4268 ioc->name, __FILE__, __LINE__, __func__);
4272 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4273 sas_iounit_pg0, sz)) != 0)
4275 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4276 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4278 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4279 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4281 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4282 PhyData[0].ControllerDevHandle);
4283 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4284 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4286 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4287 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4288 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4289 attached_handle, i, link_rate);
4292 kfree(sas_iounit_pg0);
4296 * _scsih_sas_host_add - create sas host object
4297 * @ioc: per adapter object
4299 * Creating host side data object, stored in ioc->sas_hba
4304 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4307 Mpi2ConfigReply_t mpi_reply;
4308 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4309 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4310 Mpi2SasPhyPage0_t phy_pg0;
4311 Mpi2SasDevicePage0_t sas_device_pg0;
4312 Mpi2SasEnclosurePage0_t enclosure_pg0;
4315 u8 device_missing_delay;
4317 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4318 if (!ioc->sas_hba.num_phys) {
4319 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4320 ioc->name, __FILE__, __LINE__, __func__);
4324 /* sas_iounit page 0 */
4325 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4326 sizeof(Mpi2SasIOUnit0PhyData_t));
4327 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4328 if (!sas_iounit_pg0) {
4329 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4330 ioc->name, __FILE__, __LINE__, __func__);
4333 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4334 sas_iounit_pg0, sz))) {
4335 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4336 ioc->name, __FILE__, __LINE__, __func__);
4339 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4340 MPI2_IOCSTATUS_MASK;
4341 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4342 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4343 ioc->name, __FILE__, __LINE__, __func__);
4347 /* sas_iounit page 1 */
4348 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4349 sizeof(Mpi2SasIOUnit1PhyData_t));
4350 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4351 if (!sas_iounit_pg1) {
4352 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4353 ioc->name, __FILE__, __LINE__, __func__);
4356 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4357 sas_iounit_pg1, 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 ioc->io_missing_delay =
4371 sas_iounit_pg1->IODeviceMissingDelay;
4372 device_missing_delay =
4373 sas_iounit_pg1->ReportDeviceMissingDelay;
4374 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4375 ioc->device_missing_delay = (device_missing_delay &
4376 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4378 ioc->device_missing_delay = device_missing_delay &
4379 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4381 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4382 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4383 sizeof(struct _sas_phy), GFP_KERNEL);
4384 if (!ioc->sas_hba.phy) {
4385 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4386 ioc->name, __FILE__, __LINE__, __func__);
4389 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4390 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4392 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4393 ioc->name, __FILE__, __LINE__, __func__);
4396 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4397 MPI2_IOCSTATUS_MASK;
4398 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4399 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4400 ioc->name, __FILE__, __LINE__, __func__);
4405 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4406 PhyData[0].ControllerDevHandle);
4407 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4408 ioc->sas_hba.phy[i].phy_id = i;
4409 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4410 phy_pg0, ioc->sas_hba.parent_dev);
4412 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4413 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4414 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4415 ioc->name, __FILE__, __LINE__, __func__);
4418 ioc->sas_hba.enclosure_handle =
4419 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4420 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4422 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4423 ioc->name, ioc->sas_hba.handle,
4424 (unsigned long long) ioc->sas_hba.sas_address,
4425 ioc->sas_hba.num_phys) ;
4427 if (ioc->sas_hba.enclosure_handle) {
4428 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4429 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4430 ioc->sas_hba.enclosure_handle)))
4431 ioc->sas_hba.enclosure_logical_id =
4432 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4436 kfree(sas_iounit_pg1);
4437 kfree(sas_iounit_pg0);
4441 * _scsih_expander_add - creating expander object
4442 * @ioc: per adapter object
4443 * @handle: expander handle
4445 * Creating expander object, stored in ioc->sas_expander_list.
4447 * Return 0 for success, else error.
4450 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4452 struct _sas_node *sas_expander;
4453 Mpi2ConfigReply_t mpi_reply;
4454 Mpi2ExpanderPage0_t expander_pg0;
4455 Mpi2ExpanderPage1_t expander_pg1;
4456 Mpi2SasEnclosurePage0_t enclosure_pg0;
4459 u64 sas_address, sas_address_parent = 0;
4461 unsigned long flags;
4462 struct _sas_port *mpt3sas_port = NULL;
4469 if (ioc->shost_recovery || ioc->pci_error_recovery)
4472 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4473 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4474 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4475 ioc->name, __FILE__, __LINE__, __func__);
4479 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4480 MPI2_IOCSTATUS_MASK;
4481 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4482 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4483 ioc->name, __FILE__, __LINE__, __func__);
4487 /* handle out of order topology events */
4488 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4489 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4491 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4492 ioc->name, __FILE__, __LINE__, __func__);
4495 if (sas_address_parent != ioc->sas_hba.sas_address) {
4496 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4497 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4498 sas_address_parent);
4499 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4500 if (!sas_expander) {
4501 rc = _scsih_expander_add(ioc, parent_handle);
4507 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4508 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4509 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4511 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4516 sas_expander = kzalloc(sizeof(struct _sas_node),
4518 if (!sas_expander) {
4519 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4520 ioc->name, __FILE__, __LINE__, __func__);
4524 sas_expander->handle = handle;
4525 sas_expander->num_phys = expander_pg0.NumPhys;
4526 sas_expander->sas_address_parent = sas_address_parent;
4527 sas_expander->sas_address = sas_address;
4529 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4530 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4531 handle, parent_handle, (unsigned long long)
4532 sas_expander->sas_address, sas_expander->num_phys);
4534 if (!sas_expander->num_phys)
4536 sas_expander->phy = kcalloc(sas_expander->num_phys,
4537 sizeof(struct _sas_phy), GFP_KERNEL);
4538 if (!sas_expander->phy) {
4539 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4540 ioc->name, __FILE__, __LINE__, __func__);
4545 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4546 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4547 sas_address_parent);
4548 if (!mpt3sas_port) {
4549 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4550 ioc->name, __FILE__, __LINE__, __func__);
4554 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4556 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4557 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4558 &expander_pg1, i, handle))) {
4559 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4560 ioc->name, __FILE__, __LINE__, __func__);
4564 sas_expander->phy[i].handle = handle;
4565 sas_expander->phy[i].phy_id = i;
4567 if ((mpt3sas_transport_add_expander_phy(ioc,
4568 &sas_expander->phy[i], expander_pg1,
4569 sas_expander->parent_dev))) {
4570 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4571 ioc->name, __FILE__, __LINE__, __func__);
4577 if (sas_expander->enclosure_handle) {
4578 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4579 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4580 sas_expander->enclosure_handle)))
4581 sas_expander->enclosure_logical_id =
4582 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4585 _scsih_expander_node_add(ioc, sas_expander);
4591 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4592 sas_address_parent);
4593 kfree(sas_expander);
4598 * mpt3sas_expander_remove - removing expander object
4599 * @ioc: per adapter object
4600 * @sas_address: expander sas_address
4605 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4607 struct _sas_node *sas_expander;
4608 unsigned long flags;
4610 if (ioc->shost_recovery)
4613 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4614 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4617 list_del(&sas_expander->list);
4618 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4620 _scsih_expander_node_remove(ioc, sas_expander);
4624 * _scsih_done - internal SCSI_IO callback handler.
4625 * @ioc: per adapter object
4626 * @smid: system request message index
4627 * @msix_index: MSIX table index supplied by the OS
4628 * @reply: reply message frame(lower 32bit addr)
4630 * Callback handler when sending internal generated SCSI_IO.
4631 * The callback index passed is `ioc->scsih_cb_idx`
4633 * Return 1 meaning mf should be freed from _base_interrupt
4634 * 0 means the mf is freed from this function.
4637 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4639 MPI2DefaultReply_t *mpi_reply;
4641 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4642 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4644 if (ioc->scsih_cmds.smid != smid)
4646 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4648 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4649 mpi_reply->MsgLength*4);
4650 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4652 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4653 complete(&ioc->scsih_cmds.done);
4660 #define MPT3_MAX_LUNS (255)
4664 * _scsih_check_access_status - check access flags
4665 * @ioc: per adapter object
4666 * @sas_address: sas address
4667 * @handle: sas device handle
4668 * @access_flags: errors returned during discovery of the device
4670 * Return 0 for success, else failure
4673 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4674 u16 handle, u8 access_status)
4679 switch (access_status) {
4680 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4681 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4684 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4685 desc = "sata capability failed";
4687 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4688 desc = "sata affiliation conflict";
4690 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4691 desc = "route not addressable";
4693 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4694 desc = "smp error not addressable";
4696 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4697 desc = "device blocked";
4699 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4700 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4701 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4702 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4703 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4704 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4705 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4706 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4707 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4708 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4709 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4710 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4711 desc = "sata initialization failed";
4722 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4723 ioc->name, desc, (unsigned long long)sas_address, handle);
4728 * _scsih_check_device - checking device responsiveness
4729 * @ioc: per adapter object
4730 * @parent_sas_address: sas address of parent expander or sas host
4731 * @handle: attached device handle
4732 * @phy_numberv: phy number
4733 * @link_rate: new link rate
4738 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4739 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4741 Mpi2ConfigReply_t mpi_reply;
4742 Mpi2SasDevicePage0_t sas_device_pg0;
4743 struct _sas_device *sas_device;
4745 unsigned long flags;
4747 struct scsi_target *starget;
4748 struct MPT3SAS_TARGET *sas_target_priv_data;
4752 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4753 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4756 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4757 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4760 /* wide port handling ~ we need only handle device once for the phy that
4761 * is matched in sas device page zero
4763 if (phy_number != sas_device_pg0.PhyNum)
4766 /* check if this is end device */
4767 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4768 if (!(_scsih_is_end_device(device_info)))
4771 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4772 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4773 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4777 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4781 if (unlikely(sas_device->handle != handle)) {
4782 starget = sas_device->starget;
4783 sas_target_priv_data = starget->hostdata;
4784 starget_printk(KERN_INFO, starget,
4785 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4786 sas_device->handle, handle);
4787 sas_target_priv_data->handle = handle;
4788 sas_device->handle = handle;
4791 /* check if device is present */
4792 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4793 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4795 "device is not present handle(0x%04x), flags!!!\n",
4797 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4801 /* check if there were any issues with discovery */
4802 if (_scsih_check_access_status(ioc, sas_address, handle,
4803 sas_device_pg0.AccessStatus)) {
4804 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4808 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4809 _scsih_ublock_io_device(ioc, sas_address);
4814 * _scsih_add_device - creating sas device object
4815 * @ioc: per adapter object
4816 * @handle: sas device handle
4817 * @phy_num: phy number end device attached to
4818 * @is_pd: is this hidden raid component
4820 * Creating end device object, stored in ioc->sas_device_list.
4822 * Returns 0 for success, non-zero for failure.
4825 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4828 Mpi2ConfigReply_t mpi_reply;
4829 Mpi2SasDevicePage0_t sas_device_pg0;
4830 Mpi2SasEnclosurePage0_t enclosure_pg0;
4831 struct _sas_device *sas_device;
4835 unsigned long flags;
4837 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4838 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4839 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4840 ioc->name, __FILE__, __LINE__, __func__);
4844 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4845 MPI2_IOCSTATUS_MASK;
4846 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4847 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4848 ioc->name, __FILE__, __LINE__, __func__);
4852 /* check if this is end device */
4853 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4854 if (!(_scsih_is_end_device(device_info)))
4856 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4858 /* check if device is present */
4859 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4860 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4861 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4866 /* check if there were any issues with discovery */
4867 if (_scsih_check_access_status(ioc, sas_address, handle,
4868 sas_device_pg0.AccessStatus))
4871 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4872 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4874 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4879 sas_device = kzalloc(sizeof(struct _sas_device),
4882 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4883 ioc->name, __FILE__, __LINE__, __func__);
4887 sas_device->handle = handle;
4888 if (_scsih_get_sas_address(ioc,
4889 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4890 &sas_device->sas_address_parent) != 0)
4891 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4892 ioc->name, __FILE__, __LINE__, __func__);
4893 sas_device->enclosure_handle =
4894 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4896 le16_to_cpu(sas_device_pg0.Slot);
4897 sas_device->device_info = device_info;
4898 sas_device->sas_address = sas_address;
4899 sas_device->phy = sas_device_pg0.PhyNum;
4900 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
4901 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
4903 /* get enclosure_logical_id */
4904 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
4905 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4906 sas_device->enclosure_handle)))
4907 sas_device->enclosure_logical_id =
4908 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4910 /* get device name */
4911 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
4913 if (ioc->wait_for_discovery_to_complete)
4914 _scsih_sas_device_init_add(ioc, sas_device);
4916 _scsih_sas_device_add(ioc, sas_device);
4922 * _scsih_remove_device - removing sas device object
4923 * @ioc: per adapter object
4924 * @sas_device_delete: the sas_device object
4929 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
4930 struct _sas_device *sas_device)
4932 struct MPT3SAS_TARGET *sas_target_priv_data;
4934 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
4935 (sas_device->pfa_led_on)) {
4936 _scsih_turn_off_pfa_led(ioc, sas_device);
4937 sas_device->pfa_led_on = 0;
4939 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4940 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4941 ioc->name, __func__,
4942 sas_device->handle, (unsigned long long)
4943 sas_device->sas_address));
4945 if (sas_device->starget && sas_device->starget->hostdata) {
4946 sas_target_priv_data = sas_device->starget->hostdata;
4947 sas_target_priv_data->deleted = 1;
4948 _scsih_ublock_io_device(ioc, sas_device->sas_address);
4949 sas_target_priv_data->handle =
4950 MPT3SAS_INVALID_DEVICE_HANDLE;
4952 mpt3sas_transport_port_remove(ioc,
4953 sas_device->sas_address,
4954 sas_device->sas_address_parent);
4957 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4958 ioc->name, sas_device->handle,
4959 (unsigned long long) sas_device->sas_address);
4961 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4962 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4963 ioc->name, __func__,
4964 sas_device->handle, (unsigned long long)
4965 sas_device->sas_address));
4970 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4972 * _scsih_sas_topology_change_event_debug - debug for topology event
4973 * @ioc: per adapter object
4974 * @event_data: event data payload
4978 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
4979 Mpi2EventDataSasTopologyChangeList_t *event_data)
4985 char *status_str = NULL;
4986 u8 link_rate, prev_link_rate;
4988 switch (event_data->ExpStatus) {
4989 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
4992 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
4993 status_str = "remove";
4995 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
4997 status_str = "responding";
4999 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5000 status_str = "remove delay";
5003 status_str = "unknown status";
5006 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5007 ioc->name, status_str);
5008 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5009 "start_phy(%02d), count(%d)\n",
5010 le16_to_cpu(event_data->ExpanderDevHandle),
5011 le16_to_cpu(event_data->EnclosureHandle),
5012 event_data->StartPhyNum, event_data->NumEntries);
5013 for (i = 0; i < event_data->NumEntries; i++) {
5014 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5017 phy_number = event_data->StartPhyNum + i;
5018 reason_code = event_data->PHY[i].PhyStatus &
5019 MPI2_EVENT_SAS_TOPO_RC_MASK;
5020 switch (reason_code) {
5021 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5022 status_str = "target add";
5024 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5025 status_str = "target remove";
5027 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5028 status_str = "delay target remove";
5030 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5031 status_str = "link rate change";
5033 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5034 status_str = "target responding";
5037 status_str = "unknown";
5040 link_rate = event_data->PHY[i].LinkRate >> 4;
5041 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5042 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5043 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5044 handle, status_str, link_rate, prev_link_rate);
5051 * _scsih_sas_topology_change_event - handle topology changes
5052 * @ioc: per adapter object
5053 * @fw_event: The fw_event_work object
5058 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5059 struct fw_event_work *fw_event)
5062 u16 parent_handle, handle;
5064 u8 phy_number, max_phys;
5065 struct _sas_node *sas_expander;
5067 unsigned long flags;
5068 u8 link_rate, prev_link_rate;
5069 Mpi2EventDataSasTopologyChangeList_t *event_data =
5070 (Mpi2EventDataSasTopologyChangeList_t *)
5071 fw_event->event_data;
5073 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5074 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5075 _scsih_sas_topology_change_event_debug(ioc, event_data);
5078 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5081 if (!ioc->sas_hba.num_phys)
5082 _scsih_sas_host_add(ioc);
5084 _scsih_sas_host_refresh(ioc);
5086 if (fw_event->ignore) {
5087 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5088 "ignoring expander event\n", ioc->name));
5092 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5094 /* handle expander add */
5095 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5096 if (_scsih_expander_add(ioc, parent_handle) != 0)
5099 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5100 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5103 sas_address = sas_expander->sas_address;
5104 max_phys = sas_expander->num_phys;
5105 } else if (parent_handle < ioc->sas_hba.num_phys) {
5106 sas_address = ioc->sas_hba.sas_address;
5107 max_phys = ioc->sas_hba.num_phys;
5109 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5112 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5114 /* handle siblings events */
5115 for (i = 0; i < event_data->NumEntries; i++) {
5116 if (fw_event->ignore) {
5117 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5118 "ignoring expander event\n", ioc->name));
5121 if (ioc->remove_host || ioc->pci_error_recovery)
5123 phy_number = event_data->StartPhyNum + i;
5124 if (phy_number >= max_phys)
5126 reason_code = event_data->PHY[i].PhyStatus &
5127 MPI2_EVENT_SAS_TOPO_RC_MASK;
5128 if ((event_data->PHY[i].PhyStatus &
5129 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5130 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5132 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5135 link_rate = event_data->PHY[i].LinkRate >> 4;
5136 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5137 switch (reason_code) {
5138 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5140 if (ioc->shost_recovery)
5143 if (link_rate == prev_link_rate)
5146 mpt3sas_transport_update_links(ioc, sas_address,
5147 handle, phy_number, link_rate);
5149 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5152 _scsih_check_device(ioc, sas_address, handle,
5153 phy_number, link_rate);
5156 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5158 if (ioc->shost_recovery)
5161 mpt3sas_transport_update_links(ioc, sas_address,
5162 handle, phy_number, link_rate);
5164 _scsih_add_device(ioc, handle, phy_number, 0);
5167 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5169 _scsih_device_remove_by_handle(ioc, handle);
5174 /* handle expander removal */
5175 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5177 mpt3sas_expander_remove(ioc, sas_address);
5182 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5184 * _scsih_sas_device_status_change_event_debug - debug for device event
5185 * @event_data: event data payload
5191 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5192 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5194 char *reason_str = NULL;
5196 switch (event_data->ReasonCode) {
5197 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5198 reason_str = "smart data";
5200 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5201 reason_str = "unsupported device discovered";
5203 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5204 reason_str = "internal device reset";
5206 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5207 reason_str = "internal task abort";
5209 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5210 reason_str = "internal task abort set";
5212 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5213 reason_str = "internal clear task set";
5215 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5216 reason_str = "internal query task";
5218 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5219 reason_str = "sata init failure";
5221 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5222 reason_str = "internal device reset complete";
5224 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5225 reason_str = "internal task abort complete";
5227 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5228 reason_str = "internal async notification";
5230 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5231 reason_str = "expander reduced functionality";
5233 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5234 reason_str = "expander reduced functionality complete";
5237 reason_str = "unknown reason";
5240 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5241 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5242 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5243 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5244 le16_to_cpu(event_data->TaskTag));
5245 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5246 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5247 event_data->ASC, event_data->ASCQ);
5253 * _scsih_sas_device_status_change_event - handle device status change
5254 * @ioc: per adapter object
5255 * @fw_event: The fw_event_work object
5261 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5262 struct fw_event_work *fw_event)
5264 struct MPT3SAS_TARGET *target_priv_data;
5265 struct _sas_device *sas_device;
5267 unsigned long flags;
5268 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5269 (Mpi2EventDataSasDeviceStatusChange_t *)
5270 fw_event->event_data;
5272 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5273 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5274 _scsih_sas_device_status_change_event_debug(ioc,
5278 /* In MPI Revision K (0xC), the internal device reset complete was
5279 * implemented, so avoid setting tm_busy flag for older firmware.
5281 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5284 if (event_data->ReasonCode !=
5285 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5286 event_data->ReasonCode !=
5287 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5290 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5291 sas_address = le64_to_cpu(event_data->SASAddress);
5292 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5295 if (!sas_device || !sas_device->starget) {
5296 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5300 target_priv_data = sas_device->starget->hostdata;
5301 if (!target_priv_data) {
5302 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5306 if (event_data->ReasonCode ==
5307 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5308 target_priv_data->tm_busy = 1;
5310 target_priv_data->tm_busy = 0;
5311 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5314 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5316 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5318 * @ioc: per adapter object
5319 * @event_data: event data payload
5325 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5326 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5328 char *reason_str = NULL;
5330 switch (event_data->ReasonCode) {
5331 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5332 reason_str = "enclosure add";
5334 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5335 reason_str = "enclosure remove";
5338 reason_str = "unknown reason";
5342 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5343 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5344 " number slots(%d)\n", ioc->name, reason_str,
5345 le16_to_cpu(event_data->EnclosureHandle),
5346 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5347 le16_to_cpu(event_data->StartSlot));
5352 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5353 * @ioc: per adapter object
5354 * @fw_event: The fw_event_work object
5360 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5361 struct fw_event_work *fw_event)
5363 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5364 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5365 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5366 (Mpi2EventDataSasEnclDevStatusChange_t *)
5367 fw_event->event_data);
5372 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5373 * @ioc: per adapter object
5374 * @fw_event: The fw_event_work object
5380 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5381 struct fw_event_work *fw_event)
5383 struct scsi_cmnd *scmd;
5384 struct scsi_device *sdev;
5387 struct MPT3SAS_DEVICE *sas_device_priv_data;
5388 u32 termination_count;
5390 Mpi2SCSITaskManagementReply_t *mpi_reply;
5391 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5392 (Mpi2EventDataSasBroadcastPrimitive_t *)
5393 fw_event->event_data;
5395 unsigned long flags;
5398 u8 task_abort_retries;
5400 mutex_lock(&ioc->tm_cmds.mutex);
5402 "%s: enter: phy number(%d), width(%d)\n",
5403 ioc->name, __func__, event_data->PhyNum,
5404 event_data->PortWidth);
5406 _scsih_block_io_all_device(ioc);
5408 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5409 mpi_reply = ioc->tm_cmds.reply;
5410 broadcast_aen_retry:
5412 /* sanity checks for retrying this loop */
5413 if (max_retries++ == 5) {
5414 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5415 ioc->name, __func__));
5417 } else if (max_retries > 1)
5418 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5419 ioc->name, __func__, max_retries - 1));
5421 termination_count = 0;
5423 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5424 if (ioc->shost_recovery)
5426 scmd = _scsih_scsi_lookup_get(ioc, smid);
5429 sdev = scmd->device;
5430 sas_device_priv_data = sdev->hostdata;
5431 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5433 /* skip hidden raid components */
5434 if (sas_device_priv_data->sas_target->flags &
5435 MPT_TARGET_FLAGS_RAID_COMPONENT)
5438 if (sas_device_priv_data->sas_target->flags &
5439 MPT_TARGET_FLAGS_VOLUME)
5442 handle = sas_device_priv_data->sas_target->handle;
5443 lun = sas_device_priv_data->lun;
5446 if (ioc->shost_recovery)
5449 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5450 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5451 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5454 sdev_printk(KERN_WARNING, sdev,
5455 "mpt3sas_scsih_issue_tm: FAILED when sending "
5456 "QUERY_TASK: scmd(%p)\n", scmd);
5457 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5458 goto broadcast_aen_retry;
5460 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5461 & MPI2_IOCSTATUS_MASK;
5462 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5463 sdev_printk(KERN_WARNING, sdev,
5464 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5466 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5467 goto broadcast_aen_retry;
5470 /* see if IO is still owned by IOC and target */
5471 if (mpi_reply->ResponseCode ==
5472 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5473 mpi_reply->ResponseCode ==
5474 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5475 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5478 task_abort_retries = 0;
5480 if (task_abort_retries++ == 60) {
5481 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5482 "%s: ABORT_TASK: giving up\n", ioc->name,
5484 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5485 goto broadcast_aen_retry;
5488 if (ioc->shost_recovery)
5491 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5492 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5495 sdev_printk(KERN_WARNING, sdev,
5496 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5497 "scmd(%p)\n", scmd);
5501 if (task_abort_retries > 1)
5502 sdev_printk(KERN_WARNING, sdev,
5503 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5505 task_abort_retries - 1, scmd);
5507 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5508 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5511 if (ioc->broadcast_aen_pending) {
5512 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5513 "%s: loop back due to pending AEN\n",
5514 ioc->name, __func__));
5515 ioc->broadcast_aen_pending = 0;
5516 goto broadcast_aen_retry;
5520 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5523 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5524 "%s - exit, query_count = %d termination_count = %d\n",
5525 ioc->name, __func__, query_count, termination_count));
5527 ioc->broadcast_aen_busy = 0;
5528 if (!ioc->shost_recovery)
5529 _scsih_ublock_io_all_device(ioc);
5530 mutex_unlock(&ioc->tm_cmds.mutex);
5534 * _scsih_sas_discovery_event - handle discovery events
5535 * @ioc: per adapter object
5536 * @fw_event: The fw_event_work object
5542 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5543 struct fw_event_work *fw_event)
5545 Mpi2EventDataSasDiscovery_t *event_data =
5546 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5548 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5549 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5550 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5551 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5553 if (event_data->DiscoveryStatus)
5554 pr_info("discovery_status(0x%08x)",
5555 le32_to_cpu(event_data->DiscoveryStatus));
5560 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5561 !ioc->sas_hba.num_phys) {
5562 if (disable_discovery > 0 && ioc->shost_recovery) {
5563 /* Wait for the reset to complete */
5564 while (ioc->shost_recovery)
5567 _scsih_sas_host_add(ioc);
5572 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5573 * @ioc: per adapter object
5574 * @handle: device handle for physical disk
5575 * @phys_disk_num: physical disk number
5577 * Return 0 for success, else failure.
5580 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5582 Mpi2RaidActionRequest_t *mpi_request;
5583 Mpi2RaidActionReply_t *mpi_reply;
5591 mutex_lock(&ioc->scsih_cmds.mutex);
5593 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5594 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5595 ioc->name, __func__);
5599 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5601 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5603 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5604 ioc->name, __func__);
5605 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5610 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5611 ioc->scsih_cmds.smid = smid;
5612 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5614 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5615 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5616 mpi_request->PhysDiskNum = phys_disk_num;
5618 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5619 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5620 handle, phys_disk_num));
5622 init_completion(&ioc->scsih_cmds.done);
5623 mpt3sas_base_put_smid_default(ioc, smid);
5624 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5626 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5627 pr_err(MPT3SAS_FMT "%s: timeout\n",
5628 ioc->name, __func__);
5629 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5635 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5637 mpi_reply = ioc->scsih_cmds.reply;
5638 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5639 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5640 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5643 ioc_status &= MPI2_IOCSTATUS_MASK;
5644 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5645 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5646 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5647 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5651 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5652 "IR RAID_ACTION: completed successfully\n",
5657 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5658 mutex_unlock(&ioc->scsih_cmds.mutex);
5661 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5667 * _scsih_reprobe_lun - reprobing lun
5668 * @sdev: scsi device struct
5669 * @no_uld_attach: sdev->no_uld_attach flag setting
5673 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5676 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5677 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5678 sdev->no_uld_attach ? "hidding" : "exposing");
5679 rc = scsi_device_reprobe(sdev);
5683 * _scsih_sas_volume_add - add new volume
5684 * @ioc: per adapter object
5685 * @element: IR config element data
5691 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5692 Mpi2EventIrConfigElement_t *element)
5694 struct _raid_device *raid_device;
5695 unsigned long flags;
5697 u16 handle = le16_to_cpu(element->VolDevHandle);
5700 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5703 "failure at %s:%d/%s()!\n", ioc->name,
5704 __FILE__, __LINE__, __func__);
5708 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5709 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5710 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5715 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5718 "failure at %s:%d/%s()!\n", ioc->name,
5719 __FILE__, __LINE__, __func__);
5723 raid_device->id = ioc->sas_id++;
5724 raid_device->channel = RAID_CHANNEL;
5725 raid_device->handle = handle;
5726 raid_device->wwid = wwid;
5727 _scsih_raid_device_add(ioc, raid_device);
5728 if (!ioc->wait_for_discovery_to_complete) {
5729 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5730 raid_device->id, 0);
5732 _scsih_raid_device_remove(ioc, raid_device);
5734 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5735 _scsih_determine_boot_device(ioc, raid_device, 1);
5736 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5741 * _scsih_sas_volume_delete - delete volume
5742 * @ioc: per adapter object
5743 * @handle: volume device handle
5749 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5751 struct _raid_device *raid_device;
5752 unsigned long flags;
5753 struct MPT3SAS_TARGET *sas_target_priv_data;
5754 struct scsi_target *starget = NULL;
5756 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5757 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5759 if (raid_device->starget) {
5760 starget = raid_device->starget;
5761 sas_target_priv_data = starget->hostdata;
5762 sas_target_priv_data->deleted = 1;
5764 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5765 ioc->name, raid_device->handle,
5766 (unsigned long long) raid_device->wwid);
5767 list_del(&raid_device->list);
5770 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5772 scsi_remove_target(&starget->dev);
5776 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5777 * @ioc: per adapter object
5778 * @element: IR config element data
5784 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5785 Mpi2EventIrConfigElement_t *element)
5787 struct _sas_device *sas_device;
5788 struct scsi_target *starget = NULL;
5789 struct MPT3SAS_TARGET *sas_target_priv_data;
5790 unsigned long flags;
5791 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5793 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5794 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5796 sas_device->volume_handle = 0;
5797 sas_device->volume_wwid = 0;
5798 clear_bit(handle, ioc->pd_handles);
5799 if (sas_device->starget && sas_device->starget->hostdata) {
5800 starget = sas_device->starget;
5801 sas_target_priv_data = starget->hostdata;
5802 sas_target_priv_data->flags &=
5803 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5806 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5810 /* exposing raid component */
5812 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5816 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5817 * @ioc: per adapter object
5818 * @element: IR config element data
5824 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5825 Mpi2EventIrConfigElement_t *element)
5827 struct _sas_device *sas_device;
5828 struct scsi_target *starget = NULL;
5829 struct MPT3SAS_TARGET *sas_target_priv_data;
5830 unsigned long flags;
5831 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5832 u16 volume_handle = 0;
5833 u64 volume_wwid = 0;
5835 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
5837 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
5840 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5841 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5843 set_bit(handle, ioc->pd_handles);
5844 if (sas_device->starget && sas_device->starget->hostdata) {
5845 starget = sas_device->starget;
5846 sas_target_priv_data = starget->hostdata;
5847 sas_target_priv_data->flags |=
5848 MPT_TARGET_FLAGS_RAID_COMPONENT;
5849 sas_device->volume_handle = volume_handle;
5850 sas_device->volume_wwid = volume_wwid;
5853 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5857 /* hiding raid component */
5858 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5860 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
5864 * _scsih_sas_pd_delete - delete pd component
5865 * @ioc: per adapter object
5866 * @element: IR config element data
5872 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
5873 Mpi2EventIrConfigElement_t *element)
5875 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5877 _scsih_device_remove_by_handle(ioc, handle);
5881 * _scsih_sas_pd_add - remove pd component
5882 * @ioc: per adapter object
5883 * @element: IR config element data
5889 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
5890 Mpi2EventIrConfigElement_t *element)
5892 struct _sas_device *sas_device;
5893 unsigned long flags;
5894 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5895 Mpi2ConfigReply_t mpi_reply;
5896 Mpi2SasDevicePage0_t sas_device_pg0;
5901 set_bit(handle, ioc->pd_handles);
5903 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5904 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5905 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5907 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5911 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5912 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5913 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5914 ioc->name, __FILE__, __LINE__, __func__);
5918 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5919 MPI2_IOCSTATUS_MASK;
5920 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5921 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5922 ioc->name, __FILE__, __LINE__, __func__);
5926 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5927 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5928 mpt3sas_transport_update_links(ioc, sas_address, handle,
5929 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5931 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5932 _scsih_add_device(ioc, handle, 0, 1);
5935 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5937 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5938 * @ioc: per adapter object
5939 * @event_data: event data payload
5945 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5946 Mpi2EventDataIrConfigChangeList_t *event_data)
5948 Mpi2EventIrConfigElement_t *element;
5951 char *reason_str = NULL, *element_str = NULL;
5953 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5955 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
5956 ioc->name, (le32_to_cpu(event_data->Flags) &
5957 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5958 "foreign" : "native", event_data->NumElements);
5959 for (i = 0; i < event_data->NumElements; i++, element++) {
5960 switch (element->ReasonCode) {
5961 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5964 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5965 reason_str = "remove";
5967 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5968 reason_str = "no change";
5970 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5971 reason_str = "hide";
5973 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5974 reason_str = "unhide";
5976 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5977 reason_str = "volume_created";
5979 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
5980 reason_str = "volume_deleted";
5982 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
5983 reason_str = "pd_created";
5985 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
5986 reason_str = "pd_deleted";
5989 reason_str = "unknown reason";
5992 element_type = le16_to_cpu(element->ElementFlags) &
5993 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
5994 switch (element_type) {
5995 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
5996 element_str = "volume";
5998 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
5999 element_str = "phys disk";
6001 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6002 element_str = "hot spare";
6005 element_str = "unknown element";
6008 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6009 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6010 reason_str, le16_to_cpu(element->VolDevHandle),
6011 le16_to_cpu(element->PhysDiskDevHandle),
6012 element->PhysDiskNum);
6018 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6019 * @ioc: per adapter object
6020 * @fw_event: The fw_event_work object
6026 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6027 struct fw_event_work *fw_event)
6029 Mpi2EventIrConfigElement_t *element;
6032 Mpi2EventDataIrConfigChangeList_t *event_data =
6033 (Mpi2EventDataIrConfigChangeList_t *)
6034 fw_event->event_data;
6036 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6037 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6038 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6042 foreign_config = (le32_to_cpu(event_data->Flags) &
6043 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6045 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6046 if (ioc->shost_recovery) {
6048 for (i = 0; i < event_data->NumElements; i++, element++) {
6049 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6050 _scsih_ir_fastpath(ioc,
6051 le16_to_cpu(element->PhysDiskDevHandle),
6052 element->PhysDiskNum);
6056 for (i = 0; i < event_data->NumElements; i++, element++) {
6058 switch (element->ReasonCode) {
6059 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6060 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6061 if (!foreign_config)
6062 _scsih_sas_volume_add(ioc, element);
6064 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6065 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6066 if (!foreign_config)
6067 _scsih_sas_volume_delete(ioc,
6068 le16_to_cpu(element->VolDevHandle));
6070 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6071 _scsih_sas_pd_hide(ioc, element);
6073 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6074 _scsih_sas_pd_expose(ioc, element);
6076 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6077 _scsih_sas_pd_add(ioc, element);
6079 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6080 _scsih_sas_pd_delete(ioc, element);
6087 * _scsih_sas_ir_volume_event - IR volume event
6088 * @ioc: per adapter object
6089 * @fw_event: The fw_event_work object
6095 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6096 struct fw_event_work *fw_event)
6099 unsigned long flags;
6100 struct _raid_device *raid_device;
6104 Mpi2EventDataIrVolume_t *event_data =
6105 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6107 if (ioc->shost_recovery)
6110 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6113 handle = le16_to_cpu(event_data->VolDevHandle);
6114 state = le32_to_cpu(event_data->NewValue);
6115 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6116 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6117 ioc->name, __func__, handle,
6118 le32_to_cpu(event_data->PreviousValue), state));
6120 case MPI2_RAID_VOL_STATE_MISSING:
6121 case MPI2_RAID_VOL_STATE_FAILED:
6122 _scsih_sas_volume_delete(ioc, handle);
6125 case MPI2_RAID_VOL_STATE_ONLINE:
6126 case MPI2_RAID_VOL_STATE_DEGRADED:
6127 case MPI2_RAID_VOL_STATE_OPTIMAL:
6129 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6130 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6131 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6136 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6139 "failure at %s:%d/%s()!\n", ioc->name,
6140 __FILE__, __LINE__, __func__);
6144 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6147 "failure at %s:%d/%s()!\n", ioc->name,
6148 __FILE__, __LINE__, __func__);
6152 raid_device->id = ioc->sas_id++;
6153 raid_device->channel = RAID_CHANNEL;
6154 raid_device->handle = handle;
6155 raid_device->wwid = wwid;
6156 _scsih_raid_device_add(ioc, raid_device);
6157 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6158 raid_device->id, 0);
6160 _scsih_raid_device_remove(ioc, raid_device);
6163 case MPI2_RAID_VOL_STATE_INITIALIZING:
6170 * _scsih_sas_ir_physical_disk_event - PD event
6171 * @ioc: per adapter object
6172 * @fw_event: The fw_event_work object
6178 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6179 struct fw_event_work *fw_event)
6181 u16 handle, parent_handle;
6183 struct _sas_device *sas_device;
6184 unsigned long flags;
6185 Mpi2ConfigReply_t mpi_reply;
6186 Mpi2SasDevicePage0_t sas_device_pg0;
6188 Mpi2EventDataIrPhysicalDisk_t *event_data =
6189 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6192 if (ioc->shost_recovery)
6195 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6198 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6199 state = le32_to_cpu(event_data->NewValue);
6201 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6202 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6203 ioc->name, __func__, handle,
6204 le32_to_cpu(event_data->PreviousValue), state));
6206 case MPI2_RAID_PD_STATE_ONLINE:
6207 case MPI2_RAID_PD_STATE_DEGRADED:
6208 case MPI2_RAID_PD_STATE_REBUILDING:
6209 case MPI2_RAID_PD_STATE_OPTIMAL:
6210 case MPI2_RAID_PD_STATE_HOT_SPARE:
6212 set_bit(handle, ioc->pd_handles);
6213 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6214 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6215 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6220 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6221 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6223 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6224 ioc->name, __FILE__, __LINE__, __func__);
6228 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6229 MPI2_IOCSTATUS_MASK;
6230 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6231 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6232 ioc->name, __FILE__, __LINE__, __func__);
6236 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6237 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6238 mpt3sas_transport_update_links(ioc, sas_address, handle,
6239 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6241 _scsih_add_device(ioc, handle, 0, 1);
6245 case MPI2_RAID_PD_STATE_OFFLINE:
6246 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6247 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6253 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6255 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6256 * @ioc: per adapter object
6257 * @event_data: event data payload
6263 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6264 Mpi2EventDataIrOperationStatus_t *event_data)
6266 char *reason_str = NULL;
6268 switch (event_data->RAIDOperation) {
6269 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6270 reason_str = "resync";
6272 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6273 reason_str = "online capacity expansion";
6275 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6276 reason_str = "consistency check";
6278 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6279 reason_str = "background init";
6281 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6282 reason_str = "make data consistent";
6289 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6290 "\thandle(0x%04x), percent complete(%d)\n",
6291 ioc->name, reason_str,
6292 le16_to_cpu(event_data->VolDevHandle),
6293 event_data->PercentComplete);
6298 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6299 * @ioc: per adapter object
6300 * @fw_event: The fw_event_work object
6306 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6307 struct fw_event_work *fw_event)
6309 Mpi2EventDataIrOperationStatus_t *event_data =
6310 (Mpi2EventDataIrOperationStatus_t *)
6311 fw_event->event_data;
6312 static struct _raid_device *raid_device;
6313 unsigned long flags;
6316 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6317 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6318 _scsih_sas_ir_operation_status_event_debug(ioc,
6322 /* code added for raid transport support */
6323 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6325 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6326 handle = le16_to_cpu(event_data->VolDevHandle);
6327 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6329 raid_device->percent_complete =
6330 event_data->PercentComplete;
6331 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6336 * _scsih_prep_device_scan - initialize parameters prior to device scan
6337 * @ioc: per adapter object
6339 * Set the deleted flag prior to device scan. If the device is found during
6340 * the scan, then we clear the deleted flag.
6343 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6345 struct MPT3SAS_DEVICE *sas_device_priv_data;
6346 struct scsi_device *sdev;
6348 shost_for_each_device(sdev, ioc->shost) {
6349 sas_device_priv_data = sdev->hostdata;
6350 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6351 sas_device_priv_data->sas_target->deleted = 1;
6356 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6357 * @ioc: per adapter object
6358 * @sas_address: sas address
6359 * @slot: enclosure slot id
6360 * @handle: device handle
6362 * After host reset, find out whether devices are still responding.
6363 * Used in _scsih_remove_unresponsive_sas_devices.
6368 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6369 u16 slot, u16 handle)
6371 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6372 struct scsi_target *starget;
6373 struct _sas_device *sas_device;
6374 unsigned long flags;
6376 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6377 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6378 if (sas_device->sas_address == sas_address &&
6379 sas_device->slot == slot) {
6380 sas_device->responding = 1;
6381 starget = sas_device->starget;
6382 if (starget && starget->hostdata) {
6383 sas_target_priv_data = starget->hostdata;
6384 sas_target_priv_data->tm_busy = 0;
6385 sas_target_priv_data->deleted = 0;
6387 sas_target_priv_data = NULL;
6389 starget_printk(KERN_INFO, starget,
6390 "handle(0x%04x), sas_addr(0x%016llx), "
6391 "enclosure logical id(0x%016llx), "
6392 "slot(%d)\n", handle,
6393 (unsigned long long)sas_device->sas_address,
6394 (unsigned long long)
6395 sas_device->enclosure_logical_id,
6397 if (sas_device->handle == handle)
6399 pr_info("\thandle changed from(0x%04x)!!!\n",
6400 sas_device->handle);
6401 sas_device->handle = handle;
6402 if (sas_target_priv_data)
6403 sas_target_priv_data->handle = handle;
6408 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6412 * _scsih_search_responding_sas_devices -
6413 * @ioc: per adapter object
6415 * After host reset, find out whether devices are still responding.
6421 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6423 Mpi2SasDevicePage0_t sas_device_pg0;
6424 Mpi2ConfigReply_t mpi_reply;
6429 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6431 if (list_empty(&ioc->sas_device_list))
6435 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6436 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6438 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6439 MPI2_IOCSTATUS_MASK;
6440 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6442 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6443 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6444 if (!(_scsih_is_end_device(device_info)))
6446 _scsih_mark_responding_sas_device(ioc,
6447 le64_to_cpu(sas_device_pg0.SASAddress),
6448 le16_to_cpu(sas_device_pg0.Slot), handle);
6452 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6457 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6458 * @ioc: per adapter object
6459 * @wwid: world wide identifier for raid volume
6460 * @handle: device handle
6462 * After host reset, find out whether devices are still responding.
6463 * Used in _scsih_remove_unresponsive_raid_devices.
6468 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6471 struct MPT3SAS_TARGET *sas_target_priv_data;
6472 struct scsi_target *starget;
6473 struct _raid_device *raid_device;
6474 unsigned long flags;
6476 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6477 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6478 if (raid_device->wwid == wwid && raid_device->starget) {
6479 starget = raid_device->starget;
6480 if (starget && starget->hostdata) {
6481 sas_target_priv_data = starget->hostdata;
6482 sas_target_priv_data->deleted = 0;
6484 sas_target_priv_data = NULL;
6485 raid_device->responding = 1;
6486 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6487 starget_printk(KERN_INFO, raid_device->starget,
6488 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6489 (unsigned long long)raid_device->wwid);
6490 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6491 if (raid_device->handle == handle) {
6492 spin_unlock_irqrestore(&ioc->raid_device_lock,
6496 pr_info("\thandle changed from(0x%04x)!!!\n",
6497 raid_device->handle);
6498 raid_device->handle = handle;
6499 if (sas_target_priv_data)
6500 sas_target_priv_data->handle = handle;
6501 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6505 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6509 * _scsih_search_responding_raid_devices -
6510 * @ioc: per adapter object
6512 * After host reset, find out whether devices are still responding.
6518 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6520 Mpi2RaidVolPage1_t volume_pg1;
6521 Mpi2RaidVolPage0_t volume_pg0;
6522 Mpi2RaidPhysDiskPage0_t pd_pg0;
6523 Mpi2ConfigReply_t mpi_reply;
6528 if (!ioc->ir_firmware)
6531 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6534 if (list_empty(&ioc->raid_device_list))
6538 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6539 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6540 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6541 MPI2_IOCSTATUS_MASK;
6542 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6544 handle = le16_to_cpu(volume_pg1.DevHandle);
6546 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6547 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6548 sizeof(Mpi2RaidVolPage0_t)))
6551 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6552 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6553 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6554 _scsih_mark_responding_raid_device(ioc,
6555 le64_to_cpu(volume_pg1.WWID), handle);
6558 /* refresh the pd_handles */
6559 phys_disk_num = 0xFF;
6560 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6561 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6562 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6564 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6565 MPI2_IOCSTATUS_MASK;
6566 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6568 phys_disk_num = pd_pg0.PhysDiskNum;
6569 handle = le16_to_cpu(pd_pg0.DevHandle);
6570 set_bit(handle, ioc->pd_handles);
6573 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6578 * _scsih_mark_responding_expander - mark a expander as responding
6579 * @ioc: per adapter object
6580 * @sas_address: sas address
6583 * After host reset, find out whether devices are still responding.
6584 * Used in _scsih_remove_unresponsive_expanders.
6589 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6592 struct _sas_node *sas_expander;
6593 unsigned long flags;
6596 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6597 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6598 if (sas_expander->sas_address != sas_address)
6600 sas_expander->responding = 1;
6601 if (sas_expander->handle == handle)
6603 pr_info("\texpander(0x%016llx): handle changed" \
6604 " from(0x%04x) to (0x%04x)!!!\n",
6605 (unsigned long long)sas_expander->sas_address,
6606 sas_expander->handle, handle);
6607 sas_expander->handle = handle;
6608 for (i = 0 ; i < sas_expander->num_phys ; i++)
6609 sas_expander->phy[i].handle = handle;
6613 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6617 * _scsih_search_responding_expanders -
6618 * @ioc: per adapter object
6620 * After host reset, find out whether devices are still responding.
6626 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6628 Mpi2ExpanderPage0_t expander_pg0;
6629 Mpi2ConfigReply_t mpi_reply;
6634 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6636 if (list_empty(&ioc->sas_expander_list))
6640 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6641 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6643 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6644 MPI2_IOCSTATUS_MASK;
6645 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6648 handle = le16_to_cpu(expander_pg0.DevHandle);
6649 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6650 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6652 (unsigned long long)sas_address);
6653 _scsih_mark_responding_expander(ioc, sas_address, handle);
6657 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6661 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6662 * @ioc: per adapter object
6667 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6669 struct _sas_device *sas_device, *sas_device_next;
6670 struct _sas_node *sas_expander, *sas_expander_next;
6671 struct _raid_device *raid_device, *raid_device_next;
6672 struct list_head tmp_list;
6673 unsigned long flags;
6675 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6678 /* removing unresponding end devices */
6679 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6681 list_for_each_entry_safe(sas_device, sas_device_next,
6682 &ioc->sas_device_list, list) {
6683 if (!sas_device->responding)
6684 mpt3sas_device_remove_by_sas_address(ioc,
6685 sas_device->sas_address);
6687 sas_device->responding = 0;
6690 /* removing unresponding volumes */
6691 if (ioc->ir_firmware) {
6692 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6694 list_for_each_entry_safe(raid_device, raid_device_next,
6695 &ioc->raid_device_list, list) {
6696 if (!raid_device->responding)
6697 _scsih_sas_volume_delete(ioc,
6698 raid_device->handle);
6700 raid_device->responding = 0;
6704 /* removing unresponding expanders */
6705 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6707 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6708 INIT_LIST_HEAD(&tmp_list);
6709 list_for_each_entry_safe(sas_expander, sas_expander_next,
6710 &ioc->sas_expander_list, list) {
6711 if (!sas_expander->responding)
6712 list_move_tail(&sas_expander->list, &tmp_list);
6714 sas_expander->responding = 0;
6716 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6717 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6719 list_del(&sas_expander->list);
6720 _scsih_expander_node_remove(ioc, sas_expander);
6723 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6726 /* unblock devices */
6727 _scsih_ublock_io_all_device(ioc);
6731 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6732 struct _sas_node *sas_expander, u16 handle)
6734 Mpi2ExpanderPage1_t expander_pg1;
6735 Mpi2ConfigReply_t mpi_reply;
6738 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6739 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6740 &expander_pg1, i, handle))) {
6741 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6742 ioc->name, __FILE__, __LINE__, __func__);
6746 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6747 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6748 expander_pg1.NegotiatedLinkRate >> 4);
6753 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6754 * @ioc: per adapter object
6759 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6761 Mpi2ExpanderPage0_t expander_pg0;
6762 Mpi2SasDevicePage0_t sas_device_pg0;
6763 Mpi2RaidVolPage1_t volume_pg1;
6764 Mpi2RaidVolPage0_t volume_pg0;
6765 Mpi2RaidPhysDiskPage0_t pd_pg0;
6766 Mpi2EventIrConfigElement_t element;
6767 Mpi2ConfigReply_t mpi_reply;
6770 u16 handle, parent_handle;
6772 struct _sas_device *sas_device;
6773 struct _sas_node *expander_device;
6774 static struct _raid_device *raid_device;
6776 unsigned long flags;
6778 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6780 _scsih_sas_host_refresh(ioc);
6782 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6786 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6787 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6788 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6789 MPI2_IOCSTATUS_MASK;
6790 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6791 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6792 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6793 ioc->name, ioc_status,
6794 le32_to_cpu(mpi_reply.IOCLogInfo));
6797 handle = le16_to_cpu(expander_pg0.DevHandle);
6798 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6799 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6800 ioc, le64_to_cpu(expander_pg0.SASAddress));
6801 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6802 if (expander_device)
6803 _scsih_refresh_expander_links(ioc, expander_device,
6806 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6807 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6808 handle, (unsigned long long)
6809 le64_to_cpu(expander_pg0.SASAddress));
6810 _scsih_expander_add(ioc, handle);
6811 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6812 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6813 handle, (unsigned long long)
6814 le64_to_cpu(expander_pg0.SASAddress));
6818 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6821 if (!ioc->ir_firmware)
6824 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6827 phys_disk_num = 0xFF;
6828 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6829 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6831 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6832 MPI2_IOCSTATUS_MASK;
6833 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6834 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
6835 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6836 ioc->name, ioc_status,
6837 le32_to_cpu(mpi_reply.IOCLogInfo));
6840 phys_disk_num = pd_pg0.PhysDiskNum;
6841 handle = le16_to_cpu(pd_pg0.DevHandle);
6842 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6843 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6844 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6847 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6848 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6851 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6852 MPI2_IOCSTATUS_MASK;
6853 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6854 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
6855 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6856 ioc->name, ioc_status,
6857 le32_to_cpu(mpi_reply.IOCLogInfo));
6860 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6861 if (!_scsih_get_sas_address(ioc, parent_handle,
6863 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
6864 " handle (0x%04x), sas_addr(0x%016llx)\n",
6865 ioc->name, handle, (unsigned long long)
6866 le64_to_cpu(sas_device_pg0.SASAddress));
6867 mpt3sas_transport_update_links(ioc, sas_address,
6868 handle, sas_device_pg0.PhyNum,
6869 MPI2_SAS_NEG_LINK_RATE_1_5);
6870 set_bit(handle, ioc->pd_handles);
6872 /* This will retry adding the end device.
6873 * _scsih_add_device() will decide on retries and
6874 * return "1" when it should be retried
6876 while (_scsih_add_device(ioc, handle, retry_count++,
6880 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
6881 " handle (0x%04x), sas_addr(0x%016llx)\n",
6882 ioc->name, handle, (unsigned long long)
6883 le64_to_cpu(sas_device_pg0.SASAddress));
6887 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
6890 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
6894 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6895 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6896 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6897 MPI2_IOCSTATUS_MASK;
6898 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6899 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6900 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6901 ioc->name, ioc_status,
6902 le32_to_cpu(mpi_reply.IOCLogInfo));
6905 handle = le16_to_cpu(volume_pg1.DevHandle);
6906 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6907 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6908 le64_to_cpu(volume_pg1.WWID));
6909 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6912 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6913 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6914 sizeof(Mpi2RaidVolPage0_t)))
6916 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6917 MPI2_IOCSTATUS_MASK;
6918 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6919 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6920 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6921 ioc->name, ioc_status,
6922 le32_to_cpu(mpi_reply.IOCLogInfo));
6925 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6926 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6927 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6928 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6929 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6930 element.VolDevHandle = volume_pg1.DevHandle;
6932 "\tBEFORE adding volume: handle (0x%04x)\n",
6933 ioc->name, volume_pg1.DevHandle);
6934 _scsih_sas_volume_add(ioc, &element);
6936 "\tAFTER adding volume: handle (0x%04x)\n",
6937 ioc->name, volume_pg1.DevHandle);
6941 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
6946 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
6951 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6952 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6954 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6955 MPI2_IOCSTATUS_MASK;
6956 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6957 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
6958 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6959 ioc->name, ioc_status,
6960 le32_to_cpu(mpi_reply.IOCLogInfo));
6963 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6964 if (!(_scsih_is_end_device(
6965 le32_to_cpu(sas_device_pg0.DeviceInfo))))
6967 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6968 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
6969 le64_to_cpu(sas_device_pg0.SASAddress));
6970 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6973 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6974 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
6975 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
6976 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6977 handle, (unsigned long long)
6978 le64_to_cpu(sas_device_pg0.SASAddress));
6979 mpt3sas_transport_update_links(ioc, sas_address, handle,
6980 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6982 /* This will retry adding the end device.
6983 * _scsih_add_device() will decide on retries and
6984 * return "1" when it should be retried
6986 while (_scsih_add_device(ioc, handle, retry_count++,
6990 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
6991 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6992 handle, (unsigned long long)
6993 le64_to_cpu(sas_device_pg0.SASAddress));
6996 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
6999 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7002 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7003 * @ioc: per adapter object
7004 * @reset_phase: phase
7006 * The handler for doing any required cleanup or initialization.
7008 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7009 * MPT3_IOC_DONE_RESET
7014 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7016 switch (reset_phase) {
7017 case MPT3_IOC_PRE_RESET:
7018 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7019 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7021 case MPT3_IOC_AFTER_RESET:
7022 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7023 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7024 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7025 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7026 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7027 complete(&ioc->scsih_cmds.done);
7029 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7030 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7031 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7032 complete(&ioc->tm_cmds.done);
7035 _scsih_fw_event_cleanup_queue(ioc);
7036 _scsih_flush_running_cmds(ioc);
7038 case MPT3_IOC_DONE_RESET:
7039 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7040 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7041 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7042 !ioc->sas_hba.num_phys)) {
7043 _scsih_prep_device_scan(ioc);
7044 _scsih_search_responding_sas_devices(ioc);
7045 _scsih_search_responding_raid_devices(ioc);
7046 _scsih_search_responding_expanders(ioc);
7047 _scsih_error_recovery_delete_devices(ioc);
7054 * _mpt3sas_fw_work - delayed task for processing firmware events
7055 * @ioc: per adapter object
7056 * @fw_event: The fw_event_work object
7062 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7064 /* the queue is being flushed so ignore this event */
7065 if (ioc->remove_host ||
7066 ioc->pci_error_recovery) {
7067 _scsih_fw_event_free(ioc, fw_event);
7071 switch (fw_event->event) {
7072 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7073 mpt3sas_process_trigger_data(ioc,
7074 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7075 fw_event->event_data);
7077 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7078 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7080 _scsih_remove_unresponding_sas_devices(ioc);
7081 _scsih_scan_for_devices_after_reset(ioc);
7083 case MPT3SAS_PORT_ENABLE_COMPLETE:
7084 ioc->start_scan = 0;
7085 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7086 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7088 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7089 "port enable: complete from worker thread\n",
7092 case MPT3SAS_TURN_ON_PFA_LED:
7093 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7095 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7096 _scsih_sas_topology_change_event(ioc, fw_event);
7098 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7099 _scsih_sas_device_status_change_event(ioc, fw_event);
7101 case MPI2_EVENT_SAS_DISCOVERY:
7102 _scsih_sas_discovery_event(ioc, fw_event);
7104 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7105 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7107 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7108 _scsih_sas_enclosure_dev_status_change_event(ioc,
7111 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7112 _scsih_sas_ir_config_change_event(ioc, fw_event);
7114 case MPI2_EVENT_IR_VOLUME:
7115 _scsih_sas_ir_volume_event(ioc, fw_event);
7117 case MPI2_EVENT_IR_PHYSICAL_DISK:
7118 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7120 case MPI2_EVENT_IR_OPERATION_STATUS:
7121 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7124 _scsih_fw_event_free(ioc, fw_event);
7128 * _firmware_event_work
7129 * @ioc: per adapter object
7130 * @work: The fw_event_work object
7133 * wrappers for the work thread handling firmware events
7139 _firmware_event_work(struct work_struct *work)
7141 struct fw_event_work *fw_event = container_of(work,
7142 struct fw_event_work, work);
7144 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7148 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7149 * @ioc: per adapter object
7150 * @msix_index: MSIX table index supplied by the OS
7151 * @reply: reply message frame(lower 32bit addr)
7152 * Context: interrupt.
7154 * This function merely adds a new work task into ioc->firmware_event_thread.
7155 * The tasks are worked from _firmware_event_work in user context.
7157 * Return 1 meaning mf should be freed from _base_interrupt
7158 * 0 means the mf is freed from this function.
7161 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7164 struct fw_event_work *fw_event;
7165 Mpi2EventNotificationReply_t *mpi_reply;
7169 /* events turned off due to host reset or driver unloading */
7170 if (ioc->remove_host || ioc->pci_error_recovery)
7173 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7175 if (unlikely(!mpi_reply)) {
7176 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7177 ioc->name, __FILE__, __LINE__, __func__);
7181 event = le16_to_cpu(mpi_reply->Event);
7183 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7184 mpt3sas_trigger_event(ioc, event, 0);
7188 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7190 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7191 (Mpi2EventDataSasBroadcastPrimitive_t *)
7192 mpi_reply->EventData;
7194 if (baen_data->Primitive !=
7195 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7198 if (ioc->broadcast_aen_busy) {
7199 ioc->broadcast_aen_pending++;
7202 ioc->broadcast_aen_busy = 1;
7206 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7207 _scsih_check_topo_delete_events(ioc,
7208 (Mpi2EventDataSasTopologyChangeList_t *)
7209 mpi_reply->EventData);
7211 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7212 _scsih_check_ir_config_unhide_events(ioc,
7213 (Mpi2EventDataIrConfigChangeList_t *)
7214 mpi_reply->EventData);
7216 case MPI2_EVENT_IR_VOLUME:
7217 _scsih_check_volume_delete_events(ioc,
7218 (Mpi2EventDataIrVolume_t *)
7219 mpi_reply->EventData);
7222 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7223 case MPI2_EVENT_IR_OPERATION_STATUS:
7224 case MPI2_EVENT_SAS_DISCOVERY:
7225 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7226 case MPI2_EVENT_IR_PHYSICAL_DISK:
7229 default: /* ignore the rest */
7233 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7234 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7236 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7237 ioc->name, __FILE__, __LINE__, __func__);
7241 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7242 fw_event->ioc = ioc;
7243 fw_event->VF_ID = mpi_reply->VF_ID;
7244 fw_event->VP_ID = mpi_reply->VP_ID;
7245 fw_event->event = event;
7246 _scsih_fw_event_add(ioc, fw_event);
7250 /* shost template */
7251 static struct scsi_host_template scsih_driver_template = {
7252 .module = THIS_MODULE,
7253 .name = "Fusion MPT SAS Host",
7254 .proc_name = MPT3SAS_DRIVER_NAME,
7255 .queuecommand = _scsih_qcmd,
7256 .target_alloc = _scsih_target_alloc,
7257 .slave_alloc = _scsih_slave_alloc,
7258 .slave_configure = _scsih_slave_configure,
7259 .target_destroy = _scsih_target_destroy,
7260 .slave_destroy = _scsih_slave_destroy,
7261 .scan_finished = _scsih_scan_finished,
7262 .scan_start = _scsih_scan_start,
7263 .change_queue_depth = _scsih_change_queue_depth,
7264 .change_queue_type = scsi_change_queue_type,
7265 .eh_abort_handler = _scsih_abort,
7266 .eh_device_reset_handler = _scsih_dev_reset,
7267 .eh_target_reset_handler = _scsih_target_reset,
7268 .eh_host_reset_handler = _scsih_host_reset,
7269 .bios_param = _scsih_bios_param,
7272 .sg_tablesize = MPT3SAS_SG_DEPTH,
7273 .max_sectors = 32767,
7275 .use_clustering = ENABLE_CLUSTERING,
7276 .shost_attrs = mpt3sas_host_attrs,
7277 .sdev_attrs = mpt3sas_dev_attrs,
7281 * _scsih_expander_node_remove - removing expander device from list.
7282 * @ioc: per adapter object
7283 * @sas_expander: the sas_device object
7284 * Context: Calling function should acquire ioc->sas_node_lock.
7286 * Removing object and freeing associated memory from the
7287 * ioc->sas_expander_list.
7292 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7293 struct _sas_node *sas_expander)
7295 struct _sas_port *mpt3sas_port, *next;
7297 /* remove sibling ports attached to this expander */
7298 list_for_each_entry_safe(mpt3sas_port, next,
7299 &sas_expander->sas_port_list, port_list) {
7300 if (ioc->shost_recovery)
7302 if (mpt3sas_port->remote_identify.device_type ==
7304 mpt3sas_device_remove_by_sas_address(ioc,
7305 mpt3sas_port->remote_identify.sas_address);
7306 else if (mpt3sas_port->remote_identify.device_type ==
7307 SAS_EDGE_EXPANDER_DEVICE ||
7308 mpt3sas_port->remote_identify.device_type ==
7309 SAS_FANOUT_EXPANDER_DEVICE)
7310 mpt3sas_expander_remove(ioc,
7311 mpt3sas_port->remote_identify.sas_address);
7314 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7315 sas_expander->sas_address_parent);
7318 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7320 sas_expander->handle, (unsigned long long)
7321 sas_expander->sas_address);
7323 kfree(sas_expander->phy);
7324 kfree(sas_expander);
7328 * _scsih_ir_shutdown - IR shutdown notification
7329 * @ioc: per adapter object
7331 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7332 * the host system is shutting down.
7337 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7339 Mpi2RaidActionRequest_t *mpi_request;
7340 Mpi2RaidActionReply_t *mpi_reply;
7343 /* is IR firmware build loaded ? */
7344 if (!ioc->ir_firmware)
7347 /* are there any volumes ? */
7348 if (list_empty(&ioc->raid_device_list))
7351 mutex_lock(&ioc->scsih_cmds.mutex);
7353 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7354 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7355 ioc->name, __func__);
7358 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7360 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7362 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7363 ioc->name, __func__);
7364 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7368 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7369 ioc->scsih_cmds.smid = smid;
7370 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7372 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7373 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7375 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7376 init_completion(&ioc->scsih_cmds.done);
7377 mpt3sas_base_put_smid_default(ioc, smid);
7378 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7380 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7381 pr_err(MPT3SAS_FMT "%s: timeout\n",
7382 ioc->name, __func__);
7386 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7387 mpi_reply = ioc->scsih_cmds.reply;
7389 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7390 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7391 le32_to_cpu(mpi_reply->IOCLogInfo));
7395 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7396 mutex_unlock(&ioc->scsih_cmds.mutex);
7400 * _scsih_remove - detach and remove add host
7401 * @pdev: PCI device struct
7403 * Routine called when unloading the driver.
7406 static void _scsih_remove(struct pci_dev *pdev)
7408 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7409 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7410 struct _sas_port *mpt3sas_port, *next_port;
7411 struct _raid_device *raid_device, *next;
7412 struct MPT3SAS_TARGET *sas_target_priv_data;
7413 struct workqueue_struct *wq;
7414 unsigned long flags;
7416 ioc->remove_host = 1;
7417 _scsih_fw_event_cleanup_queue(ioc);
7419 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7420 wq = ioc->firmware_event_thread;
7421 ioc->firmware_event_thread = NULL;
7422 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7424 destroy_workqueue(wq);
7426 /* release all the volumes */
7427 _scsih_ir_shutdown(ioc);
7428 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7430 if (raid_device->starget) {
7431 sas_target_priv_data =
7432 raid_device->starget->hostdata;
7433 sas_target_priv_data->deleted = 1;
7434 scsi_remove_target(&raid_device->starget->dev);
7436 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7437 ioc->name, raid_device->handle,
7438 (unsigned long long) raid_device->wwid);
7439 _scsih_raid_device_remove(ioc, raid_device);
7442 /* free ports attached to the sas_host */
7443 list_for_each_entry_safe(mpt3sas_port, next_port,
7444 &ioc->sas_hba.sas_port_list, port_list) {
7445 if (mpt3sas_port->remote_identify.device_type ==
7447 mpt3sas_device_remove_by_sas_address(ioc,
7448 mpt3sas_port->remote_identify.sas_address);
7449 else if (mpt3sas_port->remote_identify.device_type ==
7450 SAS_EDGE_EXPANDER_DEVICE ||
7451 mpt3sas_port->remote_identify.device_type ==
7452 SAS_FANOUT_EXPANDER_DEVICE)
7453 mpt3sas_expander_remove(ioc,
7454 mpt3sas_port->remote_identify.sas_address);
7457 /* free phys attached to the sas_host */
7458 if (ioc->sas_hba.num_phys) {
7459 kfree(ioc->sas_hba.phy);
7460 ioc->sas_hba.phy = NULL;
7461 ioc->sas_hba.num_phys = 0;
7464 sas_remove_host(shost);
7465 scsi_remove_host(shost);
7466 mpt3sas_base_detach(ioc);
7467 list_del(&ioc->list);
7468 scsi_host_put(shost);
7472 * _scsih_shutdown - routine call during system shutdown
7473 * @pdev: PCI device struct
7478 _scsih_shutdown(struct pci_dev *pdev)
7480 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7481 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7482 struct workqueue_struct *wq;
7483 unsigned long flags;
7485 ioc->remove_host = 1;
7486 _scsih_fw_event_cleanup_queue(ioc);
7488 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7489 wq = ioc->firmware_event_thread;
7490 ioc->firmware_event_thread = NULL;
7491 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7493 destroy_workqueue(wq);
7495 _scsih_ir_shutdown(ioc);
7496 mpt3sas_base_detach(ioc);
7501 * _scsih_probe_boot_devices - reports 1st device
7502 * @ioc: per adapter object
7504 * If specified in bios page 2, this routine reports the 1st
7505 * device scsi-ml or sas transport for persistent boot device
7506 * purposes. Please refer to function _scsih_determine_boot_device()
7509 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7513 struct _sas_device *sas_device;
7514 struct _raid_device *raid_device;
7516 u64 sas_address_parent;
7518 unsigned long flags;
7521 /* no Bios, return immediately */
7522 if (!ioc->bios_pg3.BiosVersion)
7527 if (ioc->req_boot_device.device) {
7528 device = ioc->req_boot_device.device;
7529 is_raid = ioc->req_boot_device.is_raid;
7530 } else if (ioc->req_alt_boot_device.device) {
7531 device = ioc->req_alt_boot_device.device;
7532 is_raid = ioc->req_alt_boot_device.is_raid;
7533 } else if (ioc->current_boot_device.device) {
7534 device = ioc->current_boot_device.device;
7535 is_raid = ioc->current_boot_device.is_raid;
7542 raid_device = device;
7543 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7544 raid_device->id, 0);
7546 _scsih_raid_device_remove(ioc, raid_device);
7548 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7549 sas_device = device;
7550 handle = sas_device->handle;
7551 sas_address_parent = sas_device->sas_address_parent;
7552 sas_address = sas_device->sas_address;
7553 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7554 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7556 if (!mpt3sas_transport_port_add(ioc, handle,
7557 sas_address_parent)) {
7558 _scsih_sas_device_remove(ioc, sas_device);
7559 } else if (!sas_device->starget) {
7560 if (!ioc->is_driver_loading) {
7561 mpt3sas_transport_port_remove(ioc,
7563 sas_address_parent);
7564 _scsih_sas_device_remove(ioc, sas_device);
7571 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7572 * @ioc: per adapter object
7574 * Called during initial loading of the driver.
7577 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7579 struct _raid_device *raid_device, *raid_next;
7582 list_for_each_entry_safe(raid_device, raid_next,
7583 &ioc->raid_device_list, list) {
7584 if (raid_device->starget)
7586 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7587 raid_device->id, 0);
7589 _scsih_raid_device_remove(ioc, raid_device);
7594 * _scsih_probe_sas - reporting sas devices to sas transport
7595 * @ioc: per adapter object
7597 * Called during initial loading of the driver.
7600 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7602 struct _sas_device *sas_device, *next;
7603 unsigned long flags;
7605 /* SAS Device List */
7606 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7609 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7610 sas_device->sas_address_parent)) {
7611 list_del(&sas_device->list);
7614 } else if (!sas_device->starget) {
7616 * When asyn scanning is enabled, its not possible to
7617 * remove devices while scanning is turned on due to an
7618 * oops in scsi_sysfs_add_sdev()->add_device()->
7619 * sysfs_addrm_start()
7621 if (!ioc->is_driver_loading) {
7622 mpt3sas_transport_port_remove(ioc,
7623 sas_device->sas_address,
7624 sas_device->sas_address_parent);
7625 list_del(&sas_device->list);
7631 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7632 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7633 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7638 * _scsih_probe_devices - probing for devices
7639 * @ioc: per adapter object
7641 * Called during initial loading of the driver.
7644 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7646 u16 volume_mapping_flags;
7648 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7649 return; /* return when IOC doesn't support initiator mode */
7651 _scsih_probe_boot_devices(ioc);
7653 if (ioc->ir_firmware) {
7654 volume_mapping_flags =
7655 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7656 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7657 if (volume_mapping_flags ==
7658 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7659 _scsih_probe_raid(ioc);
7660 _scsih_probe_sas(ioc);
7662 _scsih_probe_sas(ioc);
7663 _scsih_probe_raid(ioc);
7666 _scsih_probe_sas(ioc);
7670 * _scsih_scan_start - scsi lld callback for .scan_start
7671 * @shost: SCSI host pointer
7673 * The shost has the ability to discover targets on its own instead
7674 * of scanning the entire bus. In our implemention, we will kick off
7675 * firmware discovery.
7678 _scsih_scan_start(struct Scsi_Host *shost)
7680 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7682 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7683 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7685 if (disable_discovery > 0)
7688 ioc->start_scan = 1;
7689 rc = mpt3sas_port_enable(ioc);
7692 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7696 * _scsih_scan_finished - scsi lld callback for .scan_finished
7697 * @shost: SCSI host pointer
7698 * @time: elapsed time of the scan in jiffies
7700 * This function will be called periodicallyn until it returns 1 with the
7701 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7702 * we wait for firmware discovery to complete, then return 1.
7705 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7707 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7709 if (disable_discovery > 0) {
7710 ioc->is_driver_loading = 0;
7711 ioc->wait_for_discovery_to_complete = 0;
7715 if (time >= (300 * HZ)) {
7716 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7718 "port enable: FAILED with timeout (timeout=300s)\n",
7720 ioc->is_driver_loading = 0;
7724 if (ioc->start_scan)
7727 if (ioc->start_scan_failed) {
7729 "port enable: FAILED with (ioc_status=0x%08x)\n",
7730 ioc->name, ioc->start_scan_failed);
7731 ioc->is_driver_loading = 0;
7732 ioc->wait_for_discovery_to_complete = 0;
7733 ioc->remove_host = 1;
7737 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7738 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7740 if (ioc->wait_for_discovery_to_complete) {
7741 ioc->wait_for_discovery_to_complete = 0;
7742 _scsih_probe_devices(ioc);
7744 mpt3sas_base_start_watchdog(ioc);
7745 ioc->is_driver_loading = 0;
7750 * _scsih_probe - attach and add scsi host
7751 * @pdev: PCI device struct
7752 * @id: pci device id
7754 * Returns 0 success, anything else error.
7757 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7759 struct MPT3SAS_ADAPTER *ioc;
7760 struct Scsi_Host *shost;
7763 shost = scsi_host_alloc(&scsih_driver_template,
7764 sizeof(struct MPT3SAS_ADAPTER));
7768 /* init local params */
7769 ioc = shost_priv(shost);
7770 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7771 INIT_LIST_HEAD(&ioc->list);
7772 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7774 ioc->id = mpt_ids++;
7775 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
7777 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7778 ioc->tm_cb_idx = tm_cb_idx;
7779 ioc->ctl_cb_idx = ctl_cb_idx;
7780 ioc->base_cb_idx = base_cb_idx;
7781 ioc->port_enable_cb_idx = port_enable_cb_idx;
7782 ioc->transport_cb_idx = transport_cb_idx;
7783 ioc->scsih_cb_idx = scsih_cb_idx;
7784 ioc->config_cb_idx = config_cb_idx;
7785 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7786 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7787 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7788 ioc->logging_level = logging_level;
7789 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7790 /* misc semaphores and spin locks */
7791 mutex_init(&ioc->reset_in_progress_mutex);
7792 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7793 spin_lock_init(&ioc->scsi_lookup_lock);
7794 spin_lock_init(&ioc->sas_device_lock);
7795 spin_lock_init(&ioc->sas_node_lock);
7796 spin_lock_init(&ioc->fw_event_lock);
7797 spin_lock_init(&ioc->raid_device_lock);
7798 spin_lock_init(&ioc->diag_trigger_lock);
7800 INIT_LIST_HEAD(&ioc->sas_device_list);
7801 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7802 INIT_LIST_HEAD(&ioc->sas_expander_list);
7803 INIT_LIST_HEAD(&ioc->fw_event_list);
7804 INIT_LIST_HEAD(&ioc->raid_device_list);
7805 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7806 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7807 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7808 INIT_LIST_HEAD(&ioc->reply_queue_list);
7810 /* init shost parameters */
7811 shost->max_cmd_len = 32;
7812 shost->max_lun = max_lun;
7813 shost->transportt = mpt3sas_transport_template;
7814 shost->unique_id = ioc->id;
7816 if (max_sectors != 0xFFFF) {
7817 if (max_sectors < 64) {
7818 shost->max_sectors = 64;
7819 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7820 "for max_sectors, range is 64 to 32767. Assigning "
7821 "value of 64.\n", ioc->name, max_sectors);
7822 } else if (max_sectors > 32767) {
7823 shost->max_sectors = 32767;
7824 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7825 "for max_sectors, range is 64 to 32767. Assigning "
7826 "default value of 32767.\n", ioc->name,
7829 shost->max_sectors = max_sectors & 0xFFFE;
7831 "The max_sectors value is set to %d\n",
7832 ioc->name, shost->max_sectors);
7836 /* register EEDP capabilities with SCSI layer */
7838 scsi_host_set_prot(shost, prot_mask);
7840 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7841 | SHOST_DIF_TYPE2_PROTECTION
7842 | SHOST_DIF_TYPE3_PROTECTION);
7844 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7847 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7848 "fw_event%d", ioc->id);
7849 ioc->firmware_event_thread = create_singlethread_workqueue(
7850 ioc->firmware_event_name);
7851 if (!ioc->firmware_event_thread) {
7852 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7853 ioc->name, __FILE__, __LINE__, __func__);
7855 goto out_thread_fail;
7858 ioc->is_driver_loading = 1;
7859 if ((mpt3sas_base_attach(ioc))) {
7860 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7861 ioc->name, __FILE__, __LINE__, __func__);
7863 goto out_attach_fail;
7865 rv = scsi_add_host(shost, &pdev->dev);
7867 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7868 ioc->name, __FILE__, __LINE__, __func__);
7869 goto out_add_shost_fail;
7872 scsi_scan_host(shost);
7875 mpt3sas_base_detach(ioc);
7877 destroy_workqueue(ioc->firmware_event_thread);
7879 list_del(&ioc->list);
7880 scsi_host_put(shost);
7886 * _scsih_suspend - power management suspend main entry point
7887 * @pdev: PCI device struct
7888 * @state: PM state change to (usually PCI_D3)
7890 * Returns 0 success, anything else error.
7893 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7895 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7896 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7897 pci_power_t device_state;
7899 mpt3sas_base_stop_watchdog(ioc);
7900 flush_scheduled_work();
7901 scsi_block_requests(shost);
7902 device_state = pci_choose_state(pdev, state);
7904 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7905 ioc->name, pdev, pci_name(pdev), device_state);
7907 pci_save_state(pdev);
7908 mpt3sas_base_free_resources(ioc);
7909 pci_set_power_state(pdev, device_state);
7914 * _scsih_resume - power management resume main entry point
7915 * @pdev: PCI device struct
7917 * Returns 0 success, anything else error.
7920 _scsih_resume(struct pci_dev *pdev)
7922 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7923 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7924 pci_power_t device_state = pdev->current_state;
7928 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7929 ioc->name, pdev, pci_name(pdev), device_state);
7931 pci_set_power_state(pdev, PCI_D0);
7932 pci_enable_wake(pdev, PCI_D0, 0);
7933 pci_restore_state(pdev);
7935 r = mpt3sas_base_map_resources(ioc);
7939 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7940 scsi_unblock_requests(shost);
7941 mpt3sas_base_start_watchdog(ioc);
7944 #endif /* CONFIG_PM */
7947 * _scsih_pci_error_detected - Called when a PCI error is detected.
7948 * @pdev: PCI device struct
7949 * @state: PCI channel state
7951 * Description: Called when a PCI error is detected.
7954 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7956 static pci_ers_result_t
7957 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7959 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7960 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7962 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
7966 case pci_channel_io_normal:
7967 return PCI_ERS_RESULT_CAN_RECOVER;
7968 case pci_channel_io_frozen:
7969 /* Fatal error, prepare for slot reset */
7970 ioc->pci_error_recovery = 1;
7971 scsi_block_requests(ioc->shost);
7972 mpt3sas_base_stop_watchdog(ioc);
7973 mpt3sas_base_free_resources(ioc);
7974 return PCI_ERS_RESULT_NEED_RESET;
7975 case pci_channel_io_perm_failure:
7976 /* Permanent error, prepare for device removal */
7977 ioc->pci_error_recovery = 1;
7978 mpt3sas_base_stop_watchdog(ioc);
7979 _scsih_flush_running_cmds(ioc);
7980 return PCI_ERS_RESULT_DISCONNECT;
7982 return PCI_ERS_RESULT_NEED_RESET;
7986 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7987 * @pdev: PCI device struct
7989 * Description: This routine is called by the pci error recovery
7990 * code after the PCI slot has been reset, just before we
7991 * should resume normal operations.
7993 static pci_ers_result_t
7994 _scsih_pci_slot_reset(struct pci_dev *pdev)
7996 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7997 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8000 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8003 ioc->pci_error_recovery = 0;
8005 pci_restore_state(pdev);
8006 rc = mpt3sas_base_map_resources(ioc);
8008 return PCI_ERS_RESULT_DISCONNECT;
8010 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8013 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8014 (rc == 0) ? "success" : "failed");
8017 return PCI_ERS_RESULT_RECOVERED;
8019 return PCI_ERS_RESULT_DISCONNECT;
8023 * _scsih_pci_resume() - resume normal ops after PCI reset
8024 * @pdev: pointer to PCI device
8026 * Called when the error recovery driver tells us that its
8027 * OK to resume normal operation. Use completion to allow
8028 * halted scsi ops to resume.
8031 _scsih_pci_resume(struct pci_dev *pdev)
8033 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8034 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8036 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8038 pci_cleanup_aer_uncorrect_error_status(pdev);
8039 mpt3sas_base_start_watchdog(ioc);
8040 scsi_unblock_requests(ioc->shost);
8044 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8045 * @pdev: pointer to PCI device
8047 static pci_ers_result_t
8048 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8050 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8051 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8053 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8056 /* TODO - dump whatever for debugging purposes */
8058 /* Request a slot reset. */
8059 return PCI_ERS_RESULT_NEED_RESET;
8062 /* raid transport support */
8063 static struct raid_function_template mpt3sas_raid_functions = {
8064 .cookie = &scsih_driver_template,
8065 .is_raid = _scsih_is_raid,
8066 .get_resync = _scsih_get_resync,
8067 .get_state = _scsih_get_state,
8070 static struct pci_error_handlers _scsih_err_handler = {
8071 .error_detected = _scsih_pci_error_detected,
8072 .mmio_enabled = _scsih_pci_mmio_enabled,
8073 .slot_reset = _scsih_pci_slot_reset,
8074 .resume = _scsih_pci_resume,
8077 static struct pci_driver scsih_driver = {
8078 .name = MPT3SAS_DRIVER_NAME,
8079 .id_table = scsih_pci_table,
8080 .probe = _scsih_probe,
8081 .remove = _scsih_remove,
8082 .shutdown = _scsih_shutdown,
8083 .err_handler = &_scsih_err_handler,
8085 .suspend = _scsih_suspend,
8086 .resume = _scsih_resume,
8092 * _scsih_init - main entry point for this driver.
8094 * Returns 0 success, anything else error.
8103 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8104 MPT3SAS_DRIVER_VERSION);
8106 mpt3sas_transport_template =
8107 sas_attach_transport(&mpt3sas_transport_functions);
8108 if (!mpt3sas_transport_template)
8111 /* raid transport support */
8112 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8113 if (!mpt3sas_raid_template) {
8114 sas_release_transport(mpt3sas_transport_template);
8118 mpt3sas_base_initialize_callback_handler();
8120 /* queuecommand callback hander */
8121 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8123 /* task managment callback handler */
8124 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8126 /* base internal commands callback handler */
8127 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8128 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8129 mpt3sas_port_enable_done);
8131 /* transport internal commands callback handler */
8132 transport_cb_idx = mpt3sas_base_register_callback_handler(
8133 mpt3sas_transport_done);
8135 /* scsih internal commands callback handler */
8136 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8138 /* configuration page API internal commands callback handler */
8139 config_cb_idx = mpt3sas_base_register_callback_handler(
8140 mpt3sas_config_done);
8142 /* ctl module callback handler */
8143 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8145 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8146 _scsih_tm_tr_complete);
8148 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8149 _scsih_tm_volume_tr_complete);
8151 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8152 _scsih_sas_control_complete);
8156 error = pci_register_driver(&scsih_driver);
8158 /* raid transport support */
8159 raid_class_release(mpt3sas_raid_template);
8160 sas_release_transport(mpt3sas_transport_template);
8167 * _scsih_exit - exit point for this driver (when it is a module).
8169 * Returns 0 success, anything else error.
8174 pr_info("mpt3sas version %s unloading\n",
8175 MPT3SAS_DRIVER_VERSION);
8179 pci_unregister_driver(&scsih_driver);
8182 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8183 mpt3sas_base_release_callback_handler(tm_cb_idx);
8184 mpt3sas_base_release_callback_handler(base_cb_idx);
8185 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8186 mpt3sas_base_release_callback_handler(transport_cb_idx);
8187 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8188 mpt3sas_base_release_callback_handler(config_cb_idx);
8189 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8191 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8192 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8193 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8195 /* raid transport support */
8196 raid_class_release(mpt3sas_raid_template);
8197 sas_release_transport(mpt3sas_transport_template);
8200 module_init(_scsih_init);
8201 module_exit(_scsih_exit);