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 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
58 #include "mpt3sas_base.h"
60 MODULE_AUTHOR(MPT3SAS_AUTHOR);
61 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
65 #define RAID_CHANNEL 1
67 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
68 struct _sas_node *sas_expander);
69 static void _firmware_event_work(struct work_struct *work);
71 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
72 struct _sas_device *sas_device);
73 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
74 u8 retry_count, u8 is_pd);
76 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
78 static void _scsih_scan_start(struct Scsi_Host *shost);
79 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
81 /* global parameters */
82 LIST_HEAD(mpt3sas_ioc_list);
84 /* local parameters */
85 static u8 scsi_io_cb_idx = -1;
86 static u8 tm_cb_idx = -1;
87 static u8 ctl_cb_idx = -1;
88 static u8 base_cb_idx = -1;
89 static u8 port_enable_cb_idx = -1;
90 static u8 transport_cb_idx = -1;
91 static u8 scsih_cb_idx = -1;
92 static u8 config_cb_idx = -1;
95 static u8 tm_tr_cb_idx = -1 ;
96 static u8 tm_tr_volume_cb_idx = -1 ;
97 static u8 tm_sas_control_cb_idx = -1;
99 /* command line options */
100 static u32 logging_level;
101 MODULE_PARM_DESC(logging_level,
102 " bits for enabling additional logging info (default=0)");
105 static ushort max_sectors = 0xFFFF;
106 module_param(max_sectors, ushort, 0);
107 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
110 static int missing_delay[2] = {-1, -1};
111 module_param_array(missing_delay, int, NULL, 0);
112 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
114 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
115 #define MPT3SAS_MAX_LUN (16895)
116 static u64 max_lun = MPT3SAS_MAX_LUN;
117 module_param(max_lun, ullong, 0);
118 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
123 /* diag_buffer_enable is bitwise
125 * bit 1 set = SNAPSHOT
126 * bit 2 set = EXTENDED
128 * Either bit can be set, or both
130 static int diag_buffer_enable = -1;
131 module_param(diag_buffer_enable, int, 0);
132 MODULE_PARM_DESC(diag_buffer_enable,
133 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
134 static int disable_discovery = -1;
135 module_param(disable_discovery, int, 0);
136 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
139 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
140 static int prot_mask = -1;
141 module_param(prot_mask, int, 0);
142 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
145 /* raid transport support */
147 static struct raid_template *mpt3sas_raid_template;
151 * struct sense_info - common structure for obtaining sense keys
153 * @asc: additional sense code
154 * @ascq: additional sense code qualifier
162 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
163 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
164 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
165 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
166 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
168 * struct fw_event_work - firmware event struct
169 * @list: link list framework
170 * @work: work object (ioc->fault_reset_work_q)
171 * @cancel_pending_work: flag set during reset handling
172 * @ioc: per adapter object
173 * @device_handle: device handle
174 * @VF_ID: virtual function id
175 * @VP_ID: virtual port id
176 * @ignore: flag meaning this event has been marked to ignore
177 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
178 * @event_data: reply event data payload follows
180 * This object stored on ioc->fw_event_list.
182 struct fw_event_work {
183 struct list_head list;
184 struct work_struct work;
185 u8 cancel_pending_work;
186 struct delayed_work delayed_work;
188 struct MPT3SAS_ADAPTER *ioc;
194 char event_data[0] __aligned(4);
197 /* raid transport support */
198 static struct raid_template *mpt3sas_raid_template;
201 * struct _scsi_io_transfer - scsi io transfer
202 * @handle: sas device handle (assigned by firmware)
203 * @is_raid: flag set for hidden raid components
204 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
205 * @data_length: data transfer length
206 * @data_dma: dma pointer to data
209 * @cdb_length: cdb length
211 * @timeout: timeout for this command
212 * @VF_ID: virtual function id
213 * @VP_ID: virtual port id
214 * @valid_reply: flag set for reply message
215 * @sense_length: sense length
216 * @ioc_status: ioc status
217 * @scsi_state: scsi state
218 * @scsi_status: scsi staus
219 * @log_info: log information
220 * @transfer_length: data length transfer when there is a reply message
222 * Used for sending internal scsi commands to devices within this module.
223 * Refer to _scsi_send_scsi_io().
225 struct _scsi_io_transfer {
228 enum dma_data_direction dir;
231 u8 sense[SCSI_SENSE_BUFFERSIZE];
239 /* the following bits are only valid when 'valid_reply = 1' */
249 * The pci device ids are defined in mpi/mpi2_cnfg.h.
251 static const struct pci_device_id scsih_pci_table[] = {
252 /* Fury ~ 3004 and 3008 */
253 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
254 PCI_ANY_ID, PCI_ANY_ID },
255 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
256 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
265 PCI_ANY_ID, PCI_ANY_ID },
266 {0} /* Terminating entry */
268 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
271 * _scsih_set_debug_level - global setting of ioc->logging_level.
273 * Note: The logging levels are defined in mpt3sas_debug.h.
276 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
278 int ret = param_set_int(val, kp);
279 struct MPT3SAS_ADAPTER *ioc;
284 pr_info("setting logging_level(0x%08x)\n", logging_level);
285 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
286 ioc->logging_level = logging_level;
289 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
290 &logging_level, 0644);
293 * _scsih_srch_boot_sas_address - search based on sas_address
294 * @sas_address: sas address
295 * @boot_device: boot device object from bios page 2
297 * Returns 1 when there's a match, 0 means no match.
300 _scsih_srch_boot_sas_address(u64 sas_address,
301 Mpi2BootDeviceSasWwid_t *boot_device)
303 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
307 * _scsih_srch_boot_device_name - search based on device name
308 * @device_name: device name specified in INDENTIFY fram
309 * @boot_device: boot device object from bios page 2
311 * Returns 1 when there's a match, 0 means no match.
314 _scsih_srch_boot_device_name(u64 device_name,
315 Mpi2BootDeviceDeviceName_t *boot_device)
317 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
321 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
322 * @enclosure_logical_id: enclosure logical id
323 * @slot_number: slot number
324 * @boot_device: boot device object from bios page 2
326 * Returns 1 when there's a match, 0 means no match.
329 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
330 Mpi2BootDeviceEnclosureSlot_t *boot_device)
332 return (enclosure_logical_id == le64_to_cpu(boot_device->
333 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
334 SlotNumber)) ? 1 : 0;
338 * _scsih_is_boot_device - search for matching boot device.
339 * @sas_address: sas address
340 * @device_name: device name specified in INDENTIFY fram
341 * @enclosure_logical_id: enclosure logical id
342 * @slot_number: slot number
343 * @form: specifies boot device form
344 * @boot_device: boot device object from bios page 2
346 * Returns 1 when there's a match, 0 means no match.
349 _scsih_is_boot_device(u64 sas_address, u64 device_name,
350 u64 enclosure_logical_id, u16 slot, u8 form,
351 Mpi2BiosPage2BootDevice_t *boot_device)
356 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
359 rc = _scsih_srch_boot_sas_address(
360 sas_address, &boot_device->SasWwid);
362 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
363 if (!enclosure_logical_id)
365 rc = _scsih_srch_boot_encl_slot(
366 enclosure_logical_id,
367 slot, &boot_device->EnclosureSlot);
369 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
372 rc = _scsih_srch_boot_device_name(
373 device_name, &boot_device->DeviceName);
375 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
383 * _scsih_get_sas_address - set the sas_address for given device handle
384 * @handle: device handle
385 * @sas_address: sas address
387 * Returns 0 success, non-zero when failure
390 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
393 Mpi2SasDevicePage0_t sas_device_pg0;
394 Mpi2ConfigReply_t mpi_reply;
399 if (handle <= ioc->sas_hba.num_phys) {
400 *sas_address = ioc->sas_hba.sas_address;
404 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
405 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
406 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
407 __FILE__, __LINE__, __func__);
411 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
412 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
413 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
417 /* we hit this becuase the given parent handle doesn't exist */
418 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
421 /* else error case */
423 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
424 ioc->name, handle, ioc_status,
425 __FILE__, __LINE__, __func__);
430 * _scsih_determine_boot_device - determine boot device.
431 * @ioc: per adapter object
432 * @device: either sas_device or raid_device object
433 * @is_raid: [flag] 1 = raid object, 0 = sas object
435 * Determines whether this device should be first reported device to
436 * to scsi-ml or sas transport, this purpose is for persistent boot device.
437 * There are primary, alternate, and current entries in bios page 2. The order
438 * priority is primary, alternate, then current. This routine saves
439 * the corresponding device object and is_raid flag in the ioc object.
440 * The saved data to be used later in _scsih_probe_boot_devices().
443 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
444 void *device, u8 is_raid)
446 struct _sas_device *sas_device;
447 struct _raid_device *raid_device;
450 u64 enclosure_logical_id;
453 /* only process this function when driver loads */
454 if (!ioc->is_driver_loading)
457 /* no Bios, return immediately */
458 if (!ioc->bios_pg3.BiosVersion)
463 sas_address = sas_device->sas_address;
464 device_name = sas_device->device_name;
465 enclosure_logical_id = sas_device->enclosure_logical_id;
466 slot = sas_device->slot;
468 raid_device = device;
469 sas_address = raid_device->wwid;
471 enclosure_logical_id = 0;
475 if (!ioc->req_boot_device.device) {
476 if (_scsih_is_boot_device(sas_address, device_name,
477 enclosure_logical_id, slot,
478 (ioc->bios_pg2.ReqBootDeviceForm &
479 MPI2_BIOSPAGE2_FORM_MASK),
480 &ioc->bios_pg2.RequestedBootDevice)) {
481 dinitprintk(ioc, pr_info(MPT3SAS_FMT
482 "%s: req_boot_device(0x%016llx)\n",
484 (unsigned long long)sas_address));
485 ioc->req_boot_device.device = device;
486 ioc->req_boot_device.is_raid = is_raid;
490 if (!ioc->req_alt_boot_device.device) {
491 if (_scsih_is_boot_device(sas_address, device_name,
492 enclosure_logical_id, slot,
493 (ioc->bios_pg2.ReqAltBootDeviceForm &
494 MPI2_BIOSPAGE2_FORM_MASK),
495 &ioc->bios_pg2.RequestedAltBootDevice)) {
496 dinitprintk(ioc, pr_info(MPT3SAS_FMT
497 "%s: req_alt_boot_device(0x%016llx)\n",
499 (unsigned long long)sas_address));
500 ioc->req_alt_boot_device.device = device;
501 ioc->req_alt_boot_device.is_raid = is_raid;
505 if (!ioc->current_boot_device.device) {
506 if (_scsih_is_boot_device(sas_address, device_name,
507 enclosure_logical_id, slot,
508 (ioc->bios_pg2.CurrentBootDeviceForm &
509 MPI2_BIOSPAGE2_FORM_MASK),
510 &ioc->bios_pg2.CurrentBootDevice)) {
511 dinitprintk(ioc, pr_info(MPT3SAS_FMT
512 "%s: current_boot_device(0x%016llx)\n",
514 (unsigned long long)sas_address));
515 ioc->current_boot_device.device = device;
516 ioc->current_boot_device.is_raid = is_raid;
522 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
523 * @ioc: per adapter object
524 * @sas_address: sas address
525 * Context: Calling function should acquire ioc->sas_device_lock
527 * This searches for sas_device based on sas_address, then return sas_device
531 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
534 struct _sas_device *sas_device;
536 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
537 if (sas_device->sas_address == sas_address)
540 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
541 if (sas_device->sas_address == sas_address)
548 * _scsih_sas_device_find_by_handle - sas device search
549 * @ioc: per adapter object
550 * @handle: sas device handle (assigned by firmware)
551 * Context: Calling function should acquire ioc->sas_device_lock
553 * This searches for sas_device based on sas_address, then return sas_device
556 static struct _sas_device *
557 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
559 struct _sas_device *sas_device;
561 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
562 if (sas_device->handle == handle)
565 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
566 if (sas_device->handle == handle)
573 * _scsih_sas_device_remove - remove sas_device from list.
574 * @ioc: per adapter object
575 * @sas_device: the sas_device object
576 * Context: This function will acquire ioc->sas_device_lock.
578 * Removing object and freeing associated memory from the ioc->sas_device_list.
581 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
582 struct _sas_device *sas_device)
589 spin_lock_irqsave(&ioc->sas_device_lock, flags);
590 list_del(&sas_device->list);
592 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
596 * _scsih_device_remove_by_handle - removing device object by handle
597 * @ioc: per adapter object
598 * @handle: device handle
603 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
605 struct _sas_device *sas_device;
608 if (ioc->shost_recovery)
611 spin_lock_irqsave(&ioc->sas_device_lock, flags);
612 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
614 list_del(&sas_device->list);
615 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
617 _scsih_remove_device(ioc, sas_device);
621 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
622 * @ioc: per adapter object
623 * @sas_address: device sas_address
628 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
631 struct _sas_device *sas_device;
634 if (ioc->shost_recovery)
637 spin_lock_irqsave(&ioc->sas_device_lock, flags);
638 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
641 list_del(&sas_device->list);
642 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
644 _scsih_remove_device(ioc, sas_device);
648 * _scsih_sas_device_add - insert sas_device to the list.
649 * @ioc: per adapter object
650 * @sas_device: the sas_device object
651 * Context: This function will acquire ioc->sas_device_lock.
653 * Adding new object to the ioc->sas_device_list.
656 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
657 struct _sas_device *sas_device)
661 dewtprintk(ioc, pr_info(MPT3SAS_FMT
662 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
663 ioc->name, __func__, sas_device->handle,
664 (unsigned long long)sas_device->sas_address));
666 spin_lock_irqsave(&ioc->sas_device_lock, flags);
667 list_add_tail(&sas_device->list, &ioc->sas_device_list);
668 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
670 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
671 sas_device->sas_address_parent)) {
672 _scsih_sas_device_remove(ioc, sas_device);
673 } else if (!sas_device->starget) {
675 * When asyn scanning is enabled, its not possible to remove
676 * devices while scanning is turned on due to an oops in
677 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
679 if (!ioc->is_driver_loading) {
680 mpt3sas_transport_port_remove(ioc,
681 sas_device->sas_address,
682 sas_device->sas_address_parent);
683 _scsih_sas_device_remove(ioc, sas_device);
689 * _scsih_sas_device_init_add - insert sas_device to the list.
690 * @ioc: per adapter object
691 * @sas_device: the sas_device object
692 * Context: This function will acquire ioc->sas_device_lock.
694 * Adding new object at driver load time to the ioc->sas_device_init_list.
697 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
698 struct _sas_device *sas_device)
702 dewtprintk(ioc, pr_info(MPT3SAS_FMT
703 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
704 __func__, sas_device->handle,
705 (unsigned long long)sas_device->sas_address));
707 spin_lock_irqsave(&ioc->sas_device_lock, flags);
708 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
709 _scsih_determine_boot_device(ioc, sas_device, 0);
710 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
714 * _scsih_raid_device_find_by_id - raid device search
715 * @ioc: per adapter object
716 * @id: sas device target id
717 * @channel: sas device channel
718 * Context: Calling function should acquire ioc->raid_device_lock
720 * This searches for raid_device based on target id, then return raid_device
723 static struct _raid_device *
724 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
726 struct _raid_device *raid_device, *r;
729 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
730 if (raid_device->id == id && raid_device->channel == channel) {
741 * _scsih_raid_device_find_by_handle - raid device search
742 * @ioc: per adapter object
743 * @handle: sas device handle (assigned by firmware)
744 * Context: Calling function should acquire ioc->raid_device_lock
746 * This searches for raid_device based on handle, then return raid_device
749 static struct _raid_device *
750 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
752 struct _raid_device *raid_device, *r;
755 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
756 if (raid_device->handle != handle)
767 * _scsih_raid_device_find_by_wwid - raid device search
768 * @ioc: per adapter object
769 * @handle: sas device handle (assigned by firmware)
770 * Context: Calling function should acquire ioc->raid_device_lock
772 * This searches for raid_device based on wwid, then return raid_device
775 static struct _raid_device *
776 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
778 struct _raid_device *raid_device, *r;
781 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
782 if (raid_device->wwid != wwid)
793 * _scsih_raid_device_add - add raid_device object
794 * @ioc: per adapter object
795 * @raid_device: raid_device object
797 * This is added to the raid_device_list link list.
800 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
801 struct _raid_device *raid_device)
805 dewtprintk(ioc, pr_info(MPT3SAS_FMT
806 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
807 raid_device->handle, (unsigned long long)raid_device->wwid));
809 spin_lock_irqsave(&ioc->raid_device_lock, flags);
810 list_add_tail(&raid_device->list, &ioc->raid_device_list);
811 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
815 * _scsih_raid_device_remove - delete raid_device object
816 * @ioc: per adapter object
817 * @raid_device: raid_device object
821 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
822 struct _raid_device *raid_device)
826 spin_lock_irqsave(&ioc->raid_device_lock, flags);
827 list_del(&raid_device->list);
829 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
833 * mpt3sas_scsih_expander_find_by_handle - expander device search
834 * @ioc: per adapter object
835 * @handle: expander handle (assigned by firmware)
836 * Context: Calling function should acquire ioc->sas_device_lock
838 * This searches for expander device based on handle, then returns the
842 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
844 struct _sas_node *sas_expander, *r;
847 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
848 if (sas_expander->handle != handle)
858 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
859 * @ioc: per adapter object
860 * @sas_address: sas address
861 * Context: Calling function should acquire ioc->sas_node_lock.
863 * This searches for expander device based on sas_address, then returns the
867 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
870 struct _sas_node *sas_expander, *r;
873 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
874 if (sas_expander->sas_address != sas_address)
884 * _scsih_expander_node_add - insert expander device to the list.
885 * @ioc: per adapter object
886 * @sas_expander: the sas_device object
887 * Context: This function will acquire ioc->sas_node_lock.
889 * Adding new object to the ioc->sas_expander_list.
894 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
895 struct _sas_node *sas_expander)
899 spin_lock_irqsave(&ioc->sas_node_lock, flags);
900 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
901 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
905 * _scsih_is_end_device - determines if device is an end device
906 * @device_info: bitfield providing information about the device.
909 * Returns 1 if end device.
912 _scsih_is_end_device(u32 device_info)
914 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
915 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
916 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
917 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
924 * _scsih_scsi_lookup_get - returns scmd entry
925 * @ioc: per adapter object
926 * @smid: system request message index
928 * Returns the smid stored scmd pointer.
930 static struct scsi_cmnd *
931 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
933 return ioc->scsi_lookup[smid - 1].scmd;
937 * _scsih_scsi_lookup_get_clear - returns scmd entry
938 * @ioc: per adapter object
939 * @smid: system request message index
941 * Returns the smid stored scmd pointer.
942 * Then will derefrence the stored scmd pointer.
944 static inline struct scsi_cmnd *
945 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
948 struct scsi_cmnd *scmd;
950 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
951 scmd = ioc->scsi_lookup[smid - 1].scmd;
952 ioc->scsi_lookup[smid - 1].scmd = NULL;
953 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
959 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
960 * @ioc: per adapter object
961 * @smid: system request message index
962 * @scmd: pointer to scsi command object
963 * Context: This function will acquire ioc->scsi_lookup_lock.
965 * This will search for a scmd pointer in the scsi_lookup array,
966 * returning the revelent smid. A returned value of zero means invalid.
969 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
976 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
978 for (i = 0; i < ioc->scsiio_depth; i++) {
979 if (ioc->scsi_lookup[i].scmd == scmd) {
980 smid = ioc->scsi_lookup[i].smid;
985 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
990 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
991 * @ioc: per adapter object
994 * Context: This function will acquire ioc->scsi_lookup_lock.
996 * This will search for a matching channel:id in the scsi_lookup array,
997 * returning 1 if found.
1000 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1004 unsigned long flags;
1007 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1009 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1010 if (ioc->scsi_lookup[i].scmd &&
1011 (ioc->scsi_lookup[i].scmd->device->id == id &&
1012 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1018 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1023 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1024 * @ioc: per adapter object
1028 * Context: This function will acquire ioc->scsi_lookup_lock.
1030 * This will search for a matching channel:id:lun in the scsi_lookup array,
1031 * returning 1 if found.
1034 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1035 unsigned int lun, int channel)
1038 unsigned long flags;
1041 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1043 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1044 if (ioc->scsi_lookup[i].scmd &&
1045 (ioc->scsi_lookup[i].scmd->device->id == id &&
1046 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1047 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1053 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1058 * _scsih_change_queue_depth - setting device queue depth
1059 * @sdev: scsi device struct
1060 * @qdepth: requested queue depth
1062 * Returns queue depth.
1065 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1067 struct Scsi_Host *shost = sdev->host;
1069 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1070 struct MPT3SAS_DEVICE *sas_device_priv_data;
1071 struct MPT3SAS_TARGET *sas_target_priv_data;
1072 struct _sas_device *sas_device;
1073 unsigned long flags;
1075 max_depth = shost->can_queue;
1077 /* limit max device queue for SATA to 32 */
1078 sas_device_priv_data = sdev->hostdata;
1079 if (!sas_device_priv_data)
1081 sas_target_priv_data = sas_device_priv_data->sas_target;
1082 if (!sas_target_priv_data)
1084 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1086 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1087 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1088 sas_device_priv_data->sas_target->sas_address);
1089 if (sas_device && sas_device->device_info &
1090 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1091 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1092 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1096 if (!sdev->tagged_supported)
1098 if (qdepth > max_depth)
1100 return scsi_change_queue_depth(sdev, qdepth);
1104 * _scsih_target_alloc - target add routine
1105 * @starget: scsi target struct
1107 * Returns 0 if ok. Any other return is assumed to be an error and
1108 * the device is ignored.
1111 _scsih_target_alloc(struct scsi_target *starget)
1113 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1114 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1115 struct MPT3SAS_TARGET *sas_target_priv_data;
1116 struct _sas_device *sas_device;
1117 struct _raid_device *raid_device;
1118 unsigned long flags;
1119 struct sas_rphy *rphy;
1121 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1123 if (!sas_target_priv_data)
1126 starget->hostdata = sas_target_priv_data;
1127 sas_target_priv_data->starget = starget;
1128 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1131 if (starget->channel == RAID_CHANNEL) {
1132 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1133 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1136 sas_target_priv_data->handle = raid_device->handle;
1137 sas_target_priv_data->sas_address = raid_device->wwid;
1138 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1139 raid_device->starget = starget;
1141 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1145 /* sas/sata devices */
1146 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1147 rphy = dev_to_rphy(starget->dev.parent);
1148 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1149 rphy->identify.sas_address);
1152 sas_target_priv_data->handle = sas_device->handle;
1153 sas_target_priv_data->sas_address = sas_device->sas_address;
1154 sas_device->starget = starget;
1155 sas_device->id = starget->id;
1156 sas_device->channel = starget->channel;
1157 if (test_bit(sas_device->handle, ioc->pd_handles))
1158 sas_target_priv_data->flags |=
1159 MPT_TARGET_FLAGS_RAID_COMPONENT;
1160 if (sas_device->fast_path)
1161 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1163 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1169 * _scsih_target_destroy - target destroy routine
1170 * @starget: scsi target struct
1175 _scsih_target_destroy(struct scsi_target *starget)
1177 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1178 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1179 struct MPT3SAS_TARGET *sas_target_priv_data;
1180 struct _sas_device *sas_device;
1181 struct _raid_device *raid_device;
1182 unsigned long flags;
1183 struct sas_rphy *rphy;
1185 sas_target_priv_data = starget->hostdata;
1186 if (!sas_target_priv_data)
1189 if (starget->channel == RAID_CHANNEL) {
1190 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1191 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1194 raid_device->starget = NULL;
1195 raid_device->sdev = NULL;
1197 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1201 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1202 rphy = dev_to_rphy(starget->dev.parent);
1203 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1204 rphy->identify.sas_address);
1205 if (sas_device && (sas_device->starget == starget) &&
1206 (sas_device->id == starget->id) &&
1207 (sas_device->channel == starget->channel))
1208 sas_device->starget = NULL;
1210 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1213 kfree(sas_target_priv_data);
1214 starget->hostdata = NULL;
1218 * _scsih_slave_alloc - device add routine
1219 * @sdev: scsi device struct
1221 * Returns 0 if ok. Any other return is assumed to be an error and
1222 * the device is ignored.
1225 _scsih_slave_alloc(struct scsi_device *sdev)
1227 struct Scsi_Host *shost;
1228 struct MPT3SAS_ADAPTER *ioc;
1229 struct MPT3SAS_TARGET *sas_target_priv_data;
1230 struct MPT3SAS_DEVICE *sas_device_priv_data;
1231 struct scsi_target *starget;
1232 struct _raid_device *raid_device;
1233 struct _sas_device *sas_device;
1234 unsigned long flags;
1236 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1238 if (!sas_device_priv_data)
1241 sas_device_priv_data->lun = sdev->lun;
1242 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1244 starget = scsi_target(sdev);
1245 sas_target_priv_data = starget->hostdata;
1246 sas_target_priv_data->num_luns++;
1247 sas_device_priv_data->sas_target = sas_target_priv_data;
1248 sdev->hostdata = sas_device_priv_data;
1249 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1250 sdev->no_uld_attach = 1;
1252 shost = dev_to_shost(&starget->dev);
1253 ioc = shost_priv(shost);
1254 if (starget->channel == RAID_CHANNEL) {
1255 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1256 raid_device = _scsih_raid_device_find_by_id(ioc,
1257 starget->id, starget->channel);
1259 raid_device->sdev = sdev; /* raid is single lun */
1260 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1263 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1264 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1265 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1266 sas_target_priv_data->sas_address);
1267 if (sas_device && (sas_device->starget == NULL)) {
1268 sdev_printk(KERN_INFO, sdev,
1269 "%s : sas_device->starget set to starget @ %d\n",
1270 __func__, __LINE__);
1271 sas_device->starget = starget;
1273 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1280 * _scsih_slave_destroy - device destroy routine
1281 * @sdev: scsi device struct
1286 _scsih_slave_destroy(struct scsi_device *sdev)
1288 struct MPT3SAS_TARGET *sas_target_priv_data;
1289 struct scsi_target *starget;
1290 struct Scsi_Host *shost;
1291 struct MPT3SAS_ADAPTER *ioc;
1292 struct _sas_device *sas_device;
1293 unsigned long flags;
1295 if (!sdev->hostdata)
1298 starget = scsi_target(sdev);
1299 sas_target_priv_data = starget->hostdata;
1300 sas_target_priv_data->num_luns--;
1302 shost = dev_to_shost(&starget->dev);
1303 ioc = shost_priv(shost);
1305 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1306 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1307 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1308 sas_target_priv_data->sas_address);
1309 if (sas_device && !sas_target_priv_data->num_luns)
1310 sas_device->starget = NULL;
1311 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1314 kfree(sdev->hostdata);
1315 sdev->hostdata = NULL;
1319 * _scsih_display_sata_capabilities - sata capabilities
1320 * @ioc: per adapter object
1321 * @handle: device handle
1322 * @sdev: scsi device struct
1325 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1326 u16 handle, struct scsi_device *sdev)
1328 Mpi2ConfigReply_t mpi_reply;
1329 Mpi2SasDevicePage0_t sas_device_pg0;
1334 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1335 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1336 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1337 ioc->name, __FILE__, __LINE__, __func__);
1341 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1342 MPI2_IOCSTATUS_MASK;
1343 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1344 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1345 ioc->name, __FILE__, __LINE__, __func__);
1349 flags = le16_to_cpu(sas_device_pg0.Flags);
1350 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1352 sdev_printk(KERN_INFO, sdev,
1353 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1354 "sw_preserve(%s)\n",
1355 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1356 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1357 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1359 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1360 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1361 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1365 * raid transport support -
1366 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1367 * unloading the driver followed by a load - I beleive that the subroutine
1368 * raid_class_release() is not cleaning up properly.
1372 * _scsih_is_raid - return boolean indicating device is raid volume
1373 * @dev the device struct object
1376 _scsih_is_raid(struct device *dev)
1378 struct scsi_device *sdev = to_scsi_device(dev);
1380 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1384 * _scsih_get_resync - get raid volume resync percent complete
1385 * @dev the device struct object
1388 _scsih_get_resync(struct device *dev)
1390 struct scsi_device *sdev = to_scsi_device(dev);
1391 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1392 static struct _raid_device *raid_device;
1393 unsigned long flags;
1394 Mpi2RaidVolPage0_t vol_pg0;
1395 Mpi2ConfigReply_t mpi_reply;
1396 u32 volume_status_flags;
1397 u8 percent_complete;
1400 percent_complete = 0;
1402 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1403 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1406 handle = raid_device->handle;
1407 percent_complete = raid_device->percent_complete;
1409 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1414 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1415 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1416 sizeof(Mpi2RaidVolPage0_t))) {
1417 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1418 ioc->name, __FILE__, __LINE__, __func__);
1419 percent_complete = 0;
1423 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1424 if (!(volume_status_flags &
1425 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1426 percent_complete = 0;
1429 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1433 * _scsih_get_state - get raid volume level
1434 * @dev the device struct object
1437 _scsih_get_state(struct device *dev)
1439 struct scsi_device *sdev = to_scsi_device(dev);
1440 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1441 static struct _raid_device *raid_device;
1442 unsigned long flags;
1443 Mpi2RaidVolPage0_t vol_pg0;
1444 Mpi2ConfigReply_t mpi_reply;
1446 enum raid_state state = RAID_STATE_UNKNOWN;
1449 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1450 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1453 handle = raid_device->handle;
1454 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1459 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1460 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1461 sizeof(Mpi2RaidVolPage0_t))) {
1462 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1463 ioc->name, __FILE__, __LINE__, __func__);
1467 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1468 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1469 state = RAID_STATE_RESYNCING;
1473 switch (vol_pg0.VolumeState) {
1474 case MPI2_RAID_VOL_STATE_OPTIMAL:
1475 case MPI2_RAID_VOL_STATE_ONLINE:
1476 state = RAID_STATE_ACTIVE;
1478 case MPI2_RAID_VOL_STATE_DEGRADED:
1479 state = RAID_STATE_DEGRADED;
1481 case MPI2_RAID_VOL_STATE_FAILED:
1482 case MPI2_RAID_VOL_STATE_MISSING:
1483 state = RAID_STATE_OFFLINE;
1487 raid_set_state(mpt3sas_raid_template, dev, state);
1491 * _scsih_set_level - set raid level
1492 * @sdev: scsi device struct
1493 * @volume_type: volume type
1496 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1498 enum raid_level level = RAID_LEVEL_UNKNOWN;
1500 switch (volume_type) {
1501 case MPI2_RAID_VOL_TYPE_RAID0:
1502 level = RAID_LEVEL_0;
1504 case MPI2_RAID_VOL_TYPE_RAID10:
1505 level = RAID_LEVEL_10;
1507 case MPI2_RAID_VOL_TYPE_RAID1E:
1508 level = RAID_LEVEL_1E;
1510 case MPI2_RAID_VOL_TYPE_RAID1:
1511 level = RAID_LEVEL_1;
1515 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1520 * _scsih_get_volume_capabilities - volume capabilities
1521 * @ioc: per adapter object
1522 * @sas_device: the raid_device object
1524 * Returns 0 for success, else 1
1527 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1528 struct _raid_device *raid_device)
1530 Mpi2RaidVolPage0_t *vol_pg0;
1531 Mpi2RaidPhysDiskPage0_t pd_pg0;
1532 Mpi2SasDevicePage0_t sas_device_pg0;
1533 Mpi2ConfigReply_t mpi_reply;
1537 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1538 &num_pds)) || !num_pds) {
1539 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1540 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1545 raid_device->num_pds = num_pds;
1546 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1547 sizeof(Mpi2RaidVol0PhysDisk_t));
1548 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1550 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1551 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1556 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1557 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1558 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1559 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1565 raid_device->volume_type = vol_pg0->VolumeType;
1567 /* figure out what the underlying devices are by
1568 * obtaining the device_info bits for the 1st device
1570 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1571 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1572 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1573 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1574 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1575 le16_to_cpu(pd_pg0.DevHandle)))) {
1576 raid_device->device_info =
1577 le32_to_cpu(sas_device_pg0.DeviceInfo);
1588 * _scsih_enable_tlr - setting TLR flags
1589 * @ioc: per adapter object
1590 * @sdev: scsi device struct
1592 * Enabling Transaction Layer Retries for tape devices when
1593 * vpd page 0x90 is present
1597 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1601 if (sdev->type != TYPE_TAPE)
1604 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1607 sas_enable_tlr(sdev);
1608 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1609 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1615 * _scsih_slave_configure - device configure routine.
1616 * @sdev: scsi device struct
1618 * Returns 0 if ok. Any other return is assumed to be an error and
1619 * the device is ignored.
1622 _scsih_slave_configure(struct scsi_device *sdev)
1624 struct Scsi_Host *shost = sdev->host;
1625 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1626 struct MPT3SAS_DEVICE *sas_device_priv_data;
1627 struct MPT3SAS_TARGET *sas_target_priv_data;
1628 struct _sas_device *sas_device;
1629 struct _raid_device *raid_device;
1630 unsigned long flags;
1635 u16 handle, volume_handle = 0;
1636 u64 volume_wwid = 0;
1639 sas_device_priv_data = sdev->hostdata;
1640 sas_device_priv_data->configured_lun = 1;
1641 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1642 sas_target_priv_data = sas_device_priv_data->sas_target;
1643 handle = sas_target_priv_data->handle;
1645 /* raid volume handling */
1646 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1648 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1649 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1650 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1652 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1653 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1654 __LINE__, __func__));
1658 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1659 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1660 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1661 __LINE__, __func__));
1666 /* RAID Queue Depth Support
1667 * IS volume = underlying qdepth of drive type, either
1668 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1669 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1671 if (raid_device->device_info &
1672 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1673 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1676 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1677 if (raid_device->device_info &
1678 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1684 switch (raid_device->volume_type) {
1685 case MPI2_RAID_VOL_TYPE_RAID0:
1688 case MPI2_RAID_VOL_TYPE_RAID1E:
1689 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1690 if (ioc->manu_pg10.OEMIdentifier &&
1691 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1692 MFG10_GF0_R10_DISPLAY) &&
1693 !(raid_device->num_pds % 2))
1698 case MPI2_RAID_VOL_TYPE_RAID1:
1699 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1702 case MPI2_RAID_VOL_TYPE_RAID10:
1703 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1706 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1708 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1713 sdev_printk(KERN_INFO, sdev,
1714 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1715 r_level, raid_device->handle,
1716 (unsigned long long)raid_device->wwid,
1717 raid_device->num_pds, ds);
1720 _scsih_change_queue_depth(sdev, qdepth);
1722 /* raid transport support */
1723 _scsih_set_level(sdev, raid_device->volume_type);
1727 /* non-raid handling */
1728 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1729 if (mpt3sas_config_get_volume_handle(ioc, handle,
1731 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1732 "failure at %s:%d/%s()!\n", ioc->name,
1733 __FILE__, __LINE__, __func__));
1736 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1737 volume_handle, &volume_wwid)) {
1738 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1739 "failure at %s:%d/%s()!\n", ioc->name,
1740 __FILE__, __LINE__, __func__));
1745 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1746 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1747 sas_device_priv_data->sas_target->sas_address);
1749 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1750 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1751 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1756 sas_device->volume_handle = volume_handle;
1757 sas_device->volume_wwid = volume_wwid;
1758 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1759 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1763 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1764 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1766 else if (sas_device->device_info &
1767 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1771 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1772 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1773 ds, handle, (unsigned long long)sas_device->sas_address,
1774 sas_device->phy, (unsigned long long)sas_device->device_name);
1775 sdev_printk(KERN_INFO, sdev,
1776 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1777 ds, (unsigned long long)
1778 sas_device->enclosure_logical_id, sas_device->slot);
1780 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1783 _scsih_display_sata_capabilities(ioc, handle, sdev);
1786 _scsih_change_queue_depth(sdev, qdepth);
1789 sas_read_port_mode_page(sdev);
1790 _scsih_enable_tlr(ioc, sdev);
1797 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1798 * @sdev: scsi device struct
1799 * @bdev: pointer to block device context
1800 * @capacity: device size (in 512 byte sectors)
1801 * @params: three element array to place output:
1802 * params[0] number of heads (max 255)
1803 * params[1] number of sectors (max 63)
1804 * params[2] number of cylinders
1809 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1810 sector_t capacity, int params[])
1820 dummy = heads * sectors;
1821 cylinders = capacity;
1822 sector_div(cylinders, dummy);
1825 * Handle extended translation size for logical drives
1828 if ((ulong)capacity >= 0x200000) {
1831 dummy = heads * sectors;
1832 cylinders = capacity;
1833 sector_div(cylinders, dummy);
1838 params[1] = sectors;
1839 params[2] = cylinders;
1845 * _scsih_response_code - translation of device response code
1846 * @ioc: per adapter object
1847 * @response_code: response code returned by the device
1852 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1856 switch (response_code) {
1857 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1858 desc = "task management request completed";
1860 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1861 desc = "invalid frame";
1863 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1864 desc = "task management request not supported";
1866 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1867 desc = "task management request failed";
1869 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1870 desc = "task management request succeeded";
1872 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1873 desc = "invalid lun";
1876 desc = "overlapped tag attempted";
1878 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1879 desc = "task queued, however not sent to target";
1885 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1886 ioc->name, response_code, desc);
1890 * _scsih_tm_done - tm completion routine
1891 * @ioc: per adapter object
1892 * @smid: system request message index
1893 * @msix_index: MSIX table index supplied by the OS
1894 * @reply: reply message frame(lower 32bit addr)
1897 * The callback handler when using scsih_issue_tm.
1899 * Return 1 meaning mf should be freed from _base_interrupt
1900 * 0 means the mf is freed from this function.
1903 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1905 MPI2DefaultReply_t *mpi_reply;
1907 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1909 if (ioc->tm_cmds.smid != smid)
1911 mpt3sas_base_flush_reply_queues(ioc);
1912 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1913 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1915 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1916 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1918 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1919 complete(&ioc->tm_cmds.done);
1924 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1925 * @ioc: per adapter object
1926 * @handle: device handle
1928 * During taskmangement request, we need to freeze the device queue.
1931 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1933 struct MPT3SAS_DEVICE *sas_device_priv_data;
1934 struct scsi_device *sdev;
1937 shost_for_each_device(sdev, ioc->shost) {
1940 sas_device_priv_data = sdev->hostdata;
1941 if (!sas_device_priv_data)
1943 if (sas_device_priv_data->sas_target->handle == handle) {
1944 sas_device_priv_data->sas_target->tm_busy = 1;
1946 ioc->ignore_loginfos = 1;
1952 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1953 * @ioc: per adapter object
1954 * @handle: device handle
1956 * During taskmangement request, we need to freeze the device queue.
1959 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1961 struct MPT3SAS_DEVICE *sas_device_priv_data;
1962 struct scsi_device *sdev;
1965 shost_for_each_device(sdev, ioc->shost) {
1968 sas_device_priv_data = sdev->hostdata;
1969 if (!sas_device_priv_data)
1971 if (sas_device_priv_data->sas_target->handle == handle) {
1972 sas_device_priv_data->sas_target->tm_busy = 0;
1974 ioc->ignore_loginfos = 0;
1980 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
1981 * @ioc: per adapter struct
1982 * @device_handle: device handle
1983 * @channel: the channel assigned by the OS
1984 * @id: the id assigned by the OS
1986 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1987 * @smid_task: smid assigned to the task
1988 * @timeout: timeout in seconds
1989 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
1992 * A generic API for sending task management requests to firmware.
1994 * The callback index is set inside `ioc->tm_cb_idx`.
1996 * Return SUCCESS or FAILED.
1999 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2000 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2001 enum mutex_type m_type)
2003 Mpi2SCSITaskManagementRequest_t *mpi_request;
2004 Mpi2SCSITaskManagementReply_t *mpi_reply;
2007 unsigned long timeleft;
2008 struct scsiio_tracker *scsi_lookup = NULL;
2011 if (m_type == TM_MUTEX_ON)
2012 mutex_lock(&ioc->tm_cmds.mutex);
2013 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2014 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2015 __func__, ioc->name);
2020 if (ioc->shost_recovery || ioc->remove_host ||
2021 ioc->pci_error_recovery) {
2022 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2023 __func__, ioc->name);
2028 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2029 if (ioc_state & MPI2_DOORBELL_USED) {
2030 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2031 "unexpected doorbell active!\n", ioc->name));
2032 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2034 rc = (!rc) ? SUCCESS : FAILED;
2038 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2039 mpt3sas_base_fault_info(ioc, ioc_state &
2040 MPI2_DOORBELL_DATA_MASK);
2041 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2043 rc = (!rc) ? SUCCESS : FAILED;
2047 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2049 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2050 ioc->name, __func__);
2055 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2056 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2058 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2059 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2060 ioc->name, handle, type, smid_task));
2061 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2062 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2063 ioc->tm_cmds.smid = smid;
2064 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2065 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2066 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2067 mpi_request->DevHandle = cpu_to_le16(handle);
2068 mpi_request->TaskType = type;
2069 mpi_request->TaskMID = cpu_to_le16(smid_task);
2070 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2071 mpt3sas_scsih_set_tm_flag(ioc, handle);
2072 init_completion(&ioc->tm_cmds.done);
2073 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2074 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2075 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2076 pr_err(MPT3SAS_FMT "%s: timeout\n",
2077 ioc->name, __func__);
2078 _debug_dump_mf(mpi_request,
2079 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2080 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2081 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2083 rc = (!rc) ? SUCCESS : FAILED;
2084 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2085 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2090 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2091 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2092 mpi_reply = ioc->tm_cmds.reply;
2093 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2094 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2095 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2096 le32_to_cpu(mpi_reply->IOCLogInfo),
2097 le32_to_cpu(mpi_reply->TerminationCount)));
2098 if (ioc->logging_level & MPT_DEBUG_TM) {
2099 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2100 if (mpi_reply->IOCStatus)
2101 _debug_dump_mf(mpi_request,
2102 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2107 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2109 if (scsi_lookup->scmd == NULL)
2114 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2115 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2120 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2121 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2122 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2127 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2135 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2136 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2137 if (m_type == TM_MUTEX_ON)
2138 mutex_unlock(&ioc->tm_cmds.mutex);
2143 if (m_type == TM_MUTEX_ON)
2144 mutex_unlock(&ioc->tm_cmds.mutex);
2149 * _scsih_tm_display_info - displays info about the device
2150 * @ioc: per adapter struct
2151 * @scmd: pointer to scsi command object
2153 * Called by task management callback handlers.
2156 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2158 struct scsi_target *starget = scmd->device->sdev_target;
2159 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2160 struct _sas_device *sas_device = NULL;
2161 unsigned long flags;
2162 char *device_str = NULL;
2166 device_str = "volume";
2168 scsi_print_command(scmd);
2169 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2170 starget_printk(KERN_INFO, starget,
2171 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2172 device_str, priv_target->handle,
2173 device_str, (unsigned long long)priv_target->sas_address);
2175 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2176 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2177 priv_target->sas_address);
2179 if (priv_target->flags &
2180 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2181 starget_printk(KERN_INFO, starget,
2182 "volume handle(0x%04x), "
2183 "volume wwid(0x%016llx)\n",
2184 sas_device->volume_handle,
2185 (unsigned long long)sas_device->volume_wwid);
2187 starget_printk(KERN_INFO, starget,
2188 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2190 (unsigned long long)sas_device->sas_address,
2192 starget_printk(KERN_INFO, starget,
2193 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2194 (unsigned long long)sas_device->enclosure_logical_id,
2197 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2202 * _scsih_abort - eh threads main abort routine
2203 * @scmd: pointer to scsi command object
2205 * Returns SUCCESS if command aborted else FAILED
2208 _scsih_abort(struct scsi_cmnd *scmd)
2210 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2211 struct MPT3SAS_DEVICE *sas_device_priv_data;
2216 sdev_printk(KERN_INFO, scmd->device,
2217 "attempting task abort! scmd(%p)\n", scmd);
2218 _scsih_tm_display_info(ioc, scmd);
2220 sas_device_priv_data = scmd->device->hostdata;
2221 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2222 sdev_printk(KERN_INFO, scmd->device,
2223 "device been deleted! scmd(%p)\n", scmd);
2224 scmd->result = DID_NO_CONNECT << 16;
2225 scmd->scsi_done(scmd);
2230 /* search for the command */
2231 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2233 scmd->result = DID_RESET << 16;
2238 /* for hidden raid components and volumes this is not supported */
2239 if (sas_device_priv_data->sas_target->flags &
2240 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2241 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2242 scmd->result = DID_RESET << 16;
2247 mpt3sas_halt_firmware(ioc);
2249 handle = sas_device_priv_data->sas_target->handle;
2250 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2251 scmd->device->id, scmd->device->lun,
2252 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2255 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2256 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2261 * _scsih_dev_reset - eh threads main device reset routine
2262 * @scmd: pointer to scsi command object
2264 * Returns SUCCESS if command aborted else FAILED
2267 _scsih_dev_reset(struct scsi_cmnd *scmd)
2269 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2270 struct MPT3SAS_DEVICE *sas_device_priv_data;
2271 struct _sas_device *sas_device;
2272 unsigned long flags;
2276 sdev_printk(KERN_INFO, scmd->device,
2277 "attempting device reset! scmd(%p)\n", scmd);
2278 _scsih_tm_display_info(ioc, scmd);
2280 sas_device_priv_data = scmd->device->hostdata;
2281 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2282 sdev_printk(KERN_INFO, scmd->device,
2283 "device been deleted! scmd(%p)\n", scmd);
2284 scmd->result = DID_NO_CONNECT << 16;
2285 scmd->scsi_done(scmd);
2290 /* for hidden raid components obtain the volume_handle */
2292 if (sas_device_priv_data->sas_target->flags &
2293 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2294 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2295 sas_device = _scsih_sas_device_find_by_handle(ioc,
2296 sas_device_priv_data->sas_target->handle);
2298 handle = sas_device->volume_handle;
2299 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2301 handle = sas_device_priv_data->sas_target->handle;
2304 scmd->result = DID_RESET << 16;
2309 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2310 scmd->device->id, scmd->device->lun,
2311 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2314 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2315 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2320 * _scsih_target_reset - eh threads main target reset routine
2321 * @scmd: pointer to scsi command object
2323 * Returns SUCCESS if command aborted else FAILED
2326 _scsih_target_reset(struct scsi_cmnd *scmd)
2328 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2329 struct MPT3SAS_DEVICE *sas_device_priv_data;
2330 struct _sas_device *sas_device;
2331 unsigned long flags;
2334 struct scsi_target *starget = scmd->device->sdev_target;
2336 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2338 _scsih_tm_display_info(ioc, scmd);
2340 sas_device_priv_data = scmd->device->hostdata;
2341 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2342 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2344 scmd->result = DID_NO_CONNECT << 16;
2345 scmd->scsi_done(scmd);
2350 /* for hidden raid components obtain the volume_handle */
2352 if (sas_device_priv_data->sas_target->flags &
2353 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2354 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2355 sas_device = _scsih_sas_device_find_by_handle(ioc,
2356 sas_device_priv_data->sas_target->handle);
2358 handle = sas_device->volume_handle;
2359 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2361 handle = sas_device_priv_data->sas_target->handle;
2364 scmd->result = DID_RESET << 16;
2369 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2370 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2374 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2375 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2381 * _scsih_host_reset - eh threads main host reset routine
2382 * @scmd: pointer to scsi command object
2384 * Returns SUCCESS if command aborted else FAILED
2387 _scsih_host_reset(struct scsi_cmnd *scmd)
2389 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2392 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2394 scsi_print_command(scmd);
2396 if (ioc->is_driver_loading) {
2397 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2403 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2405 r = (retval < 0) ? FAILED : SUCCESS;
2407 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2408 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2414 * _scsih_fw_event_add - insert and queue up fw_event
2415 * @ioc: per adapter object
2416 * @fw_event: object describing the event
2417 * Context: This function will acquire ioc->fw_event_lock.
2419 * This adds the firmware event object into link list, then queues it up to
2420 * be processed from user context.
2425 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2427 unsigned long flags;
2429 if (ioc->firmware_event_thread == NULL)
2432 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2433 INIT_LIST_HEAD(&fw_event->list);
2434 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2435 INIT_WORK(&fw_event->work, _firmware_event_work);
2436 queue_work(ioc->firmware_event_thread, &fw_event->work);
2437 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2441 * _scsih_fw_event_free - delete fw_event
2442 * @ioc: per adapter object
2443 * @fw_event: object describing the event
2444 * Context: This function will acquire ioc->fw_event_lock.
2446 * This removes firmware event object from link list, frees associated memory.
2451 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2454 unsigned long flags;
2456 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2457 list_del(&fw_event->list);
2459 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2464 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2465 * @ioc: per adapter object
2466 * @event_data: trigger event data
2471 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2472 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2474 struct fw_event_work *fw_event;
2476 if (ioc->is_driver_loading)
2478 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2482 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2483 fw_event->ioc = ioc;
2484 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2485 _scsih_fw_event_add(ioc, fw_event);
2489 * _scsih_error_recovery_delete_devices - remove devices not responding
2490 * @ioc: per adapter object
2495 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2497 struct fw_event_work *fw_event;
2499 if (ioc->is_driver_loading)
2501 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2504 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2505 fw_event->ioc = ioc;
2506 _scsih_fw_event_add(ioc, fw_event);
2510 * mpt3sas_port_enable_complete - port enable completed (fake event)
2511 * @ioc: per adapter object
2516 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2518 struct fw_event_work *fw_event;
2520 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2523 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2524 fw_event->ioc = ioc;
2525 _scsih_fw_event_add(ioc, fw_event);
2529 * _scsih_fw_event_cleanup_queue - cleanup event queue
2530 * @ioc: per adapter object
2532 * Walk the firmware event queue, either killing timers, or waiting
2533 * for outstanding events to complete
2538 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2540 struct fw_event_work *fw_event, *next;
2542 if (list_empty(&ioc->fw_event_list) ||
2543 !ioc->firmware_event_thread || in_interrupt())
2546 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2547 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2548 _scsih_fw_event_free(ioc, fw_event);
2555 * _scsih_ublock_io_all_device - unblock every device
2556 * @ioc: per adapter object
2558 * change the device state from block to running
2561 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2563 struct MPT3SAS_DEVICE *sas_device_priv_data;
2564 struct scsi_device *sdev;
2566 shost_for_each_device(sdev, ioc->shost) {
2567 sas_device_priv_data = sdev->hostdata;
2568 if (!sas_device_priv_data)
2570 if (!sas_device_priv_data->block)
2573 sas_device_priv_data->block = 0;
2574 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2575 "device_running, handle(0x%04x)\n",
2576 sas_device_priv_data->sas_target->handle));
2577 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2583 * _scsih_ublock_io_device - prepare device to be deleted
2584 * @ioc: per adapter object
2585 * @sas_addr: sas address
2587 * unblock then put device in offline state
2590 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2592 struct MPT3SAS_DEVICE *sas_device_priv_data;
2593 struct scsi_device *sdev;
2595 shost_for_each_device(sdev, ioc->shost) {
2596 sas_device_priv_data = sdev->hostdata;
2597 if (!sas_device_priv_data)
2599 if (sas_device_priv_data->sas_target->sas_address
2602 if (sas_device_priv_data->block) {
2603 sas_device_priv_data->block = 0;
2604 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2610 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2611 * @ioc: per adapter object
2612 * @handle: device handle
2614 * During device pull we need to appropiately set the sdev state.
2617 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2619 struct MPT3SAS_DEVICE *sas_device_priv_data;
2620 struct scsi_device *sdev;
2622 shost_for_each_device(sdev, ioc->shost) {
2623 sas_device_priv_data = sdev->hostdata;
2624 if (!sas_device_priv_data)
2626 if (sas_device_priv_data->block)
2628 sas_device_priv_data->block = 1;
2629 scsi_internal_device_block(sdev);
2630 sdev_printk(KERN_INFO, sdev, "device_blocked, handle(0x%04x)\n",
2631 sas_device_priv_data->sas_target->handle);
2636 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2637 * @ioc: per adapter object
2638 * @handle: device handle
2640 * During device pull we need to appropiately set the sdev state.
2643 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2645 struct MPT3SAS_DEVICE *sas_device_priv_data;
2646 struct scsi_device *sdev;
2648 shost_for_each_device(sdev, ioc->shost) {
2649 sas_device_priv_data = sdev->hostdata;
2650 if (!sas_device_priv_data)
2652 if (sas_device_priv_data->sas_target->handle != handle)
2654 if (sas_device_priv_data->block)
2656 sas_device_priv_data->block = 1;
2657 scsi_internal_device_block(sdev);
2658 sdev_printk(KERN_INFO, sdev,
2659 "device_blocked, handle(0x%04x)\n", handle);
2664 * _scsih_block_io_to_children_attached_to_ex
2665 * @ioc: per adapter object
2666 * @sas_expander: the sas_device object
2668 * This routine set sdev state to SDEV_BLOCK for all devices
2669 * attached to this expander. This function called when expander is
2673 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2674 struct _sas_node *sas_expander)
2676 struct _sas_port *mpt3sas_port;
2677 struct _sas_device *sas_device;
2678 struct _sas_node *expander_sibling;
2679 unsigned long flags;
2684 list_for_each_entry(mpt3sas_port,
2685 &sas_expander->sas_port_list, port_list) {
2686 if (mpt3sas_port->remote_identify.device_type ==
2688 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2690 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2691 mpt3sas_port->remote_identify.sas_address);
2693 set_bit(sas_device->handle,
2694 ioc->blocking_handles);
2695 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2699 list_for_each_entry(mpt3sas_port,
2700 &sas_expander->sas_port_list, port_list) {
2702 if (mpt3sas_port->remote_identify.device_type ==
2703 SAS_EDGE_EXPANDER_DEVICE ||
2704 mpt3sas_port->remote_identify.device_type ==
2705 SAS_FANOUT_EXPANDER_DEVICE) {
2707 mpt3sas_scsih_expander_find_by_sas_address(
2708 ioc, mpt3sas_port->remote_identify.sas_address);
2709 _scsih_block_io_to_children_attached_to_ex(ioc,
2716 * _scsih_block_io_to_children_attached_directly
2717 * @ioc: per adapter object
2718 * @event_data: topology change event data
2720 * This routine set sdev state to SDEV_BLOCK for all devices
2721 * direct attached during device pull.
2724 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2725 Mpi2EventDataSasTopologyChangeList_t *event_data)
2731 for (i = 0; i < event_data->NumEntries; i++) {
2732 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2735 reason_code = event_data->PHY[i].PhyStatus &
2736 MPI2_EVENT_SAS_TOPO_RC_MASK;
2737 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2738 _scsih_block_io_device(ioc, handle);
2743 * _scsih_tm_tr_send - send task management request
2744 * @ioc: per adapter object
2745 * @handle: device handle
2746 * Context: interrupt time.
2748 * This code is to initiate the device removal handshake protocol
2749 * with controller firmware. This function will issue target reset
2750 * using high priority request queue. It will send a sas iounit
2751 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2753 * This is designed to send muliple task management request at the same
2754 * time to the fifo. If the fifo is full, we will append the request,
2755 * and process it in a future completion.
2758 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2760 Mpi2SCSITaskManagementRequest_t *mpi_request;
2762 struct _sas_device *sas_device;
2763 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2764 u64 sas_address = 0;
2765 unsigned long flags;
2766 struct _tr_list *delayed_tr;
2769 if (ioc->remove_host) {
2770 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2771 "%s: host has been removed: handle(0x%04x)\n",
2772 __func__, ioc->name, handle));
2774 } else if (ioc->pci_error_recovery) {
2775 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2776 "%s: host in pci error recovery: handle(0x%04x)\n",
2777 __func__, ioc->name,
2781 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2782 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2783 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2784 "%s: host is not operational: handle(0x%04x)\n",
2785 __func__, ioc->name,
2790 /* if PD, then return */
2791 if (test_bit(handle, ioc->pd_handles))
2794 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2795 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2796 if (sas_device && sas_device->starget &&
2797 sas_device->starget->hostdata) {
2798 sas_target_priv_data = sas_device->starget->hostdata;
2799 sas_target_priv_data->deleted = 1;
2800 sas_address = sas_device->sas_address;
2802 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2804 if (sas_target_priv_data) {
2805 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2806 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2808 (unsigned long long)sas_address));
2809 _scsih_ublock_io_device(ioc, sas_address);
2810 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2813 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2815 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2818 INIT_LIST_HEAD(&delayed_tr->list);
2819 delayed_tr->handle = handle;
2820 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2821 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2822 "DELAYED:tr:handle(0x%04x), (open)\n",
2823 ioc->name, handle));
2827 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2828 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2829 ioc->name, handle, smid,
2830 ioc->tm_tr_cb_idx));
2831 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2832 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2833 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2834 mpi_request->DevHandle = cpu_to_le16(handle);
2835 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2836 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2837 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2841 * _scsih_tm_tr_complete -
2842 * @ioc: per adapter object
2843 * @smid: system request message index
2844 * @msix_index: MSIX table index supplied by the OS
2845 * @reply: reply message frame(lower 32bit addr)
2846 * Context: interrupt time.
2848 * This is the target reset completion routine.
2849 * This code is part of the code to initiate the device removal
2850 * handshake protocol with controller firmware.
2851 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2853 * Return 1 meaning mf should be freed from _base_interrupt
2854 * 0 means the mf is freed from this function.
2857 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2861 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2862 Mpi2SCSITaskManagementReply_t *mpi_reply =
2863 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2864 Mpi2SasIoUnitControlRequest_t *mpi_request;
2868 if (ioc->remove_host) {
2869 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2870 "%s: host has been removed\n", __func__, ioc->name));
2872 } else if (ioc->pci_error_recovery) {
2873 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2874 "%s: host in pci error recovery\n", __func__,
2878 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2879 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2880 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2881 "%s: host is not operational\n", __func__, ioc->name));
2884 if (unlikely(!mpi_reply)) {
2885 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2886 ioc->name, __FILE__, __LINE__, __func__);
2889 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2890 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2891 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2892 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2893 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2895 le16_to_cpu(mpi_reply->DevHandle), smid));
2899 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2900 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2901 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
2902 "loginfo(0x%08x), completed(%d)\n", ioc->name,
2903 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
2904 le32_to_cpu(mpi_reply->IOCLogInfo),
2905 le32_to_cpu(mpi_reply->TerminationCount)));
2907 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2908 if (!smid_sas_ctrl) {
2909 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2910 ioc->name, __func__);
2914 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2915 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2916 ioc->name, handle, smid_sas_ctrl,
2917 ioc->tm_sas_control_cb_idx));
2918 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2919 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2920 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2921 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2922 mpi_request->DevHandle = mpi_request_tm->DevHandle;
2923 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
2925 return _scsih_check_for_pending_tm(ioc, smid);
2930 * _scsih_sas_control_complete - completion routine
2931 * @ioc: per adapter object
2932 * @smid: system request message index
2933 * @msix_index: MSIX table index supplied by the OS
2934 * @reply: reply message frame(lower 32bit addr)
2935 * Context: interrupt time.
2937 * This is the sas iounit control completion routine.
2938 * This code is part of the code to initiate the device removal
2939 * handshake protocol with controller firmware.
2941 * Return 1 meaning mf should be freed from _base_interrupt
2942 * 0 means the mf is freed from this function.
2945 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
2946 u8 msix_index, u32 reply)
2948 Mpi2SasIoUnitControlReply_t *mpi_reply =
2949 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2951 if (likely(mpi_reply)) {
2952 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2953 "sc_complete:handle(0x%04x), (open) "
2954 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
2955 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
2956 le16_to_cpu(mpi_reply->IOCStatus),
2957 le32_to_cpu(mpi_reply->IOCLogInfo)));
2959 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2960 ioc->name, __FILE__, __LINE__, __func__);
2966 * _scsih_tm_tr_volume_send - send target reset request for volumes
2967 * @ioc: per adapter object
2968 * @handle: device handle
2969 * Context: interrupt time.
2971 * This is designed to send muliple task management request at the same
2972 * time to the fifo. If the fifo is full, we will append the request,
2973 * and process it in a future completion.
2976 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2978 Mpi2SCSITaskManagementRequest_t *mpi_request;
2980 struct _tr_list *delayed_tr;
2982 if (ioc->shost_recovery || ioc->remove_host ||
2983 ioc->pci_error_recovery) {
2984 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2985 "%s: host reset in progress!\n",
2986 __func__, ioc->name));
2990 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
2992 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2995 INIT_LIST_HEAD(&delayed_tr->list);
2996 delayed_tr->handle = handle;
2997 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
2998 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2999 "DELAYED:tr:handle(0x%04x), (open)\n",
3000 ioc->name, handle));
3004 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3005 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3006 ioc->name, handle, smid,
3007 ioc->tm_tr_volume_cb_idx));
3008 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3009 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3010 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3011 mpi_request->DevHandle = cpu_to_le16(handle);
3012 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3013 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3017 * _scsih_tm_volume_tr_complete - target reset completion
3018 * @ioc: per adapter object
3019 * @smid: system request message index
3020 * @msix_index: MSIX table index supplied by the OS
3021 * @reply: reply message frame(lower 32bit addr)
3022 * Context: interrupt time.
3024 * Return 1 meaning mf should be freed from _base_interrupt
3025 * 0 means the mf is freed from this function.
3028 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3029 u8 msix_index, u32 reply)
3032 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3033 Mpi2SCSITaskManagementReply_t *mpi_reply =
3034 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3036 if (ioc->shost_recovery || ioc->remove_host ||
3037 ioc->pci_error_recovery) {
3038 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3039 "%s: host reset in progress!\n",
3040 __func__, ioc->name));
3043 if (unlikely(!mpi_reply)) {
3044 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3045 ioc->name, __FILE__, __LINE__, __func__);
3049 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3050 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3051 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3052 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3053 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3055 le16_to_cpu(mpi_reply->DevHandle), smid));
3059 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3060 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3061 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3062 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3063 le32_to_cpu(mpi_reply->IOCLogInfo),
3064 le32_to_cpu(mpi_reply->TerminationCount)));
3066 return _scsih_check_for_pending_tm(ioc, smid);
3071 * _scsih_check_for_pending_tm - check for pending task management
3072 * @ioc: per adapter object
3073 * @smid: system request message index
3075 * This will check delayed target reset list, and feed the
3078 * Return 1 meaning mf should be freed from _base_interrupt
3079 * 0 means the mf is freed from this function.
3082 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3084 struct _tr_list *delayed_tr;
3086 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3087 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3088 struct _tr_list, list);
3089 mpt3sas_base_free_smid(ioc, smid);
3090 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3091 list_del(&delayed_tr->list);
3096 if (!list_empty(&ioc->delayed_tr_list)) {
3097 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3098 struct _tr_list, list);
3099 mpt3sas_base_free_smid(ioc, smid);
3100 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3101 list_del(&delayed_tr->list);
3110 * _scsih_check_topo_delete_events - sanity check on topo events
3111 * @ioc: per adapter object
3112 * @event_data: the event data payload
3114 * This routine added to better handle cable breaker.
3116 * This handles the case where driver receives multiple expander
3117 * add and delete events in a single shot. When there is a delete event
3118 * the routine will void any pending add events waiting in the event queue.
3123 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3124 Mpi2EventDataSasTopologyChangeList_t *event_data)
3126 struct fw_event_work *fw_event;
3127 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3128 u16 expander_handle;
3129 struct _sas_node *sas_expander;
3130 unsigned long flags;
3134 for (i = 0 ; i < event_data->NumEntries; i++) {
3135 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3138 reason_code = event_data->PHY[i].PhyStatus &
3139 MPI2_EVENT_SAS_TOPO_RC_MASK;
3140 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3141 _scsih_tm_tr_send(ioc, handle);
3144 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3145 if (expander_handle < ioc->sas_hba.num_phys) {
3146 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3149 if (event_data->ExpStatus ==
3150 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3151 /* put expander attached devices into blocking state */
3152 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3153 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3155 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3156 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3158 handle = find_first_bit(ioc->blocking_handles,
3159 ioc->facts.MaxDevHandle);
3160 if (handle < ioc->facts.MaxDevHandle)
3161 _scsih_block_io_device(ioc, handle);
3162 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3163 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3164 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3166 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3169 /* mark ignore flag for pending events */
3170 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3171 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3172 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3175 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3176 fw_event->event_data;
3177 if (local_event_data->ExpStatus ==
3178 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3179 local_event_data->ExpStatus ==
3180 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3181 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3183 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3184 "setting ignoring flag\n", ioc->name));
3185 fw_event->ignore = 1;
3189 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3193 * _scsih_set_volume_delete_flag - setting volume delete flag
3194 * @ioc: per adapter object
3195 * @handle: device handle
3197 * This returns nothing.
3200 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3202 struct _raid_device *raid_device;
3203 struct MPT3SAS_TARGET *sas_target_priv_data;
3204 unsigned long flags;
3206 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3207 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3208 if (raid_device && raid_device->starget &&
3209 raid_device->starget->hostdata) {
3210 sas_target_priv_data =
3211 raid_device->starget->hostdata;
3212 sas_target_priv_data->deleted = 1;
3213 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3214 "setting delete flag: handle(0x%04x), "
3215 "wwid(0x%016llx)\n", ioc->name, handle,
3216 (unsigned long long) raid_device->wwid));
3218 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3222 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3223 * @handle: input handle
3224 * @a: handle for volume a
3225 * @b: handle for volume b
3227 * IR firmware only supports two raid volumes. The purpose of this
3228 * routine is to set the volume handle in either a or b. When the given
3229 * input handle is non-zero, or when a and b have not been set before.
3232 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3234 if (!handle || handle == *a || handle == *b)
3243 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3244 * @ioc: per adapter object
3245 * @event_data: the event data payload
3246 * Context: interrupt time.
3248 * This routine will send target reset to volume, followed by target
3249 * resets to the PDs. This is called when a PD has been removed, or
3250 * volume has been deleted or removed. When the target reset is sent
3251 * to volume, the PD target resets need to be queued to start upon
3252 * completion of the volume target reset.
3257 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3258 Mpi2EventDataIrConfigChangeList_t *event_data)
3260 Mpi2EventIrConfigElement_t *element;
3262 u16 handle, volume_handle, a, b;
3263 struct _tr_list *delayed_tr;
3268 /* Volume Resets for Deleted or Removed */
3269 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3270 for (i = 0; i < event_data->NumElements; i++, element++) {
3271 if (le32_to_cpu(event_data->Flags) &
3272 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3274 if (element->ReasonCode ==
3275 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3276 element->ReasonCode ==
3277 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3278 volume_handle = le16_to_cpu(element->VolDevHandle);
3279 _scsih_set_volume_delete_flag(ioc, volume_handle);
3280 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3284 /* Volume Resets for UNHIDE events */
3285 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3286 for (i = 0; i < event_data->NumElements; i++, element++) {
3287 if (le32_to_cpu(event_data->Flags) &
3288 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3290 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3291 volume_handle = le16_to_cpu(element->VolDevHandle);
3292 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3297 _scsih_tm_tr_volume_send(ioc, a);
3299 _scsih_tm_tr_volume_send(ioc, b);
3301 /* PD target resets */
3302 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3303 for (i = 0; i < event_data->NumElements; i++, element++) {
3304 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3306 handle = le16_to_cpu(element->PhysDiskDevHandle);
3307 volume_handle = le16_to_cpu(element->VolDevHandle);
3308 clear_bit(handle, ioc->pd_handles);
3310 _scsih_tm_tr_send(ioc, handle);
3311 else if (volume_handle == a || volume_handle == b) {
3312 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3313 BUG_ON(!delayed_tr);
3314 INIT_LIST_HEAD(&delayed_tr->list);
3315 delayed_tr->handle = handle;
3316 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3317 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3318 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3321 _scsih_tm_tr_send(ioc, handle);
3327 * _scsih_check_volume_delete_events - set delete flag for volumes
3328 * @ioc: per adapter object
3329 * @event_data: the event data payload
3330 * Context: interrupt time.
3332 * This will handle the case when the cable connected to entire volume is
3333 * pulled. We will take care of setting the deleted flag so normal IO will
3339 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3340 Mpi2EventDataIrVolume_t *event_data)
3344 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3346 state = le32_to_cpu(event_data->NewValue);
3347 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3348 MPI2_RAID_VOL_STATE_FAILED)
3349 _scsih_set_volume_delete_flag(ioc,
3350 le16_to_cpu(event_data->VolDevHandle));
3354 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3355 * @ioc: per adapter object
3356 * @event_data: the temp threshold event data
3357 * Context: interrupt time.
3362 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3363 Mpi2EventDataTemperature_t *event_data)
3365 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3366 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3367 " exceeded for Sensor: %d !!!\n", ioc->name,
3368 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3369 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3370 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3371 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3372 event_data->SensorNum);
3373 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3374 ioc->name, event_data->CurrentTemperature);
3379 * _scsih_flush_running_cmds - completing outstanding commands.
3380 * @ioc: per adapter object
3382 * The flushing out of all pending scmd commands following host reset,
3383 * where all IO is dropped to the floor.
3388 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3390 struct scsi_cmnd *scmd;
3394 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3395 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3399 mpt3sas_base_free_smid(ioc, smid);
3400 scsi_dma_unmap(scmd);
3401 if (ioc->pci_error_recovery)
3402 scmd->result = DID_NO_CONNECT << 16;
3404 scmd->result = DID_RESET << 16;
3405 scmd->scsi_done(scmd);
3407 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3412 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3413 * @ioc: per adapter object
3414 * @scmd: pointer to scsi command object
3415 * @mpi_request: pointer to the SCSI_IO reqest message frame
3417 * Supporting protection 1 and 3.
3422 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3423 Mpi2SCSIIORequest_t *mpi_request)
3426 unsigned char prot_op = scsi_get_prot_op(scmd);
3427 unsigned char prot_type = scsi_get_prot_type(scmd);
3428 Mpi25SCSIIORequest_t *mpi_request_3v =
3429 (Mpi25SCSIIORequest_t *)mpi_request;
3431 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3434 if (prot_op == SCSI_PROT_READ_STRIP)
3435 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3436 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3437 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3441 switch (prot_type) {
3442 case SCSI_PROT_DIF_TYPE1:
3443 case SCSI_PROT_DIF_TYPE2:
3446 * enable ref/guard checking
3447 * auto increment ref tag
3449 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3450 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3451 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3452 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3453 cpu_to_be32(scsi_get_lba(scmd));
3456 case SCSI_PROT_DIF_TYPE3:
3459 * enable guard checking
3461 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3466 mpi_request_3v->EEDPBlockSize =
3467 cpu_to_le16(scmd->device->sector_size);
3468 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3472 * _scsih_eedp_error_handling - return sense code for EEDP errors
3473 * @scmd: pointer to scsi command object
3474 * @ioc_status: ioc status
3479 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3483 switch (ioc_status) {
3484 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3487 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3490 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3497 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3499 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3500 SAM_STAT_CHECK_CONDITION;
3505 * _scsih_qcmd - main scsi request entry point
3506 * @scmd: pointer to scsi command object
3507 * @done: function pointer to be invoked on completion
3509 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3511 * Returns 0 on success. If there's a failure, return either:
3512 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3513 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3516 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3518 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3519 struct MPT3SAS_DEVICE *sas_device_priv_data;
3520 struct MPT3SAS_TARGET *sas_target_priv_data;
3521 Mpi2SCSIIORequest_t *mpi_request;
3526 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3527 if (ioc->logging_level & MPT_DEBUG_SCSI)
3528 scsi_print_command(scmd);
3531 sas_device_priv_data = scmd->device->hostdata;
3532 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3533 scmd->result = DID_NO_CONNECT << 16;
3534 scmd->scsi_done(scmd);
3538 if (ioc->pci_error_recovery || ioc->remove_host) {
3539 scmd->result = DID_NO_CONNECT << 16;
3540 scmd->scsi_done(scmd);
3544 sas_target_priv_data = sas_device_priv_data->sas_target;
3546 /* invalid device handle */
3547 handle = sas_target_priv_data->handle;
3548 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3549 scmd->result = DID_NO_CONNECT << 16;
3550 scmd->scsi_done(scmd);
3555 /* host recovery or link resets sent via IOCTLs */
3556 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3557 return SCSI_MLQUEUE_HOST_BUSY;
3559 /* device has been deleted */
3560 else if (sas_target_priv_data->deleted) {
3561 scmd->result = DID_NO_CONNECT << 16;
3562 scmd->scsi_done(scmd);
3564 /* device busy with task managment */
3565 } else if (sas_target_priv_data->tm_busy ||
3566 sas_device_priv_data->block)
3567 return SCSI_MLQUEUE_DEVICE_BUSY;
3569 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3570 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3571 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3572 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3574 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3577 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3579 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3580 scmd->cmd_len != 32)
3581 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3583 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3585 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3586 ioc->name, __func__);
3589 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3590 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3591 _scsih_setup_eedp(ioc, scmd, mpi_request);
3593 if (scmd->cmd_len == 32)
3594 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3595 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3596 if (sas_device_priv_data->sas_target->flags &
3597 MPT_TARGET_FLAGS_RAID_COMPONENT)
3598 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3600 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3601 mpi_request->DevHandle = cpu_to_le16(handle);
3602 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3603 mpi_request->Control = cpu_to_le32(mpi_control);
3604 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3605 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3606 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3607 mpi_request->SenseBufferLowAddress =
3608 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3609 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3610 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3612 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3614 if (mpi_request->DataLength) {
3615 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3616 mpt3sas_base_free_smid(ioc, smid);
3620 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3622 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3623 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3624 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3625 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3626 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3628 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3630 mpt3sas_base_put_smid_default(ioc, smid);
3634 return SCSI_MLQUEUE_HOST_BUSY;
3638 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3639 * @sense_buffer: sense data returned by target
3640 * @data: normalized skey/asc/ascq
3645 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3647 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3648 /* descriptor format */
3649 data->skey = sense_buffer[1] & 0x0F;
3650 data->asc = sense_buffer[2];
3651 data->ascq = sense_buffer[3];
3654 data->skey = sense_buffer[2] & 0x0F;
3655 data->asc = sense_buffer[12];
3656 data->ascq = sense_buffer[13];
3660 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3662 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3663 * @ioc: per adapter object
3664 * @scmd: pointer to scsi command object
3665 * @mpi_reply: reply mf payload returned from firmware
3667 * scsi_status - SCSI Status code returned from target device
3668 * scsi_state - state info associated with SCSI_IO determined by ioc
3669 * ioc_status - ioc supplied status info
3674 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3675 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3679 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3680 MPI2_IOCSTATUS_MASK;
3681 u8 scsi_state = mpi_reply->SCSIState;
3682 u8 scsi_status = mpi_reply->SCSIStatus;
3683 char *desc_ioc_state = NULL;
3684 char *desc_scsi_status = NULL;
3685 char *desc_scsi_state = ioc->tmp_string;
3686 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3687 struct _sas_device *sas_device = NULL;
3688 unsigned long flags;
3689 struct scsi_target *starget = scmd->device->sdev_target;
3690 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3691 char *device_str = NULL;
3695 device_str = "volume";
3697 if (log_info == 0x31170000)
3700 switch (ioc_status) {
3701 case MPI2_IOCSTATUS_SUCCESS:
3702 desc_ioc_state = "success";
3704 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3705 desc_ioc_state = "invalid function";
3707 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3708 desc_ioc_state = "scsi recovered error";
3710 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3711 desc_ioc_state = "scsi invalid dev handle";
3713 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3714 desc_ioc_state = "scsi device not there";
3716 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3717 desc_ioc_state = "scsi data overrun";
3719 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3720 desc_ioc_state = "scsi data underrun";
3722 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3723 desc_ioc_state = "scsi io data error";
3725 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3726 desc_ioc_state = "scsi protocol error";
3728 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3729 desc_ioc_state = "scsi task terminated";
3731 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3732 desc_ioc_state = "scsi residual mismatch";
3734 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3735 desc_ioc_state = "scsi task mgmt failed";
3737 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3738 desc_ioc_state = "scsi ioc terminated";
3740 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3741 desc_ioc_state = "scsi ext terminated";
3743 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3744 desc_ioc_state = "eedp guard error";
3746 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3747 desc_ioc_state = "eedp ref tag error";
3749 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3750 desc_ioc_state = "eedp app tag error";
3753 desc_ioc_state = "unknown";
3757 switch (scsi_status) {
3758 case MPI2_SCSI_STATUS_GOOD:
3759 desc_scsi_status = "good";
3761 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3762 desc_scsi_status = "check condition";
3764 case MPI2_SCSI_STATUS_CONDITION_MET:
3765 desc_scsi_status = "condition met";
3767 case MPI2_SCSI_STATUS_BUSY:
3768 desc_scsi_status = "busy";
3770 case MPI2_SCSI_STATUS_INTERMEDIATE:
3771 desc_scsi_status = "intermediate";
3773 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3774 desc_scsi_status = "intermediate condmet";
3776 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3777 desc_scsi_status = "reservation conflict";
3779 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3780 desc_scsi_status = "command terminated";
3782 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3783 desc_scsi_status = "task set full";
3785 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3786 desc_scsi_status = "aca active";
3788 case MPI2_SCSI_STATUS_TASK_ABORTED:
3789 desc_scsi_status = "task aborted";
3792 desc_scsi_status = "unknown";
3796 desc_scsi_state[0] = '\0';
3798 desc_scsi_state = " ";
3799 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3800 strcat(desc_scsi_state, "response info ");
3801 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3802 strcat(desc_scsi_state, "state terminated ");
3803 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3804 strcat(desc_scsi_state, "no status ");
3805 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3806 strcat(desc_scsi_state, "autosense failed ");
3807 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3808 strcat(desc_scsi_state, "autosense valid ");
3810 scsi_print_command(scmd);
3812 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3813 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3814 device_str, (unsigned long long)priv_target->sas_address);
3816 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3817 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3818 priv_target->sas_address);
3821 "\tsas_address(0x%016llx), phy(%d)\n",
3822 ioc->name, (unsigned long long)
3823 sas_device->sas_address, sas_device->phy);
3825 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
3826 ioc->name, (unsigned long long)
3827 sas_device->enclosure_logical_id, sas_device->slot);
3829 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3833 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3834 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3835 desc_ioc_state, ioc_status, smid);
3837 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3838 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3839 scsi_get_resid(scmd));
3841 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3842 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3843 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3845 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3846 ioc->name, desc_scsi_status,
3847 scsi_status, desc_scsi_state, scsi_state);
3849 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3850 struct sense_info data;
3851 _scsih_normalize_sense(scmd->sense_buffer, &data);
3853 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3854 ioc->name, data.skey,
3855 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3858 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3859 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3860 response_bytes = (u8 *)&response_info;
3861 _scsih_response_code(ioc, response_bytes[0]);
3867 * _scsih_turn_on_pfa_led - illuminate PFA LED
3868 * @ioc: per adapter object
3869 * @handle: device handle
3875 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3877 Mpi2SepReply_t mpi_reply;
3878 Mpi2SepRequest_t mpi_request;
3879 struct _sas_device *sas_device;
3881 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3885 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3886 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3887 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3888 mpi_request.SlotStatus =
3889 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3890 mpi_request.DevHandle = cpu_to_le16(handle);
3891 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3892 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3893 &mpi_request)) != 0) {
3894 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3895 __FILE__, __LINE__, __func__);
3898 sas_device->pfa_led_on = 1;
3900 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3901 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3902 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3903 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3904 le32_to_cpu(mpi_reply.IOCLogInfo)));
3909 * _scsih_turn_off_pfa_led - turn off Fault LED
3910 * @ioc: per adapter object
3911 * @sas_device: sas device whose PFA LED has to turned off
3917 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
3918 struct _sas_device *sas_device)
3920 Mpi2SepReply_t mpi_reply;
3921 Mpi2SepRequest_t mpi_request;
3923 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3924 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3925 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3926 mpi_request.SlotStatus = 0;
3927 mpi_request.Slot = cpu_to_le16(sas_device->slot);
3928 mpi_request.DevHandle = 0;
3929 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
3930 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
3931 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3932 &mpi_request)) != 0) {
3933 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
3934 __FILE__, __LINE__, __func__);
3938 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3939 dewtprintk(ioc, printk(MPT3SAS_FMT
3940 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
3941 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
3942 le32_to_cpu(mpi_reply.IOCLogInfo)));
3947 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
3948 * @ioc: per adapter object
3949 * @handle: device handle
3950 * Context: interrupt.
3955 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3957 struct fw_event_work *fw_event;
3959 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
3962 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
3963 fw_event->device_handle = handle;
3964 fw_event->ioc = ioc;
3965 _scsih_fw_event_add(ioc, fw_event);
3969 * _scsih_smart_predicted_fault - process smart errors
3970 * @ioc: per adapter object
3971 * @handle: device handle
3972 * Context: interrupt.
3977 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3979 struct scsi_target *starget;
3980 struct MPT3SAS_TARGET *sas_target_priv_data;
3981 Mpi2EventNotificationReply_t *event_reply;
3982 Mpi2EventDataSasDeviceStatusChange_t *event_data;
3983 struct _sas_device *sas_device;
3985 unsigned long flags;
3987 /* only handle non-raid devices */
3988 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3989 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3991 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3994 starget = sas_device->starget;
3995 sas_target_priv_data = starget->hostdata;
3997 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
3998 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
3999 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4002 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4003 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4005 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4006 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4008 /* insert into event log */
4009 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4010 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4011 event_reply = kzalloc(sz, GFP_KERNEL);
4013 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4014 ioc->name, __FILE__, __LINE__, __func__);
4018 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4019 event_reply->Event =
4020 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4021 event_reply->MsgLength = sz/4;
4022 event_reply->EventDataLength =
4023 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4024 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4025 event_reply->EventData;
4026 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4027 event_data->ASC = 0x5D;
4028 event_data->DevHandle = cpu_to_le16(handle);
4029 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4030 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4035 * _scsih_io_done - scsi request callback
4036 * @ioc: per adapter object
4037 * @smid: system request message index
4038 * @msix_index: MSIX table index supplied by the OS
4039 * @reply: reply message frame(lower 32bit addr)
4041 * Callback handler when using _scsih_qcmd.
4043 * Return 1 meaning mf should be freed from _base_interrupt
4044 * 0 means the mf is freed from this function.
4047 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4049 Mpi2SCSIIORequest_t *mpi_request;
4050 Mpi2SCSIIOReply_t *mpi_reply;
4051 struct scsi_cmnd *scmd;
4057 struct MPT3SAS_DEVICE *sas_device_priv_data;
4058 u32 response_code = 0;
4060 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4061 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4065 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4067 if (mpi_reply == NULL) {
4068 scmd->result = DID_OK << 16;
4072 sas_device_priv_data = scmd->device->hostdata;
4073 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4074 sas_device_priv_data->sas_target->deleted) {
4075 scmd->result = DID_NO_CONNECT << 16;
4078 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4080 /* turning off TLR */
4081 scsi_state = mpi_reply->SCSIState;
4082 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4084 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4085 if (!sas_device_priv_data->tlr_snoop_check) {
4086 sas_device_priv_data->tlr_snoop_check++;
4087 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4088 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4089 sas_device_priv_data->flags &=
4093 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4094 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4095 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4096 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4099 ioc_status &= MPI2_IOCSTATUS_MASK;
4100 scsi_status = mpi_reply->SCSIStatus;
4102 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4103 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4104 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4105 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4106 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4109 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4110 struct sense_info data;
4111 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4113 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4114 le32_to_cpu(mpi_reply->SenseCount));
4115 memcpy(scmd->sense_buffer, sense_data, sz);
4116 _scsih_normalize_sense(scmd->sense_buffer, &data);
4117 /* failure prediction threshold exceeded */
4118 if (data.asc == 0x5D)
4119 _scsih_smart_predicted_fault(ioc,
4120 le16_to_cpu(mpi_reply->DevHandle));
4121 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4124 switch (ioc_status) {
4125 case MPI2_IOCSTATUS_BUSY:
4126 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4127 scmd->result = SAM_STAT_BUSY;
4130 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4131 scmd->result = DID_NO_CONNECT << 16;
4134 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4135 if (sas_device_priv_data->block) {
4136 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4139 if (log_info == 0x31110630) {
4140 if (scmd->retries > 2) {
4141 scmd->result = DID_NO_CONNECT << 16;
4142 scsi_device_set_state(scmd->device,
4145 scmd->result = DID_SOFT_ERROR << 16;
4146 scmd->device->expecting_cc_ua = 1;
4150 scmd->result = DID_SOFT_ERROR << 16;
4152 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4153 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4154 scmd->result = DID_RESET << 16;
4157 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4158 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4159 scmd->result = DID_SOFT_ERROR << 16;
4161 scmd->result = (DID_OK << 16) | scsi_status;
4164 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4165 scmd->result = (DID_OK << 16) | scsi_status;
4167 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4170 if (xfer_cnt < scmd->underflow) {
4171 if (scsi_status == SAM_STAT_BUSY)
4172 scmd->result = SAM_STAT_BUSY;
4174 scmd->result = DID_SOFT_ERROR << 16;
4175 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4176 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4177 scmd->result = DID_SOFT_ERROR << 16;
4178 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4179 scmd->result = DID_RESET << 16;
4180 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4181 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4182 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4183 scmd->result = (DRIVER_SENSE << 24) |
4184 SAM_STAT_CHECK_CONDITION;
4185 scmd->sense_buffer[0] = 0x70;
4186 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4187 scmd->sense_buffer[12] = 0x20;
4188 scmd->sense_buffer[13] = 0;
4192 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4193 scsi_set_resid(scmd, 0);
4194 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4195 case MPI2_IOCSTATUS_SUCCESS:
4196 scmd->result = (DID_OK << 16) | scsi_status;
4197 if (response_code ==
4198 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4199 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4200 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4201 scmd->result = DID_SOFT_ERROR << 16;
4202 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4203 scmd->result = DID_RESET << 16;
4206 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4207 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4208 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4209 _scsih_eedp_error_handling(scmd, ioc_status);
4212 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4213 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4214 case MPI2_IOCSTATUS_INVALID_SGL:
4215 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4216 case MPI2_IOCSTATUS_INVALID_FIELD:
4217 case MPI2_IOCSTATUS_INVALID_STATE:
4218 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4219 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4221 scmd->result = DID_SOFT_ERROR << 16;
4226 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4227 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4228 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4233 scsi_dma_unmap(scmd);
4235 scmd->scsi_done(scmd);
4240 * _scsih_sas_host_refresh - refreshing sas host object contents
4241 * @ioc: per adapter object
4244 * During port enable, fw will send topology events for every device. Its
4245 * possible that the handles may change from the previous setting, so this
4246 * code keeping handles updating if changed.
4251 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4256 Mpi2ConfigReply_t mpi_reply;
4257 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4258 u16 attached_handle;
4261 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4262 "updating handles for sas_host(0x%016llx)\n",
4263 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4265 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4266 * sizeof(Mpi2SasIOUnit0PhyData_t));
4267 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4268 if (!sas_iounit_pg0) {
4269 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4270 ioc->name, __FILE__, __LINE__, __func__);
4274 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4275 sas_iounit_pg0, sz)) != 0)
4277 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4278 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4280 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4281 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4283 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4284 PhyData[0].ControllerDevHandle);
4285 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4286 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4288 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4289 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4290 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4291 attached_handle, i, link_rate);
4294 kfree(sas_iounit_pg0);
4298 * _scsih_sas_host_add - create sas host object
4299 * @ioc: per adapter object
4301 * Creating host side data object, stored in ioc->sas_hba
4306 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4309 Mpi2ConfigReply_t mpi_reply;
4310 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4311 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4312 Mpi2SasPhyPage0_t phy_pg0;
4313 Mpi2SasDevicePage0_t sas_device_pg0;
4314 Mpi2SasEnclosurePage0_t enclosure_pg0;
4317 u8 device_missing_delay;
4319 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4320 if (!ioc->sas_hba.num_phys) {
4321 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4322 ioc->name, __FILE__, __LINE__, __func__);
4326 /* sas_iounit page 0 */
4327 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4328 sizeof(Mpi2SasIOUnit0PhyData_t));
4329 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4330 if (!sas_iounit_pg0) {
4331 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4332 ioc->name, __FILE__, __LINE__, __func__);
4335 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4336 sas_iounit_pg0, sz))) {
4337 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4338 ioc->name, __FILE__, __LINE__, __func__);
4341 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4342 MPI2_IOCSTATUS_MASK;
4343 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4344 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4345 ioc->name, __FILE__, __LINE__, __func__);
4349 /* sas_iounit page 1 */
4350 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4351 sizeof(Mpi2SasIOUnit1PhyData_t));
4352 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4353 if (!sas_iounit_pg1) {
4354 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4355 ioc->name, __FILE__, __LINE__, __func__);
4358 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4359 sas_iounit_pg1, sz))) {
4360 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4361 ioc->name, __FILE__, __LINE__, __func__);
4364 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4365 MPI2_IOCSTATUS_MASK;
4366 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4367 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4368 ioc->name, __FILE__, __LINE__, __func__);
4372 ioc->io_missing_delay =
4373 sas_iounit_pg1->IODeviceMissingDelay;
4374 device_missing_delay =
4375 sas_iounit_pg1->ReportDeviceMissingDelay;
4376 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4377 ioc->device_missing_delay = (device_missing_delay &
4378 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4380 ioc->device_missing_delay = device_missing_delay &
4381 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4383 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4384 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4385 sizeof(struct _sas_phy), GFP_KERNEL);
4386 if (!ioc->sas_hba.phy) {
4387 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4388 ioc->name, __FILE__, __LINE__, __func__);
4391 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4392 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4394 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4395 ioc->name, __FILE__, __LINE__, __func__);
4398 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4399 MPI2_IOCSTATUS_MASK;
4400 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4401 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4402 ioc->name, __FILE__, __LINE__, __func__);
4407 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4408 PhyData[0].ControllerDevHandle);
4409 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4410 ioc->sas_hba.phy[i].phy_id = i;
4411 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4412 phy_pg0, ioc->sas_hba.parent_dev);
4414 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4415 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4416 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4417 ioc->name, __FILE__, __LINE__, __func__);
4420 ioc->sas_hba.enclosure_handle =
4421 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4422 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4424 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4425 ioc->name, ioc->sas_hba.handle,
4426 (unsigned long long) ioc->sas_hba.sas_address,
4427 ioc->sas_hba.num_phys) ;
4429 if (ioc->sas_hba.enclosure_handle) {
4430 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4431 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4432 ioc->sas_hba.enclosure_handle)))
4433 ioc->sas_hba.enclosure_logical_id =
4434 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4438 kfree(sas_iounit_pg1);
4439 kfree(sas_iounit_pg0);
4443 * _scsih_expander_add - creating expander object
4444 * @ioc: per adapter object
4445 * @handle: expander handle
4447 * Creating expander object, stored in ioc->sas_expander_list.
4449 * Return 0 for success, else error.
4452 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4454 struct _sas_node *sas_expander;
4455 Mpi2ConfigReply_t mpi_reply;
4456 Mpi2ExpanderPage0_t expander_pg0;
4457 Mpi2ExpanderPage1_t expander_pg1;
4458 Mpi2SasEnclosurePage0_t enclosure_pg0;
4461 u64 sas_address, sas_address_parent = 0;
4463 unsigned long flags;
4464 struct _sas_port *mpt3sas_port = NULL;
4471 if (ioc->shost_recovery || ioc->pci_error_recovery)
4474 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4475 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4476 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4477 ioc->name, __FILE__, __LINE__, __func__);
4481 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4482 MPI2_IOCSTATUS_MASK;
4483 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4484 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4485 ioc->name, __FILE__, __LINE__, __func__);
4489 /* handle out of order topology events */
4490 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4491 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4493 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4494 ioc->name, __FILE__, __LINE__, __func__);
4497 if (sas_address_parent != ioc->sas_hba.sas_address) {
4498 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4499 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4500 sas_address_parent);
4501 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4502 if (!sas_expander) {
4503 rc = _scsih_expander_add(ioc, parent_handle);
4509 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4510 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4511 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4513 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4518 sas_expander = kzalloc(sizeof(struct _sas_node),
4520 if (!sas_expander) {
4521 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4522 ioc->name, __FILE__, __LINE__, __func__);
4526 sas_expander->handle = handle;
4527 sas_expander->num_phys = expander_pg0.NumPhys;
4528 sas_expander->sas_address_parent = sas_address_parent;
4529 sas_expander->sas_address = sas_address;
4531 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4532 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4533 handle, parent_handle, (unsigned long long)
4534 sas_expander->sas_address, sas_expander->num_phys);
4536 if (!sas_expander->num_phys)
4538 sas_expander->phy = kcalloc(sas_expander->num_phys,
4539 sizeof(struct _sas_phy), GFP_KERNEL);
4540 if (!sas_expander->phy) {
4541 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4542 ioc->name, __FILE__, __LINE__, __func__);
4547 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4548 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4549 sas_address_parent);
4550 if (!mpt3sas_port) {
4551 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4552 ioc->name, __FILE__, __LINE__, __func__);
4556 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4558 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4559 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4560 &expander_pg1, i, handle))) {
4561 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4562 ioc->name, __FILE__, __LINE__, __func__);
4566 sas_expander->phy[i].handle = handle;
4567 sas_expander->phy[i].phy_id = i;
4569 if ((mpt3sas_transport_add_expander_phy(ioc,
4570 &sas_expander->phy[i], expander_pg1,
4571 sas_expander->parent_dev))) {
4572 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4573 ioc->name, __FILE__, __LINE__, __func__);
4579 if (sas_expander->enclosure_handle) {
4580 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4581 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4582 sas_expander->enclosure_handle)))
4583 sas_expander->enclosure_logical_id =
4584 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4587 _scsih_expander_node_add(ioc, sas_expander);
4593 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4594 sas_address_parent);
4595 kfree(sas_expander);
4600 * mpt3sas_expander_remove - removing expander object
4601 * @ioc: per adapter object
4602 * @sas_address: expander sas_address
4607 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4609 struct _sas_node *sas_expander;
4610 unsigned long flags;
4612 if (ioc->shost_recovery)
4615 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4616 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4619 list_del(&sas_expander->list);
4620 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4622 _scsih_expander_node_remove(ioc, sas_expander);
4626 * _scsih_done - internal SCSI_IO callback handler.
4627 * @ioc: per adapter object
4628 * @smid: system request message index
4629 * @msix_index: MSIX table index supplied by the OS
4630 * @reply: reply message frame(lower 32bit addr)
4632 * Callback handler when sending internal generated SCSI_IO.
4633 * The callback index passed is `ioc->scsih_cb_idx`
4635 * Return 1 meaning mf should be freed from _base_interrupt
4636 * 0 means the mf is freed from this function.
4639 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4641 MPI2DefaultReply_t *mpi_reply;
4643 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4644 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4646 if (ioc->scsih_cmds.smid != smid)
4648 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4650 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4651 mpi_reply->MsgLength*4);
4652 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4654 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4655 complete(&ioc->scsih_cmds.done);
4662 #define MPT3_MAX_LUNS (255)
4666 * _scsih_check_access_status - check access flags
4667 * @ioc: per adapter object
4668 * @sas_address: sas address
4669 * @handle: sas device handle
4670 * @access_flags: errors returned during discovery of the device
4672 * Return 0 for success, else failure
4675 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4676 u16 handle, u8 access_status)
4681 switch (access_status) {
4682 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4683 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4686 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4687 desc = "sata capability failed";
4689 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4690 desc = "sata affiliation conflict";
4692 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4693 desc = "route not addressable";
4695 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4696 desc = "smp error not addressable";
4698 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4699 desc = "device blocked";
4701 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4702 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4703 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4704 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4705 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4706 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4707 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4708 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4709 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4710 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4711 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4712 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4713 desc = "sata initialization failed";
4724 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4725 ioc->name, desc, (unsigned long long)sas_address, handle);
4730 * _scsih_check_device - checking device responsiveness
4731 * @ioc: per adapter object
4732 * @parent_sas_address: sas address of parent expander or sas host
4733 * @handle: attached device handle
4734 * @phy_numberv: phy number
4735 * @link_rate: new link rate
4740 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4741 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4743 Mpi2ConfigReply_t mpi_reply;
4744 Mpi2SasDevicePage0_t sas_device_pg0;
4745 struct _sas_device *sas_device;
4747 unsigned long flags;
4749 struct scsi_target *starget;
4750 struct MPT3SAS_TARGET *sas_target_priv_data;
4754 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4755 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4758 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4759 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4762 /* wide port handling ~ we need only handle device once for the phy that
4763 * is matched in sas device page zero
4765 if (phy_number != sas_device_pg0.PhyNum)
4768 /* check if this is end device */
4769 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4770 if (!(_scsih_is_end_device(device_info)))
4773 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4774 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4775 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4779 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4783 if (unlikely(sas_device->handle != handle)) {
4784 starget = sas_device->starget;
4785 sas_target_priv_data = starget->hostdata;
4786 starget_printk(KERN_INFO, starget,
4787 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4788 sas_device->handle, handle);
4789 sas_target_priv_data->handle = handle;
4790 sas_device->handle = handle;
4793 /* check if device is present */
4794 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4795 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4797 "device is not present handle(0x%04x), flags!!!\n",
4799 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4803 /* check if there were any issues with discovery */
4804 if (_scsih_check_access_status(ioc, sas_address, handle,
4805 sas_device_pg0.AccessStatus)) {
4806 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4810 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4811 _scsih_ublock_io_device(ioc, sas_address);
4816 * _scsih_add_device - creating sas device object
4817 * @ioc: per adapter object
4818 * @handle: sas device handle
4819 * @phy_num: phy number end device attached to
4820 * @is_pd: is this hidden raid component
4822 * Creating end device object, stored in ioc->sas_device_list.
4824 * Returns 0 for success, non-zero for failure.
4827 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4830 Mpi2ConfigReply_t mpi_reply;
4831 Mpi2SasDevicePage0_t sas_device_pg0;
4832 Mpi2SasEnclosurePage0_t enclosure_pg0;
4833 struct _sas_device *sas_device;
4837 unsigned long flags;
4839 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4840 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4841 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4842 ioc->name, __FILE__, __LINE__, __func__);
4846 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4847 MPI2_IOCSTATUS_MASK;
4848 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4849 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4850 ioc->name, __FILE__, __LINE__, __func__);
4854 /* check if this is end device */
4855 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4856 if (!(_scsih_is_end_device(device_info)))
4858 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4860 /* check if device is present */
4861 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4862 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4863 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4868 /* check if there were any issues with discovery */
4869 if (_scsih_check_access_status(ioc, sas_address, handle,
4870 sas_device_pg0.AccessStatus))
4873 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4874 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4876 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4881 sas_device = kzalloc(sizeof(struct _sas_device),
4884 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4885 ioc->name, __FILE__, __LINE__, __func__);
4889 sas_device->handle = handle;
4890 if (_scsih_get_sas_address(ioc,
4891 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4892 &sas_device->sas_address_parent) != 0)
4893 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4894 ioc->name, __FILE__, __LINE__, __func__);
4895 sas_device->enclosure_handle =
4896 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4898 le16_to_cpu(sas_device_pg0.Slot);
4899 sas_device->device_info = device_info;
4900 sas_device->sas_address = sas_address;
4901 sas_device->phy = sas_device_pg0.PhyNum;
4902 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
4903 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
4905 /* get enclosure_logical_id */
4906 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
4907 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4908 sas_device->enclosure_handle)))
4909 sas_device->enclosure_logical_id =
4910 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4912 /* get device name */
4913 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
4915 if (ioc->wait_for_discovery_to_complete)
4916 _scsih_sas_device_init_add(ioc, sas_device);
4918 _scsih_sas_device_add(ioc, sas_device);
4924 * _scsih_remove_device - removing sas device object
4925 * @ioc: per adapter object
4926 * @sas_device_delete: the sas_device object
4931 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
4932 struct _sas_device *sas_device)
4934 struct MPT3SAS_TARGET *sas_target_priv_data;
4936 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
4937 (sas_device->pfa_led_on)) {
4938 _scsih_turn_off_pfa_led(ioc, sas_device);
4939 sas_device->pfa_led_on = 0;
4941 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4942 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
4943 ioc->name, __func__,
4944 sas_device->handle, (unsigned long long)
4945 sas_device->sas_address));
4947 if (sas_device->starget && sas_device->starget->hostdata) {
4948 sas_target_priv_data = sas_device->starget->hostdata;
4949 sas_target_priv_data->deleted = 1;
4950 _scsih_ublock_io_device(ioc, sas_device->sas_address);
4951 sas_target_priv_data->handle =
4952 MPT3SAS_INVALID_DEVICE_HANDLE;
4954 mpt3sas_transport_port_remove(ioc,
4955 sas_device->sas_address,
4956 sas_device->sas_address_parent);
4959 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
4960 ioc->name, sas_device->handle,
4961 (unsigned long long) sas_device->sas_address);
4963 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4964 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
4965 ioc->name, __func__,
4966 sas_device->handle, (unsigned long long)
4967 sas_device->sas_address));
4972 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4974 * _scsih_sas_topology_change_event_debug - debug for topology event
4975 * @ioc: per adapter object
4976 * @event_data: event data payload
4980 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
4981 Mpi2EventDataSasTopologyChangeList_t *event_data)
4987 char *status_str = NULL;
4988 u8 link_rate, prev_link_rate;
4990 switch (event_data->ExpStatus) {
4991 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
4994 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
4995 status_str = "remove";
4997 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
4999 status_str = "responding";
5001 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5002 status_str = "remove delay";
5005 status_str = "unknown status";
5008 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5009 ioc->name, status_str);
5010 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5011 "start_phy(%02d), count(%d)\n",
5012 le16_to_cpu(event_data->ExpanderDevHandle),
5013 le16_to_cpu(event_data->EnclosureHandle),
5014 event_data->StartPhyNum, event_data->NumEntries);
5015 for (i = 0; i < event_data->NumEntries; i++) {
5016 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5019 phy_number = event_data->StartPhyNum + i;
5020 reason_code = event_data->PHY[i].PhyStatus &
5021 MPI2_EVENT_SAS_TOPO_RC_MASK;
5022 switch (reason_code) {
5023 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5024 status_str = "target add";
5026 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5027 status_str = "target remove";
5029 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5030 status_str = "delay target remove";
5032 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5033 status_str = "link rate change";
5035 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5036 status_str = "target responding";
5039 status_str = "unknown";
5042 link_rate = event_data->PHY[i].LinkRate >> 4;
5043 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5044 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5045 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5046 handle, status_str, link_rate, prev_link_rate);
5053 * _scsih_sas_topology_change_event - handle topology changes
5054 * @ioc: per adapter object
5055 * @fw_event: The fw_event_work object
5060 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5061 struct fw_event_work *fw_event)
5064 u16 parent_handle, handle;
5066 u8 phy_number, max_phys;
5067 struct _sas_node *sas_expander;
5069 unsigned long flags;
5070 u8 link_rate, prev_link_rate;
5071 Mpi2EventDataSasTopologyChangeList_t *event_data =
5072 (Mpi2EventDataSasTopologyChangeList_t *)
5073 fw_event->event_data;
5075 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5076 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5077 _scsih_sas_topology_change_event_debug(ioc, event_data);
5080 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5083 if (!ioc->sas_hba.num_phys)
5084 _scsih_sas_host_add(ioc);
5086 _scsih_sas_host_refresh(ioc);
5088 if (fw_event->ignore) {
5089 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5090 "ignoring expander event\n", ioc->name));
5094 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5096 /* handle expander add */
5097 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5098 if (_scsih_expander_add(ioc, parent_handle) != 0)
5101 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5102 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5105 sas_address = sas_expander->sas_address;
5106 max_phys = sas_expander->num_phys;
5107 } else if (parent_handle < ioc->sas_hba.num_phys) {
5108 sas_address = ioc->sas_hba.sas_address;
5109 max_phys = ioc->sas_hba.num_phys;
5111 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5114 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5116 /* handle siblings events */
5117 for (i = 0; i < event_data->NumEntries; i++) {
5118 if (fw_event->ignore) {
5119 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5120 "ignoring expander event\n", ioc->name));
5123 if (ioc->remove_host || ioc->pci_error_recovery)
5125 phy_number = event_data->StartPhyNum + i;
5126 if (phy_number >= max_phys)
5128 reason_code = event_data->PHY[i].PhyStatus &
5129 MPI2_EVENT_SAS_TOPO_RC_MASK;
5130 if ((event_data->PHY[i].PhyStatus &
5131 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5132 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5134 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5137 link_rate = event_data->PHY[i].LinkRate >> 4;
5138 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5139 switch (reason_code) {
5140 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5142 if (ioc->shost_recovery)
5145 if (link_rate == prev_link_rate)
5148 mpt3sas_transport_update_links(ioc, sas_address,
5149 handle, phy_number, link_rate);
5151 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5154 _scsih_check_device(ioc, sas_address, handle,
5155 phy_number, link_rate);
5158 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5160 if (ioc->shost_recovery)
5163 mpt3sas_transport_update_links(ioc, sas_address,
5164 handle, phy_number, link_rate);
5166 _scsih_add_device(ioc, handle, phy_number, 0);
5169 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5171 _scsih_device_remove_by_handle(ioc, handle);
5176 /* handle expander removal */
5177 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5179 mpt3sas_expander_remove(ioc, sas_address);
5184 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5186 * _scsih_sas_device_status_change_event_debug - debug for device event
5187 * @event_data: event data payload
5193 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5194 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5196 char *reason_str = NULL;
5198 switch (event_data->ReasonCode) {
5199 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5200 reason_str = "smart data";
5202 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5203 reason_str = "unsupported device discovered";
5205 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5206 reason_str = "internal device reset";
5208 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5209 reason_str = "internal task abort";
5211 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5212 reason_str = "internal task abort set";
5214 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5215 reason_str = "internal clear task set";
5217 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5218 reason_str = "internal query task";
5220 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5221 reason_str = "sata init failure";
5223 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5224 reason_str = "internal device reset complete";
5226 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5227 reason_str = "internal task abort complete";
5229 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5230 reason_str = "internal async notification";
5232 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5233 reason_str = "expander reduced functionality";
5235 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5236 reason_str = "expander reduced functionality complete";
5239 reason_str = "unknown reason";
5242 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5243 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5244 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5245 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5246 le16_to_cpu(event_data->TaskTag));
5247 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5248 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5249 event_data->ASC, event_data->ASCQ);
5255 * _scsih_sas_device_status_change_event - handle device status change
5256 * @ioc: per adapter object
5257 * @fw_event: The fw_event_work object
5263 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5264 struct fw_event_work *fw_event)
5266 struct MPT3SAS_TARGET *target_priv_data;
5267 struct _sas_device *sas_device;
5269 unsigned long flags;
5270 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5271 (Mpi2EventDataSasDeviceStatusChange_t *)
5272 fw_event->event_data;
5274 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5275 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5276 _scsih_sas_device_status_change_event_debug(ioc,
5280 /* In MPI Revision K (0xC), the internal device reset complete was
5281 * implemented, so avoid setting tm_busy flag for older firmware.
5283 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5286 if (event_data->ReasonCode !=
5287 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5288 event_data->ReasonCode !=
5289 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5292 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5293 sas_address = le64_to_cpu(event_data->SASAddress);
5294 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5297 if (!sas_device || !sas_device->starget) {
5298 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5302 target_priv_data = sas_device->starget->hostdata;
5303 if (!target_priv_data) {
5304 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5308 if (event_data->ReasonCode ==
5309 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5310 target_priv_data->tm_busy = 1;
5312 target_priv_data->tm_busy = 0;
5313 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5316 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5318 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5320 * @ioc: per adapter object
5321 * @event_data: event data payload
5327 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5328 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5330 char *reason_str = NULL;
5332 switch (event_data->ReasonCode) {
5333 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5334 reason_str = "enclosure add";
5336 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5337 reason_str = "enclosure remove";
5340 reason_str = "unknown reason";
5344 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5345 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5346 " number slots(%d)\n", ioc->name, reason_str,
5347 le16_to_cpu(event_data->EnclosureHandle),
5348 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5349 le16_to_cpu(event_data->StartSlot));
5354 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5355 * @ioc: per adapter object
5356 * @fw_event: The fw_event_work object
5362 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5363 struct fw_event_work *fw_event)
5365 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5366 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5367 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5368 (Mpi2EventDataSasEnclDevStatusChange_t *)
5369 fw_event->event_data);
5374 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5375 * @ioc: per adapter object
5376 * @fw_event: The fw_event_work object
5382 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5383 struct fw_event_work *fw_event)
5385 struct scsi_cmnd *scmd;
5386 struct scsi_device *sdev;
5389 struct MPT3SAS_DEVICE *sas_device_priv_data;
5390 u32 termination_count;
5392 Mpi2SCSITaskManagementReply_t *mpi_reply;
5393 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5394 (Mpi2EventDataSasBroadcastPrimitive_t *)
5395 fw_event->event_data;
5397 unsigned long flags;
5400 u8 task_abort_retries;
5402 mutex_lock(&ioc->tm_cmds.mutex);
5404 "%s: enter: phy number(%d), width(%d)\n",
5405 ioc->name, __func__, event_data->PhyNum,
5406 event_data->PortWidth);
5408 _scsih_block_io_all_device(ioc);
5410 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5411 mpi_reply = ioc->tm_cmds.reply;
5412 broadcast_aen_retry:
5414 /* sanity checks for retrying this loop */
5415 if (max_retries++ == 5) {
5416 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5417 ioc->name, __func__));
5419 } else if (max_retries > 1)
5420 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5421 ioc->name, __func__, max_retries - 1));
5423 termination_count = 0;
5425 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5426 if (ioc->shost_recovery)
5428 scmd = _scsih_scsi_lookup_get(ioc, smid);
5431 sdev = scmd->device;
5432 sas_device_priv_data = sdev->hostdata;
5433 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5435 /* skip hidden raid components */
5436 if (sas_device_priv_data->sas_target->flags &
5437 MPT_TARGET_FLAGS_RAID_COMPONENT)
5440 if (sas_device_priv_data->sas_target->flags &
5441 MPT_TARGET_FLAGS_VOLUME)
5444 handle = sas_device_priv_data->sas_target->handle;
5445 lun = sas_device_priv_data->lun;
5448 if (ioc->shost_recovery)
5451 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5452 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5453 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5456 sdev_printk(KERN_WARNING, sdev,
5457 "mpt3sas_scsih_issue_tm: FAILED when sending "
5458 "QUERY_TASK: scmd(%p)\n", scmd);
5459 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5460 goto broadcast_aen_retry;
5462 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5463 & MPI2_IOCSTATUS_MASK;
5464 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5465 sdev_printk(KERN_WARNING, sdev,
5466 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5468 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5469 goto broadcast_aen_retry;
5472 /* see if IO is still owned by IOC and target */
5473 if (mpi_reply->ResponseCode ==
5474 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5475 mpi_reply->ResponseCode ==
5476 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5477 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5480 task_abort_retries = 0;
5482 if (task_abort_retries++ == 60) {
5483 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5484 "%s: ABORT_TASK: giving up\n", ioc->name,
5486 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5487 goto broadcast_aen_retry;
5490 if (ioc->shost_recovery)
5493 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5494 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5497 sdev_printk(KERN_WARNING, sdev,
5498 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5499 "scmd(%p)\n", scmd);
5503 if (task_abort_retries > 1)
5504 sdev_printk(KERN_WARNING, sdev,
5505 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5507 task_abort_retries - 1, scmd);
5509 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5510 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5513 if (ioc->broadcast_aen_pending) {
5514 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5515 "%s: loop back due to pending AEN\n",
5516 ioc->name, __func__));
5517 ioc->broadcast_aen_pending = 0;
5518 goto broadcast_aen_retry;
5522 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5525 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5526 "%s - exit, query_count = %d termination_count = %d\n",
5527 ioc->name, __func__, query_count, termination_count));
5529 ioc->broadcast_aen_busy = 0;
5530 if (!ioc->shost_recovery)
5531 _scsih_ublock_io_all_device(ioc);
5532 mutex_unlock(&ioc->tm_cmds.mutex);
5536 * _scsih_sas_discovery_event - handle discovery events
5537 * @ioc: per adapter object
5538 * @fw_event: The fw_event_work object
5544 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5545 struct fw_event_work *fw_event)
5547 Mpi2EventDataSasDiscovery_t *event_data =
5548 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5550 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5551 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5552 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5553 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5555 if (event_data->DiscoveryStatus)
5556 pr_info("discovery_status(0x%08x)",
5557 le32_to_cpu(event_data->DiscoveryStatus));
5562 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5563 !ioc->sas_hba.num_phys) {
5564 if (disable_discovery > 0 && ioc->shost_recovery) {
5565 /* Wait for the reset to complete */
5566 while (ioc->shost_recovery)
5569 _scsih_sas_host_add(ioc);
5574 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5575 * @ioc: per adapter object
5576 * @handle: device handle for physical disk
5577 * @phys_disk_num: physical disk number
5579 * Return 0 for success, else failure.
5582 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5584 Mpi2RaidActionRequest_t *mpi_request;
5585 Mpi2RaidActionReply_t *mpi_reply;
5593 mutex_lock(&ioc->scsih_cmds.mutex);
5595 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5596 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5597 ioc->name, __func__);
5601 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5603 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5605 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5606 ioc->name, __func__);
5607 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5612 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5613 ioc->scsih_cmds.smid = smid;
5614 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5616 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5617 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5618 mpi_request->PhysDiskNum = phys_disk_num;
5620 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5621 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5622 handle, phys_disk_num));
5624 init_completion(&ioc->scsih_cmds.done);
5625 mpt3sas_base_put_smid_default(ioc, smid);
5626 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5628 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5629 pr_err(MPT3SAS_FMT "%s: timeout\n",
5630 ioc->name, __func__);
5631 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5637 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5639 mpi_reply = ioc->scsih_cmds.reply;
5640 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5641 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5642 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5645 ioc_status &= MPI2_IOCSTATUS_MASK;
5646 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5647 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5648 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5649 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5653 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5654 "IR RAID_ACTION: completed successfully\n",
5659 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5660 mutex_unlock(&ioc->scsih_cmds.mutex);
5663 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5669 * _scsih_reprobe_lun - reprobing lun
5670 * @sdev: scsi device struct
5671 * @no_uld_attach: sdev->no_uld_attach flag setting
5675 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5678 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5679 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5680 sdev->no_uld_attach ? "hidding" : "exposing");
5681 rc = scsi_device_reprobe(sdev);
5685 * _scsih_sas_volume_add - add new volume
5686 * @ioc: per adapter object
5687 * @element: IR config element data
5693 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5694 Mpi2EventIrConfigElement_t *element)
5696 struct _raid_device *raid_device;
5697 unsigned long flags;
5699 u16 handle = le16_to_cpu(element->VolDevHandle);
5702 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5705 "failure at %s:%d/%s()!\n", ioc->name,
5706 __FILE__, __LINE__, __func__);
5710 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5711 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5712 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5717 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5720 "failure at %s:%d/%s()!\n", ioc->name,
5721 __FILE__, __LINE__, __func__);
5725 raid_device->id = ioc->sas_id++;
5726 raid_device->channel = RAID_CHANNEL;
5727 raid_device->handle = handle;
5728 raid_device->wwid = wwid;
5729 _scsih_raid_device_add(ioc, raid_device);
5730 if (!ioc->wait_for_discovery_to_complete) {
5731 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5732 raid_device->id, 0);
5734 _scsih_raid_device_remove(ioc, raid_device);
5736 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5737 _scsih_determine_boot_device(ioc, raid_device, 1);
5738 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5743 * _scsih_sas_volume_delete - delete volume
5744 * @ioc: per adapter object
5745 * @handle: volume device handle
5751 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5753 struct _raid_device *raid_device;
5754 unsigned long flags;
5755 struct MPT3SAS_TARGET *sas_target_priv_data;
5756 struct scsi_target *starget = NULL;
5758 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5759 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5761 if (raid_device->starget) {
5762 starget = raid_device->starget;
5763 sas_target_priv_data = starget->hostdata;
5764 sas_target_priv_data->deleted = 1;
5766 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5767 ioc->name, raid_device->handle,
5768 (unsigned long long) raid_device->wwid);
5769 list_del(&raid_device->list);
5772 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5774 scsi_remove_target(&starget->dev);
5778 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5779 * @ioc: per adapter object
5780 * @element: IR config element data
5786 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5787 Mpi2EventIrConfigElement_t *element)
5789 struct _sas_device *sas_device;
5790 struct scsi_target *starget = NULL;
5791 struct MPT3SAS_TARGET *sas_target_priv_data;
5792 unsigned long flags;
5793 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5795 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5796 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5798 sas_device->volume_handle = 0;
5799 sas_device->volume_wwid = 0;
5800 clear_bit(handle, ioc->pd_handles);
5801 if (sas_device->starget && sas_device->starget->hostdata) {
5802 starget = sas_device->starget;
5803 sas_target_priv_data = starget->hostdata;
5804 sas_target_priv_data->flags &=
5805 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5808 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5812 /* exposing raid component */
5814 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5818 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5819 * @ioc: per adapter object
5820 * @element: IR config element data
5826 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5827 Mpi2EventIrConfigElement_t *element)
5829 struct _sas_device *sas_device;
5830 struct scsi_target *starget = NULL;
5831 struct MPT3SAS_TARGET *sas_target_priv_data;
5832 unsigned long flags;
5833 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5834 u16 volume_handle = 0;
5835 u64 volume_wwid = 0;
5837 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
5839 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
5842 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5843 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5845 set_bit(handle, ioc->pd_handles);
5846 if (sas_device->starget && sas_device->starget->hostdata) {
5847 starget = sas_device->starget;
5848 sas_target_priv_data = starget->hostdata;
5849 sas_target_priv_data->flags |=
5850 MPT_TARGET_FLAGS_RAID_COMPONENT;
5851 sas_device->volume_handle = volume_handle;
5852 sas_device->volume_wwid = volume_wwid;
5855 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5859 /* hiding raid component */
5860 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5862 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
5866 * _scsih_sas_pd_delete - delete pd component
5867 * @ioc: per adapter object
5868 * @element: IR config element data
5874 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
5875 Mpi2EventIrConfigElement_t *element)
5877 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5879 _scsih_device_remove_by_handle(ioc, handle);
5883 * _scsih_sas_pd_add - remove pd component
5884 * @ioc: per adapter object
5885 * @element: IR config element data
5891 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
5892 Mpi2EventIrConfigElement_t *element)
5894 struct _sas_device *sas_device;
5895 unsigned long flags;
5896 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5897 Mpi2ConfigReply_t mpi_reply;
5898 Mpi2SasDevicePage0_t sas_device_pg0;
5903 set_bit(handle, ioc->pd_handles);
5905 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5906 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5907 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5909 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5913 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5914 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5915 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5916 ioc->name, __FILE__, __LINE__, __func__);
5920 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5921 MPI2_IOCSTATUS_MASK;
5922 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5923 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5924 ioc->name, __FILE__, __LINE__, __func__);
5928 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
5929 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
5930 mpt3sas_transport_update_links(ioc, sas_address, handle,
5931 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
5933 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
5934 _scsih_add_device(ioc, handle, 0, 1);
5937 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5939 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
5940 * @ioc: per adapter object
5941 * @event_data: event data payload
5947 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5948 Mpi2EventDataIrConfigChangeList_t *event_data)
5950 Mpi2EventIrConfigElement_t *element;
5953 char *reason_str = NULL, *element_str = NULL;
5955 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
5957 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
5958 ioc->name, (le32_to_cpu(event_data->Flags) &
5959 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
5960 "foreign" : "native", event_data->NumElements);
5961 for (i = 0; i < event_data->NumElements; i++, element++) {
5962 switch (element->ReasonCode) {
5963 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
5966 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
5967 reason_str = "remove";
5969 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
5970 reason_str = "no change";
5972 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
5973 reason_str = "hide";
5975 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
5976 reason_str = "unhide";
5978 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
5979 reason_str = "volume_created";
5981 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
5982 reason_str = "volume_deleted";
5984 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
5985 reason_str = "pd_created";
5987 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
5988 reason_str = "pd_deleted";
5991 reason_str = "unknown reason";
5994 element_type = le16_to_cpu(element->ElementFlags) &
5995 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
5996 switch (element_type) {
5997 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
5998 element_str = "volume";
6000 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6001 element_str = "phys disk";
6003 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6004 element_str = "hot spare";
6007 element_str = "unknown element";
6010 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6011 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6012 reason_str, le16_to_cpu(element->VolDevHandle),
6013 le16_to_cpu(element->PhysDiskDevHandle),
6014 element->PhysDiskNum);
6020 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6021 * @ioc: per adapter object
6022 * @fw_event: The fw_event_work object
6028 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6029 struct fw_event_work *fw_event)
6031 Mpi2EventIrConfigElement_t *element;
6034 Mpi2EventDataIrConfigChangeList_t *event_data =
6035 (Mpi2EventDataIrConfigChangeList_t *)
6036 fw_event->event_data;
6038 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6039 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6040 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6044 foreign_config = (le32_to_cpu(event_data->Flags) &
6045 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6047 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6048 if (ioc->shost_recovery) {
6050 for (i = 0; i < event_data->NumElements; i++, element++) {
6051 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6052 _scsih_ir_fastpath(ioc,
6053 le16_to_cpu(element->PhysDiskDevHandle),
6054 element->PhysDiskNum);
6058 for (i = 0; i < event_data->NumElements; i++, element++) {
6060 switch (element->ReasonCode) {
6061 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6062 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6063 if (!foreign_config)
6064 _scsih_sas_volume_add(ioc, element);
6066 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6067 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6068 if (!foreign_config)
6069 _scsih_sas_volume_delete(ioc,
6070 le16_to_cpu(element->VolDevHandle));
6072 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6073 _scsih_sas_pd_hide(ioc, element);
6075 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6076 _scsih_sas_pd_expose(ioc, element);
6078 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6079 _scsih_sas_pd_add(ioc, element);
6081 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6082 _scsih_sas_pd_delete(ioc, element);
6089 * _scsih_sas_ir_volume_event - IR volume event
6090 * @ioc: per adapter object
6091 * @fw_event: The fw_event_work object
6097 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6098 struct fw_event_work *fw_event)
6101 unsigned long flags;
6102 struct _raid_device *raid_device;
6106 Mpi2EventDataIrVolume_t *event_data =
6107 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6109 if (ioc->shost_recovery)
6112 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6115 handle = le16_to_cpu(event_data->VolDevHandle);
6116 state = le32_to_cpu(event_data->NewValue);
6117 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6118 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6119 ioc->name, __func__, handle,
6120 le32_to_cpu(event_data->PreviousValue), state));
6122 case MPI2_RAID_VOL_STATE_MISSING:
6123 case MPI2_RAID_VOL_STATE_FAILED:
6124 _scsih_sas_volume_delete(ioc, handle);
6127 case MPI2_RAID_VOL_STATE_ONLINE:
6128 case MPI2_RAID_VOL_STATE_DEGRADED:
6129 case MPI2_RAID_VOL_STATE_OPTIMAL:
6131 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6132 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6133 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6138 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6141 "failure at %s:%d/%s()!\n", ioc->name,
6142 __FILE__, __LINE__, __func__);
6146 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6149 "failure at %s:%d/%s()!\n", ioc->name,
6150 __FILE__, __LINE__, __func__);
6154 raid_device->id = ioc->sas_id++;
6155 raid_device->channel = RAID_CHANNEL;
6156 raid_device->handle = handle;
6157 raid_device->wwid = wwid;
6158 _scsih_raid_device_add(ioc, raid_device);
6159 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6160 raid_device->id, 0);
6162 _scsih_raid_device_remove(ioc, raid_device);
6165 case MPI2_RAID_VOL_STATE_INITIALIZING:
6172 * _scsih_sas_ir_physical_disk_event - PD event
6173 * @ioc: per adapter object
6174 * @fw_event: The fw_event_work object
6180 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6181 struct fw_event_work *fw_event)
6183 u16 handle, parent_handle;
6185 struct _sas_device *sas_device;
6186 unsigned long flags;
6187 Mpi2ConfigReply_t mpi_reply;
6188 Mpi2SasDevicePage0_t sas_device_pg0;
6190 Mpi2EventDataIrPhysicalDisk_t *event_data =
6191 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6194 if (ioc->shost_recovery)
6197 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6200 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6201 state = le32_to_cpu(event_data->NewValue);
6203 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6204 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6205 ioc->name, __func__, handle,
6206 le32_to_cpu(event_data->PreviousValue), state));
6208 case MPI2_RAID_PD_STATE_ONLINE:
6209 case MPI2_RAID_PD_STATE_DEGRADED:
6210 case MPI2_RAID_PD_STATE_REBUILDING:
6211 case MPI2_RAID_PD_STATE_OPTIMAL:
6212 case MPI2_RAID_PD_STATE_HOT_SPARE:
6214 set_bit(handle, ioc->pd_handles);
6215 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6216 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6217 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6222 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6223 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6225 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6226 ioc->name, __FILE__, __LINE__, __func__);
6230 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6231 MPI2_IOCSTATUS_MASK;
6232 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6233 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6234 ioc->name, __FILE__, __LINE__, __func__);
6238 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6239 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6240 mpt3sas_transport_update_links(ioc, sas_address, handle,
6241 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6243 _scsih_add_device(ioc, handle, 0, 1);
6247 case MPI2_RAID_PD_STATE_OFFLINE:
6248 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6249 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6255 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6257 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6258 * @ioc: per adapter object
6259 * @event_data: event data payload
6265 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6266 Mpi2EventDataIrOperationStatus_t *event_data)
6268 char *reason_str = NULL;
6270 switch (event_data->RAIDOperation) {
6271 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6272 reason_str = "resync";
6274 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6275 reason_str = "online capacity expansion";
6277 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6278 reason_str = "consistency check";
6280 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6281 reason_str = "background init";
6283 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6284 reason_str = "make data consistent";
6291 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6292 "\thandle(0x%04x), percent complete(%d)\n",
6293 ioc->name, reason_str,
6294 le16_to_cpu(event_data->VolDevHandle),
6295 event_data->PercentComplete);
6300 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6301 * @ioc: per adapter object
6302 * @fw_event: The fw_event_work object
6308 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6309 struct fw_event_work *fw_event)
6311 Mpi2EventDataIrOperationStatus_t *event_data =
6312 (Mpi2EventDataIrOperationStatus_t *)
6313 fw_event->event_data;
6314 static struct _raid_device *raid_device;
6315 unsigned long flags;
6318 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6319 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6320 _scsih_sas_ir_operation_status_event_debug(ioc,
6324 /* code added for raid transport support */
6325 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6327 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6328 handle = le16_to_cpu(event_data->VolDevHandle);
6329 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6331 raid_device->percent_complete =
6332 event_data->PercentComplete;
6333 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6338 * _scsih_prep_device_scan - initialize parameters prior to device scan
6339 * @ioc: per adapter object
6341 * Set the deleted flag prior to device scan. If the device is found during
6342 * the scan, then we clear the deleted flag.
6345 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6347 struct MPT3SAS_DEVICE *sas_device_priv_data;
6348 struct scsi_device *sdev;
6350 shost_for_each_device(sdev, ioc->shost) {
6351 sas_device_priv_data = sdev->hostdata;
6352 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6353 sas_device_priv_data->sas_target->deleted = 1;
6358 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6359 * @ioc: per adapter object
6360 * @sas_address: sas address
6361 * @slot: enclosure slot id
6362 * @handle: device handle
6364 * After host reset, find out whether devices are still responding.
6365 * Used in _scsih_remove_unresponsive_sas_devices.
6370 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6371 u16 slot, u16 handle)
6373 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6374 struct scsi_target *starget;
6375 struct _sas_device *sas_device;
6376 unsigned long flags;
6378 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6379 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6380 if (sas_device->sas_address == sas_address &&
6381 sas_device->slot == slot) {
6382 sas_device->responding = 1;
6383 starget = sas_device->starget;
6384 if (starget && starget->hostdata) {
6385 sas_target_priv_data = starget->hostdata;
6386 sas_target_priv_data->tm_busy = 0;
6387 sas_target_priv_data->deleted = 0;
6389 sas_target_priv_data = NULL;
6391 starget_printk(KERN_INFO, starget,
6392 "handle(0x%04x), sas_addr(0x%016llx), "
6393 "enclosure logical id(0x%016llx), "
6394 "slot(%d)\n", handle,
6395 (unsigned long long)sas_device->sas_address,
6396 (unsigned long long)
6397 sas_device->enclosure_logical_id,
6399 if (sas_device->handle == handle)
6401 pr_info("\thandle changed from(0x%04x)!!!\n",
6402 sas_device->handle);
6403 sas_device->handle = handle;
6404 if (sas_target_priv_data)
6405 sas_target_priv_data->handle = handle;
6410 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6414 * _scsih_search_responding_sas_devices -
6415 * @ioc: per adapter object
6417 * After host reset, find out whether devices are still responding.
6423 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6425 Mpi2SasDevicePage0_t sas_device_pg0;
6426 Mpi2ConfigReply_t mpi_reply;
6431 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6433 if (list_empty(&ioc->sas_device_list))
6437 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6438 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6440 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6441 MPI2_IOCSTATUS_MASK;
6442 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6444 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6445 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6446 if (!(_scsih_is_end_device(device_info)))
6448 _scsih_mark_responding_sas_device(ioc,
6449 le64_to_cpu(sas_device_pg0.SASAddress),
6450 le16_to_cpu(sas_device_pg0.Slot), handle);
6454 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6459 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6460 * @ioc: per adapter object
6461 * @wwid: world wide identifier for raid volume
6462 * @handle: device handle
6464 * After host reset, find out whether devices are still responding.
6465 * Used in _scsih_remove_unresponsive_raid_devices.
6470 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6473 struct MPT3SAS_TARGET *sas_target_priv_data;
6474 struct scsi_target *starget;
6475 struct _raid_device *raid_device;
6476 unsigned long flags;
6478 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6479 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6480 if (raid_device->wwid == wwid && raid_device->starget) {
6481 starget = raid_device->starget;
6482 if (starget && starget->hostdata) {
6483 sas_target_priv_data = starget->hostdata;
6484 sas_target_priv_data->deleted = 0;
6486 sas_target_priv_data = NULL;
6487 raid_device->responding = 1;
6488 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6489 starget_printk(KERN_INFO, raid_device->starget,
6490 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6491 (unsigned long long)raid_device->wwid);
6492 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6493 if (raid_device->handle == handle) {
6494 spin_unlock_irqrestore(&ioc->raid_device_lock,
6498 pr_info("\thandle changed from(0x%04x)!!!\n",
6499 raid_device->handle);
6500 raid_device->handle = handle;
6501 if (sas_target_priv_data)
6502 sas_target_priv_data->handle = handle;
6503 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6507 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6511 * _scsih_search_responding_raid_devices -
6512 * @ioc: per adapter object
6514 * After host reset, find out whether devices are still responding.
6520 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6522 Mpi2RaidVolPage1_t volume_pg1;
6523 Mpi2RaidVolPage0_t volume_pg0;
6524 Mpi2RaidPhysDiskPage0_t pd_pg0;
6525 Mpi2ConfigReply_t mpi_reply;
6530 if (!ioc->ir_firmware)
6533 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6536 if (list_empty(&ioc->raid_device_list))
6540 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6541 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6542 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6543 MPI2_IOCSTATUS_MASK;
6544 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6546 handle = le16_to_cpu(volume_pg1.DevHandle);
6548 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6549 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6550 sizeof(Mpi2RaidVolPage0_t)))
6553 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6554 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6555 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6556 _scsih_mark_responding_raid_device(ioc,
6557 le64_to_cpu(volume_pg1.WWID), handle);
6560 /* refresh the pd_handles */
6561 phys_disk_num = 0xFF;
6562 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6563 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6564 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6566 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6567 MPI2_IOCSTATUS_MASK;
6568 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6570 phys_disk_num = pd_pg0.PhysDiskNum;
6571 handle = le16_to_cpu(pd_pg0.DevHandle);
6572 set_bit(handle, ioc->pd_handles);
6575 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6580 * _scsih_mark_responding_expander - mark a expander as responding
6581 * @ioc: per adapter object
6582 * @sas_address: sas address
6585 * After host reset, find out whether devices are still responding.
6586 * Used in _scsih_remove_unresponsive_expanders.
6591 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6594 struct _sas_node *sas_expander;
6595 unsigned long flags;
6598 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6599 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6600 if (sas_expander->sas_address != sas_address)
6602 sas_expander->responding = 1;
6603 if (sas_expander->handle == handle)
6605 pr_info("\texpander(0x%016llx): handle changed" \
6606 " from(0x%04x) to (0x%04x)!!!\n",
6607 (unsigned long long)sas_expander->sas_address,
6608 sas_expander->handle, handle);
6609 sas_expander->handle = handle;
6610 for (i = 0 ; i < sas_expander->num_phys ; i++)
6611 sas_expander->phy[i].handle = handle;
6615 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6619 * _scsih_search_responding_expanders -
6620 * @ioc: per adapter object
6622 * After host reset, find out whether devices are still responding.
6628 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6630 Mpi2ExpanderPage0_t expander_pg0;
6631 Mpi2ConfigReply_t mpi_reply;
6636 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6638 if (list_empty(&ioc->sas_expander_list))
6642 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6643 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6645 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6646 MPI2_IOCSTATUS_MASK;
6647 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6650 handle = le16_to_cpu(expander_pg0.DevHandle);
6651 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6652 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6654 (unsigned long long)sas_address);
6655 _scsih_mark_responding_expander(ioc, sas_address, handle);
6659 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6663 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6664 * @ioc: per adapter object
6669 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6671 struct _sas_device *sas_device, *sas_device_next;
6672 struct _sas_node *sas_expander, *sas_expander_next;
6673 struct _raid_device *raid_device, *raid_device_next;
6674 struct list_head tmp_list;
6675 unsigned long flags;
6677 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6680 /* removing unresponding end devices */
6681 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6683 list_for_each_entry_safe(sas_device, sas_device_next,
6684 &ioc->sas_device_list, list) {
6685 if (!sas_device->responding)
6686 mpt3sas_device_remove_by_sas_address(ioc,
6687 sas_device->sas_address);
6689 sas_device->responding = 0;
6692 /* removing unresponding volumes */
6693 if (ioc->ir_firmware) {
6694 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6696 list_for_each_entry_safe(raid_device, raid_device_next,
6697 &ioc->raid_device_list, list) {
6698 if (!raid_device->responding)
6699 _scsih_sas_volume_delete(ioc,
6700 raid_device->handle);
6702 raid_device->responding = 0;
6706 /* removing unresponding expanders */
6707 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6709 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6710 INIT_LIST_HEAD(&tmp_list);
6711 list_for_each_entry_safe(sas_expander, sas_expander_next,
6712 &ioc->sas_expander_list, list) {
6713 if (!sas_expander->responding)
6714 list_move_tail(&sas_expander->list, &tmp_list);
6716 sas_expander->responding = 0;
6718 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6719 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6721 list_del(&sas_expander->list);
6722 _scsih_expander_node_remove(ioc, sas_expander);
6725 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6728 /* unblock devices */
6729 _scsih_ublock_io_all_device(ioc);
6733 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6734 struct _sas_node *sas_expander, u16 handle)
6736 Mpi2ExpanderPage1_t expander_pg1;
6737 Mpi2ConfigReply_t mpi_reply;
6740 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6741 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6742 &expander_pg1, i, handle))) {
6743 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6744 ioc->name, __FILE__, __LINE__, __func__);
6748 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6749 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6750 expander_pg1.NegotiatedLinkRate >> 4);
6755 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6756 * @ioc: per adapter object
6761 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6763 Mpi2ExpanderPage0_t expander_pg0;
6764 Mpi2SasDevicePage0_t sas_device_pg0;
6765 Mpi2RaidVolPage1_t volume_pg1;
6766 Mpi2RaidVolPage0_t volume_pg0;
6767 Mpi2RaidPhysDiskPage0_t pd_pg0;
6768 Mpi2EventIrConfigElement_t element;
6769 Mpi2ConfigReply_t mpi_reply;
6772 u16 handle, parent_handle;
6774 struct _sas_device *sas_device;
6775 struct _sas_node *expander_device;
6776 static struct _raid_device *raid_device;
6778 unsigned long flags;
6780 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6782 _scsih_sas_host_refresh(ioc);
6784 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6788 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6789 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6790 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6791 MPI2_IOCSTATUS_MASK;
6792 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6793 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6794 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6795 ioc->name, ioc_status,
6796 le32_to_cpu(mpi_reply.IOCLogInfo));
6799 handle = le16_to_cpu(expander_pg0.DevHandle);
6800 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6801 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6802 ioc, le64_to_cpu(expander_pg0.SASAddress));
6803 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6804 if (expander_device)
6805 _scsih_refresh_expander_links(ioc, expander_device,
6808 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6809 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6810 handle, (unsigned long long)
6811 le64_to_cpu(expander_pg0.SASAddress));
6812 _scsih_expander_add(ioc, handle);
6813 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6814 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6815 handle, (unsigned long long)
6816 le64_to_cpu(expander_pg0.SASAddress));
6820 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6823 if (!ioc->ir_firmware)
6826 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6829 phys_disk_num = 0xFF;
6830 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6831 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6833 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6834 MPI2_IOCSTATUS_MASK;
6835 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6836 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
6837 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6838 ioc->name, ioc_status,
6839 le32_to_cpu(mpi_reply.IOCLogInfo));
6842 phys_disk_num = pd_pg0.PhysDiskNum;
6843 handle = le16_to_cpu(pd_pg0.DevHandle);
6844 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6845 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6846 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6849 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6850 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6853 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6854 MPI2_IOCSTATUS_MASK;
6855 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6856 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
6857 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6858 ioc->name, ioc_status,
6859 le32_to_cpu(mpi_reply.IOCLogInfo));
6862 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6863 if (!_scsih_get_sas_address(ioc, parent_handle,
6865 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
6866 " handle (0x%04x), sas_addr(0x%016llx)\n",
6867 ioc->name, handle, (unsigned long long)
6868 le64_to_cpu(sas_device_pg0.SASAddress));
6869 mpt3sas_transport_update_links(ioc, sas_address,
6870 handle, sas_device_pg0.PhyNum,
6871 MPI2_SAS_NEG_LINK_RATE_1_5);
6872 set_bit(handle, ioc->pd_handles);
6874 /* This will retry adding the end device.
6875 * _scsih_add_device() will decide on retries and
6876 * return "1" when it should be retried
6878 while (_scsih_add_device(ioc, handle, retry_count++,
6882 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
6883 " handle (0x%04x), sas_addr(0x%016llx)\n",
6884 ioc->name, handle, (unsigned long long)
6885 le64_to_cpu(sas_device_pg0.SASAddress));
6889 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
6892 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
6896 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6897 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6898 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6899 MPI2_IOCSTATUS_MASK;
6900 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6901 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6902 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6903 ioc->name, ioc_status,
6904 le32_to_cpu(mpi_reply.IOCLogInfo));
6907 handle = le16_to_cpu(volume_pg1.DevHandle);
6908 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6909 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6910 le64_to_cpu(volume_pg1.WWID));
6911 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6914 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6915 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6916 sizeof(Mpi2RaidVolPage0_t)))
6918 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6919 MPI2_IOCSTATUS_MASK;
6920 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6921 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
6922 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6923 ioc->name, ioc_status,
6924 le32_to_cpu(mpi_reply.IOCLogInfo));
6927 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6928 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6929 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6930 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6931 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6932 element.VolDevHandle = volume_pg1.DevHandle;
6934 "\tBEFORE adding volume: handle (0x%04x)\n",
6935 ioc->name, volume_pg1.DevHandle);
6936 _scsih_sas_volume_add(ioc, &element);
6938 "\tAFTER adding volume: handle (0x%04x)\n",
6939 ioc->name, volume_pg1.DevHandle);
6943 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
6948 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
6953 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6954 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6956 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6957 MPI2_IOCSTATUS_MASK;
6958 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6959 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
6960 " ioc_status(0x%04x), loginfo(0x%08x)\n",
6961 ioc->name, ioc_status,
6962 le32_to_cpu(mpi_reply.IOCLogInfo));
6965 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6966 if (!(_scsih_is_end_device(
6967 le32_to_cpu(sas_device_pg0.DeviceInfo))))
6969 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6970 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
6971 le64_to_cpu(sas_device_pg0.SASAddress));
6972 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6975 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6976 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
6977 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
6978 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6979 handle, (unsigned long long)
6980 le64_to_cpu(sas_device_pg0.SASAddress));
6981 mpt3sas_transport_update_links(ioc, sas_address, handle,
6982 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6984 /* This will retry adding the end device.
6985 * _scsih_add_device() will decide on retries and
6986 * return "1" when it should be retried
6988 while (_scsih_add_device(ioc, handle, retry_count++,
6992 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
6993 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6994 handle, (unsigned long long)
6995 le64_to_cpu(sas_device_pg0.SASAddress));
6998 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7001 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7004 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7005 * @ioc: per adapter object
7006 * @reset_phase: phase
7008 * The handler for doing any required cleanup or initialization.
7010 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7011 * MPT3_IOC_DONE_RESET
7016 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7018 switch (reset_phase) {
7019 case MPT3_IOC_PRE_RESET:
7020 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7021 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7023 case MPT3_IOC_AFTER_RESET:
7024 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7025 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7026 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7027 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7028 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7029 complete(&ioc->scsih_cmds.done);
7031 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7032 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7033 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7034 complete(&ioc->tm_cmds.done);
7037 _scsih_fw_event_cleanup_queue(ioc);
7038 _scsih_flush_running_cmds(ioc);
7040 case MPT3_IOC_DONE_RESET:
7041 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7042 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7043 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7044 !ioc->sas_hba.num_phys)) {
7045 _scsih_prep_device_scan(ioc);
7046 _scsih_search_responding_sas_devices(ioc);
7047 _scsih_search_responding_raid_devices(ioc);
7048 _scsih_search_responding_expanders(ioc);
7049 _scsih_error_recovery_delete_devices(ioc);
7056 * _mpt3sas_fw_work - delayed task for processing firmware events
7057 * @ioc: per adapter object
7058 * @fw_event: The fw_event_work object
7064 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7066 /* the queue is being flushed so ignore this event */
7067 if (ioc->remove_host ||
7068 ioc->pci_error_recovery) {
7069 _scsih_fw_event_free(ioc, fw_event);
7073 switch (fw_event->event) {
7074 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7075 mpt3sas_process_trigger_data(ioc,
7076 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7077 fw_event->event_data);
7079 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7080 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7082 _scsih_remove_unresponding_sas_devices(ioc);
7083 _scsih_scan_for_devices_after_reset(ioc);
7085 case MPT3SAS_PORT_ENABLE_COMPLETE:
7086 ioc->start_scan = 0;
7087 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7088 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7090 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7091 "port enable: complete from worker thread\n",
7094 case MPT3SAS_TURN_ON_PFA_LED:
7095 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7097 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7098 _scsih_sas_topology_change_event(ioc, fw_event);
7100 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7101 _scsih_sas_device_status_change_event(ioc, fw_event);
7103 case MPI2_EVENT_SAS_DISCOVERY:
7104 _scsih_sas_discovery_event(ioc, fw_event);
7106 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7107 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7109 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7110 _scsih_sas_enclosure_dev_status_change_event(ioc,
7113 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7114 _scsih_sas_ir_config_change_event(ioc, fw_event);
7116 case MPI2_EVENT_IR_VOLUME:
7117 _scsih_sas_ir_volume_event(ioc, fw_event);
7119 case MPI2_EVENT_IR_PHYSICAL_DISK:
7120 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7122 case MPI2_EVENT_IR_OPERATION_STATUS:
7123 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7126 _scsih_fw_event_free(ioc, fw_event);
7130 * _firmware_event_work
7131 * @ioc: per adapter object
7132 * @work: The fw_event_work object
7135 * wrappers for the work thread handling firmware events
7141 _firmware_event_work(struct work_struct *work)
7143 struct fw_event_work *fw_event = container_of(work,
7144 struct fw_event_work, work);
7146 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7150 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7151 * @ioc: per adapter object
7152 * @msix_index: MSIX table index supplied by the OS
7153 * @reply: reply message frame(lower 32bit addr)
7154 * Context: interrupt.
7156 * This function merely adds a new work task into ioc->firmware_event_thread.
7157 * The tasks are worked from _firmware_event_work in user context.
7159 * Return 1 meaning mf should be freed from _base_interrupt
7160 * 0 means the mf is freed from this function.
7163 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7166 struct fw_event_work *fw_event;
7167 Mpi2EventNotificationReply_t *mpi_reply;
7171 /* events turned off due to host reset or driver unloading */
7172 if (ioc->remove_host || ioc->pci_error_recovery)
7175 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7177 if (unlikely(!mpi_reply)) {
7178 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7179 ioc->name, __FILE__, __LINE__, __func__);
7183 event = le16_to_cpu(mpi_reply->Event);
7185 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7186 mpt3sas_trigger_event(ioc, event, 0);
7190 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7192 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7193 (Mpi2EventDataSasBroadcastPrimitive_t *)
7194 mpi_reply->EventData;
7196 if (baen_data->Primitive !=
7197 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7200 if (ioc->broadcast_aen_busy) {
7201 ioc->broadcast_aen_pending++;
7204 ioc->broadcast_aen_busy = 1;
7208 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7209 _scsih_check_topo_delete_events(ioc,
7210 (Mpi2EventDataSasTopologyChangeList_t *)
7211 mpi_reply->EventData);
7213 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7214 _scsih_check_ir_config_unhide_events(ioc,
7215 (Mpi2EventDataIrConfigChangeList_t *)
7216 mpi_reply->EventData);
7218 case MPI2_EVENT_IR_VOLUME:
7219 _scsih_check_volume_delete_events(ioc,
7220 (Mpi2EventDataIrVolume_t *)
7221 mpi_reply->EventData);
7224 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7225 case MPI2_EVENT_IR_OPERATION_STATUS:
7226 case MPI2_EVENT_SAS_DISCOVERY:
7227 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7228 case MPI2_EVENT_IR_PHYSICAL_DISK:
7231 case MPI2_EVENT_TEMP_THRESHOLD:
7232 _scsih_temp_threshold_events(ioc,
7233 (Mpi2EventDataTemperature_t *)
7234 mpi_reply->EventData);
7237 default: /* ignore the rest */
7241 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7242 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7244 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7245 ioc->name, __FILE__, __LINE__, __func__);
7249 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7250 fw_event->ioc = ioc;
7251 fw_event->VF_ID = mpi_reply->VF_ID;
7252 fw_event->VP_ID = mpi_reply->VP_ID;
7253 fw_event->event = event;
7254 _scsih_fw_event_add(ioc, fw_event);
7258 /* shost template */
7259 static struct scsi_host_template scsih_driver_template = {
7260 .module = THIS_MODULE,
7261 .name = "Fusion MPT SAS Host",
7262 .proc_name = MPT3SAS_DRIVER_NAME,
7263 .queuecommand = _scsih_qcmd,
7264 .target_alloc = _scsih_target_alloc,
7265 .slave_alloc = _scsih_slave_alloc,
7266 .slave_configure = _scsih_slave_configure,
7267 .target_destroy = _scsih_target_destroy,
7268 .slave_destroy = _scsih_slave_destroy,
7269 .scan_finished = _scsih_scan_finished,
7270 .scan_start = _scsih_scan_start,
7271 .change_queue_depth = _scsih_change_queue_depth,
7272 .eh_abort_handler = _scsih_abort,
7273 .eh_device_reset_handler = _scsih_dev_reset,
7274 .eh_target_reset_handler = _scsih_target_reset,
7275 .eh_host_reset_handler = _scsih_host_reset,
7276 .bios_param = _scsih_bios_param,
7279 .sg_tablesize = MPT3SAS_SG_DEPTH,
7280 .max_sectors = 32767,
7282 .use_clustering = ENABLE_CLUSTERING,
7283 .shost_attrs = mpt3sas_host_attrs,
7284 .sdev_attrs = mpt3sas_dev_attrs,
7285 .track_queue_depth = 1,
7289 * _scsih_expander_node_remove - removing expander device from list.
7290 * @ioc: per adapter object
7291 * @sas_expander: the sas_device object
7292 * Context: Calling function should acquire ioc->sas_node_lock.
7294 * Removing object and freeing associated memory from the
7295 * ioc->sas_expander_list.
7300 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7301 struct _sas_node *sas_expander)
7303 struct _sas_port *mpt3sas_port, *next;
7305 /* remove sibling ports attached to this expander */
7306 list_for_each_entry_safe(mpt3sas_port, next,
7307 &sas_expander->sas_port_list, port_list) {
7308 if (ioc->shost_recovery)
7310 if (mpt3sas_port->remote_identify.device_type ==
7312 mpt3sas_device_remove_by_sas_address(ioc,
7313 mpt3sas_port->remote_identify.sas_address);
7314 else if (mpt3sas_port->remote_identify.device_type ==
7315 SAS_EDGE_EXPANDER_DEVICE ||
7316 mpt3sas_port->remote_identify.device_type ==
7317 SAS_FANOUT_EXPANDER_DEVICE)
7318 mpt3sas_expander_remove(ioc,
7319 mpt3sas_port->remote_identify.sas_address);
7322 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7323 sas_expander->sas_address_parent);
7326 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7328 sas_expander->handle, (unsigned long long)
7329 sas_expander->sas_address);
7331 kfree(sas_expander->phy);
7332 kfree(sas_expander);
7336 * _scsih_ir_shutdown - IR shutdown notification
7337 * @ioc: per adapter object
7339 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7340 * the host system is shutting down.
7345 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7347 Mpi2RaidActionRequest_t *mpi_request;
7348 Mpi2RaidActionReply_t *mpi_reply;
7351 /* is IR firmware build loaded ? */
7352 if (!ioc->ir_firmware)
7355 /* are there any volumes ? */
7356 if (list_empty(&ioc->raid_device_list))
7359 mutex_lock(&ioc->scsih_cmds.mutex);
7361 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7362 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7363 ioc->name, __func__);
7366 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7368 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7370 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7371 ioc->name, __func__);
7372 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7376 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7377 ioc->scsih_cmds.smid = smid;
7378 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7380 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7381 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7383 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7384 init_completion(&ioc->scsih_cmds.done);
7385 mpt3sas_base_put_smid_default(ioc, smid);
7386 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7388 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7389 pr_err(MPT3SAS_FMT "%s: timeout\n",
7390 ioc->name, __func__);
7394 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7395 mpi_reply = ioc->scsih_cmds.reply;
7397 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7398 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7399 le32_to_cpu(mpi_reply->IOCLogInfo));
7403 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7404 mutex_unlock(&ioc->scsih_cmds.mutex);
7408 * _scsih_remove - detach and remove add host
7409 * @pdev: PCI device struct
7411 * Routine called when unloading the driver.
7414 static void _scsih_remove(struct pci_dev *pdev)
7416 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7417 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7418 struct _sas_port *mpt3sas_port, *next_port;
7419 struct _raid_device *raid_device, *next;
7420 struct MPT3SAS_TARGET *sas_target_priv_data;
7421 struct workqueue_struct *wq;
7422 unsigned long flags;
7424 ioc->remove_host = 1;
7425 _scsih_fw_event_cleanup_queue(ioc);
7427 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7428 wq = ioc->firmware_event_thread;
7429 ioc->firmware_event_thread = NULL;
7430 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7432 destroy_workqueue(wq);
7434 /* release all the volumes */
7435 _scsih_ir_shutdown(ioc);
7436 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7438 if (raid_device->starget) {
7439 sas_target_priv_data =
7440 raid_device->starget->hostdata;
7441 sas_target_priv_data->deleted = 1;
7442 scsi_remove_target(&raid_device->starget->dev);
7444 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7445 ioc->name, raid_device->handle,
7446 (unsigned long long) raid_device->wwid);
7447 _scsih_raid_device_remove(ioc, raid_device);
7450 /* free ports attached to the sas_host */
7451 list_for_each_entry_safe(mpt3sas_port, next_port,
7452 &ioc->sas_hba.sas_port_list, port_list) {
7453 if (mpt3sas_port->remote_identify.device_type ==
7455 mpt3sas_device_remove_by_sas_address(ioc,
7456 mpt3sas_port->remote_identify.sas_address);
7457 else if (mpt3sas_port->remote_identify.device_type ==
7458 SAS_EDGE_EXPANDER_DEVICE ||
7459 mpt3sas_port->remote_identify.device_type ==
7460 SAS_FANOUT_EXPANDER_DEVICE)
7461 mpt3sas_expander_remove(ioc,
7462 mpt3sas_port->remote_identify.sas_address);
7465 /* free phys attached to the sas_host */
7466 if (ioc->sas_hba.num_phys) {
7467 kfree(ioc->sas_hba.phy);
7468 ioc->sas_hba.phy = NULL;
7469 ioc->sas_hba.num_phys = 0;
7472 sas_remove_host(shost);
7473 scsi_remove_host(shost);
7474 mpt3sas_base_detach(ioc);
7475 list_del(&ioc->list);
7476 scsi_host_put(shost);
7480 * _scsih_shutdown - routine call during system shutdown
7481 * @pdev: PCI device struct
7486 _scsih_shutdown(struct pci_dev *pdev)
7488 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7489 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7490 struct workqueue_struct *wq;
7491 unsigned long flags;
7493 ioc->remove_host = 1;
7494 _scsih_fw_event_cleanup_queue(ioc);
7496 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7497 wq = ioc->firmware_event_thread;
7498 ioc->firmware_event_thread = NULL;
7499 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7501 destroy_workqueue(wq);
7503 _scsih_ir_shutdown(ioc);
7504 mpt3sas_base_detach(ioc);
7509 * _scsih_probe_boot_devices - reports 1st device
7510 * @ioc: per adapter object
7512 * If specified in bios page 2, this routine reports the 1st
7513 * device scsi-ml or sas transport for persistent boot device
7514 * purposes. Please refer to function _scsih_determine_boot_device()
7517 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7521 struct _sas_device *sas_device;
7522 struct _raid_device *raid_device;
7524 u64 sas_address_parent;
7526 unsigned long flags;
7529 /* no Bios, return immediately */
7530 if (!ioc->bios_pg3.BiosVersion)
7535 if (ioc->req_boot_device.device) {
7536 device = ioc->req_boot_device.device;
7537 is_raid = ioc->req_boot_device.is_raid;
7538 } else if (ioc->req_alt_boot_device.device) {
7539 device = ioc->req_alt_boot_device.device;
7540 is_raid = ioc->req_alt_boot_device.is_raid;
7541 } else if (ioc->current_boot_device.device) {
7542 device = ioc->current_boot_device.device;
7543 is_raid = ioc->current_boot_device.is_raid;
7550 raid_device = device;
7551 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7552 raid_device->id, 0);
7554 _scsih_raid_device_remove(ioc, raid_device);
7556 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7557 sas_device = device;
7558 handle = sas_device->handle;
7559 sas_address_parent = sas_device->sas_address_parent;
7560 sas_address = sas_device->sas_address;
7561 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7562 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7564 if (!mpt3sas_transport_port_add(ioc, handle,
7565 sas_address_parent)) {
7566 _scsih_sas_device_remove(ioc, sas_device);
7567 } else if (!sas_device->starget) {
7568 if (!ioc->is_driver_loading) {
7569 mpt3sas_transport_port_remove(ioc,
7571 sas_address_parent);
7572 _scsih_sas_device_remove(ioc, sas_device);
7579 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7580 * @ioc: per adapter object
7582 * Called during initial loading of the driver.
7585 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7587 struct _raid_device *raid_device, *raid_next;
7590 list_for_each_entry_safe(raid_device, raid_next,
7591 &ioc->raid_device_list, list) {
7592 if (raid_device->starget)
7594 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7595 raid_device->id, 0);
7597 _scsih_raid_device_remove(ioc, raid_device);
7602 * _scsih_probe_sas - reporting sas devices to sas transport
7603 * @ioc: per adapter object
7605 * Called during initial loading of the driver.
7608 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7610 struct _sas_device *sas_device, *next;
7611 unsigned long flags;
7613 /* SAS Device List */
7614 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7617 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7618 sas_device->sas_address_parent)) {
7619 list_del(&sas_device->list);
7622 } else if (!sas_device->starget) {
7624 * When asyn scanning is enabled, its not possible to
7625 * remove devices while scanning is turned on due to an
7626 * oops in scsi_sysfs_add_sdev()->add_device()->
7627 * sysfs_addrm_start()
7629 if (!ioc->is_driver_loading) {
7630 mpt3sas_transport_port_remove(ioc,
7631 sas_device->sas_address,
7632 sas_device->sas_address_parent);
7633 list_del(&sas_device->list);
7639 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7640 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7641 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7646 * _scsih_probe_devices - probing for devices
7647 * @ioc: per adapter object
7649 * Called during initial loading of the driver.
7652 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7654 u16 volume_mapping_flags;
7656 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7657 return; /* return when IOC doesn't support initiator mode */
7659 _scsih_probe_boot_devices(ioc);
7661 if (ioc->ir_firmware) {
7662 volume_mapping_flags =
7663 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7664 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7665 if (volume_mapping_flags ==
7666 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7667 _scsih_probe_raid(ioc);
7668 _scsih_probe_sas(ioc);
7670 _scsih_probe_sas(ioc);
7671 _scsih_probe_raid(ioc);
7674 _scsih_probe_sas(ioc);
7678 * _scsih_scan_start - scsi lld callback for .scan_start
7679 * @shost: SCSI host pointer
7681 * The shost has the ability to discover targets on its own instead
7682 * of scanning the entire bus. In our implemention, we will kick off
7683 * firmware discovery.
7686 _scsih_scan_start(struct Scsi_Host *shost)
7688 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7690 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7691 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7693 if (disable_discovery > 0)
7696 ioc->start_scan = 1;
7697 rc = mpt3sas_port_enable(ioc);
7700 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7704 * _scsih_scan_finished - scsi lld callback for .scan_finished
7705 * @shost: SCSI host pointer
7706 * @time: elapsed time of the scan in jiffies
7708 * This function will be called periodicallyn until it returns 1 with the
7709 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7710 * we wait for firmware discovery to complete, then return 1.
7713 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7715 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7717 if (disable_discovery > 0) {
7718 ioc->is_driver_loading = 0;
7719 ioc->wait_for_discovery_to_complete = 0;
7723 if (time >= (300 * HZ)) {
7724 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7726 "port enable: FAILED with timeout (timeout=300s)\n",
7728 ioc->is_driver_loading = 0;
7732 if (ioc->start_scan)
7735 if (ioc->start_scan_failed) {
7737 "port enable: FAILED with (ioc_status=0x%08x)\n",
7738 ioc->name, ioc->start_scan_failed);
7739 ioc->is_driver_loading = 0;
7740 ioc->wait_for_discovery_to_complete = 0;
7741 ioc->remove_host = 1;
7745 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7746 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7748 if (ioc->wait_for_discovery_to_complete) {
7749 ioc->wait_for_discovery_to_complete = 0;
7750 _scsih_probe_devices(ioc);
7752 mpt3sas_base_start_watchdog(ioc);
7753 ioc->is_driver_loading = 0;
7758 * _scsih_probe - attach and add scsi host
7759 * @pdev: PCI device struct
7760 * @id: pci device id
7762 * Returns 0 success, anything else error.
7765 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7767 struct MPT3SAS_ADAPTER *ioc;
7768 struct Scsi_Host *shost;
7771 shost = scsi_host_alloc(&scsih_driver_template,
7772 sizeof(struct MPT3SAS_ADAPTER));
7776 /* init local params */
7777 ioc = shost_priv(shost);
7778 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7779 INIT_LIST_HEAD(&ioc->list);
7780 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7782 ioc->id = mpt_ids++;
7783 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
7785 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7786 ioc->tm_cb_idx = tm_cb_idx;
7787 ioc->ctl_cb_idx = ctl_cb_idx;
7788 ioc->base_cb_idx = base_cb_idx;
7789 ioc->port_enable_cb_idx = port_enable_cb_idx;
7790 ioc->transport_cb_idx = transport_cb_idx;
7791 ioc->scsih_cb_idx = scsih_cb_idx;
7792 ioc->config_cb_idx = config_cb_idx;
7793 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7794 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7795 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7796 ioc->logging_level = logging_level;
7797 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7798 /* misc semaphores and spin locks */
7799 mutex_init(&ioc->reset_in_progress_mutex);
7800 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7801 spin_lock_init(&ioc->scsi_lookup_lock);
7802 spin_lock_init(&ioc->sas_device_lock);
7803 spin_lock_init(&ioc->sas_node_lock);
7804 spin_lock_init(&ioc->fw_event_lock);
7805 spin_lock_init(&ioc->raid_device_lock);
7806 spin_lock_init(&ioc->diag_trigger_lock);
7808 INIT_LIST_HEAD(&ioc->sas_device_list);
7809 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7810 INIT_LIST_HEAD(&ioc->sas_expander_list);
7811 INIT_LIST_HEAD(&ioc->fw_event_list);
7812 INIT_LIST_HEAD(&ioc->raid_device_list);
7813 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7814 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7815 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7816 INIT_LIST_HEAD(&ioc->reply_queue_list);
7818 /* init shost parameters */
7819 shost->max_cmd_len = 32;
7820 shost->max_lun = max_lun;
7821 shost->transportt = mpt3sas_transport_template;
7822 shost->unique_id = ioc->id;
7824 if (max_sectors != 0xFFFF) {
7825 if (max_sectors < 64) {
7826 shost->max_sectors = 64;
7827 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7828 "for max_sectors, range is 64 to 32767. Assigning "
7829 "value of 64.\n", ioc->name, max_sectors);
7830 } else if (max_sectors > 32767) {
7831 shost->max_sectors = 32767;
7832 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7833 "for max_sectors, range is 64 to 32767. Assigning "
7834 "default value of 32767.\n", ioc->name,
7837 shost->max_sectors = max_sectors & 0xFFFE;
7839 "The max_sectors value is set to %d\n",
7840 ioc->name, shost->max_sectors);
7844 /* register EEDP capabilities with SCSI layer */
7846 scsi_host_set_prot(shost, prot_mask);
7848 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7849 | SHOST_DIF_TYPE2_PROTECTION
7850 | SHOST_DIF_TYPE3_PROTECTION);
7852 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7855 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7856 "fw_event%d", ioc->id);
7857 ioc->firmware_event_thread = create_singlethread_workqueue(
7858 ioc->firmware_event_name);
7859 if (!ioc->firmware_event_thread) {
7860 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7861 ioc->name, __FILE__, __LINE__, __func__);
7863 goto out_thread_fail;
7866 ioc->is_driver_loading = 1;
7867 if ((mpt3sas_base_attach(ioc))) {
7868 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7869 ioc->name, __FILE__, __LINE__, __func__);
7871 goto out_attach_fail;
7873 rv = scsi_add_host(shost, &pdev->dev);
7875 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7876 ioc->name, __FILE__, __LINE__, __func__);
7877 goto out_add_shost_fail;
7880 scsi_scan_host(shost);
7883 mpt3sas_base_detach(ioc);
7885 destroy_workqueue(ioc->firmware_event_thread);
7887 list_del(&ioc->list);
7888 scsi_host_put(shost);
7894 * _scsih_suspend - power management suspend main entry point
7895 * @pdev: PCI device struct
7896 * @state: PM state change to (usually PCI_D3)
7898 * Returns 0 success, anything else error.
7901 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7903 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7904 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7905 pci_power_t device_state;
7907 mpt3sas_base_stop_watchdog(ioc);
7908 flush_scheduled_work();
7909 scsi_block_requests(shost);
7910 device_state = pci_choose_state(pdev, state);
7912 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
7913 ioc->name, pdev, pci_name(pdev), device_state);
7915 pci_save_state(pdev);
7916 mpt3sas_base_free_resources(ioc);
7917 pci_set_power_state(pdev, device_state);
7922 * _scsih_resume - power management resume main entry point
7923 * @pdev: PCI device struct
7925 * Returns 0 success, anything else error.
7928 _scsih_resume(struct pci_dev *pdev)
7930 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7931 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7932 pci_power_t device_state = pdev->current_state;
7936 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
7937 ioc->name, pdev, pci_name(pdev), device_state);
7939 pci_set_power_state(pdev, PCI_D0);
7940 pci_enable_wake(pdev, PCI_D0, 0);
7941 pci_restore_state(pdev);
7943 r = mpt3sas_base_map_resources(ioc);
7947 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7948 scsi_unblock_requests(shost);
7949 mpt3sas_base_start_watchdog(ioc);
7952 #endif /* CONFIG_PM */
7955 * _scsih_pci_error_detected - Called when a PCI error is detected.
7956 * @pdev: PCI device struct
7957 * @state: PCI channel state
7959 * Description: Called when a PCI error is detected.
7962 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7964 static pci_ers_result_t
7965 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7967 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7968 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7970 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
7974 case pci_channel_io_normal:
7975 return PCI_ERS_RESULT_CAN_RECOVER;
7976 case pci_channel_io_frozen:
7977 /* Fatal error, prepare for slot reset */
7978 ioc->pci_error_recovery = 1;
7979 scsi_block_requests(ioc->shost);
7980 mpt3sas_base_stop_watchdog(ioc);
7981 mpt3sas_base_free_resources(ioc);
7982 return PCI_ERS_RESULT_NEED_RESET;
7983 case pci_channel_io_perm_failure:
7984 /* Permanent error, prepare for device removal */
7985 ioc->pci_error_recovery = 1;
7986 mpt3sas_base_stop_watchdog(ioc);
7987 _scsih_flush_running_cmds(ioc);
7988 return PCI_ERS_RESULT_DISCONNECT;
7990 return PCI_ERS_RESULT_NEED_RESET;
7994 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7995 * @pdev: PCI device struct
7997 * Description: This routine is called by the pci error recovery
7998 * code after the PCI slot has been reset, just before we
7999 * should resume normal operations.
8001 static pci_ers_result_t
8002 _scsih_pci_slot_reset(struct pci_dev *pdev)
8004 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8005 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8008 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8011 ioc->pci_error_recovery = 0;
8013 pci_restore_state(pdev);
8014 rc = mpt3sas_base_map_resources(ioc);
8016 return PCI_ERS_RESULT_DISCONNECT;
8018 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8021 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8022 (rc == 0) ? "success" : "failed");
8025 return PCI_ERS_RESULT_RECOVERED;
8027 return PCI_ERS_RESULT_DISCONNECT;
8031 * _scsih_pci_resume() - resume normal ops after PCI reset
8032 * @pdev: pointer to PCI device
8034 * Called when the error recovery driver tells us that its
8035 * OK to resume normal operation. Use completion to allow
8036 * halted scsi ops to resume.
8039 _scsih_pci_resume(struct pci_dev *pdev)
8041 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8042 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8044 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8046 pci_cleanup_aer_uncorrect_error_status(pdev);
8047 mpt3sas_base_start_watchdog(ioc);
8048 scsi_unblock_requests(ioc->shost);
8052 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8053 * @pdev: pointer to PCI device
8055 static pci_ers_result_t
8056 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8058 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8059 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8061 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8064 /* TODO - dump whatever for debugging purposes */
8066 /* Request a slot reset. */
8067 return PCI_ERS_RESULT_NEED_RESET;
8070 /* raid transport support */
8071 static struct raid_function_template mpt3sas_raid_functions = {
8072 .cookie = &scsih_driver_template,
8073 .is_raid = _scsih_is_raid,
8074 .get_resync = _scsih_get_resync,
8075 .get_state = _scsih_get_state,
8078 static struct pci_error_handlers _scsih_err_handler = {
8079 .error_detected = _scsih_pci_error_detected,
8080 .mmio_enabled = _scsih_pci_mmio_enabled,
8081 .slot_reset = _scsih_pci_slot_reset,
8082 .resume = _scsih_pci_resume,
8085 static struct pci_driver scsih_driver = {
8086 .name = MPT3SAS_DRIVER_NAME,
8087 .id_table = scsih_pci_table,
8088 .probe = _scsih_probe,
8089 .remove = _scsih_remove,
8090 .shutdown = _scsih_shutdown,
8091 .err_handler = &_scsih_err_handler,
8093 .suspend = _scsih_suspend,
8094 .resume = _scsih_resume,
8100 * _scsih_init - main entry point for this driver.
8102 * Returns 0 success, anything else error.
8111 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8112 MPT3SAS_DRIVER_VERSION);
8114 mpt3sas_transport_template =
8115 sas_attach_transport(&mpt3sas_transport_functions);
8116 if (!mpt3sas_transport_template)
8119 /* raid transport support */
8120 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8121 if (!mpt3sas_raid_template) {
8122 sas_release_transport(mpt3sas_transport_template);
8126 mpt3sas_base_initialize_callback_handler();
8128 /* queuecommand callback hander */
8129 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8131 /* task managment callback handler */
8132 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8134 /* base internal commands callback handler */
8135 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8136 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8137 mpt3sas_port_enable_done);
8139 /* transport internal commands callback handler */
8140 transport_cb_idx = mpt3sas_base_register_callback_handler(
8141 mpt3sas_transport_done);
8143 /* scsih internal commands callback handler */
8144 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8146 /* configuration page API internal commands callback handler */
8147 config_cb_idx = mpt3sas_base_register_callback_handler(
8148 mpt3sas_config_done);
8150 /* ctl module callback handler */
8151 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8153 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8154 _scsih_tm_tr_complete);
8156 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8157 _scsih_tm_volume_tr_complete);
8159 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8160 _scsih_sas_control_complete);
8164 error = pci_register_driver(&scsih_driver);
8166 /* raid transport support */
8167 raid_class_release(mpt3sas_raid_template);
8168 sas_release_transport(mpt3sas_transport_template);
8175 * _scsih_exit - exit point for this driver (when it is a module).
8177 * Returns 0 success, anything else error.
8182 pr_info("mpt3sas version %s unloading\n",
8183 MPT3SAS_DRIVER_VERSION);
8187 pci_unregister_driver(&scsih_driver);
8190 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8191 mpt3sas_base_release_callback_handler(tm_cb_idx);
8192 mpt3sas_base_release_callback_handler(base_cb_idx);
8193 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8194 mpt3sas_base_release_callback_handler(transport_cb_idx);
8195 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8196 mpt3sas_base_release_callback_handler(config_cb_idx);
8197 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8199 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8200 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8201 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8203 /* raid transport support */
8204 raid_class_release(mpt3sas_raid_template);
8205 sas_release_transport(mpt3sas_transport_template);
8208 module_init(_scsih_init);
8209 module_exit(_scsih_exit);