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>
57 #include <asm/unaligned.h>
59 #include "mpt3sas_base.h"
61 #define RAID_CHANNEL 1
63 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
64 struct _sas_node *sas_expander);
65 static void _firmware_event_work(struct work_struct *work);
67 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
68 struct _sas_device *sas_device);
69 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
70 u8 retry_count, u8 is_pd);
72 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
74 /* global parameters */
75 LIST_HEAD(mpt3sas_ioc_list);
76 /* global ioc lock for list operations */
77 DEFINE_SPINLOCK(gioc_lock);
79 MODULE_AUTHOR(MPT3SAS_AUTHOR);
80 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
83 MODULE_ALIAS("mpt2sas");
85 /* local parameters */
86 static u8 scsi_io_cb_idx = -1;
87 static u8 tm_cb_idx = -1;
88 static u8 ctl_cb_idx = -1;
89 static u8 base_cb_idx = -1;
90 static u8 port_enable_cb_idx = -1;
91 static u8 transport_cb_idx = -1;
92 static u8 scsih_cb_idx = -1;
93 static u8 config_cb_idx = -1;
97 static u8 tm_tr_cb_idx = -1 ;
98 static u8 tm_tr_volume_cb_idx = -1 ;
99 static u8 tm_sas_control_cb_idx = -1;
101 /* command line options */
102 static u32 logging_level;
103 MODULE_PARM_DESC(logging_level,
104 " bits for enabling additional logging info (default=0)");
107 static ushort max_sectors = 0xFFFF;
108 module_param(max_sectors, ushort, 0);
109 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
112 static int missing_delay[2] = {-1, -1};
113 module_param_array(missing_delay, int, NULL, 0);
114 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
116 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
117 #define MPT3SAS_MAX_LUN (16895)
118 static u64 max_lun = MPT3SAS_MAX_LUN;
119 module_param(max_lun, ullong, 0);
120 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
122 static ushort hbas_to_enumerate;
123 module_param(hbas_to_enumerate, ushort, 0);
124 MODULE_PARM_DESC(hbas_to_enumerate,
125 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
126 1 - enumerates only SAS 2.0 generation HBAs\n \
127 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
129 /* diag_buffer_enable is bitwise
131 * bit 1 set = SNAPSHOT
132 * bit 2 set = EXTENDED
134 * Either bit can be set, or both
136 static int diag_buffer_enable = -1;
137 module_param(diag_buffer_enable, int, 0);
138 MODULE_PARM_DESC(diag_buffer_enable,
139 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
140 static int disable_discovery = -1;
141 module_param(disable_discovery, int, 0);
142 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
145 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
146 static int prot_mask = -1;
147 module_param(prot_mask, int, 0);
148 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
151 /* raid transport support */
152 struct raid_template *mpt3sas_raid_template;
153 struct raid_template *mpt2sas_raid_template;
157 * struct sense_info - common structure for obtaining sense keys
159 * @asc: additional sense code
160 * @ascq: additional sense code qualifier
168 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
169 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
170 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
171 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
172 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
174 * struct fw_event_work - firmware event struct
175 * @list: link list framework
176 * @work: work object (ioc->fault_reset_work_q)
177 * @cancel_pending_work: flag set during reset handling
178 * @ioc: per adapter object
179 * @device_handle: device handle
180 * @VF_ID: virtual function id
181 * @VP_ID: virtual port id
182 * @ignore: flag meaning this event has been marked to ignore
183 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
184 * @event_data: reply event data payload follows
186 * This object stored on ioc->fw_event_list.
188 struct fw_event_work {
189 struct list_head list;
190 struct work_struct work;
191 u8 cancel_pending_work;
192 struct delayed_work delayed_work;
194 struct MPT3SAS_ADAPTER *ioc;
200 struct kref refcount;
201 char event_data[0] __aligned(4);
204 static void fw_event_work_free(struct kref *r)
206 kfree(container_of(r, struct fw_event_work, refcount));
209 static void fw_event_work_get(struct fw_event_work *fw_work)
211 kref_get(&fw_work->refcount);
214 static void fw_event_work_put(struct fw_event_work *fw_work)
216 kref_put(&fw_work->refcount, fw_event_work_free);
219 static struct fw_event_work *alloc_fw_event_work(int len)
221 struct fw_event_work *fw_event;
223 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
227 kref_init(&fw_event->refcount);
232 * struct _scsi_io_transfer - scsi io transfer
233 * @handle: sas device handle (assigned by firmware)
234 * @is_raid: flag set for hidden raid components
235 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
236 * @data_length: data transfer length
237 * @data_dma: dma pointer to data
240 * @cdb_length: cdb length
242 * @timeout: timeout for this command
243 * @VF_ID: virtual function id
244 * @VP_ID: virtual port id
245 * @valid_reply: flag set for reply message
246 * @sense_length: sense length
247 * @ioc_status: ioc status
248 * @scsi_state: scsi state
249 * @scsi_status: scsi staus
250 * @log_info: log information
251 * @transfer_length: data length transfer when there is a reply message
253 * Used for sending internal scsi commands to devices within this module.
254 * Refer to _scsi_send_scsi_io().
256 struct _scsi_io_transfer {
259 enum dma_data_direction dir;
262 u8 sense[SCSI_SENSE_BUFFERSIZE];
270 /* the following bits are only valid when 'valid_reply = 1' */
280 * _scsih_set_debug_level - global setting of ioc->logging_level.
282 * Note: The logging levels are defined in mpt3sas_debug.h.
285 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
287 int ret = param_set_int(val, kp);
288 struct MPT3SAS_ADAPTER *ioc;
293 pr_info("setting logging_level(0x%08x)\n", logging_level);
294 spin_lock(&gioc_lock);
295 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
296 ioc->logging_level = logging_level;
297 spin_unlock(&gioc_lock);
300 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
301 &logging_level, 0644);
304 * _scsih_srch_boot_sas_address - search based on sas_address
305 * @sas_address: sas address
306 * @boot_device: boot device object from bios page 2
308 * Returns 1 when there's a match, 0 means no match.
311 _scsih_srch_boot_sas_address(u64 sas_address,
312 Mpi2BootDeviceSasWwid_t *boot_device)
314 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
318 * _scsih_srch_boot_device_name - search based on device name
319 * @device_name: device name specified in INDENTIFY fram
320 * @boot_device: boot device object from bios page 2
322 * Returns 1 when there's a match, 0 means no match.
325 _scsih_srch_boot_device_name(u64 device_name,
326 Mpi2BootDeviceDeviceName_t *boot_device)
328 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
332 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
333 * @enclosure_logical_id: enclosure logical id
334 * @slot_number: slot number
335 * @boot_device: boot device object from bios page 2
337 * Returns 1 when there's a match, 0 means no match.
340 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
341 Mpi2BootDeviceEnclosureSlot_t *boot_device)
343 return (enclosure_logical_id == le64_to_cpu(boot_device->
344 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
345 SlotNumber)) ? 1 : 0;
349 * _scsih_is_boot_device - search for matching boot device.
350 * @sas_address: sas address
351 * @device_name: device name specified in INDENTIFY fram
352 * @enclosure_logical_id: enclosure logical id
353 * @slot_number: slot number
354 * @form: specifies boot device form
355 * @boot_device: boot device object from bios page 2
357 * Returns 1 when there's a match, 0 means no match.
360 _scsih_is_boot_device(u64 sas_address, u64 device_name,
361 u64 enclosure_logical_id, u16 slot, u8 form,
362 Mpi2BiosPage2BootDevice_t *boot_device)
367 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
370 rc = _scsih_srch_boot_sas_address(
371 sas_address, &boot_device->SasWwid);
373 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
374 if (!enclosure_logical_id)
376 rc = _scsih_srch_boot_encl_slot(
377 enclosure_logical_id,
378 slot, &boot_device->EnclosureSlot);
380 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
383 rc = _scsih_srch_boot_device_name(
384 device_name, &boot_device->DeviceName);
386 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
394 * _scsih_get_sas_address - set the sas_address for given device handle
395 * @handle: device handle
396 * @sas_address: sas address
398 * Returns 0 success, non-zero when failure
401 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
404 Mpi2SasDevicePage0_t sas_device_pg0;
405 Mpi2ConfigReply_t mpi_reply;
410 if (handle <= ioc->sas_hba.num_phys) {
411 *sas_address = ioc->sas_hba.sas_address;
415 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
416 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
417 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
418 __FILE__, __LINE__, __func__);
422 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
423 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
424 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
428 /* we hit this becuase the given parent handle doesn't exist */
429 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
432 /* else error case */
434 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
435 ioc->name, handle, ioc_status,
436 __FILE__, __LINE__, __func__);
441 * _scsih_determine_boot_device - determine boot device.
442 * @ioc: per adapter object
443 * @device: either sas_device or raid_device object
444 * @is_raid: [flag] 1 = raid object, 0 = sas object
446 * Determines whether this device should be first reported device to
447 * to scsi-ml or sas transport, this purpose is for persistent boot device.
448 * There are primary, alternate, and current entries in bios page 2. The order
449 * priority is primary, alternate, then current. This routine saves
450 * the corresponding device object and is_raid flag in the ioc object.
451 * The saved data to be used later in _scsih_probe_boot_devices().
454 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
455 void *device, u8 is_raid)
457 struct _sas_device *sas_device;
458 struct _raid_device *raid_device;
461 u64 enclosure_logical_id;
464 /* only process this function when driver loads */
465 if (!ioc->is_driver_loading)
468 /* no Bios, return immediately */
469 if (!ioc->bios_pg3.BiosVersion)
474 sas_address = sas_device->sas_address;
475 device_name = sas_device->device_name;
476 enclosure_logical_id = sas_device->enclosure_logical_id;
477 slot = sas_device->slot;
479 raid_device = device;
480 sas_address = raid_device->wwid;
482 enclosure_logical_id = 0;
486 if (!ioc->req_boot_device.device) {
487 if (_scsih_is_boot_device(sas_address, device_name,
488 enclosure_logical_id, slot,
489 (ioc->bios_pg2.ReqBootDeviceForm &
490 MPI2_BIOSPAGE2_FORM_MASK),
491 &ioc->bios_pg2.RequestedBootDevice)) {
492 dinitprintk(ioc, pr_info(MPT3SAS_FMT
493 "%s: req_boot_device(0x%016llx)\n",
495 (unsigned long long)sas_address));
496 ioc->req_boot_device.device = device;
497 ioc->req_boot_device.is_raid = is_raid;
501 if (!ioc->req_alt_boot_device.device) {
502 if (_scsih_is_boot_device(sas_address, device_name,
503 enclosure_logical_id, slot,
504 (ioc->bios_pg2.ReqAltBootDeviceForm &
505 MPI2_BIOSPAGE2_FORM_MASK),
506 &ioc->bios_pg2.RequestedAltBootDevice)) {
507 dinitprintk(ioc, pr_info(MPT3SAS_FMT
508 "%s: req_alt_boot_device(0x%016llx)\n",
510 (unsigned long long)sas_address));
511 ioc->req_alt_boot_device.device = device;
512 ioc->req_alt_boot_device.is_raid = is_raid;
516 if (!ioc->current_boot_device.device) {
517 if (_scsih_is_boot_device(sas_address, device_name,
518 enclosure_logical_id, slot,
519 (ioc->bios_pg2.CurrentBootDeviceForm &
520 MPI2_BIOSPAGE2_FORM_MASK),
521 &ioc->bios_pg2.CurrentBootDevice)) {
522 dinitprintk(ioc, pr_info(MPT3SAS_FMT
523 "%s: current_boot_device(0x%016llx)\n",
525 (unsigned long long)sas_address));
526 ioc->current_boot_device.device = device;
527 ioc->current_boot_device.is_raid = is_raid;
532 static struct _sas_device *
533 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
534 struct MPT3SAS_TARGET *tgt_priv)
536 struct _sas_device *ret;
538 assert_spin_locked(&ioc->sas_device_lock);
540 ret = tgt_priv->sdev;
547 static struct _sas_device *
548 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
549 struct MPT3SAS_TARGET *tgt_priv)
551 struct _sas_device *ret;
554 spin_lock_irqsave(&ioc->sas_device_lock, flags);
555 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
556 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
563 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
566 struct _sas_device *sas_device;
568 assert_spin_locked(&ioc->sas_device_lock);
570 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
571 if (sas_device->sas_address == sas_address)
574 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
575 if (sas_device->sas_address == sas_address)
581 sas_device_get(sas_device);
586 * mpt3sas_get_sdev_by_addr - sas device search
587 * @ioc: per adapter object
588 * @sas_address: sas address
589 * Context: Calling function should acquire ioc->sas_device_lock
591 * This searches for sas_device based on sas_address, then return sas_device
595 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
598 struct _sas_device *sas_device;
601 spin_lock_irqsave(&ioc->sas_device_lock, flags);
602 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
604 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
609 static struct _sas_device *
610 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
612 struct _sas_device *sas_device;
614 assert_spin_locked(&ioc->sas_device_lock);
616 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
617 if (sas_device->handle == handle)
620 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
621 if (sas_device->handle == handle)
627 sas_device_get(sas_device);
632 * mpt3sas_get_sdev_by_handle - sas device search
633 * @ioc: per adapter object
634 * @handle: sas device handle (assigned by firmware)
635 * Context: Calling function should acquire ioc->sas_device_lock
637 * This searches for sas_device based on sas_address, then return sas_device
640 static struct _sas_device *
641 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
643 struct _sas_device *sas_device;
646 spin_lock_irqsave(&ioc->sas_device_lock, flags);
647 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
648 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
654 * _scsih_sas_device_remove - remove sas_device from list.
655 * @ioc: per adapter object
656 * @sas_device: the sas_device object
657 * Context: This function will acquire ioc->sas_device_lock.
659 * If sas_device is on the list, remove it and decrement its reference count.
662 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
663 struct _sas_device *sas_device)
670 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
671 ioc->name, sas_device->handle,
672 (unsigned long long) sas_device->sas_address);
674 if (sas_device->enclosure_handle != 0)
676 "removing enclosure logical id(0x%016llx), slot(%d)\n",
677 ioc->name, (unsigned long long)
678 sas_device->enclosure_logical_id, sas_device->slot);
680 if (sas_device->connector_name[0] != '\0')
682 "removing enclosure level(0x%04x), connector name( %s)\n",
683 ioc->name, sas_device->enclosure_level,
684 sas_device->connector_name);
687 * The lock serializes access to the list, but we still need to verify
688 * that nobody removed the entry while we were waiting on the lock.
690 spin_lock_irqsave(&ioc->sas_device_lock, flags);
691 if (!list_empty(&sas_device->list)) {
692 list_del_init(&sas_device->list);
693 sas_device_put(sas_device);
695 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
699 * _scsih_device_remove_by_handle - removing device object by handle
700 * @ioc: per adapter object
701 * @handle: device handle
706 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
708 struct _sas_device *sas_device;
711 if (ioc->shost_recovery)
714 spin_lock_irqsave(&ioc->sas_device_lock, flags);
715 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
717 list_del_init(&sas_device->list);
718 sas_device_put(sas_device);
720 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
722 _scsih_remove_device(ioc, sas_device);
723 sas_device_put(sas_device);
728 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
729 * @ioc: per adapter object
730 * @sas_address: device sas_address
735 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
738 struct _sas_device *sas_device;
741 if (ioc->shost_recovery)
744 spin_lock_irqsave(&ioc->sas_device_lock, flags);
745 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
747 list_del_init(&sas_device->list);
748 sas_device_put(sas_device);
750 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
752 _scsih_remove_device(ioc, sas_device);
753 sas_device_put(sas_device);
758 * _scsih_sas_device_add - insert sas_device to the list.
759 * @ioc: per adapter object
760 * @sas_device: the sas_device object
761 * Context: This function will acquire ioc->sas_device_lock.
763 * Adding new object to the ioc->sas_device_list.
766 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
767 struct _sas_device *sas_device)
771 dewtprintk(ioc, pr_info(MPT3SAS_FMT
772 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
773 ioc->name, __func__, sas_device->handle,
774 (unsigned long long)sas_device->sas_address));
776 if (sas_device->enclosure_handle != 0)
777 dewtprintk(ioc, pr_info(MPT3SAS_FMT
778 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
779 ioc->name, __func__, (unsigned long long)
780 sas_device->enclosure_logical_id, sas_device->slot));
782 if (sas_device->connector_name[0] != '\0')
783 dewtprintk(ioc, pr_info(MPT3SAS_FMT
784 "%s: enclosure level(0x%04x), connector name( %s)\n",
786 sas_device->enclosure_level, sas_device->connector_name));
788 spin_lock_irqsave(&ioc->sas_device_lock, flags);
789 sas_device_get(sas_device);
790 list_add_tail(&sas_device->list, &ioc->sas_device_list);
791 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
793 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
794 sas_device->sas_address_parent)) {
795 _scsih_sas_device_remove(ioc, sas_device);
796 } else if (!sas_device->starget) {
798 * When asyn scanning is enabled, its not possible to remove
799 * devices while scanning is turned on due to an oops in
800 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
802 if (!ioc->is_driver_loading) {
803 mpt3sas_transport_port_remove(ioc,
804 sas_device->sas_address,
805 sas_device->sas_address_parent);
806 _scsih_sas_device_remove(ioc, sas_device);
812 * _scsih_sas_device_init_add - insert sas_device to the list.
813 * @ioc: per adapter object
814 * @sas_device: the sas_device object
815 * Context: This function will acquire ioc->sas_device_lock.
817 * Adding new object at driver load time to the ioc->sas_device_init_list.
820 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
821 struct _sas_device *sas_device)
825 dewtprintk(ioc, pr_info(MPT3SAS_FMT
826 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
827 __func__, sas_device->handle,
828 (unsigned long long)sas_device->sas_address));
830 if (sas_device->enclosure_handle != 0)
831 dewtprintk(ioc, pr_info(MPT3SAS_FMT
832 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
833 ioc->name, __func__, (unsigned long long)
834 sas_device->enclosure_logical_id, sas_device->slot));
836 if (sas_device->connector_name[0] != '\0')
837 dewtprintk(ioc, pr_info(MPT3SAS_FMT
838 "%s: enclosure level(0x%04x), connector name( %s)\n",
839 ioc->name, __func__, sas_device->enclosure_level,
840 sas_device->connector_name));
842 spin_lock_irqsave(&ioc->sas_device_lock, flags);
843 sas_device_get(sas_device);
844 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
845 _scsih_determine_boot_device(ioc, sas_device, 0);
846 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
850 * _scsih_raid_device_find_by_id - raid device search
851 * @ioc: per adapter object
852 * @id: sas device target id
853 * @channel: sas device channel
854 * Context: Calling function should acquire ioc->raid_device_lock
856 * This searches for raid_device based on target id, then return raid_device
859 static struct _raid_device *
860 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
862 struct _raid_device *raid_device, *r;
865 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
866 if (raid_device->id == id && raid_device->channel == channel) {
877 * mpt3sas_raid_device_find_by_handle - raid device search
878 * @ioc: per adapter object
879 * @handle: sas device handle (assigned by firmware)
880 * Context: Calling function should acquire ioc->raid_device_lock
882 * This searches for raid_device based on handle, then return raid_device
885 struct _raid_device *
886 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
888 struct _raid_device *raid_device, *r;
891 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
892 if (raid_device->handle != handle)
903 * _scsih_raid_device_find_by_wwid - raid device search
904 * @ioc: per adapter object
905 * @handle: sas device handle (assigned by firmware)
906 * Context: Calling function should acquire ioc->raid_device_lock
908 * This searches for raid_device based on wwid, then return raid_device
911 static struct _raid_device *
912 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
914 struct _raid_device *raid_device, *r;
917 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
918 if (raid_device->wwid != wwid)
929 * _scsih_raid_device_add - add raid_device object
930 * @ioc: per adapter object
931 * @raid_device: raid_device object
933 * This is added to the raid_device_list link list.
936 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
937 struct _raid_device *raid_device)
941 dewtprintk(ioc, pr_info(MPT3SAS_FMT
942 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
943 raid_device->handle, (unsigned long long)raid_device->wwid));
945 spin_lock_irqsave(&ioc->raid_device_lock, flags);
946 list_add_tail(&raid_device->list, &ioc->raid_device_list);
947 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
951 * _scsih_raid_device_remove - delete raid_device object
952 * @ioc: per adapter object
953 * @raid_device: raid_device object
957 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
958 struct _raid_device *raid_device)
962 spin_lock_irqsave(&ioc->raid_device_lock, flags);
963 list_del(&raid_device->list);
965 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
969 * mpt3sas_scsih_expander_find_by_handle - expander device search
970 * @ioc: per adapter object
971 * @handle: expander handle (assigned by firmware)
972 * Context: Calling function should acquire ioc->sas_device_lock
974 * This searches for expander device based on handle, then returns the
978 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
980 struct _sas_node *sas_expander, *r;
983 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
984 if (sas_expander->handle != handle)
994 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
995 * @ioc: per adapter object
996 * @sas_address: sas address
997 * Context: Calling function should acquire ioc->sas_node_lock.
999 * This searches for expander device based on sas_address, then returns the
1003 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1006 struct _sas_node *sas_expander, *r;
1009 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1010 if (sas_expander->sas_address != sas_address)
1020 * _scsih_expander_node_add - insert expander device to the list.
1021 * @ioc: per adapter object
1022 * @sas_expander: the sas_device object
1023 * Context: This function will acquire ioc->sas_node_lock.
1025 * Adding new object to the ioc->sas_expander_list.
1030 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1031 struct _sas_node *sas_expander)
1033 unsigned long flags;
1035 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1036 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1037 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1041 * _scsih_is_end_device - determines if device is an end device
1042 * @device_info: bitfield providing information about the device.
1045 * Returns 1 if end device.
1048 _scsih_is_end_device(u32 device_info)
1050 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1051 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1052 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1053 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1060 * _scsih_scsi_lookup_get - returns scmd entry
1061 * @ioc: per adapter object
1062 * @smid: system request message index
1064 * Returns the smid stored scmd pointer.
1066 static struct scsi_cmnd *
1067 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1069 return ioc->scsi_lookup[smid - 1].scmd;
1073 * _scsih_scsi_lookup_get_clear - returns scmd entry
1074 * @ioc: per adapter object
1075 * @smid: system request message index
1077 * Returns the smid stored scmd pointer.
1078 * Then will derefrence the stored scmd pointer.
1080 static inline struct scsi_cmnd *
1081 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1083 unsigned long flags;
1084 struct scsi_cmnd *scmd;
1086 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1087 scmd = ioc->scsi_lookup[smid - 1].scmd;
1088 ioc->scsi_lookup[smid - 1].scmd = NULL;
1089 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1095 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1096 * @ioc: per adapter object
1097 * @smid: system request message index
1098 * @scmd: pointer to scsi command object
1099 * Context: This function will acquire ioc->scsi_lookup_lock.
1101 * This will search for a scmd pointer in the scsi_lookup array,
1102 * returning the revelent smid. A returned value of zero means invalid.
1105 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
1109 unsigned long flags;
1112 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1114 for (i = 0; i < ioc->scsiio_depth; i++) {
1115 if (ioc->scsi_lookup[i].scmd == scmd) {
1116 smid = ioc->scsi_lookup[i].smid;
1121 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1126 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1127 * @ioc: per adapter object
1130 * Context: This function will acquire ioc->scsi_lookup_lock.
1132 * This will search for a matching channel:id in the scsi_lookup array,
1133 * returning 1 if found.
1136 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1140 unsigned long flags;
1143 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1145 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1146 if (ioc->scsi_lookup[i].scmd &&
1147 (ioc->scsi_lookup[i].scmd->device->id == id &&
1148 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1154 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1159 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1160 * @ioc: per adapter object
1164 * Context: This function will acquire ioc->scsi_lookup_lock.
1166 * This will search for a matching channel:id:lun in the scsi_lookup array,
1167 * returning 1 if found.
1170 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1171 unsigned int lun, int channel)
1174 unsigned long flags;
1177 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1179 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1180 if (ioc->scsi_lookup[i].scmd &&
1181 (ioc->scsi_lookup[i].scmd->device->id == id &&
1182 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1183 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1189 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1194 * scsih_change_queue_depth - setting device queue depth
1195 * @sdev: scsi device struct
1196 * @qdepth: requested queue depth
1198 * Returns queue depth.
1201 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1203 struct Scsi_Host *shost = sdev->host;
1205 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1206 struct MPT3SAS_DEVICE *sas_device_priv_data;
1207 struct MPT3SAS_TARGET *sas_target_priv_data;
1208 struct _sas_device *sas_device;
1209 unsigned long flags;
1211 max_depth = shost->can_queue;
1213 /* limit max device queue for SATA to 32 */
1214 sas_device_priv_data = sdev->hostdata;
1215 if (!sas_device_priv_data)
1217 sas_target_priv_data = sas_device_priv_data->sas_target;
1218 if (!sas_target_priv_data)
1220 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1223 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1224 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1226 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1227 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1229 sas_device_put(sas_device);
1231 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1235 if (!sdev->tagged_supported)
1237 if (qdepth > max_depth)
1239 return scsi_change_queue_depth(sdev, qdepth);
1243 * scsih_target_alloc - target add routine
1244 * @starget: scsi target struct
1246 * Returns 0 if ok. Any other return is assumed to be an error and
1247 * the device is ignored.
1250 scsih_target_alloc(struct scsi_target *starget)
1252 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1253 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1254 struct MPT3SAS_TARGET *sas_target_priv_data;
1255 struct _sas_device *sas_device;
1256 struct _raid_device *raid_device;
1257 unsigned long flags;
1258 struct sas_rphy *rphy;
1260 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1262 if (!sas_target_priv_data)
1265 starget->hostdata = sas_target_priv_data;
1266 sas_target_priv_data->starget = starget;
1267 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1270 if (starget->channel == RAID_CHANNEL) {
1271 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1272 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1275 sas_target_priv_data->handle = raid_device->handle;
1276 sas_target_priv_data->sas_address = raid_device->wwid;
1277 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1278 sas_target_priv_data->raid_device = raid_device;
1279 if (ioc->is_warpdrive)
1280 raid_device->starget = starget;
1282 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1286 /* sas/sata devices */
1287 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1288 rphy = dev_to_rphy(starget->dev.parent);
1289 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1290 rphy->identify.sas_address);
1293 sas_target_priv_data->handle = sas_device->handle;
1294 sas_target_priv_data->sas_address = sas_device->sas_address;
1295 sas_target_priv_data->sdev = sas_device;
1296 sas_device->starget = starget;
1297 sas_device->id = starget->id;
1298 sas_device->channel = starget->channel;
1299 if (test_bit(sas_device->handle, ioc->pd_handles))
1300 sas_target_priv_data->flags |=
1301 MPT_TARGET_FLAGS_RAID_COMPONENT;
1302 if (sas_device->fast_path)
1303 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1305 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1311 * scsih_target_destroy - target destroy routine
1312 * @starget: scsi target struct
1317 scsih_target_destroy(struct scsi_target *starget)
1319 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1320 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1321 struct MPT3SAS_TARGET *sas_target_priv_data;
1322 struct _sas_device *sas_device;
1323 struct _raid_device *raid_device;
1324 unsigned long flags;
1325 struct sas_rphy *rphy;
1327 sas_target_priv_data = starget->hostdata;
1328 if (!sas_target_priv_data)
1331 if (starget->channel == RAID_CHANNEL) {
1332 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1333 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1336 raid_device->starget = NULL;
1337 raid_device->sdev = NULL;
1339 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1343 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1344 rphy = dev_to_rphy(starget->dev.parent);
1345 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1346 if (sas_device && (sas_device->starget == starget) &&
1347 (sas_device->id == starget->id) &&
1348 (sas_device->channel == starget->channel))
1349 sas_device->starget = NULL;
1353 * Corresponding get() is in _scsih_target_alloc()
1355 sas_target_priv_data->sdev = NULL;
1356 sas_device_put(sas_device);
1358 sas_device_put(sas_device);
1360 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1363 kfree(sas_target_priv_data);
1364 starget->hostdata = NULL;
1368 * scsih_slave_alloc - device add routine
1369 * @sdev: scsi device struct
1371 * Returns 0 if ok. Any other return is assumed to be an error and
1372 * the device is ignored.
1375 scsih_slave_alloc(struct scsi_device *sdev)
1377 struct Scsi_Host *shost;
1378 struct MPT3SAS_ADAPTER *ioc;
1379 struct MPT3SAS_TARGET *sas_target_priv_data;
1380 struct MPT3SAS_DEVICE *sas_device_priv_data;
1381 struct scsi_target *starget;
1382 struct _raid_device *raid_device;
1383 struct _sas_device *sas_device;
1384 unsigned long flags;
1386 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1388 if (!sas_device_priv_data)
1391 sas_device_priv_data->lun = sdev->lun;
1392 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1394 starget = scsi_target(sdev);
1395 sas_target_priv_data = starget->hostdata;
1396 sas_target_priv_data->num_luns++;
1397 sas_device_priv_data->sas_target = sas_target_priv_data;
1398 sdev->hostdata = sas_device_priv_data;
1399 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1400 sdev->no_uld_attach = 1;
1402 shost = dev_to_shost(&starget->dev);
1403 ioc = shost_priv(shost);
1404 if (starget->channel == RAID_CHANNEL) {
1405 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1406 raid_device = _scsih_raid_device_find_by_id(ioc,
1407 starget->id, starget->channel);
1409 raid_device->sdev = sdev; /* raid is single lun */
1410 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1413 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1414 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1415 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1416 sas_target_priv_data->sas_address);
1417 if (sas_device && (sas_device->starget == NULL)) {
1418 sdev_printk(KERN_INFO, sdev,
1419 "%s : sas_device->starget set to starget @ %d\n",
1420 __func__, __LINE__);
1421 sas_device->starget = starget;
1425 sas_device_put(sas_device);
1427 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1434 * scsih_slave_destroy - device destroy routine
1435 * @sdev: scsi device struct
1440 scsih_slave_destroy(struct scsi_device *sdev)
1442 struct MPT3SAS_TARGET *sas_target_priv_data;
1443 struct scsi_target *starget;
1444 struct Scsi_Host *shost;
1445 struct MPT3SAS_ADAPTER *ioc;
1446 struct _sas_device *sas_device;
1447 unsigned long flags;
1449 if (!sdev->hostdata)
1452 starget = scsi_target(sdev);
1453 sas_target_priv_data = starget->hostdata;
1454 sas_target_priv_data->num_luns--;
1456 shost = dev_to_shost(&starget->dev);
1457 ioc = shost_priv(shost);
1459 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1460 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1461 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1462 sas_target_priv_data);
1463 if (sas_device && !sas_target_priv_data->num_luns)
1464 sas_device->starget = NULL;
1467 sas_device_put(sas_device);
1468 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1471 kfree(sdev->hostdata);
1472 sdev->hostdata = NULL;
1476 * _scsih_display_sata_capabilities - sata capabilities
1477 * @ioc: per adapter object
1478 * @handle: device handle
1479 * @sdev: scsi device struct
1482 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1483 u16 handle, struct scsi_device *sdev)
1485 Mpi2ConfigReply_t mpi_reply;
1486 Mpi2SasDevicePage0_t sas_device_pg0;
1491 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1492 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1493 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1494 ioc->name, __FILE__, __LINE__, __func__);
1498 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1499 MPI2_IOCSTATUS_MASK;
1500 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1501 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1502 ioc->name, __FILE__, __LINE__, __func__);
1506 flags = le16_to_cpu(sas_device_pg0.Flags);
1507 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1509 sdev_printk(KERN_INFO, sdev,
1510 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1511 "sw_preserve(%s)\n",
1512 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1513 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1514 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1516 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1517 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1518 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1522 * raid transport support -
1523 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1524 * unloading the driver followed by a load - I beleive that the subroutine
1525 * raid_class_release() is not cleaning up properly.
1529 * scsih_is_raid - return boolean indicating device is raid volume
1530 * @dev the device struct object
1533 scsih_is_raid(struct device *dev)
1535 struct scsi_device *sdev = to_scsi_device(dev);
1536 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1538 if (ioc->is_warpdrive)
1540 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1544 * scsih_get_resync - get raid volume resync percent complete
1545 * @dev the device struct object
1548 scsih_get_resync(struct device *dev)
1550 struct scsi_device *sdev = to_scsi_device(dev);
1551 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1552 static struct _raid_device *raid_device;
1553 unsigned long flags;
1554 Mpi2RaidVolPage0_t vol_pg0;
1555 Mpi2ConfigReply_t mpi_reply;
1556 u32 volume_status_flags;
1557 u8 percent_complete;
1560 percent_complete = 0;
1562 if (ioc->is_warpdrive)
1565 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1566 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1569 handle = raid_device->handle;
1570 percent_complete = raid_device->percent_complete;
1572 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1577 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1578 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1579 sizeof(Mpi2RaidVolPage0_t))) {
1580 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1581 ioc->name, __FILE__, __LINE__, __func__);
1582 percent_complete = 0;
1586 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1587 if (!(volume_status_flags &
1588 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1589 percent_complete = 0;
1592 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1593 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1594 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1595 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1599 * scsih_get_state - get raid volume level
1600 * @dev the device struct object
1603 scsih_get_state(struct device *dev)
1605 struct scsi_device *sdev = to_scsi_device(dev);
1606 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1607 static struct _raid_device *raid_device;
1608 unsigned long flags;
1609 Mpi2RaidVolPage0_t vol_pg0;
1610 Mpi2ConfigReply_t mpi_reply;
1612 enum raid_state state = RAID_STATE_UNKNOWN;
1615 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1616 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1619 handle = raid_device->handle;
1620 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1625 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1626 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1627 sizeof(Mpi2RaidVolPage0_t))) {
1628 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1629 ioc->name, __FILE__, __LINE__, __func__);
1633 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1634 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1635 state = RAID_STATE_RESYNCING;
1639 switch (vol_pg0.VolumeState) {
1640 case MPI2_RAID_VOL_STATE_OPTIMAL:
1641 case MPI2_RAID_VOL_STATE_ONLINE:
1642 state = RAID_STATE_ACTIVE;
1644 case MPI2_RAID_VOL_STATE_DEGRADED:
1645 state = RAID_STATE_DEGRADED;
1647 case MPI2_RAID_VOL_STATE_FAILED:
1648 case MPI2_RAID_VOL_STATE_MISSING:
1649 state = RAID_STATE_OFFLINE;
1653 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1654 raid_set_state(mpt2sas_raid_template, dev, state);
1655 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1656 raid_set_state(mpt3sas_raid_template, dev, state);
1660 * _scsih_set_level - set raid level
1661 * @sdev: scsi device struct
1662 * @volume_type: volume type
1665 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
1666 struct scsi_device *sdev, u8 volume_type)
1668 enum raid_level level = RAID_LEVEL_UNKNOWN;
1670 switch (volume_type) {
1671 case MPI2_RAID_VOL_TYPE_RAID0:
1672 level = RAID_LEVEL_0;
1674 case MPI2_RAID_VOL_TYPE_RAID10:
1675 level = RAID_LEVEL_10;
1677 case MPI2_RAID_VOL_TYPE_RAID1E:
1678 level = RAID_LEVEL_1E;
1680 case MPI2_RAID_VOL_TYPE_RAID1:
1681 level = RAID_LEVEL_1;
1685 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1686 raid_set_level(mpt2sas_raid_template,
1687 &sdev->sdev_gendev, level);
1688 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1689 raid_set_level(mpt3sas_raid_template,
1690 &sdev->sdev_gendev, level);
1695 * _scsih_get_volume_capabilities - volume capabilities
1696 * @ioc: per adapter object
1697 * @sas_device: the raid_device object
1699 * Returns 0 for success, else 1
1702 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1703 struct _raid_device *raid_device)
1705 Mpi2RaidVolPage0_t *vol_pg0;
1706 Mpi2RaidPhysDiskPage0_t pd_pg0;
1707 Mpi2SasDevicePage0_t sas_device_pg0;
1708 Mpi2ConfigReply_t mpi_reply;
1712 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1713 &num_pds)) || !num_pds) {
1714 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1715 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1720 raid_device->num_pds = num_pds;
1721 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1722 sizeof(Mpi2RaidVol0PhysDisk_t));
1723 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1725 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1726 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1731 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1732 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1733 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1734 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1740 raid_device->volume_type = vol_pg0->VolumeType;
1742 /* figure out what the underlying devices are by
1743 * obtaining the device_info bits for the 1st device
1745 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1746 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1747 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1748 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1749 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1750 le16_to_cpu(pd_pg0.DevHandle)))) {
1751 raid_device->device_info =
1752 le32_to_cpu(sas_device_pg0.DeviceInfo);
1761 * _scsih_enable_tlr - setting TLR flags
1762 * @ioc: per adapter object
1763 * @sdev: scsi device struct
1765 * Enabling Transaction Layer Retries for tape devices when
1766 * vpd page 0x90 is present
1770 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1774 if (sdev->type != TYPE_TAPE)
1777 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1780 sas_enable_tlr(sdev);
1781 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1782 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1788 * scsih_slave_configure - device configure routine.
1789 * @sdev: scsi device struct
1791 * Returns 0 if ok. Any other return is assumed to be an error and
1792 * the device is ignored.
1795 scsih_slave_configure(struct scsi_device *sdev)
1797 struct Scsi_Host *shost = sdev->host;
1798 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1799 struct MPT3SAS_DEVICE *sas_device_priv_data;
1800 struct MPT3SAS_TARGET *sas_target_priv_data;
1801 struct _sas_device *sas_device;
1802 struct _raid_device *raid_device;
1803 unsigned long flags;
1808 u16 handle, volume_handle = 0;
1809 u64 volume_wwid = 0;
1812 sas_device_priv_data = sdev->hostdata;
1813 sas_device_priv_data->configured_lun = 1;
1814 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1815 sas_target_priv_data = sas_device_priv_data->sas_target;
1816 handle = sas_target_priv_data->handle;
1818 /* raid volume handling */
1819 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1821 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1822 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
1823 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1825 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1826 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1827 __LINE__, __func__));
1831 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1832 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1833 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1834 __LINE__, __func__));
1839 * WARPDRIVE: Initialize the required data for Direct IO
1841 mpt3sas_init_warpdrive_properties(ioc, raid_device);
1843 /* RAID Queue Depth Support
1844 * IS volume = underlying qdepth of drive type, either
1845 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1846 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1848 if (raid_device->device_info &
1849 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1850 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1853 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1854 if (raid_device->device_info &
1855 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1861 switch (raid_device->volume_type) {
1862 case MPI2_RAID_VOL_TYPE_RAID0:
1865 case MPI2_RAID_VOL_TYPE_RAID1E:
1866 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1867 if (ioc->manu_pg10.OEMIdentifier &&
1868 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1869 MFG10_GF0_R10_DISPLAY) &&
1870 !(raid_device->num_pds % 2))
1875 case MPI2_RAID_VOL_TYPE_RAID1:
1876 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1879 case MPI2_RAID_VOL_TYPE_RAID10:
1880 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1883 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1885 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1890 if (!ioc->hide_ir_msg)
1891 sdev_printk(KERN_INFO, sdev,
1892 "%s: handle(0x%04x), wwid(0x%016llx),"
1893 " pd_count(%d), type(%s)\n",
1894 r_level, raid_device->handle,
1895 (unsigned long long)raid_device->wwid,
1896 raid_device->num_pds, ds);
1898 scsih_change_queue_depth(sdev, qdepth);
1900 /* raid transport support */
1901 if (!ioc->is_warpdrive)
1902 _scsih_set_level(ioc, sdev, raid_device->volume_type);
1906 /* non-raid handling */
1907 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1908 if (mpt3sas_config_get_volume_handle(ioc, handle,
1910 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1911 "failure at %s:%d/%s()!\n", ioc->name,
1912 __FILE__, __LINE__, __func__));
1915 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1916 volume_handle, &volume_wwid)) {
1917 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1918 "failure at %s:%d/%s()!\n", ioc->name,
1919 __FILE__, __LINE__, __func__));
1924 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1925 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1926 sas_device_priv_data->sas_target->sas_address);
1928 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1929 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1930 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1935 sas_device->volume_handle = volume_handle;
1936 sas_device->volume_wwid = volume_wwid;
1937 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1938 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1942 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1943 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1945 else if (sas_device->device_info &
1946 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1950 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1951 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1952 ds, handle, (unsigned long long)sas_device->sas_address,
1953 sas_device->phy, (unsigned long long)sas_device->device_name);
1954 if (sas_device->enclosure_handle != 0)
1955 sdev_printk(KERN_INFO, sdev,
1956 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1957 ds, (unsigned long long)
1958 sas_device->enclosure_logical_id, sas_device->slot);
1959 if (sas_device->connector_name[0] != '\0')
1960 sdev_printk(KERN_INFO, sdev,
1961 "%s: enclosure level(0x%04x), connector name( %s)\n",
1962 ds, sas_device->enclosure_level,
1963 sas_device->connector_name);
1965 sas_device_put(sas_device);
1966 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1969 _scsih_display_sata_capabilities(ioc, handle, sdev);
1972 scsih_change_queue_depth(sdev, qdepth);
1975 sas_read_port_mode_page(sdev);
1976 _scsih_enable_tlr(ioc, sdev);
1983 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1984 * @sdev: scsi device struct
1985 * @bdev: pointer to block device context
1986 * @capacity: device size (in 512 byte sectors)
1987 * @params: three element array to place output:
1988 * params[0] number of heads (max 255)
1989 * params[1] number of sectors (max 63)
1990 * params[2] number of cylinders
1995 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1996 sector_t capacity, int params[])
2006 dummy = heads * sectors;
2007 cylinders = capacity;
2008 sector_div(cylinders, dummy);
2011 * Handle extended translation size for logical drives
2014 if ((ulong)capacity >= 0x200000) {
2017 dummy = heads * sectors;
2018 cylinders = capacity;
2019 sector_div(cylinders, dummy);
2024 params[1] = sectors;
2025 params[2] = cylinders;
2031 * _scsih_response_code - translation of device response code
2032 * @ioc: per adapter object
2033 * @response_code: response code returned by the device
2038 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2042 switch (response_code) {
2043 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2044 desc = "task management request completed";
2046 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2047 desc = "invalid frame";
2049 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2050 desc = "task management request not supported";
2052 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2053 desc = "task management request failed";
2055 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2056 desc = "task management request succeeded";
2058 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2059 desc = "invalid lun";
2062 desc = "overlapped tag attempted";
2064 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2065 desc = "task queued, however not sent to target";
2071 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2072 ioc->name, response_code, desc);
2076 * _scsih_tm_done - tm completion routine
2077 * @ioc: per adapter object
2078 * @smid: system request message index
2079 * @msix_index: MSIX table index supplied by the OS
2080 * @reply: reply message frame(lower 32bit addr)
2083 * The callback handler when using scsih_issue_tm.
2085 * Return 1 meaning mf should be freed from _base_interrupt
2086 * 0 means the mf is freed from this function.
2089 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2091 MPI2DefaultReply_t *mpi_reply;
2093 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2095 if (ioc->tm_cmds.smid != smid)
2097 mpt3sas_base_flush_reply_queues(ioc);
2098 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2099 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2101 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2102 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2104 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2105 complete(&ioc->tm_cmds.done);
2110 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2111 * @ioc: per adapter object
2112 * @handle: device handle
2114 * During taskmangement request, we need to freeze the device queue.
2117 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2119 struct MPT3SAS_DEVICE *sas_device_priv_data;
2120 struct scsi_device *sdev;
2123 shost_for_each_device(sdev, ioc->shost) {
2126 sas_device_priv_data = sdev->hostdata;
2127 if (!sas_device_priv_data)
2129 if (sas_device_priv_data->sas_target->handle == handle) {
2130 sas_device_priv_data->sas_target->tm_busy = 1;
2132 ioc->ignore_loginfos = 1;
2138 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2139 * @ioc: per adapter object
2140 * @handle: device handle
2142 * During taskmangement request, we need to freeze the device queue.
2145 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2147 struct MPT3SAS_DEVICE *sas_device_priv_data;
2148 struct scsi_device *sdev;
2151 shost_for_each_device(sdev, ioc->shost) {
2154 sas_device_priv_data = sdev->hostdata;
2155 if (!sas_device_priv_data)
2157 if (sas_device_priv_data->sas_target->handle == handle) {
2158 sas_device_priv_data->sas_target->tm_busy = 0;
2160 ioc->ignore_loginfos = 0;
2166 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2167 * @ioc: per adapter struct
2168 * @device_handle: device handle
2169 * @channel: the channel assigned by the OS
2170 * @id: the id assigned by the OS
2172 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2173 * @smid_task: smid assigned to the task
2174 * @timeout: timeout in seconds
2175 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2178 * A generic API for sending task management requests to firmware.
2180 * The callback index is set inside `ioc->tm_cb_idx`.
2182 * Return SUCCESS or FAILED.
2185 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2186 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2187 enum mutex_type m_type)
2189 Mpi2SCSITaskManagementRequest_t *mpi_request;
2190 Mpi2SCSITaskManagementReply_t *mpi_reply;
2193 unsigned long timeleft;
2194 struct scsiio_tracker *scsi_lookup = NULL;
2198 if (m_type == TM_MUTEX_ON)
2199 mutex_lock(&ioc->tm_cmds.mutex);
2200 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2201 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2202 __func__, ioc->name);
2207 if (ioc->shost_recovery || ioc->remove_host ||
2208 ioc->pci_error_recovery) {
2209 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2210 __func__, ioc->name);
2215 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2216 if (ioc_state & MPI2_DOORBELL_USED) {
2217 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2218 "unexpected doorbell active!\n", ioc->name));
2219 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2221 rc = (!rc) ? SUCCESS : FAILED;
2225 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2226 mpt3sas_base_fault_info(ioc, ioc_state &
2227 MPI2_DOORBELL_DATA_MASK);
2228 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2230 rc = (!rc) ? SUCCESS : FAILED;
2234 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2236 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2237 ioc->name, __func__);
2242 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2243 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2245 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2246 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2247 ioc->name, handle, type, smid_task));
2248 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2249 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2250 ioc->tm_cmds.smid = smid;
2251 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2252 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2253 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2254 mpi_request->DevHandle = cpu_to_le16(handle);
2255 mpi_request->TaskType = type;
2256 mpi_request->TaskMID = cpu_to_le16(smid_task);
2257 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2258 mpt3sas_scsih_set_tm_flag(ioc, handle);
2259 init_completion(&ioc->tm_cmds.done);
2260 if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
2261 (scsi_lookup->msix_io < ioc->reply_queue_count))
2262 msix_task = scsi_lookup->msix_io;
2265 mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
2266 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2267 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2268 pr_err(MPT3SAS_FMT "%s: timeout\n",
2269 ioc->name, __func__);
2270 _debug_dump_mf(mpi_request,
2271 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2272 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2273 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2275 rc = (!rc) ? SUCCESS : FAILED;
2276 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2277 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2282 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2283 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2284 mpi_reply = ioc->tm_cmds.reply;
2285 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2286 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2287 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2288 le32_to_cpu(mpi_reply->IOCLogInfo),
2289 le32_to_cpu(mpi_reply->TerminationCount)));
2290 if (ioc->logging_level & MPT_DEBUG_TM) {
2291 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2292 if (mpi_reply->IOCStatus)
2293 _debug_dump_mf(mpi_request,
2294 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2299 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2301 if (scsi_lookup->scmd == NULL)
2306 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2307 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2312 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2313 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2314 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2319 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2327 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2328 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2329 if (m_type == TM_MUTEX_ON)
2330 mutex_unlock(&ioc->tm_cmds.mutex);
2335 if (m_type == TM_MUTEX_ON)
2336 mutex_unlock(&ioc->tm_cmds.mutex);
2341 * _scsih_tm_display_info - displays info about the device
2342 * @ioc: per adapter struct
2343 * @scmd: pointer to scsi command object
2345 * Called by task management callback handlers.
2348 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2350 struct scsi_target *starget = scmd->device->sdev_target;
2351 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2352 struct _sas_device *sas_device = NULL;
2353 unsigned long flags;
2354 char *device_str = NULL;
2358 if (ioc->hide_ir_msg)
2359 device_str = "WarpDrive";
2361 device_str = "volume";
2363 scsi_print_command(scmd);
2364 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2365 starget_printk(KERN_INFO, starget,
2366 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2367 device_str, priv_target->handle,
2368 device_str, (unsigned long long)priv_target->sas_address);
2370 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2371 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2373 if (priv_target->flags &
2374 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2375 starget_printk(KERN_INFO, starget,
2376 "volume handle(0x%04x), "
2377 "volume wwid(0x%016llx)\n",
2378 sas_device->volume_handle,
2379 (unsigned long long)sas_device->volume_wwid);
2381 starget_printk(KERN_INFO, starget,
2382 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2384 (unsigned long long)sas_device->sas_address,
2386 if (sas_device->enclosure_handle != 0)
2387 starget_printk(KERN_INFO, starget,
2388 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2389 (unsigned long long)
2390 sas_device->enclosure_logical_id,
2392 if (sas_device->connector_name)
2393 starget_printk(KERN_INFO, starget,
2394 "enclosure level(0x%04x),connector name(%s)\n",
2395 sas_device->enclosure_level,
2396 sas_device->connector_name);
2398 sas_device_put(sas_device);
2400 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2405 * scsih_abort - eh threads main abort routine
2406 * @scmd: pointer to scsi command object
2408 * Returns SUCCESS if command aborted else FAILED
2411 scsih_abort(struct scsi_cmnd *scmd)
2413 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2414 struct MPT3SAS_DEVICE *sas_device_priv_data;
2419 sdev_printk(KERN_INFO, scmd->device,
2420 "attempting task abort! scmd(%p)\n", scmd);
2421 _scsih_tm_display_info(ioc, scmd);
2423 sas_device_priv_data = scmd->device->hostdata;
2424 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2425 sdev_printk(KERN_INFO, scmd->device,
2426 "device been deleted! scmd(%p)\n", scmd);
2427 scmd->result = DID_NO_CONNECT << 16;
2428 scmd->scsi_done(scmd);
2433 /* search for the command */
2434 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2436 scmd->result = DID_RESET << 16;
2441 /* for hidden raid components and volumes this is not supported */
2442 if (sas_device_priv_data->sas_target->flags &
2443 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2444 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2445 scmd->result = DID_RESET << 16;
2450 mpt3sas_halt_firmware(ioc);
2452 handle = sas_device_priv_data->sas_target->handle;
2453 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2454 scmd->device->id, scmd->device->lun,
2455 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2458 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2459 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2464 * scsih_dev_reset - eh threads main device reset routine
2465 * @scmd: pointer to scsi command object
2467 * Returns SUCCESS if command aborted else FAILED
2470 scsih_dev_reset(struct scsi_cmnd *scmd)
2472 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2473 struct MPT3SAS_DEVICE *sas_device_priv_data;
2474 struct _sas_device *sas_device = NULL;
2478 struct scsi_target *starget = scmd->device->sdev_target;
2479 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2481 sdev_printk(KERN_INFO, scmd->device,
2482 "attempting device reset! scmd(%p)\n", scmd);
2483 _scsih_tm_display_info(ioc, scmd);
2485 sas_device_priv_data = scmd->device->hostdata;
2486 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2487 sdev_printk(KERN_INFO, scmd->device,
2488 "device been deleted! scmd(%p)\n", scmd);
2489 scmd->result = DID_NO_CONNECT << 16;
2490 scmd->scsi_done(scmd);
2495 /* for hidden raid components obtain the volume_handle */
2497 if (sas_device_priv_data->sas_target->flags &
2498 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2499 sas_device = mpt3sas_get_sdev_from_target(ioc,
2502 handle = sas_device->volume_handle;
2504 handle = sas_device_priv_data->sas_target->handle;
2507 scmd->result = DID_RESET << 16;
2512 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2513 scmd->device->id, scmd->device->lun,
2514 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2517 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2518 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2521 sas_device_put(sas_device);
2527 * scsih_target_reset - eh threads main target reset routine
2528 * @scmd: pointer to scsi command object
2530 * Returns SUCCESS if command aborted else FAILED
2533 scsih_target_reset(struct scsi_cmnd *scmd)
2535 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2536 struct MPT3SAS_DEVICE *sas_device_priv_data;
2537 struct _sas_device *sas_device = NULL;
2540 struct scsi_target *starget = scmd->device->sdev_target;
2541 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2543 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2545 _scsih_tm_display_info(ioc, scmd);
2547 sas_device_priv_data = scmd->device->hostdata;
2548 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2549 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2551 scmd->result = DID_NO_CONNECT << 16;
2552 scmd->scsi_done(scmd);
2557 /* for hidden raid components obtain the volume_handle */
2559 if (sas_device_priv_data->sas_target->flags &
2560 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2561 sas_device = mpt3sas_get_sdev_from_target(ioc,
2564 handle = sas_device->volume_handle;
2566 handle = sas_device_priv_data->sas_target->handle;
2569 scmd->result = DID_RESET << 16;
2574 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2575 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2579 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2580 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2583 sas_device_put(sas_device);
2590 * scsih_host_reset - eh threads main host reset routine
2591 * @scmd: pointer to scsi command object
2593 * Returns SUCCESS if command aborted else FAILED
2596 scsih_host_reset(struct scsi_cmnd *scmd)
2598 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2601 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2603 scsi_print_command(scmd);
2605 if (ioc->is_driver_loading) {
2606 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2612 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2614 r = (retval < 0) ? FAILED : SUCCESS;
2616 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2617 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2623 * _scsih_fw_event_add - insert and queue up fw_event
2624 * @ioc: per adapter object
2625 * @fw_event: object describing the event
2626 * Context: This function will acquire ioc->fw_event_lock.
2628 * This adds the firmware event object into link list, then queues it up to
2629 * be processed from user context.
2634 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2636 unsigned long flags;
2638 if (ioc->firmware_event_thread == NULL)
2641 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2642 fw_event_work_get(fw_event);
2643 INIT_LIST_HEAD(&fw_event->list);
2644 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2645 INIT_WORK(&fw_event->work, _firmware_event_work);
2646 fw_event_work_get(fw_event);
2647 queue_work(ioc->firmware_event_thread, &fw_event->work);
2648 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2652 * _scsih_fw_event_del_from_list - delete fw_event from the list
2653 * @ioc: per adapter object
2654 * @fw_event: object describing the event
2655 * Context: This function will acquire ioc->fw_event_lock.
2657 * If the fw_event is on the fw_event_list, remove it and do a put.
2662 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2665 unsigned long flags;
2667 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2668 if (!list_empty(&fw_event->list)) {
2669 list_del_init(&fw_event->list);
2670 fw_event_work_put(fw_event);
2672 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2677 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2678 * @ioc: per adapter object
2679 * @event_data: trigger event data
2684 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2685 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2687 struct fw_event_work *fw_event;
2690 if (ioc->is_driver_loading)
2692 sz = sizeof(*event_data);
2693 fw_event = alloc_fw_event_work(sz);
2696 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2697 fw_event->ioc = ioc;
2698 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2699 _scsih_fw_event_add(ioc, fw_event);
2700 fw_event_work_put(fw_event);
2704 * _scsih_error_recovery_delete_devices - remove devices not responding
2705 * @ioc: per adapter object
2710 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2712 struct fw_event_work *fw_event;
2714 if (ioc->is_driver_loading)
2716 fw_event = alloc_fw_event_work(0);
2719 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2720 fw_event->ioc = ioc;
2721 _scsih_fw_event_add(ioc, fw_event);
2722 fw_event_work_put(fw_event);
2726 * mpt3sas_port_enable_complete - port enable completed (fake event)
2727 * @ioc: per adapter object
2732 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2734 struct fw_event_work *fw_event;
2736 fw_event = alloc_fw_event_work(0);
2739 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2740 fw_event->ioc = ioc;
2741 _scsih_fw_event_add(ioc, fw_event);
2742 fw_event_work_put(fw_event);
2745 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
2747 unsigned long flags;
2748 struct fw_event_work *fw_event = NULL;
2750 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2751 if (!list_empty(&ioc->fw_event_list)) {
2752 fw_event = list_first_entry(&ioc->fw_event_list,
2753 struct fw_event_work, list);
2754 list_del_init(&fw_event->list);
2756 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2762 * _scsih_fw_event_cleanup_queue - cleanup event queue
2763 * @ioc: per adapter object
2765 * Walk the firmware event queue, either killing timers, or waiting
2766 * for outstanding events to complete
2771 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2773 struct fw_event_work *fw_event;
2775 if (list_empty(&ioc->fw_event_list) ||
2776 !ioc->firmware_event_thread || in_interrupt())
2779 while ((fw_event = dequeue_next_fw_event(ioc))) {
2781 * Wait on the fw_event to complete. If this returns 1, then
2782 * the event was never executed, and we need a put for the
2783 * reference the delayed_work had on the fw_event.
2785 * If it did execute, we wait for it to finish, and the put will
2786 * happen from _firmware_event_work()
2788 if (cancel_delayed_work_sync(&fw_event->delayed_work))
2789 fw_event_work_put(fw_event);
2791 fw_event_work_put(fw_event);
2796 * _scsih_internal_device_block - block the sdev device
2797 * @sdev: per device object
2798 * @sas_device_priv_data : per device driver private data
2800 * make sure device is blocked without error, if not
2804 _scsih_internal_device_block(struct scsi_device *sdev,
2805 struct MPT3SAS_DEVICE *sas_device_priv_data)
2809 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2810 sas_device_priv_data->sas_target->handle);
2811 sas_device_priv_data->block = 1;
2813 r = scsi_internal_device_block(sdev);
2815 sdev_printk(KERN_WARNING, sdev,
2816 "device_block failed with return(%d) for handle(0x%04x)\n",
2817 sas_device_priv_data->sas_target->handle, r);
2821 * _scsih_internal_device_unblock - unblock the sdev device
2822 * @sdev: per device object
2823 * @sas_device_priv_data : per device driver private data
2824 * make sure device is unblocked without error, if not retry
2825 * by blocking and then unblocking
2829 _scsih_internal_device_unblock(struct scsi_device *sdev,
2830 struct MPT3SAS_DEVICE *sas_device_priv_data)
2834 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2835 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2836 sas_device_priv_data->block = 0;
2837 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2839 /* The device has been set to SDEV_RUNNING by SD layer during
2840 * device addition but the request queue is still stopped by
2841 * our earlier block call. We need to perform a block again
2842 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2844 sdev_printk(KERN_WARNING, sdev,
2845 "device_unblock failed with return(%d) for handle(0x%04x) "
2846 "performing a block followed by an unblock\n",
2847 sas_device_priv_data->sas_target->handle, r);
2848 sas_device_priv_data->block = 1;
2849 r = scsi_internal_device_block(sdev);
2851 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2852 "failed with return(%d) for handle(0x%04x)\n",
2853 sas_device_priv_data->sas_target->handle, r);
2855 sas_device_priv_data->block = 0;
2856 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2858 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2859 " failed with return(%d) for handle(0x%04x)\n",
2860 sas_device_priv_data->sas_target->handle, r);
2865 * _scsih_ublock_io_all_device - unblock every device
2866 * @ioc: per adapter object
2868 * change the device state from block to running
2871 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2873 struct MPT3SAS_DEVICE *sas_device_priv_data;
2874 struct scsi_device *sdev;
2876 shost_for_each_device(sdev, ioc->shost) {
2877 sas_device_priv_data = sdev->hostdata;
2878 if (!sas_device_priv_data)
2880 if (!sas_device_priv_data->block)
2883 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2884 "device_running, handle(0x%04x)\n",
2885 sas_device_priv_data->sas_target->handle));
2886 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2892 * _scsih_ublock_io_device - prepare device to be deleted
2893 * @ioc: per adapter object
2894 * @sas_addr: sas address
2896 * unblock then put device in offline state
2899 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2901 struct MPT3SAS_DEVICE *sas_device_priv_data;
2902 struct scsi_device *sdev;
2904 shost_for_each_device(sdev, ioc->shost) {
2905 sas_device_priv_data = sdev->hostdata;
2906 if (!sas_device_priv_data)
2908 if (sas_device_priv_data->sas_target->sas_address
2911 if (sas_device_priv_data->block)
2912 _scsih_internal_device_unblock(sdev,
2913 sas_device_priv_data);
2918 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2919 * @ioc: per adapter object
2920 * @handle: device handle
2922 * During device pull we need to appropiately set the sdev state.
2925 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2927 struct MPT3SAS_DEVICE *sas_device_priv_data;
2928 struct scsi_device *sdev;
2930 shost_for_each_device(sdev, ioc->shost) {
2931 sas_device_priv_data = sdev->hostdata;
2932 if (!sas_device_priv_data)
2934 if (sas_device_priv_data->block)
2936 _scsih_internal_device_block(sdev, sas_device_priv_data);
2941 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2942 * @ioc: per adapter object
2943 * @handle: device handle
2945 * During device pull we need to appropiately set the sdev state.
2948 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2950 struct MPT3SAS_DEVICE *sas_device_priv_data;
2951 struct scsi_device *sdev;
2952 struct _sas_device *sas_device;
2954 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
2958 shost_for_each_device(sdev, ioc->shost) {
2959 sas_device_priv_data = sdev->hostdata;
2960 if (!sas_device_priv_data)
2962 if (sas_device_priv_data->sas_target->handle != handle)
2964 if (sas_device_priv_data->block)
2966 if (sas_device->pend_sas_rphy_add)
2968 _scsih_internal_device_block(sdev, sas_device_priv_data);
2971 sas_device_put(sas_device);
2975 * _scsih_block_io_to_children_attached_to_ex
2976 * @ioc: per adapter object
2977 * @sas_expander: the sas_device object
2979 * This routine set sdev state to SDEV_BLOCK for all devices
2980 * attached to this expander. This function called when expander is
2984 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2985 struct _sas_node *sas_expander)
2987 struct _sas_port *mpt3sas_port;
2988 struct _sas_device *sas_device;
2989 struct _sas_node *expander_sibling;
2990 unsigned long flags;
2995 list_for_each_entry(mpt3sas_port,
2996 &sas_expander->sas_port_list, port_list) {
2997 if (mpt3sas_port->remote_identify.device_type ==
2999 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3000 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3001 mpt3sas_port->remote_identify.sas_address);
3003 set_bit(sas_device->handle,
3004 ioc->blocking_handles);
3005 sas_device_put(sas_device);
3007 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3011 list_for_each_entry(mpt3sas_port,
3012 &sas_expander->sas_port_list, port_list) {
3014 if (mpt3sas_port->remote_identify.device_type ==
3015 SAS_EDGE_EXPANDER_DEVICE ||
3016 mpt3sas_port->remote_identify.device_type ==
3017 SAS_FANOUT_EXPANDER_DEVICE) {
3019 mpt3sas_scsih_expander_find_by_sas_address(
3020 ioc, mpt3sas_port->remote_identify.sas_address);
3021 _scsih_block_io_to_children_attached_to_ex(ioc,
3028 * _scsih_block_io_to_children_attached_directly
3029 * @ioc: per adapter object
3030 * @event_data: topology change event data
3032 * This routine set sdev state to SDEV_BLOCK for all devices
3033 * direct attached during device pull.
3036 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3037 Mpi2EventDataSasTopologyChangeList_t *event_data)
3043 for (i = 0; i < event_data->NumEntries; i++) {
3044 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3047 reason_code = event_data->PHY[i].PhyStatus &
3048 MPI2_EVENT_SAS_TOPO_RC_MASK;
3049 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3050 _scsih_block_io_device(ioc, handle);
3055 * _scsih_tm_tr_send - send task management request
3056 * @ioc: per adapter object
3057 * @handle: device handle
3058 * Context: interrupt time.
3060 * This code is to initiate the device removal handshake protocol
3061 * with controller firmware. This function will issue target reset
3062 * using high priority request queue. It will send a sas iounit
3063 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3065 * This is designed to send muliple task management request at the same
3066 * time to the fifo. If the fifo is full, we will append the request,
3067 * and process it in a future completion.
3070 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3072 Mpi2SCSITaskManagementRequest_t *mpi_request;
3074 struct _sas_device *sas_device = NULL;
3075 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3076 u64 sas_address = 0;
3077 unsigned long flags;
3078 struct _tr_list *delayed_tr;
3081 if (ioc->remove_host) {
3082 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3083 "%s: host has been removed: handle(0x%04x)\n",
3084 __func__, ioc->name, handle));
3086 } else if (ioc->pci_error_recovery) {
3087 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3088 "%s: host in pci error recovery: handle(0x%04x)\n",
3089 __func__, ioc->name,
3093 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3094 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3095 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3096 "%s: host is not operational: handle(0x%04x)\n",
3097 __func__, ioc->name,
3102 /* if PD, then return */
3103 if (test_bit(handle, ioc->pd_handles))
3106 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3107 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3108 if (sas_device && sas_device->starget &&
3109 sas_device->starget->hostdata) {
3110 sas_target_priv_data = sas_device->starget->hostdata;
3111 sas_target_priv_data->deleted = 1;
3112 sas_address = sas_device->sas_address;
3114 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3116 if (sas_target_priv_data) {
3117 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3118 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3120 (unsigned long long)sas_address));
3121 if (sas_device->enclosure_handle != 0)
3122 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3123 "setting delete flag:enclosure logical id(0x%016llx),"
3124 " slot(%d)\n", ioc->name, (unsigned long long)
3125 sas_device->enclosure_logical_id,
3127 if (sas_device->connector_name)
3128 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3129 "setting delete flag: enclosure level(0x%04x),"
3130 " connector name( %s)\n", ioc->name,
3131 sas_device->enclosure_level,
3132 sas_device->connector_name));
3133 _scsih_ublock_io_device(ioc, sas_address);
3134 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3137 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3139 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3142 INIT_LIST_HEAD(&delayed_tr->list);
3143 delayed_tr->handle = handle;
3144 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3145 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3146 "DELAYED:tr:handle(0x%04x), (open)\n",
3147 ioc->name, handle));
3151 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3152 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3153 ioc->name, handle, smid,
3154 ioc->tm_tr_cb_idx));
3155 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3156 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3157 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3158 mpi_request->DevHandle = cpu_to_le16(handle);
3159 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3160 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3161 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3165 sas_device_put(sas_device);
3169 * _scsih_tm_tr_complete -
3170 * @ioc: per adapter object
3171 * @smid: system request message index
3172 * @msix_index: MSIX table index supplied by the OS
3173 * @reply: reply message frame(lower 32bit addr)
3174 * Context: interrupt time.
3176 * This is the target reset completion routine.
3177 * This code is part of the code to initiate the device removal
3178 * handshake protocol with controller firmware.
3179 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3181 * Return 1 meaning mf should be freed from _base_interrupt
3182 * 0 means the mf is freed from this function.
3185 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3189 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3190 Mpi2SCSITaskManagementReply_t *mpi_reply =
3191 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3192 Mpi2SasIoUnitControlRequest_t *mpi_request;
3196 if (ioc->remove_host) {
3197 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3198 "%s: host has been removed\n", __func__, ioc->name));
3200 } else if (ioc->pci_error_recovery) {
3201 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3202 "%s: host in pci error recovery\n", __func__,
3206 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3207 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3208 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3209 "%s: host is not operational\n", __func__, ioc->name));
3212 if (unlikely(!mpi_reply)) {
3213 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3214 ioc->name, __FILE__, __LINE__, __func__);
3217 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3218 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3219 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3220 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3221 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3223 le16_to_cpu(mpi_reply->DevHandle), smid));
3227 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3228 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3229 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3230 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3231 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3232 le32_to_cpu(mpi_reply->IOCLogInfo),
3233 le32_to_cpu(mpi_reply->TerminationCount)));
3235 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3236 if (!smid_sas_ctrl) {
3237 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3238 ioc->name, __func__);
3242 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3243 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3244 ioc->name, handle, smid_sas_ctrl,
3245 ioc->tm_sas_control_cb_idx));
3246 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3247 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3248 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3249 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3250 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3251 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3253 return _scsih_check_for_pending_tm(ioc, smid);
3258 * _scsih_sas_control_complete - completion routine
3259 * @ioc: per adapter object
3260 * @smid: system request message index
3261 * @msix_index: MSIX table index supplied by the OS
3262 * @reply: reply message frame(lower 32bit addr)
3263 * Context: interrupt time.
3265 * This is the sas iounit control completion routine.
3266 * This code is part of the code to initiate the device removal
3267 * handshake protocol with controller firmware.
3269 * Return 1 meaning mf should be freed from _base_interrupt
3270 * 0 means the mf is freed from this function.
3273 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3274 u8 msix_index, u32 reply)
3276 Mpi2SasIoUnitControlReply_t *mpi_reply =
3277 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3279 if (likely(mpi_reply)) {
3280 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3281 "sc_complete:handle(0x%04x), (open) "
3282 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3283 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3284 le16_to_cpu(mpi_reply->IOCStatus),
3285 le32_to_cpu(mpi_reply->IOCLogInfo)));
3287 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3288 ioc->name, __FILE__, __LINE__, __func__);
3294 * _scsih_tm_tr_volume_send - send target reset request for volumes
3295 * @ioc: per adapter object
3296 * @handle: device handle
3297 * Context: interrupt time.
3299 * This is designed to send muliple task management request at the same
3300 * time to the fifo. If the fifo is full, we will append the request,
3301 * and process it in a future completion.
3304 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3306 Mpi2SCSITaskManagementRequest_t *mpi_request;
3308 struct _tr_list *delayed_tr;
3310 if (ioc->shost_recovery || ioc->remove_host ||
3311 ioc->pci_error_recovery) {
3312 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3313 "%s: host reset in progress!\n",
3314 __func__, ioc->name));
3318 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3320 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3323 INIT_LIST_HEAD(&delayed_tr->list);
3324 delayed_tr->handle = handle;
3325 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3326 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3327 "DELAYED:tr:handle(0x%04x), (open)\n",
3328 ioc->name, handle));
3332 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3333 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3334 ioc->name, handle, smid,
3335 ioc->tm_tr_volume_cb_idx));
3336 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3337 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3338 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3339 mpi_request->DevHandle = cpu_to_le16(handle);
3340 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3341 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3345 * _scsih_tm_volume_tr_complete - target reset completion
3346 * @ioc: per adapter object
3347 * @smid: system request message index
3348 * @msix_index: MSIX table index supplied by the OS
3349 * @reply: reply message frame(lower 32bit addr)
3350 * Context: interrupt time.
3352 * Return 1 meaning mf should be freed from _base_interrupt
3353 * 0 means the mf is freed from this function.
3356 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3357 u8 msix_index, u32 reply)
3360 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3361 Mpi2SCSITaskManagementReply_t *mpi_reply =
3362 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3364 if (ioc->shost_recovery || ioc->remove_host ||
3365 ioc->pci_error_recovery) {
3366 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3367 "%s: host reset in progress!\n",
3368 __func__, ioc->name));
3371 if (unlikely(!mpi_reply)) {
3372 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3373 ioc->name, __FILE__, __LINE__, __func__);
3377 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3378 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3379 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3380 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3381 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3383 le16_to_cpu(mpi_reply->DevHandle), smid));
3387 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3388 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3389 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3390 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3391 le32_to_cpu(mpi_reply->IOCLogInfo),
3392 le32_to_cpu(mpi_reply->TerminationCount)));
3394 return _scsih_check_for_pending_tm(ioc, smid);
3399 * _scsih_check_for_pending_tm - check for pending task management
3400 * @ioc: per adapter object
3401 * @smid: system request message index
3403 * This will check delayed target reset list, and feed the
3406 * Return 1 meaning mf should be freed from _base_interrupt
3407 * 0 means the mf is freed from this function.
3410 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3412 struct _tr_list *delayed_tr;
3414 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3415 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3416 struct _tr_list, list);
3417 mpt3sas_base_free_smid(ioc, smid);
3418 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3419 list_del(&delayed_tr->list);
3424 if (!list_empty(&ioc->delayed_tr_list)) {
3425 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3426 struct _tr_list, list);
3427 mpt3sas_base_free_smid(ioc, smid);
3428 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3429 list_del(&delayed_tr->list);
3438 * _scsih_check_topo_delete_events - sanity check on topo events
3439 * @ioc: per adapter object
3440 * @event_data: the event data payload
3442 * This routine added to better handle cable breaker.
3444 * This handles the case where driver receives multiple expander
3445 * add and delete events in a single shot. When there is a delete event
3446 * the routine will void any pending add events waiting in the event queue.
3451 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3452 Mpi2EventDataSasTopologyChangeList_t *event_data)
3454 struct fw_event_work *fw_event;
3455 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3456 u16 expander_handle;
3457 struct _sas_node *sas_expander;
3458 unsigned long flags;
3462 for (i = 0 ; i < event_data->NumEntries; i++) {
3463 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3466 reason_code = event_data->PHY[i].PhyStatus &
3467 MPI2_EVENT_SAS_TOPO_RC_MASK;
3468 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3469 _scsih_tm_tr_send(ioc, handle);
3472 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3473 if (expander_handle < ioc->sas_hba.num_phys) {
3474 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3477 if (event_data->ExpStatus ==
3478 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3479 /* put expander attached devices into blocking state */
3480 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3481 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3483 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3484 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3486 handle = find_first_bit(ioc->blocking_handles,
3487 ioc->facts.MaxDevHandle);
3488 if (handle < ioc->facts.MaxDevHandle)
3489 _scsih_block_io_device(ioc, handle);
3490 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3491 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3492 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3494 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3497 /* mark ignore flag for pending events */
3498 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3499 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3500 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3503 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3504 fw_event->event_data;
3505 if (local_event_data->ExpStatus ==
3506 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3507 local_event_data->ExpStatus ==
3508 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3509 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3511 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3512 "setting ignoring flag\n", ioc->name));
3513 fw_event->ignore = 1;
3517 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3521 * _scsih_set_volume_delete_flag - setting volume delete flag
3522 * @ioc: per adapter object
3523 * @handle: device handle
3525 * This returns nothing.
3528 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3530 struct _raid_device *raid_device;
3531 struct MPT3SAS_TARGET *sas_target_priv_data;
3532 unsigned long flags;
3534 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3535 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3536 if (raid_device && raid_device->starget &&
3537 raid_device->starget->hostdata) {
3538 sas_target_priv_data =
3539 raid_device->starget->hostdata;
3540 sas_target_priv_data->deleted = 1;
3541 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3542 "setting delete flag: handle(0x%04x), "
3543 "wwid(0x%016llx)\n", ioc->name, handle,
3544 (unsigned long long) raid_device->wwid));
3546 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3550 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3551 * @handle: input handle
3552 * @a: handle for volume a
3553 * @b: handle for volume b
3555 * IR firmware only supports two raid volumes. The purpose of this
3556 * routine is to set the volume handle in either a or b. When the given
3557 * input handle is non-zero, or when a and b have not been set before.
3560 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3562 if (!handle || handle == *a || handle == *b)
3571 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3572 * @ioc: per adapter object
3573 * @event_data: the event data payload
3574 * Context: interrupt time.
3576 * This routine will send target reset to volume, followed by target
3577 * resets to the PDs. This is called when a PD has been removed, or
3578 * volume has been deleted or removed. When the target reset is sent
3579 * to volume, the PD target resets need to be queued to start upon
3580 * completion of the volume target reset.
3585 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3586 Mpi2EventDataIrConfigChangeList_t *event_data)
3588 Mpi2EventIrConfigElement_t *element;
3590 u16 handle, volume_handle, a, b;
3591 struct _tr_list *delayed_tr;
3596 if (ioc->is_warpdrive)
3599 /* Volume Resets for Deleted or Removed */
3600 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3601 for (i = 0; i < event_data->NumElements; i++, element++) {
3602 if (le32_to_cpu(event_data->Flags) &
3603 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3605 if (element->ReasonCode ==
3606 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3607 element->ReasonCode ==
3608 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3609 volume_handle = le16_to_cpu(element->VolDevHandle);
3610 _scsih_set_volume_delete_flag(ioc, volume_handle);
3611 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3615 /* Volume Resets for UNHIDE events */
3616 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3617 for (i = 0; i < event_data->NumElements; i++, element++) {
3618 if (le32_to_cpu(event_data->Flags) &
3619 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3621 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3622 volume_handle = le16_to_cpu(element->VolDevHandle);
3623 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3628 _scsih_tm_tr_volume_send(ioc, a);
3630 _scsih_tm_tr_volume_send(ioc, b);
3632 /* PD target resets */
3633 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3634 for (i = 0; i < event_data->NumElements; i++, element++) {
3635 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3637 handle = le16_to_cpu(element->PhysDiskDevHandle);
3638 volume_handle = le16_to_cpu(element->VolDevHandle);
3639 clear_bit(handle, ioc->pd_handles);
3641 _scsih_tm_tr_send(ioc, handle);
3642 else if (volume_handle == a || volume_handle == b) {
3643 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3644 BUG_ON(!delayed_tr);
3645 INIT_LIST_HEAD(&delayed_tr->list);
3646 delayed_tr->handle = handle;
3647 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3648 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3649 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3652 _scsih_tm_tr_send(ioc, handle);
3658 * _scsih_check_volume_delete_events - set delete flag for volumes
3659 * @ioc: per adapter object
3660 * @event_data: the event data payload
3661 * Context: interrupt time.
3663 * This will handle the case when the cable connected to entire volume is
3664 * pulled. We will take care of setting the deleted flag so normal IO will
3670 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3671 Mpi2EventDataIrVolume_t *event_data)
3675 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3677 state = le32_to_cpu(event_data->NewValue);
3678 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3679 MPI2_RAID_VOL_STATE_FAILED)
3680 _scsih_set_volume_delete_flag(ioc,
3681 le16_to_cpu(event_data->VolDevHandle));
3685 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3686 * @ioc: per adapter object
3687 * @event_data: the temp threshold event data
3688 * Context: interrupt time.
3693 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3694 Mpi2EventDataTemperature_t *event_data)
3696 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3697 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3698 " exceeded for Sensor: %d !!!\n", ioc->name,
3699 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3700 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3701 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3702 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3703 event_data->SensorNum);
3704 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3705 ioc->name, event_data->CurrentTemperature);
3710 * _scsih_flush_running_cmds - completing outstanding commands.
3711 * @ioc: per adapter object
3713 * The flushing out of all pending scmd commands following host reset,
3714 * where all IO is dropped to the floor.
3719 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3721 struct scsi_cmnd *scmd;
3725 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3726 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3730 mpt3sas_base_free_smid(ioc, smid);
3731 scsi_dma_unmap(scmd);
3732 if (ioc->pci_error_recovery)
3733 scmd->result = DID_NO_CONNECT << 16;
3735 scmd->result = DID_RESET << 16;
3736 scmd->scsi_done(scmd);
3738 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3743 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3744 * @ioc: per adapter object
3745 * @scmd: pointer to scsi command object
3746 * @mpi_request: pointer to the SCSI_IO reqest message frame
3748 * Supporting protection 1 and 3.
3753 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3754 Mpi2SCSIIORequest_t *mpi_request)
3757 unsigned char prot_op = scsi_get_prot_op(scmd);
3758 unsigned char prot_type = scsi_get_prot_type(scmd);
3759 Mpi25SCSIIORequest_t *mpi_request_3v =
3760 (Mpi25SCSIIORequest_t *)mpi_request;
3762 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3765 if (prot_op == SCSI_PROT_READ_STRIP)
3766 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3767 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3768 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3772 switch (prot_type) {
3773 case SCSI_PROT_DIF_TYPE1:
3774 case SCSI_PROT_DIF_TYPE2:
3777 * enable ref/guard checking
3778 * auto increment ref tag
3780 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3781 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3782 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3783 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3784 cpu_to_be32(scsi_get_lba(scmd));
3787 case SCSI_PROT_DIF_TYPE3:
3790 * enable guard checking
3792 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3797 mpi_request_3v->EEDPBlockSize =
3798 cpu_to_le16(scmd->device->sector_size);
3799 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3803 * _scsih_eedp_error_handling - return sense code for EEDP errors
3804 * @scmd: pointer to scsi command object
3805 * @ioc_status: ioc status
3810 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3814 switch (ioc_status) {
3815 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3818 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3821 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3828 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3830 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3831 SAM_STAT_CHECK_CONDITION;
3837 * scsih_qcmd - main scsi request entry point
3838 * @scmd: pointer to scsi command object
3839 * @done: function pointer to be invoked on completion
3841 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3843 * Returns 0 on success. If there's a failure, return either:
3844 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3845 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3848 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3850 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3851 struct MPT3SAS_DEVICE *sas_device_priv_data;
3852 struct MPT3SAS_TARGET *sas_target_priv_data;
3853 struct _raid_device *raid_device;
3854 Mpi2SCSIIORequest_t *mpi_request;
3859 if (ioc->logging_level & MPT_DEBUG_SCSI)
3860 scsi_print_command(scmd);
3862 sas_device_priv_data = scmd->device->hostdata;
3863 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3864 scmd->result = DID_NO_CONNECT << 16;
3865 scmd->scsi_done(scmd);
3869 if (ioc->pci_error_recovery || ioc->remove_host) {
3870 scmd->result = DID_NO_CONNECT << 16;
3871 scmd->scsi_done(scmd);
3875 sas_target_priv_data = sas_device_priv_data->sas_target;
3877 /* invalid device handle */
3878 handle = sas_target_priv_data->handle;
3879 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3880 scmd->result = DID_NO_CONNECT << 16;
3881 scmd->scsi_done(scmd);
3886 /* host recovery or link resets sent via IOCTLs */
3887 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3888 return SCSI_MLQUEUE_HOST_BUSY;
3890 /* device has been deleted */
3891 else if (sas_target_priv_data->deleted) {
3892 scmd->result = DID_NO_CONNECT << 16;
3893 scmd->scsi_done(scmd);
3895 /* device busy with task managment */
3896 } else if (sas_target_priv_data->tm_busy ||
3897 sas_device_priv_data->block)
3898 return SCSI_MLQUEUE_DEVICE_BUSY;
3900 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3901 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3902 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3903 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3905 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3908 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3910 /* Make sure Device is not raid volume.
3911 * We do not expose raid functionality to upper layer for warpdrive.
3913 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
3914 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3915 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3917 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3919 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3920 ioc->name, __func__);
3923 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3924 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3925 _scsih_setup_eedp(ioc, scmd, mpi_request);
3927 if (scmd->cmd_len == 32)
3928 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3929 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3930 if (sas_device_priv_data->sas_target->flags &
3931 MPT_TARGET_FLAGS_RAID_COMPONENT)
3932 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3934 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3935 mpi_request->DevHandle = cpu_to_le16(handle);
3936 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3937 mpi_request->Control = cpu_to_le32(mpi_control);
3938 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3939 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3940 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3941 mpi_request->SenseBufferLowAddress =
3942 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3943 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3944 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3946 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3948 if (mpi_request->DataLength) {
3949 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3950 mpt3sas_base_free_smid(ioc, smid);
3954 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3956 raid_device = sas_target_priv_data->raid_device;
3957 if (raid_device && raid_device->direct_io_enabled)
3958 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3961 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3962 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3963 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3964 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3965 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3967 mpt3sas_base_put_smid_scsi_io(ioc, smid,
3968 le16_to_cpu(mpi_request->DevHandle));
3970 mpt3sas_base_put_smid_default(ioc, smid);
3974 return SCSI_MLQUEUE_HOST_BUSY;
3978 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3979 * @sense_buffer: sense data returned by target
3980 * @data: normalized skey/asc/ascq
3985 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3987 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3988 /* descriptor format */
3989 data->skey = sense_buffer[1] & 0x0F;
3990 data->asc = sense_buffer[2];
3991 data->ascq = sense_buffer[3];
3994 data->skey = sense_buffer[2] & 0x0F;
3995 data->asc = sense_buffer[12];
3996 data->ascq = sense_buffer[13];
4001 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4002 * @ioc: per adapter object
4003 * @scmd: pointer to scsi command object
4004 * @mpi_reply: reply mf payload returned from firmware
4006 * scsi_status - SCSI Status code returned from target device
4007 * scsi_state - state info associated with SCSI_IO determined by ioc
4008 * ioc_status - ioc supplied status info
4013 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4014 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4018 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4019 MPI2_IOCSTATUS_MASK;
4020 u8 scsi_state = mpi_reply->SCSIState;
4021 u8 scsi_status = mpi_reply->SCSIStatus;
4022 char *desc_ioc_state = NULL;
4023 char *desc_scsi_status = NULL;
4024 char *desc_scsi_state = ioc->tmp_string;
4025 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4026 struct _sas_device *sas_device = NULL;
4027 struct scsi_target *starget = scmd->device->sdev_target;
4028 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4029 char *device_str = NULL;
4033 if (ioc->hide_ir_msg)
4034 device_str = "WarpDrive";
4036 device_str = "volume";
4038 if (log_info == 0x31170000)
4041 switch (ioc_status) {
4042 case MPI2_IOCSTATUS_SUCCESS:
4043 desc_ioc_state = "success";
4045 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4046 desc_ioc_state = "invalid function";
4048 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4049 desc_ioc_state = "scsi recovered error";
4051 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4052 desc_ioc_state = "scsi invalid dev handle";
4054 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4055 desc_ioc_state = "scsi device not there";
4057 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4058 desc_ioc_state = "scsi data overrun";
4060 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4061 desc_ioc_state = "scsi data underrun";
4063 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4064 desc_ioc_state = "scsi io data error";
4066 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4067 desc_ioc_state = "scsi protocol error";
4069 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4070 desc_ioc_state = "scsi task terminated";
4072 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4073 desc_ioc_state = "scsi residual mismatch";
4075 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4076 desc_ioc_state = "scsi task mgmt failed";
4078 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4079 desc_ioc_state = "scsi ioc terminated";
4081 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4082 desc_ioc_state = "scsi ext terminated";
4084 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4085 desc_ioc_state = "eedp guard error";
4087 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4088 desc_ioc_state = "eedp ref tag error";
4090 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4091 desc_ioc_state = "eedp app tag error";
4094 desc_ioc_state = "unknown";
4098 switch (scsi_status) {
4099 case MPI2_SCSI_STATUS_GOOD:
4100 desc_scsi_status = "good";
4102 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4103 desc_scsi_status = "check condition";
4105 case MPI2_SCSI_STATUS_CONDITION_MET:
4106 desc_scsi_status = "condition met";
4108 case MPI2_SCSI_STATUS_BUSY:
4109 desc_scsi_status = "busy";
4111 case MPI2_SCSI_STATUS_INTERMEDIATE:
4112 desc_scsi_status = "intermediate";
4114 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4115 desc_scsi_status = "intermediate condmet";
4117 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4118 desc_scsi_status = "reservation conflict";
4120 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4121 desc_scsi_status = "command terminated";
4123 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4124 desc_scsi_status = "task set full";
4126 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4127 desc_scsi_status = "aca active";
4129 case MPI2_SCSI_STATUS_TASK_ABORTED:
4130 desc_scsi_status = "task aborted";
4133 desc_scsi_status = "unknown";
4137 desc_scsi_state[0] = '\0';
4139 desc_scsi_state = " ";
4140 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4141 strcat(desc_scsi_state, "response info ");
4142 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4143 strcat(desc_scsi_state, "state terminated ");
4144 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4145 strcat(desc_scsi_state, "no status ");
4146 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4147 strcat(desc_scsi_state, "autosense failed ");
4148 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4149 strcat(desc_scsi_state, "autosense valid ");
4151 scsi_print_command(scmd);
4153 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4154 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4155 device_str, (unsigned long long)priv_target->sas_address);
4157 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4160 "\tsas_address(0x%016llx), phy(%d)\n",
4161 ioc->name, (unsigned long long)
4162 sas_device->sas_address, sas_device->phy);
4163 if (sas_device->enclosure_handle != 0)
4165 "\tenclosure_logical_id(0x%016llx),"
4166 "slot(%d)\n", ioc->name,
4167 (unsigned long long)
4168 sas_device->enclosure_logical_id,
4170 if (sas_device->connector_name[0])
4172 "\tenclosure level(0x%04x),"
4173 " connector name( %s)\n", ioc->name,
4174 sas_device->enclosure_level,
4175 sas_device->connector_name);
4177 sas_device_put(sas_device);
4182 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4183 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4184 desc_ioc_state, ioc_status, smid);
4186 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4187 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4188 scsi_get_resid(scmd));
4190 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4191 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4192 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4194 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4195 ioc->name, desc_scsi_status,
4196 scsi_status, desc_scsi_state, scsi_state);
4198 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4199 struct sense_info data;
4200 _scsih_normalize_sense(scmd->sense_buffer, &data);
4202 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4203 ioc->name, data.skey,
4204 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4207 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4208 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4209 response_bytes = (u8 *)&response_info;
4210 _scsih_response_code(ioc, response_bytes[0]);
4215 * _scsih_turn_on_pfa_led - illuminate PFA LED
4216 * @ioc: per adapter object
4217 * @handle: device handle
4223 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4225 Mpi2SepReply_t mpi_reply;
4226 Mpi2SepRequest_t mpi_request;
4227 struct _sas_device *sas_device;
4229 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4233 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4234 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4235 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4236 mpi_request.SlotStatus =
4237 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4238 mpi_request.DevHandle = cpu_to_le16(handle);
4239 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4240 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4241 &mpi_request)) != 0) {
4242 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4243 __FILE__, __LINE__, __func__);
4246 sas_device->pfa_led_on = 1;
4248 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4249 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4250 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4251 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4252 le32_to_cpu(mpi_reply.IOCLogInfo)));
4256 sas_device_put(sas_device);
4260 * _scsih_turn_off_pfa_led - turn off Fault LED
4261 * @ioc: per adapter object
4262 * @sas_device: sas device whose PFA LED has to turned off
4268 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4269 struct _sas_device *sas_device)
4271 Mpi2SepReply_t mpi_reply;
4272 Mpi2SepRequest_t mpi_request;
4274 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4275 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4276 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4277 mpi_request.SlotStatus = 0;
4278 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4279 mpi_request.DevHandle = 0;
4280 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4281 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4282 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4283 &mpi_request)) != 0) {
4284 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4285 __FILE__, __LINE__, __func__);
4289 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4290 dewtprintk(ioc, printk(MPT3SAS_FMT
4291 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4292 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4293 le32_to_cpu(mpi_reply.IOCLogInfo)));
4299 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4300 * @ioc: per adapter object
4301 * @handle: device handle
4302 * Context: interrupt.
4307 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4309 struct fw_event_work *fw_event;
4311 fw_event = alloc_fw_event_work(0);
4314 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4315 fw_event->device_handle = handle;
4316 fw_event->ioc = ioc;
4317 _scsih_fw_event_add(ioc, fw_event);
4318 fw_event_work_put(fw_event);
4322 * _scsih_smart_predicted_fault - process smart errors
4323 * @ioc: per adapter object
4324 * @handle: device handle
4325 * Context: interrupt.
4330 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4332 struct scsi_target *starget;
4333 struct MPT3SAS_TARGET *sas_target_priv_data;
4334 Mpi2EventNotificationReply_t *event_reply;
4335 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4336 struct _sas_device *sas_device;
4338 unsigned long flags;
4340 /* only handle non-raid devices */
4341 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4342 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4346 starget = sas_device->starget;
4347 sas_target_priv_data = starget->hostdata;
4349 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4350 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4353 if (sas_device->enclosure_handle != 0)
4354 starget_printk(KERN_INFO, starget, "predicted fault, "
4355 "enclosure logical id(0x%016llx), slot(%d)\n",
4356 (unsigned long long)sas_device->enclosure_logical_id,
4358 if (sas_device->connector_name[0] != '\0')
4359 starget_printk(KERN_WARNING, starget, "predicted fault, "
4360 "enclosure level(0x%04x), connector name( %s)\n",
4361 sas_device->enclosure_level,
4362 sas_device->connector_name);
4363 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4365 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4366 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4368 /* insert into event log */
4369 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4370 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4371 event_reply = kzalloc(sz, GFP_KERNEL);
4373 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4374 ioc->name, __FILE__, __LINE__, __func__);
4378 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4379 event_reply->Event =
4380 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4381 event_reply->MsgLength = sz/4;
4382 event_reply->EventDataLength =
4383 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4384 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4385 event_reply->EventData;
4386 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4387 event_data->ASC = 0x5D;
4388 event_data->DevHandle = cpu_to_le16(handle);
4389 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4390 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4394 sas_device_put(sas_device);
4398 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4403 * _scsih_io_done - scsi request callback
4404 * @ioc: per adapter object
4405 * @smid: system request message index
4406 * @msix_index: MSIX table index supplied by the OS
4407 * @reply: reply message frame(lower 32bit addr)
4409 * Callback handler when using _scsih_qcmd.
4411 * Return 1 meaning mf should be freed from _base_interrupt
4412 * 0 means the mf is freed from this function.
4415 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4417 Mpi2SCSIIORequest_t *mpi_request;
4418 Mpi2SCSIIOReply_t *mpi_reply;
4419 struct scsi_cmnd *scmd;
4425 struct MPT3SAS_DEVICE *sas_device_priv_data;
4426 u32 response_code = 0;
4427 unsigned long flags;
4429 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4430 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4434 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4436 if (mpi_reply == NULL) {
4437 scmd->result = DID_OK << 16;
4441 sas_device_priv_data = scmd->device->hostdata;
4442 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4443 sas_device_priv_data->sas_target->deleted) {
4444 scmd->result = DID_NO_CONNECT << 16;
4447 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4450 * WARPDRIVE: If direct_io is set then it is directIO,
4451 * the failed direct I/O should be redirected to volume
4453 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4454 ((ioc_status & MPI2_IOCSTATUS_MASK)
4455 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4456 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4457 ioc->scsi_lookup[smid - 1].scmd = scmd;
4458 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4459 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4460 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4461 mpi_request->DevHandle =
4462 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4463 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4464 sas_device_priv_data->sas_target->handle);
4467 /* turning off TLR */
4468 scsi_state = mpi_reply->SCSIState;
4469 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4471 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4472 if (!sas_device_priv_data->tlr_snoop_check) {
4473 sas_device_priv_data->tlr_snoop_check++;
4474 if (!ioc->is_warpdrive &&
4475 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4476 sas_is_tlr_enabled(scmd->device) &&
4477 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4478 sas_disable_tlr(scmd->device);
4479 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4483 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4484 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4485 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4486 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4489 ioc_status &= MPI2_IOCSTATUS_MASK;
4490 scsi_status = mpi_reply->SCSIStatus;
4492 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4493 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4494 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4495 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4496 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4499 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4500 struct sense_info data;
4501 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4503 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4504 le32_to_cpu(mpi_reply->SenseCount));
4505 memcpy(scmd->sense_buffer, sense_data, sz);
4506 _scsih_normalize_sense(scmd->sense_buffer, &data);
4507 /* failure prediction threshold exceeded */
4508 if (data.asc == 0x5D)
4509 _scsih_smart_predicted_fault(ioc,
4510 le16_to_cpu(mpi_reply->DevHandle));
4511 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4513 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
4514 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4515 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4516 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4517 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4519 switch (ioc_status) {
4520 case MPI2_IOCSTATUS_BUSY:
4521 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4522 scmd->result = SAM_STAT_BUSY;
4525 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4526 scmd->result = DID_NO_CONNECT << 16;
4529 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4530 if (sas_device_priv_data->block) {
4531 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4534 if (log_info == 0x31110630) {
4535 if (scmd->retries > 2) {
4536 scmd->result = DID_NO_CONNECT << 16;
4537 scsi_device_set_state(scmd->device,
4540 scmd->result = DID_SOFT_ERROR << 16;
4541 scmd->device->expecting_cc_ua = 1;
4544 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4545 scmd->result = DID_RESET << 16;
4548 scmd->result = DID_SOFT_ERROR << 16;
4550 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4551 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4552 scmd->result = DID_RESET << 16;
4555 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4556 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4557 scmd->result = DID_SOFT_ERROR << 16;
4559 scmd->result = (DID_OK << 16) | scsi_status;
4562 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4563 scmd->result = (DID_OK << 16) | scsi_status;
4565 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4568 if (xfer_cnt < scmd->underflow) {
4569 if (scsi_status == SAM_STAT_BUSY)
4570 scmd->result = SAM_STAT_BUSY;
4572 scmd->result = DID_SOFT_ERROR << 16;
4573 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4574 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4575 scmd->result = DID_SOFT_ERROR << 16;
4576 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4577 scmd->result = DID_RESET << 16;
4578 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4579 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4580 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4581 scmd->result = (DRIVER_SENSE << 24) |
4582 SAM_STAT_CHECK_CONDITION;
4583 scmd->sense_buffer[0] = 0x70;
4584 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4585 scmd->sense_buffer[12] = 0x20;
4586 scmd->sense_buffer[13] = 0;
4590 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4591 scsi_set_resid(scmd, 0);
4592 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4593 case MPI2_IOCSTATUS_SUCCESS:
4594 scmd->result = (DID_OK << 16) | scsi_status;
4595 if (response_code ==
4596 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4597 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4598 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4599 scmd->result = DID_SOFT_ERROR << 16;
4600 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4601 scmd->result = DID_RESET << 16;
4604 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4605 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4606 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4607 _scsih_eedp_error_handling(scmd, ioc_status);
4610 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4611 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4612 case MPI2_IOCSTATUS_INVALID_SGL:
4613 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4614 case MPI2_IOCSTATUS_INVALID_FIELD:
4615 case MPI2_IOCSTATUS_INVALID_STATE:
4616 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4617 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4619 scmd->result = DID_SOFT_ERROR << 16;
4624 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4625 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4629 scsi_dma_unmap(scmd);
4631 scmd->scsi_done(scmd);
4636 * _scsih_sas_host_refresh - refreshing sas host object contents
4637 * @ioc: per adapter object
4640 * During port enable, fw will send topology events for every device. Its
4641 * possible that the handles may change from the previous setting, so this
4642 * code keeping handles updating if changed.
4647 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4652 Mpi2ConfigReply_t mpi_reply;
4653 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4654 u16 attached_handle;
4657 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4658 "updating handles for sas_host(0x%016llx)\n",
4659 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4661 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4662 * sizeof(Mpi2SasIOUnit0PhyData_t));
4663 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4664 if (!sas_iounit_pg0) {
4665 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4666 ioc->name, __FILE__, __LINE__, __func__);
4670 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4671 sas_iounit_pg0, sz)) != 0)
4673 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4674 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4676 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4677 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4679 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4680 PhyData[0].ControllerDevHandle);
4681 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4682 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4684 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4685 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4686 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4687 attached_handle, i, link_rate);
4690 kfree(sas_iounit_pg0);
4694 * _scsih_sas_host_add - create sas host object
4695 * @ioc: per adapter object
4697 * Creating host side data object, stored in ioc->sas_hba
4702 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4705 Mpi2ConfigReply_t mpi_reply;
4706 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4707 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4708 Mpi2SasPhyPage0_t phy_pg0;
4709 Mpi2SasDevicePage0_t sas_device_pg0;
4710 Mpi2SasEnclosurePage0_t enclosure_pg0;
4713 u8 device_missing_delay;
4715 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4716 if (!ioc->sas_hba.num_phys) {
4717 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4718 ioc->name, __FILE__, __LINE__, __func__);
4722 /* sas_iounit page 0 */
4723 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4724 sizeof(Mpi2SasIOUnit0PhyData_t));
4725 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4726 if (!sas_iounit_pg0) {
4727 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4728 ioc->name, __FILE__, __LINE__, __func__);
4731 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4732 sas_iounit_pg0, sz))) {
4733 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4734 ioc->name, __FILE__, __LINE__, __func__);
4737 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4738 MPI2_IOCSTATUS_MASK;
4739 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4740 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4741 ioc->name, __FILE__, __LINE__, __func__);
4745 /* sas_iounit page 1 */
4746 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4747 sizeof(Mpi2SasIOUnit1PhyData_t));
4748 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4749 if (!sas_iounit_pg1) {
4750 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4754 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4755 sas_iounit_pg1, sz))) {
4756 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4757 ioc->name, __FILE__, __LINE__, __func__);
4760 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4761 MPI2_IOCSTATUS_MASK;
4762 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4763 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4764 ioc->name, __FILE__, __LINE__, __func__);
4768 ioc->io_missing_delay =
4769 sas_iounit_pg1->IODeviceMissingDelay;
4770 device_missing_delay =
4771 sas_iounit_pg1->ReportDeviceMissingDelay;
4772 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4773 ioc->device_missing_delay = (device_missing_delay &
4774 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4776 ioc->device_missing_delay = device_missing_delay &
4777 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4779 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4780 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4781 sizeof(struct _sas_phy), GFP_KERNEL);
4782 if (!ioc->sas_hba.phy) {
4783 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4784 ioc->name, __FILE__, __LINE__, __func__);
4787 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4788 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4790 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4791 ioc->name, __FILE__, __LINE__, __func__);
4794 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4795 MPI2_IOCSTATUS_MASK;
4796 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4797 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4798 ioc->name, __FILE__, __LINE__, __func__);
4803 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4804 PhyData[0].ControllerDevHandle);
4805 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4806 ioc->sas_hba.phy[i].phy_id = i;
4807 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4808 phy_pg0, ioc->sas_hba.parent_dev);
4810 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4811 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4812 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4813 ioc->name, __FILE__, __LINE__, __func__);
4816 ioc->sas_hba.enclosure_handle =
4817 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4818 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4820 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4821 ioc->name, ioc->sas_hba.handle,
4822 (unsigned long long) ioc->sas_hba.sas_address,
4823 ioc->sas_hba.num_phys) ;
4825 if (ioc->sas_hba.enclosure_handle) {
4826 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4827 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4828 ioc->sas_hba.enclosure_handle)))
4829 ioc->sas_hba.enclosure_logical_id =
4830 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4834 kfree(sas_iounit_pg1);
4835 kfree(sas_iounit_pg0);
4839 * _scsih_expander_add - creating expander object
4840 * @ioc: per adapter object
4841 * @handle: expander handle
4843 * Creating expander object, stored in ioc->sas_expander_list.
4845 * Return 0 for success, else error.
4848 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4850 struct _sas_node *sas_expander;
4851 Mpi2ConfigReply_t mpi_reply;
4852 Mpi2ExpanderPage0_t expander_pg0;
4853 Mpi2ExpanderPage1_t expander_pg1;
4854 Mpi2SasEnclosurePage0_t enclosure_pg0;
4857 u64 sas_address, sas_address_parent = 0;
4859 unsigned long flags;
4860 struct _sas_port *mpt3sas_port = NULL;
4867 if (ioc->shost_recovery || ioc->pci_error_recovery)
4870 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4871 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4872 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4873 ioc->name, __FILE__, __LINE__, __func__);
4877 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4878 MPI2_IOCSTATUS_MASK;
4879 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4880 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4881 ioc->name, __FILE__, __LINE__, __func__);
4885 /* handle out of order topology events */
4886 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4887 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4889 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4890 ioc->name, __FILE__, __LINE__, __func__);
4893 if (sas_address_parent != ioc->sas_hba.sas_address) {
4894 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4895 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4896 sas_address_parent);
4897 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4898 if (!sas_expander) {
4899 rc = _scsih_expander_add(ioc, parent_handle);
4905 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4906 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4907 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4909 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4914 sas_expander = kzalloc(sizeof(struct _sas_node),
4916 if (!sas_expander) {
4917 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4918 ioc->name, __FILE__, __LINE__, __func__);
4922 sas_expander->handle = handle;
4923 sas_expander->num_phys = expander_pg0.NumPhys;
4924 sas_expander->sas_address_parent = sas_address_parent;
4925 sas_expander->sas_address = sas_address;
4927 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4928 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4929 handle, parent_handle, (unsigned long long)
4930 sas_expander->sas_address, sas_expander->num_phys);
4932 if (!sas_expander->num_phys)
4934 sas_expander->phy = kcalloc(sas_expander->num_phys,
4935 sizeof(struct _sas_phy), GFP_KERNEL);
4936 if (!sas_expander->phy) {
4937 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4938 ioc->name, __FILE__, __LINE__, __func__);
4943 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4944 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4945 sas_address_parent);
4946 if (!mpt3sas_port) {
4947 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4948 ioc->name, __FILE__, __LINE__, __func__);
4952 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4954 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4955 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4956 &expander_pg1, i, handle))) {
4957 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4958 ioc->name, __FILE__, __LINE__, __func__);
4962 sas_expander->phy[i].handle = handle;
4963 sas_expander->phy[i].phy_id = i;
4965 if ((mpt3sas_transport_add_expander_phy(ioc,
4966 &sas_expander->phy[i], expander_pg1,
4967 sas_expander->parent_dev))) {
4968 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4969 ioc->name, __FILE__, __LINE__, __func__);
4975 if (sas_expander->enclosure_handle) {
4976 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4977 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4978 sas_expander->enclosure_handle)))
4979 sas_expander->enclosure_logical_id =
4980 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4983 _scsih_expander_node_add(ioc, sas_expander);
4989 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4990 sas_address_parent);
4991 kfree(sas_expander);
4996 * mpt3sas_expander_remove - removing expander object
4997 * @ioc: per adapter object
4998 * @sas_address: expander sas_address
5003 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5005 struct _sas_node *sas_expander;
5006 unsigned long flags;
5008 if (ioc->shost_recovery)
5011 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5012 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5015 list_del(&sas_expander->list);
5016 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5018 _scsih_expander_node_remove(ioc, sas_expander);
5022 * _scsih_done - internal SCSI_IO callback handler.
5023 * @ioc: per adapter object
5024 * @smid: system request message index
5025 * @msix_index: MSIX table index supplied by the OS
5026 * @reply: reply message frame(lower 32bit addr)
5028 * Callback handler when sending internal generated SCSI_IO.
5029 * The callback index passed is `ioc->scsih_cb_idx`
5031 * Return 1 meaning mf should be freed from _base_interrupt
5032 * 0 means the mf is freed from this function.
5035 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5037 MPI2DefaultReply_t *mpi_reply;
5039 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5040 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5042 if (ioc->scsih_cmds.smid != smid)
5044 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5046 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5047 mpi_reply->MsgLength*4);
5048 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5050 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5051 complete(&ioc->scsih_cmds.done);
5058 #define MPT3_MAX_LUNS (255)
5062 * _scsih_check_access_status - check access flags
5063 * @ioc: per adapter object
5064 * @sas_address: sas address
5065 * @handle: sas device handle
5066 * @access_flags: errors returned during discovery of the device
5068 * Return 0 for success, else failure
5071 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5072 u16 handle, u8 access_status)
5077 switch (access_status) {
5078 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5082 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5083 desc = "sata capability failed";
5085 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5086 desc = "sata affiliation conflict";
5088 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5089 desc = "route not addressable";
5091 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5092 desc = "smp error not addressable";
5094 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5095 desc = "device blocked";
5097 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5103 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5104 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5105 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5106 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5107 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5108 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5109 desc = "sata initialization failed";
5120 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5121 ioc->name, desc, (unsigned long long)sas_address, handle);
5126 * _scsih_check_device - checking device responsiveness
5127 * @ioc: per adapter object
5128 * @parent_sas_address: sas address of parent expander or sas host
5129 * @handle: attached device handle
5130 * @phy_numberv: phy number
5131 * @link_rate: new link rate
5136 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5137 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5139 Mpi2ConfigReply_t mpi_reply;
5140 Mpi2SasDevicePage0_t sas_device_pg0;
5141 struct _sas_device *sas_device;
5143 unsigned long flags;
5145 struct scsi_target *starget;
5146 struct MPT3SAS_TARGET *sas_target_priv_data;
5150 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5151 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5154 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5155 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5158 /* wide port handling ~ we need only handle device once for the phy that
5159 * is matched in sas device page zero
5161 if (phy_number != sas_device_pg0.PhyNum)
5164 /* check if this is end device */
5165 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5166 if (!(_scsih_is_end_device(device_info)))
5169 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5170 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5171 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5177 if (unlikely(sas_device->handle != handle)) {
5178 starget = sas_device->starget;
5179 sas_target_priv_data = starget->hostdata;
5180 starget_printk(KERN_INFO, starget,
5181 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5182 sas_device->handle, handle);
5183 sas_target_priv_data->handle = handle;
5184 sas_device->handle = handle;
5185 if (sas_device_pg0.Flags &
5186 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5187 sas_device->enclosure_level =
5188 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5189 memcpy(&sas_device->connector_name[0],
5190 &sas_device_pg0.ConnectorName[0], 4);
5192 sas_device->enclosure_level = 0;
5193 sas_device->connector_name[0] = '\0';
5197 /* check if device is present */
5198 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5199 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5201 "device is not present handle(0x%04x), flags!!!\n",
5206 /* check if there were any issues with discovery */
5207 if (_scsih_check_access_status(ioc, sas_address, handle,
5208 sas_device_pg0.AccessStatus))
5211 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5212 _scsih_ublock_io_device(ioc, sas_address);
5215 sas_device_put(sas_device);
5219 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5221 sas_device_put(sas_device);
5225 * _scsih_add_device - creating sas device object
5226 * @ioc: per adapter object
5227 * @handle: sas device handle
5228 * @phy_num: phy number end device attached to
5229 * @is_pd: is this hidden raid component
5231 * Creating end device object, stored in ioc->sas_device_list.
5233 * Returns 0 for success, non-zero for failure.
5236 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5239 Mpi2ConfigReply_t mpi_reply;
5240 Mpi2SasDevicePage0_t sas_device_pg0;
5241 Mpi2SasEnclosurePage0_t enclosure_pg0;
5242 struct _sas_device *sas_device;
5247 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5248 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5249 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5250 ioc->name, __FILE__, __LINE__, __func__);
5254 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5255 MPI2_IOCSTATUS_MASK;
5256 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5257 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5258 ioc->name, __FILE__, __LINE__, __func__);
5262 /* check if this is end device */
5263 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5264 if (!(_scsih_is_end_device(device_info)))
5266 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5268 /* check if device is present */
5269 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5270 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5271 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5276 /* check if there were any issues with discovery */
5277 if (_scsih_check_access_status(ioc, sas_address, handle,
5278 sas_device_pg0.AccessStatus))
5281 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5284 sas_device_put(sas_device);
5288 sas_device = kzalloc(sizeof(struct _sas_device),
5291 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5292 ioc->name, __FILE__, __LINE__, __func__);
5296 kref_init(&sas_device->refcount);
5297 sas_device->handle = handle;
5298 if (_scsih_get_sas_address(ioc,
5299 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5300 &sas_device->sas_address_parent) != 0)
5301 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5302 ioc->name, __FILE__, __LINE__, __func__);
5303 sas_device->enclosure_handle =
5304 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5305 if (sas_device->enclosure_handle != 0)
5307 le16_to_cpu(sas_device_pg0.Slot);
5308 sas_device->device_info = device_info;
5309 sas_device->sas_address = sas_address;
5310 sas_device->phy = sas_device_pg0.PhyNum;
5311 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5312 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5314 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5315 sas_device->enclosure_level =
5316 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5317 memcpy(&sas_device->connector_name[0],
5318 &sas_device_pg0.ConnectorName[0], 4);
5320 sas_device->enclosure_level = 0;
5321 sas_device->connector_name[0] = '\0';
5323 /* get enclosure_logical_id */
5324 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5325 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5326 sas_device->enclosure_handle)))
5327 sas_device->enclosure_logical_id =
5328 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5330 /* get device name */
5331 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5333 if (ioc->wait_for_discovery_to_complete)
5334 _scsih_sas_device_init_add(ioc, sas_device);
5336 _scsih_sas_device_add(ioc, sas_device);
5338 sas_device_put(sas_device);
5343 * _scsih_remove_device - removing sas device object
5344 * @ioc: per adapter object
5345 * @sas_device_delete: the sas_device object
5350 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5351 struct _sas_device *sas_device)
5353 struct MPT3SAS_TARGET *sas_target_priv_data;
5355 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5356 (sas_device->pfa_led_on)) {
5357 _scsih_turn_off_pfa_led(ioc, sas_device);
5358 sas_device->pfa_led_on = 0;
5360 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5361 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5362 ioc->name, __func__,
5363 sas_device->handle, (unsigned long long)
5364 sas_device->sas_address));
5365 if (sas_device->enclosure_handle != 0)
5366 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5367 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5368 ioc->name, __func__,
5369 (unsigned long long)sas_device->enclosure_logical_id,
5371 if (sas_device->connector_name[0] != '\0')
5372 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5373 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5374 ioc->name, __func__,
5375 sas_device->enclosure_level,
5376 sas_device->connector_name));
5378 if (sas_device->starget && sas_device->starget->hostdata) {
5379 sas_target_priv_data = sas_device->starget->hostdata;
5380 sas_target_priv_data->deleted = 1;
5381 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5382 sas_target_priv_data->handle =
5383 MPT3SAS_INVALID_DEVICE_HANDLE;
5386 if (!ioc->hide_drives)
5387 mpt3sas_transport_port_remove(ioc,
5388 sas_device->sas_address,
5389 sas_device->sas_address_parent);
5392 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5393 ioc->name, sas_device->handle,
5394 (unsigned long long) sas_device->sas_address);
5395 if (sas_device->enclosure_handle != 0)
5397 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5399 (unsigned long long)sas_device->enclosure_logical_id,
5401 if (sas_device->connector_name[0] != '\0')
5403 "removing enclosure level(0x%04x), connector name( %s)\n",
5404 ioc->name, sas_device->enclosure_level,
5405 sas_device->connector_name);
5407 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5408 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5409 ioc->name, __func__,
5410 sas_device->handle, (unsigned long long)
5411 sas_device->sas_address));
5412 if (sas_device->enclosure_handle != 0)
5413 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5414 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5415 ioc->name, __func__,
5416 (unsigned long long)sas_device->enclosure_logical_id,
5418 if (sas_device->connector_name[0] != '\0')
5419 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5420 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5421 ioc->name, __func__, sas_device->enclosure_level,
5422 sas_device->connector_name));
5426 * _scsih_sas_topology_change_event_debug - debug for topology event
5427 * @ioc: per adapter object
5428 * @event_data: event data payload
5432 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5433 Mpi2EventDataSasTopologyChangeList_t *event_data)
5439 char *status_str = NULL;
5440 u8 link_rate, prev_link_rate;
5442 switch (event_data->ExpStatus) {
5443 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5446 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5447 status_str = "remove";
5449 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5451 status_str = "responding";
5453 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5454 status_str = "remove delay";
5457 status_str = "unknown status";
5460 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5461 ioc->name, status_str);
5462 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5463 "start_phy(%02d), count(%d)\n",
5464 le16_to_cpu(event_data->ExpanderDevHandle),
5465 le16_to_cpu(event_data->EnclosureHandle),
5466 event_data->StartPhyNum, event_data->NumEntries);
5467 for (i = 0; i < event_data->NumEntries; i++) {
5468 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5471 phy_number = event_data->StartPhyNum + i;
5472 reason_code = event_data->PHY[i].PhyStatus &
5473 MPI2_EVENT_SAS_TOPO_RC_MASK;
5474 switch (reason_code) {
5475 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5476 status_str = "target add";
5478 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5479 status_str = "target remove";
5481 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5482 status_str = "delay target remove";
5484 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5485 status_str = "link rate change";
5487 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5488 status_str = "target responding";
5491 status_str = "unknown";
5494 link_rate = event_data->PHY[i].LinkRate >> 4;
5495 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5496 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5497 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5498 handle, status_str, link_rate, prev_link_rate);
5504 * _scsih_sas_topology_change_event - handle topology changes
5505 * @ioc: per adapter object
5506 * @fw_event: The fw_event_work object
5511 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5512 struct fw_event_work *fw_event)
5515 u16 parent_handle, handle;
5517 u8 phy_number, max_phys;
5518 struct _sas_node *sas_expander;
5520 unsigned long flags;
5521 u8 link_rate, prev_link_rate;
5522 Mpi2EventDataSasTopologyChangeList_t *event_data =
5523 (Mpi2EventDataSasTopologyChangeList_t *)
5524 fw_event->event_data;
5526 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5527 _scsih_sas_topology_change_event_debug(ioc, event_data);
5529 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5532 if (!ioc->sas_hba.num_phys)
5533 _scsih_sas_host_add(ioc);
5535 _scsih_sas_host_refresh(ioc);
5537 if (fw_event->ignore) {
5538 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5539 "ignoring expander event\n", ioc->name));
5543 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5545 /* handle expander add */
5546 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5547 if (_scsih_expander_add(ioc, parent_handle) != 0)
5550 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5551 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5554 sas_address = sas_expander->sas_address;
5555 max_phys = sas_expander->num_phys;
5556 } else if (parent_handle < ioc->sas_hba.num_phys) {
5557 sas_address = ioc->sas_hba.sas_address;
5558 max_phys = ioc->sas_hba.num_phys;
5560 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5563 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5565 /* handle siblings events */
5566 for (i = 0; i < event_data->NumEntries; i++) {
5567 if (fw_event->ignore) {
5568 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5569 "ignoring expander event\n", ioc->name));
5572 if (ioc->remove_host || ioc->pci_error_recovery)
5574 phy_number = event_data->StartPhyNum + i;
5575 if (phy_number >= max_phys)
5577 reason_code = event_data->PHY[i].PhyStatus &
5578 MPI2_EVENT_SAS_TOPO_RC_MASK;
5579 if ((event_data->PHY[i].PhyStatus &
5580 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5581 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5583 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5586 link_rate = event_data->PHY[i].LinkRate >> 4;
5587 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5588 switch (reason_code) {
5589 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5591 if (ioc->shost_recovery)
5594 if (link_rate == prev_link_rate)
5597 mpt3sas_transport_update_links(ioc, sas_address,
5598 handle, phy_number, link_rate);
5600 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5603 _scsih_check_device(ioc, sas_address, handle,
5604 phy_number, link_rate);
5607 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5609 if (ioc->shost_recovery)
5612 mpt3sas_transport_update_links(ioc, sas_address,
5613 handle, phy_number, link_rate);
5615 _scsih_add_device(ioc, handle, phy_number, 0);
5618 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5620 _scsih_device_remove_by_handle(ioc, handle);
5625 /* handle expander removal */
5626 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5628 mpt3sas_expander_remove(ioc, sas_address);
5634 * _scsih_sas_device_status_change_event_debug - debug for device event
5635 * @event_data: event data payload
5641 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5642 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5644 char *reason_str = NULL;
5646 switch (event_data->ReasonCode) {
5647 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5648 reason_str = "smart data";
5650 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5651 reason_str = "unsupported device discovered";
5653 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5654 reason_str = "internal device reset";
5656 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5657 reason_str = "internal task abort";
5659 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5660 reason_str = "internal task abort set";
5662 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5663 reason_str = "internal clear task set";
5665 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5666 reason_str = "internal query task";
5668 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5669 reason_str = "sata init failure";
5671 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5672 reason_str = "internal device reset complete";
5674 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5675 reason_str = "internal task abort complete";
5677 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5678 reason_str = "internal async notification";
5680 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5681 reason_str = "expander reduced functionality";
5683 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5684 reason_str = "expander reduced functionality complete";
5687 reason_str = "unknown reason";
5690 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5691 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5692 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5693 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5694 le16_to_cpu(event_data->TaskTag));
5695 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5696 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5697 event_data->ASC, event_data->ASCQ);
5702 * _scsih_sas_device_status_change_event - handle device status change
5703 * @ioc: per adapter object
5704 * @fw_event: The fw_event_work object
5710 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5711 struct fw_event_work *fw_event)
5713 struct MPT3SAS_TARGET *target_priv_data;
5714 struct _sas_device *sas_device;
5716 unsigned long flags;
5717 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5718 (Mpi2EventDataSasDeviceStatusChange_t *)
5719 fw_event->event_data;
5721 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5722 _scsih_sas_device_status_change_event_debug(ioc,
5725 /* In MPI Revision K (0xC), the internal device reset complete was
5726 * implemented, so avoid setting tm_busy flag for older firmware.
5728 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5731 if (event_data->ReasonCode !=
5732 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5733 event_data->ReasonCode !=
5734 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5737 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5738 sas_address = le64_to_cpu(event_data->SASAddress);
5739 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5742 if (!sas_device || !sas_device->starget)
5745 target_priv_data = sas_device->starget->hostdata;
5746 if (!target_priv_data)
5749 if (event_data->ReasonCode ==
5750 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5751 target_priv_data->tm_busy = 1;
5753 target_priv_data->tm_busy = 0;
5757 sas_device_put(sas_device);
5759 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5764 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5766 * @ioc: per adapter object
5767 * @event_data: event data payload
5773 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5774 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5776 char *reason_str = NULL;
5778 switch (event_data->ReasonCode) {
5779 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5780 reason_str = "enclosure add";
5782 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5783 reason_str = "enclosure remove";
5786 reason_str = "unknown reason";
5790 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5791 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5792 " number slots(%d)\n", ioc->name, reason_str,
5793 le16_to_cpu(event_data->EnclosureHandle),
5794 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5795 le16_to_cpu(event_data->StartSlot));
5799 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5800 * @ioc: per adapter object
5801 * @fw_event: The fw_event_work object
5807 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5808 struct fw_event_work *fw_event)
5810 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5811 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5812 (Mpi2EventDataSasEnclDevStatusChange_t *)
5813 fw_event->event_data);
5817 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5818 * @ioc: per adapter object
5819 * @fw_event: The fw_event_work object
5825 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5826 struct fw_event_work *fw_event)
5828 struct scsi_cmnd *scmd;
5829 struct scsi_device *sdev;
5832 struct MPT3SAS_DEVICE *sas_device_priv_data;
5833 u32 termination_count;
5835 Mpi2SCSITaskManagementReply_t *mpi_reply;
5836 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5837 (Mpi2EventDataSasBroadcastPrimitive_t *)
5838 fw_event->event_data;
5840 unsigned long flags;
5843 u8 task_abort_retries;
5845 mutex_lock(&ioc->tm_cmds.mutex);
5847 "%s: enter: phy number(%d), width(%d)\n",
5848 ioc->name, __func__, event_data->PhyNum,
5849 event_data->PortWidth);
5851 _scsih_block_io_all_device(ioc);
5853 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5854 mpi_reply = ioc->tm_cmds.reply;
5855 broadcast_aen_retry:
5857 /* sanity checks for retrying this loop */
5858 if (max_retries++ == 5) {
5859 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5860 ioc->name, __func__));
5862 } else if (max_retries > 1)
5863 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5864 ioc->name, __func__, max_retries - 1));
5866 termination_count = 0;
5868 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5869 if (ioc->shost_recovery)
5871 scmd = _scsih_scsi_lookup_get(ioc, smid);
5874 sdev = scmd->device;
5875 sas_device_priv_data = sdev->hostdata;
5876 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5878 /* skip hidden raid components */
5879 if (sas_device_priv_data->sas_target->flags &
5880 MPT_TARGET_FLAGS_RAID_COMPONENT)
5883 if (sas_device_priv_data->sas_target->flags &
5884 MPT_TARGET_FLAGS_VOLUME)
5887 handle = sas_device_priv_data->sas_target->handle;
5888 lun = sas_device_priv_data->lun;
5891 if (ioc->shost_recovery)
5894 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5895 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5896 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5899 sdev_printk(KERN_WARNING, sdev,
5900 "mpt3sas_scsih_issue_tm: FAILED when sending "
5901 "QUERY_TASK: scmd(%p)\n", scmd);
5902 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5903 goto broadcast_aen_retry;
5905 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5906 & MPI2_IOCSTATUS_MASK;
5907 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5908 sdev_printk(KERN_WARNING, sdev,
5909 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5911 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5912 goto broadcast_aen_retry;
5915 /* see if IO is still owned by IOC and target */
5916 if (mpi_reply->ResponseCode ==
5917 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5918 mpi_reply->ResponseCode ==
5919 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5920 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5923 task_abort_retries = 0;
5925 if (task_abort_retries++ == 60) {
5926 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5927 "%s: ABORT_TASK: giving up\n", ioc->name,
5929 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5930 goto broadcast_aen_retry;
5933 if (ioc->shost_recovery)
5936 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5937 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5940 sdev_printk(KERN_WARNING, sdev,
5941 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5942 "scmd(%p)\n", scmd);
5946 if (task_abort_retries > 1)
5947 sdev_printk(KERN_WARNING, sdev,
5948 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5950 task_abort_retries - 1, scmd);
5952 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5953 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5956 if (ioc->broadcast_aen_pending) {
5957 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5958 "%s: loop back due to pending AEN\n",
5959 ioc->name, __func__));
5960 ioc->broadcast_aen_pending = 0;
5961 goto broadcast_aen_retry;
5965 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5968 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5969 "%s - exit, query_count = %d termination_count = %d\n",
5970 ioc->name, __func__, query_count, termination_count));
5972 ioc->broadcast_aen_busy = 0;
5973 if (!ioc->shost_recovery)
5974 _scsih_ublock_io_all_device(ioc);
5975 mutex_unlock(&ioc->tm_cmds.mutex);
5979 * _scsih_sas_discovery_event - handle discovery events
5980 * @ioc: per adapter object
5981 * @fw_event: The fw_event_work object
5987 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5988 struct fw_event_work *fw_event)
5990 Mpi2EventDataSasDiscovery_t *event_data =
5991 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5993 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5994 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5995 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5997 if (event_data->DiscoveryStatus)
5998 pr_info("discovery_status(0x%08x)",
5999 le32_to_cpu(event_data->DiscoveryStatus));
6003 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6004 !ioc->sas_hba.num_phys) {
6005 if (disable_discovery > 0 && ioc->shost_recovery) {
6006 /* Wait for the reset to complete */
6007 while (ioc->shost_recovery)
6010 _scsih_sas_host_add(ioc);
6015 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6016 * @ioc: per adapter object
6017 * @handle: device handle for physical disk
6018 * @phys_disk_num: physical disk number
6020 * Return 0 for success, else failure.
6023 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
6025 Mpi2RaidActionRequest_t *mpi_request;
6026 Mpi2RaidActionReply_t *mpi_reply;
6033 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6036 mutex_lock(&ioc->scsih_cmds.mutex);
6038 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
6039 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
6040 ioc->name, __func__);
6044 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
6046 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
6048 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
6049 ioc->name, __func__);
6050 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6055 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
6056 ioc->scsih_cmds.smid = smid;
6057 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
6059 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
6060 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
6061 mpi_request->PhysDiskNum = phys_disk_num;
6063 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
6064 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
6065 handle, phys_disk_num));
6067 init_completion(&ioc->scsih_cmds.done);
6068 mpt3sas_base_put_smid_default(ioc, smid);
6069 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
6071 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
6072 pr_err(MPT3SAS_FMT "%s: timeout\n",
6073 ioc->name, __func__);
6074 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
6080 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
6082 mpi_reply = ioc->scsih_cmds.reply;
6083 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
6084 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
6085 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
6088 ioc_status &= MPI2_IOCSTATUS_MASK;
6089 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6090 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6091 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6092 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
6096 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6097 "IR RAID_ACTION: completed successfully\n",
6102 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6103 mutex_unlock(&ioc->scsih_cmds.mutex);
6106 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
6112 * _scsih_reprobe_lun - reprobing lun
6113 * @sdev: scsi device struct
6114 * @no_uld_attach: sdev->no_uld_attach flag setting
6118 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6121 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6122 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6123 sdev->no_uld_attach ? "hidding" : "exposing");
6124 rc = scsi_device_reprobe(sdev);
6128 * _scsih_sas_volume_add - add new volume
6129 * @ioc: per adapter object
6130 * @element: IR config element data
6136 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
6137 Mpi2EventIrConfigElement_t *element)
6139 struct _raid_device *raid_device;
6140 unsigned long flags;
6142 u16 handle = le16_to_cpu(element->VolDevHandle);
6145 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6148 "failure at %s:%d/%s()!\n", ioc->name,
6149 __FILE__, __LINE__, __func__);
6153 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6154 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6155 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6160 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6163 "failure at %s:%d/%s()!\n", ioc->name,
6164 __FILE__, __LINE__, __func__);
6168 raid_device->id = ioc->sas_id++;
6169 raid_device->channel = RAID_CHANNEL;
6170 raid_device->handle = handle;
6171 raid_device->wwid = wwid;
6172 _scsih_raid_device_add(ioc, raid_device);
6173 if (!ioc->wait_for_discovery_to_complete) {
6174 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6175 raid_device->id, 0);
6177 _scsih_raid_device_remove(ioc, raid_device);
6179 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6180 _scsih_determine_boot_device(ioc, raid_device, 1);
6181 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6186 * _scsih_sas_volume_delete - delete volume
6187 * @ioc: per adapter object
6188 * @handle: volume device handle
6194 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6196 struct _raid_device *raid_device;
6197 unsigned long flags;
6198 struct MPT3SAS_TARGET *sas_target_priv_data;
6199 struct scsi_target *starget = NULL;
6201 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6202 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6204 if (raid_device->starget) {
6205 starget = raid_device->starget;
6206 sas_target_priv_data = starget->hostdata;
6207 sas_target_priv_data->deleted = 1;
6209 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
6210 ioc->name, raid_device->handle,
6211 (unsigned long long) raid_device->wwid);
6212 list_del(&raid_device->list);
6215 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6217 scsi_remove_target(&starget->dev);
6221 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6222 * @ioc: per adapter object
6223 * @element: IR config element data
6229 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6230 Mpi2EventIrConfigElement_t *element)
6232 struct _sas_device *sas_device;
6233 struct scsi_target *starget = NULL;
6234 struct MPT3SAS_TARGET *sas_target_priv_data;
6235 unsigned long flags;
6236 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6238 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6239 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6241 sas_device->volume_handle = 0;
6242 sas_device->volume_wwid = 0;
6243 clear_bit(handle, ioc->pd_handles);
6244 if (sas_device->starget && sas_device->starget->hostdata) {
6245 starget = sas_device->starget;
6246 sas_target_priv_data = starget->hostdata;
6247 sas_target_priv_data->flags &=
6248 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6251 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6255 /* exposing raid component */
6257 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6259 sas_device_put(sas_device);
6263 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6264 * @ioc: per adapter object
6265 * @element: IR config element data
6271 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6272 Mpi2EventIrConfigElement_t *element)
6274 struct _sas_device *sas_device;
6275 struct scsi_target *starget = NULL;
6276 struct MPT3SAS_TARGET *sas_target_priv_data;
6277 unsigned long flags;
6278 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6279 u16 volume_handle = 0;
6280 u64 volume_wwid = 0;
6282 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6284 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6287 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6288 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6290 set_bit(handle, ioc->pd_handles);
6291 if (sas_device->starget && sas_device->starget->hostdata) {
6292 starget = sas_device->starget;
6293 sas_target_priv_data = starget->hostdata;
6294 sas_target_priv_data->flags |=
6295 MPT_TARGET_FLAGS_RAID_COMPONENT;
6296 sas_device->volume_handle = volume_handle;
6297 sas_device->volume_wwid = volume_wwid;
6300 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6304 /* hiding raid component */
6305 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6308 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6310 sas_device_put(sas_device);
6314 * _scsih_sas_pd_delete - delete pd component
6315 * @ioc: per adapter object
6316 * @element: IR config element data
6322 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6323 Mpi2EventIrConfigElement_t *element)
6325 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6327 _scsih_device_remove_by_handle(ioc, handle);
6331 * _scsih_sas_pd_add - remove pd component
6332 * @ioc: per adapter object
6333 * @element: IR config element data
6339 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6340 Mpi2EventIrConfigElement_t *element)
6342 struct _sas_device *sas_device;
6343 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6344 Mpi2ConfigReply_t mpi_reply;
6345 Mpi2SasDevicePage0_t sas_device_pg0;
6350 set_bit(handle, ioc->pd_handles);
6352 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6354 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6355 sas_device_put(sas_device);
6359 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6360 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6361 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6362 ioc->name, __FILE__, __LINE__, __func__);
6366 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6367 MPI2_IOCSTATUS_MASK;
6368 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6369 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6370 ioc->name, __FILE__, __LINE__, __func__);
6374 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6375 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6376 mpt3sas_transport_update_links(ioc, sas_address, handle,
6377 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6379 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6380 _scsih_add_device(ioc, handle, 0, 1);
6384 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6385 * @ioc: per adapter object
6386 * @event_data: event data payload
6392 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6393 Mpi2EventDataIrConfigChangeList_t *event_data)
6395 Mpi2EventIrConfigElement_t *element;
6398 char *reason_str = NULL, *element_str = NULL;
6400 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6402 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6403 ioc->name, (le32_to_cpu(event_data->Flags) &
6404 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6405 "foreign" : "native", event_data->NumElements);
6406 for (i = 0; i < event_data->NumElements; i++, element++) {
6407 switch (element->ReasonCode) {
6408 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6411 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6412 reason_str = "remove";
6414 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6415 reason_str = "no change";
6417 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6418 reason_str = "hide";
6420 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6421 reason_str = "unhide";
6423 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6424 reason_str = "volume_created";
6426 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6427 reason_str = "volume_deleted";
6429 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6430 reason_str = "pd_created";
6432 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6433 reason_str = "pd_deleted";
6436 reason_str = "unknown reason";
6439 element_type = le16_to_cpu(element->ElementFlags) &
6440 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6441 switch (element_type) {
6442 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6443 element_str = "volume";
6445 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6446 element_str = "phys disk";
6448 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6449 element_str = "hot spare";
6452 element_str = "unknown element";
6455 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6456 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6457 reason_str, le16_to_cpu(element->VolDevHandle),
6458 le16_to_cpu(element->PhysDiskDevHandle),
6459 element->PhysDiskNum);
6464 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6465 * @ioc: per adapter object
6466 * @fw_event: The fw_event_work object
6472 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6473 struct fw_event_work *fw_event)
6475 Mpi2EventIrConfigElement_t *element;
6478 Mpi2EventDataIrConfigChangeList_t *event_data =
6479 (Mpi2EventDataIrConfigChangeList_t *)
6480 fw_event->event_data;
6482 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6483 (!ioc->hide_ir_msg))
6484 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6486 foreign_config = (le32_to_cpu(event_data->Flags) &
6487 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6489 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6490 if (ioc->shost_recovery &&
6491 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6492 for (i = 0; i < event_data->NumElements; i++, element++) {
6493 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6494 _scsih_ir_fastpath(ioc,
6495 le16_to_cpu(element->PhysDiskDevHandle),
6496 element->PhysDiskNum);
6501 for (i = 0; i < event_data->NumElements; i++, element++) {
6503 switch (element->ReasonCode) {
6504 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6505 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6506 if (!foreign_config)
6507 _scsih_sas_volume_add(ioc, element);
6509 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6510 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6511 if (!foreign_config)
6512 _scsih_sas_volume_delete(ioc,
6513 le16_to_cpu(element->VolDevHandle));
6515 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6516 if (!ioc->is_warpdrive)
6517 _scsih_sas_pd_hide(ioc, element);
6519 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6520 if (!ioc->is_warpdrive)
6521 _scsih_sas_pd_expose(ioc, element);
6523 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6524 if (!ioc->is_warpdrive)
6525 _scsih_sas_pd_add(ioc, element);
6527 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6528 if (!ioc->is_warpdrive)
6529 _scsih_sas_pd_delete(ioc, element);
6536 * _scsih_sas_ir_volume_event - IR volume event
6537 * @ioc: per adapter object
6538 * @fw_event: The fw_event_work object
6544 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6545 struct fw_event_work *fw_event)
6548 unsigned long flags;
6549 struct _raid_device *raid_device;
6553 Mpi2EventDataIrVolume_t *event_data =
6554 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6556 if (ioc->shost_recovery)
6559 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6562 handle = le16_to_cpu(event_data->VolDevHandle);
6563 state = le32_to_cpu(event_data->NewValue);
6564 if (!ioc->hide_ir_msg)
6565 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6566 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6567 ioc->name, __func__, handle,
6568 le32_to_cpu(event_data->PreviousValue), state));
6570 case MPI2_RAID_VOL_STATE_MISSING:
6571 case MPI2_RAID_VOL_STATE_FAILED:
6572 _scsih_sas_volume_delete(ioc, handle);
6575 case MPI2_RAID_VOL_STATE_ONLINE:
6576 case MPI2_RAID_VOL_STATE_DEGRADED:
6577 case MPI2_RAID_VOL_STATE_OPTIMAL:
6579 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6580 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6581 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6586 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6589 "failure at %s:%d/%s()!\n", ioc->name,
6590 __FILE__, __LINE__, __func__);
6594 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6597 "failure at %s:%d/%s()!\n", ioc->name,
6598 __FILE__, __LINE__, __func__);
6602 raid_device->id = ioc->sas_id++;
6603 raid_device->channel = RAID_CHANNEL;
6604 raid_device->handle = handle;
6605 raid_device->wwid = wwid;
6606 _scsih_raid_device_add(ioc, raid_device);
6607 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6608 raid_device->id, 0);
6610 _scsih_raid_device_remove(ioc, raid_device);
6613 case MPI2_RAID_VOL_STATE_INITIALIZING:
6620 * _scsih_sas_ir_physical_disk_event - PD event
6621 * @ioc: per adapter object
6622 * @fw_event: The fw_event_work object
6628 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6629 struct fw_event_work *fw_event)
6631 u16 handle, parent_handle;
6633 struct _sas_device *sas_device;
6634 Mpi2ConfigReply_t mpi_reply;
6635 Mpi2SasDevicePage0_t sas_device_pg0;
6637 Mpi2EventDataIrPhysicalDisk_t *event_data =
6638 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6641 if (ioc->shost_recovery)
6644 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6647 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6648 state = le32_to_cpu(event_data->NewValue);
6650 if (!ioc->hide_ir_msg)
6651 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6652 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6653 ioc->name, __func__, handle,
6654 le32_to_cpu(event_data->PreviousValue), state));
6657 case MPI2_RAID_PD_STATE_ONLINE:
6658 case MPI2_RAID_PD_STATE_DEGRADED:
6659 case MPI2_RAID_PD_STATE_REBUILDING:
6660 case MPI2_RAID_PD_STATE_OPTIMAL:
6661 case MPI2_RAID_PD_STATE_HOT_SPARE:
6663 if (!ioc->is_warpdrive)
6664 set_bit(handle, ioc->pd_handles);
6666 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6668 sas_device_put(sas_device);
6672 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6673 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6675 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6676 ioc->name, __FILE__, __LINE__, __func__);
6680 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6681 MPI2_IOCSTATUS_MASK;
6682 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6683 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6684 ioc->name, __FILE__, __LINE__, __func__);
6688 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6689 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6690 mpt3sas_transport_update_links(ioc, sas_address, handle,
6691 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6693 _scsih_add_device(ioc, handle, 0, 1);
6697 case MPI2_RAID_PD_STATE_OFFLINE:
6698 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6699 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6706 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6707 * @ioc: per adapter object
6708 * @event_data: event data payload
6714 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6715 Mpi2EventDataIrOperationStatus_t *event_data)
6717 char *reason_str = NULL;
6719 switch (event_data->RAIDOperation) {
6720 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6721 reason_str = "resync";
6723 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6724 reason_str = "online capacity expansion";
6726 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6727 reason_str = "consistency check";
6729 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6730 reason_str = "background init";
6732 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6733 reason_str = "make data consistent";
6740 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6741 "\thandle(0x%04x), percent complete(%d)\n",
6742 ioc->name, reason_str,
6743 le16_to_cpu(event_data->VolDevHandle),
6744 event_data->PercentComplete);
6748 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6749 * @ioc: per adapter object
6750 * @fw_event: The fw_event_work object
6756 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6757 struct fw_event_work *fw_event)
6759 Mpi2EventDataIrOperationStatus_t *event_data =
6760 (Mpi2EventDataIrOperationStatus_t *)
6761 fw_event->event_data;
6762 static struct _raid_device *raid_device;
6763 unsigned long flags;
6766 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6767 (!ioc->hide_ir_msg))
6768 _scsih_sas_ir_operation_status_event_debug(ioc,
6771 /* code added for raid transport support */
6772 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6774 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6775 handle = le16_to_cpu(event_data->VolDevHandle);
6776 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6778 raid_device->percent_complete =
6779 event_data->PercentComplete;
6780 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6785 * _scsih_prep_device_scan - initialize parameters prior to device scan
6786 * @ioc: per adapter object
6788 * Set the deleted flag prior to device scan. If the device is found during
6789 * the scan, then we clear the deleted flag.
6792 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6794 struct MPT3SAS_DEVICE *sas_device_priv_data;
6795 struct scsi_device *sdev;
6797 shost_for_each_device(sdev, ioc->shost) {
6798 sas_device_priv_data = sdev->hostdata;
6799 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6800 sas_device_priv_data->sas_target->deleted = 1;
6805 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6806 * @ioc: per adapter object
6807 * @sas_device_pg0: SAS Device page 0
6809 * After host reset, find out whether devices are still responding.
6810 * Used in _scsih_remove_unresponsive_sas_devices.
6815 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
6816 Mpi2SasDevicePage0_t *sas_device_pg0)
6818 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6819 struct scsi_target *starget;
6820 struct _sas_device *sas_device;
6821 unsigned long flags;
6823 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6824 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6825 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
6826 (sas_device->slot == sas_device_pg0->Slot)) {
6827 sas_device->responding = 1;
6828 starget = sas_device->starget;
6829 if (starget && starget->hostdata) {
6830 sas_target_priv_data = starget->hostdata;
6831 sas_target_priv_data->tm_busy = 0;
6832 sas_target_priv_data->deleted = 0;
6834 sas_target_priv_data = NULL;
6836 starget_printk(KERN_INFO, starget,
6837 "handle(0x%04x), sas_addr(0x%016llx)\n",
6838 sas_device_pg0->DevHandle,
6839 (unsigned long long)
6840 sas_device->sas_address);
6842 if (sas_device->enclosure_handle != 0)
6843 starget_printk(KERN_INFO, starget,
6844 "enclosure logical id(0x%016llx),"
6846 (unsigned long long)
6847 sas_device->enclosure_logical_id,
6850 if (sas_device_pg0->Flags &
6851 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6852 sas_device->enclosure_level =
6853 le16_to_cpu(sas_device_pg0->EnclosureLevel);
6854 memcpy(&sas_device->connector_name[0],
6855 &sas_device_pg0->ConnectorName[0], 4);
6857 sas_device->enclosure_level = 0;
6858 sas_device->connector_name[0] = '\0';
6861 if (sas_device->handle == sas_device_pg0->DevHandle)
6863 pr_info("\thandle changed from(0x%04x)!!!\n",
6864 sas_device->handle);
6865 sas_device->handle = sas_device_pg0->DevHandle;
6866 if (sas_target_priv_data)
6867 sas_target_priv_data->handle =
6868 sas_device_pg0->DevHandle;
6873 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6877 * _scsih_search_responding_sas_devices -
6878 * @ioc: per adapter object
6880 * After host reset, find out whether devices are still responding.
6886 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6888 Mpi2SasDevicePage0_t sas_device_pg0;
6889 Mpi2ConfigReply_t mpi_reply;
6894 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6896 if (list_empty(&ioc->sas_device_list))
6900 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6901 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6903 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6904 MPI2_IOCSTATUS_MASK;
6905 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6907 handle = sas_device_pg0.DevHandle =
6908 le16_to_cpu(sas_device_pg0.DevHandle);
6909 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6910 if (!(_scsih_is_end_device(device_info)))
6912 sas_device_pg0.SASAddress =
6913 le64_to_cpu(sas_device_pg0.SASAddress);
6914 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
6915 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
6919 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6924 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6925 * @ioc: per adapter object
6926 * @wwid: world wide identifier for raid volume
6927 * @handle: device handle
6929 * After host reset, find out whether devices are still responding.
6930 * Used in _scsih_remove_unresponsive_raid_devices.
6935 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6938 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6939 struct scsi_target *starget;
6940 struct _raid_device *raid_device;
6941 unsigned long flags;
6943 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6944 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6945 if (raid_device->wwid == wwid && raid_device->starget) {
6946 starget = raid_device->starget;
6947 if (starget && starget->hostdata) {
6948 sas_target_priv_data = starget->hostdata;
6949 sas_target_priv_data->deleted = 0;
6951 sas_target_priv_data = NULL;
6952 raid_device->responding = 1;
6953 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6954 starget_printk(KERN_INFO, raid_device->starget,
6955 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6956 (unsigned long long)raid_device->wwid);
6959 * WARPDRIVE: The handles of the PDs might have changed
6960 * across the host reset so re-initialize the
6961 * required data for Direct IO
6963 mpt3sas_init_warpdrive_properties(ioc, raid_device);
6964 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6965 if (raid_device->handle == handle) {
6966 spin_unlock_irqrestore(&ioc->raid_device_lock,
6970 pr_info("\thandle changed from(0x%04x)!!!\n",
6971 raid_device->handle);
6972 raid_device->handle = handle;
6973 if (sas_target_priv_data)
6974 sas_target_priv_data->handle = handle;
6975 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6979 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6983 * _scsih_search_responding_raid_devices -
6984 * @ioc: per adapter object
6986 * After host reset, find out whether devices are still responding.
6992 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6994 Mpi2RaidVolPage1_t volume_pg1;
6995 Mpi2RaidVolPage0_t volume_pg0;
6996 Mpi2RaidPhysDiskPage0_t pd_pg0;
6997 Mpi2ConfigReply_t mpi_reply;
7002 if (!ioc->ir_firmware)
7005 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
7008 if (list_empty(&ioc->raid_device_list))
7012 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7013 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7014 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7015 MPI2_IOCSTATUS_MASK;
7016 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7018 handle = le16_to_cpu(volume_pg1.DevHandle);
7020 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7021 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7022 sizeof(Mpi2RaidVolPage0_t)))
7025 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7026 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7027 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7028 _scsih_mark_responding_raid_device(ioc,
7029 le64_to_cpu(volume_pg1.WWID), handle);
7032 /* refresh the pd_handles */
7033 if (!ioc->is_warpdrive) {
7034 phys_disk_num = 0xFF;
7035 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7036 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7037 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7039 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7040 MPI2_IOCSTATUS_MASK;
7041 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7043 phys_disk_num = pd_pg0.PhysDiskNum;
7044 handle = le16_to_cpu(pd_pg0.DevHandle);
7045 set_bit(handle, ioc->pd_handles);
7049 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
7054 * _scsih_mark_responding_expander - mark a expander as responding
7055 * @ioc: per adapter object
7056 * @sas_address: sas address
7059 * After host reset, find out whether devices are still responding.
7060 * Used in _scsih_remove_unresponsive_expanders.
7065 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7068 struct _sas_node *sas_expander;
7069 unsigned long flags;
7072 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7073 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7074 if (sas_expander->sas_address != sas_address)
7076 sas_expander->responding = 1;
7077 if (sas_expander->handle == handle)
7079 pr_info("\texpander(0x%016llx): handle changed" \
7080 " from(0x%04x) to (0x%04x)!!!\n",
7081 (unsigned long long)sas_expander->sas_address,
7082 sas_expander->handle, handle);
7083 sas_expander->handle = handle;
7084 for (i = 0 ; i < sas_expander->num_phys ; i++)
7085 sas_expander->phy[i].handle = handle;
7089 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7093 * _scsih_search_responding_expanders -
7094 * @ioc: per adapter object
7096 * After host reset, find out whether devices are still responding.
7102 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
7104 Mpi2ExpanderPage0_t expander_pg0;
7105 Mpi2ConfigReply_t mpi_reply;
7110 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
7112 if (list_empty(&ioc->sas_expander_list))
7116 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7117 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7119 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7120 MPI2_IOCSTATUS_MASK;
7121 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7124 handle = le16_to_cpu(expander_pg0.DevHandle);
7125 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7126 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7128 (unsigned long long)sas_address);
7129 _scsih_mark_responding_expander(ioc, sas_address, handle);
7133 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
7137 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7138 * @ioc: per adapter object
7143 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7145 struct _sas_device *sas_device, *sas_device_next;
7146 struct _sas_node *sas_expander, *sas_expander_next;
7147 struct _raid_device *raid_device, *raid_device_next;
7148 struct list_head tmp_list;
7149 unsigned long flags;
7152 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
7155 /* removing unresponding end devices */
7156 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
7159 * Iterate, pulling off devices marked as non-responding. We become the
7160 * owner for the reference the list had on any object we prune.
7162 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7163 list_for_each_entry_safe(sas_device, sas_device_next,
7164 &ioc->sas_device_list, list) {
7165 if (!sas_device->responding)
7166 list_move_tail(&sas_device->list, &head);
7168 sas_device->responding = 0;
7170 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7173 * Now, uninitialize and remove the unresponding devices we pruned.
7175 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7176 _scsih_remove_device(ioc, sas_device);
7177 list_del_init(&sas_device->list);
7178 sas_device_put(sas_device);
7181 /* removing unresponding volumes */
7182 if (ioc->ir_firmware) {
7183 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
7185 list_for_each_entry_safe(raid_device, raid_device_next,
7186 &ioc->raid_device_list, list) {
7187 if (!raid_device->responding)
7188 _scsih_sas_volume_delete(ioc,
7189 raid_device->handle);
7191 raid_device->responding = 0;
7195 /* removing unresponding expanders */
7196 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
7198 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7199 INIT_LIST_HEAD(&tmp_list);
7200 list_for_each_entry_safe(sas_expander, sas_expander_next,
7201 &ioc->sas_expander_list, list) {
7202 if (!sas_expander->responding)
7203 list_move_tail(&sas_expander->list, &tmp_list);
7205 sas_expander->responding = 0;
7207 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7208 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7210 list_del(&sas_expander->list);
7211 _scsih_expander_node_remove(ioc, sas_expander);
7214 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
7217 /* unblock devices */
7218 _scsih_ublock_io_all_device(ioc);
7222 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
7223 struct _sas_node *sas_expander, u16 handle)
7225 Mpi2ExpanderPage1_t expander_pg1;
7226 Mpi2ConfigReply_t mpi_reply;
7229 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7230 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
7231 &expander_pg1, i, handle))) {
7232 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7233 ioc->name, __FILE__, __LINE__, __func__);
7237 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
7238 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7239 expander_pg1.NegotiatedLinkRate >> 4);
7244 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7245 * @ioc: per adapter object
7250 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7252 Mpi2ExpanderPage0_t expander_pg0;
7253 Mpi2SasDevicePage0_t sas_device_pg0;
7254 Mpi2RaidVolPage1_t volume_pg1;
7255 Mpi2RaidVolPage0_t volume_pg0;
7256 Mpi2RaidPhysDiskPage0_t pd_pg0;
7257 Mpi2EventIrConfigElement_t element;
7258 Mpi2ConfigReply_t mpi_reply;
7261 u16 handle, parent_handle;
7263 struct _sas_device *sas_device;
7264 struct _sas_node *expander_device;
7265 static struct _raid_device *raid_device;
7267 unsigned long flags;
7269 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7271 _scsih_sas_host_refresh(ioc);
7273 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7277 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7278 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7279 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7280 MPI2_IOCSTATUS_MASK;
7281 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7282 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7283 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7284 ioc->name, ioc_status,
7285 le32_to_cpu(mpi_reply.IOCLogInfo));
7288 handle = le16_to_cpu(expander_pg0.DevHandle);
7289 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7290 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7291 ioc, le64_to_cpu(expander_pg0.SASAddress));
7292 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7293 if (expander_device)
7294 _scsih_refresh_expander_links(ioc, expander_device,
7297 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7298 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7299 handle, (unsigned long long)
7300 le64_to_cpu(expander_pg0.SASAddress));
7301 _scsih_expander_add(ioc, handle);
7302 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7303 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7304 handle, (unsigned long long)
7305 le64_to_cpu(expander_pg0.SASAddress));
7309 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7312 if (!ioc->ir_firmware)
7315 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7318 phys_disk_num = 0xFF;
7319 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7320 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7322 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7323 MPI2_IOCSTATUS_MASK;
7324 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7325 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7326 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7327 ioc->name, ioc_status,
7328 le32_to_cpu(mpi_reply.IOCLogInfo));
7331 phys_disk_num = pd_pg0.PhysDiskNum;
7332 handle = le16_to_cpu(pd_pg0.DevHandle);
7333 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7335 sas_device_put(sas_device);
7338 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7339 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7342 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7343 MPI2_IOCSTATUS_MASK;
7344 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7345 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7346 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7347 ioc->name, ioc_status,
7348 le32_to_cpu(mpi_reply.IOCLogInfo));
7351 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7352 if (!_scsih_get_sas_address(ioc, parent_handle,
7354 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7355 " handle (0x%04x), sas_addr(0x%016llx)\n",
7356 ioc->name, handle, (unsigned long long)
7357 le64_to_cpu(sas_device_pg0.SASAddress));
7358 mpt3sas_transport_update_links(ioc, sas_address,
7359 handle, sas_device_pg0.PhyNum,
7360 MPI2_SAS_NEG_LINK_RATE_1_5);
7361 set_bit(handle, ioc->pd_handles);
7363 /* This will retry adding the end device.
7364 * _scsih_add_device() will decide on retries and
7365 * return "1" when it should be retried
7367 while (_scsih_add_device(ioc, handle, retry_count++,
7371 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7372 " handle (0x%04x), sas_addr(0x%016llx)\n",
7373 ioc->name, handle, (unsigned long long)
7374 le64_to_cpu(sas_device_pg0.SASAddress));
7378 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7381 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7385 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7386 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7387 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7388 MPI2_IOCSTATUS_MASK;
7389 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7390 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7391 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7392 ioc->name, ioc_status,
7393 le32_to_cpu(mpi_reply.IOCLogInfo));
7396 handle = le16_to_cpu(volume_pg1.DevHandle);
7397 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7398 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7399 le64_to_cpu(volume_pg1.WWID));
7400 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7403 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7404 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7405 sizeof(Mpi2RaidVolPage0_t)))
7407 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7408 MPI2_IOCSTATUS_MASK;
7409 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7410 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7411 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7412 ioc->name, ioc_status,
7413 le32_to_cpu(mpi_reply.IOCLogInfo));
7416 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7417 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7418 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7419 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7420 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7421 element.VolDevHandle = volume_pg1.DevHandle;
7423 "\tBEFORE adding volume: handle (0x%04x)\n",
7424 ioc->name, volume_pg1.DevHandle);
7425 _scsih_sas_volume_add(ioc, &element);
7427 "\tAFTER adding volume: handle (0x%04x)\n",
7428 ioc->name, volume_pg1.DevHandle);
7432 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7437 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7442 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7443 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7445 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7446 MPI2_IOCSTATUS_MASK;
7447 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7448 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7449 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7450 ioc->name, ioc_status,
7451 le32_to_cpu(mpi_reply.IOCLogInfo));
7454 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7455 if (!(_scsih_is_end_device(
7456 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7458 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7459 le64_to_cpu(sas_device_pg0.SASAddress));
7461 sas_device_put(sas_device);
7464 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7465 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7466 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7467 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7468 handle, (unsigned long long)
7469 le64_to_cpu(sas_device_pg0.SASAddress));
7470 mpt3sas_transport_update_links(ioc, sas_address, handle,
7471 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7473 /* This will retry adding the end device.
7474 * _scsih_add_device() will decide on retries and
7475 * return "1" when it should be retried
7477 while (_scsih_add_device(ioc, handle, retry_count++,
7481 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7482 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7483 handle, (unsigned long long)
7484 le64_to_cpu(sas_device_pg0.SASAddress));
7487 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7490 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7493 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7494 * @ioc: per adapter object
7495 * @reset_phase: phase
7497 * The handler for doing any required cleanup or initialization.
7499 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7500 * MPT3_IOC_DONE_RESET
7505 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7507 switch (reset_phase) {
7508 case MPT3_IOC_PRE_RESET:
7509 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7510 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7512 case MPT3_IOC_AFTER_RESET:
7513 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7514 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7515 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7516 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7517 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7518 complete(&ioc->scsih_cmds.done);
7520 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7521 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7522 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7523 complete(&ioc->tm_cmds.done);
7526 _scsih_fw_event_cleanup_queue(ioc);
7527 _scsih_flush_running_cmds(ioc);
7529 case MPT3_IOC_DONE_RESET:
7530 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7531 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7532 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7533 !ioc->sas_hba.num_phys)) {
7534 _scsih_prep_device_scan(ioc);
7535 _scsih_search_responding_sas_devices(ioc);
7536 _scsih_search_responding_raid_devices(ioc);
7537 _scsih_search_responding_expanders(ioc);
7538 _scsih_error_recovery_delete_devices(ioc);
7545 * _mpt3sas_fw_work - delayed task for processing firmware events
7546 * @ioc: per adapter object
7547 * @fw_event: The fw_event_work object
7553 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7555 _scsih_fw_event_del_from_list(ioc, fw_event);
7557 /* the queue is being flushed so ignore this event */
7558 if (ioc->remove_host || ioc->pci_error_recovery) {
7559 fw_event_work_put(fw_event);
7563 switch (fw_event->event) {
7564 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7565 mpt3sas_process_trigger_data(ioc,
7566 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7567 fw_event->event_data);
7569 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7570 while (scsi_host_in_recovery(ioc->shost) ||
7571 ioc->shost_recovery) {
7573 * If we're unloading, bail. Otherwise, this can become
7576 if (ioc->remove_host)
7580 _scsih_remove_unresponding_sas_devices(ioc);
7581 _scsih_scan_for_devices_after_reset(ioc);
7583 case MPT3SAS_PORT_ENABLE_COMPLETE:
7584 ioc->start_scan = 0;
7585 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7586 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7588 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7589 "port enable: complete from worker thread\n",
7592 case MPT3SAS_TURN_ON_PFA_LED:
7593 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7595 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7596 _scsih_sas_topology_change_event(ioc, fw_event);
7598 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7599 _scsih_sas_device_status_change_event(ioc, fw_event);
7601 case MPI2_EVENT_SAS_DISCOVERY:
7602 _scsih_sas_discovery_event(ioc, fw_event);
7604 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7605 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7607 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7608 _scsih_sas_enclosure_dev_status_change_event(ioc,
7611 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7612 _scsih_sas_ir_config_change_event(ioc, fw_event);
7614 case MPI2_EVENT_IR_VOLUME:
7615 _scsih_sas_ir_volume_event(ioc, fw_event);
7617 case MPI2_EVENT_IR_PHYSICAL_DISK:
7618 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7620 case MPI2_EVENT_IR_OPERATION_STATUS:
7621 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7625 fw_event_work_put(fw_event);
7629 * _firmware_event_work
7630 * @ioc: per adapter object
7631 * @work: The fw_event_work object
7634 * wrappers for the work thread handling firmware events
7640 _firmware_event_work(struct work_struct *work)
7642 struct fw_event_work *fw_event = container_of(work,
7643 struct fw_event_work, work);
7645 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7649 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7650 * @ioc: per adapter object
7651 * @msix_index: MSIX table index supplied by the OS
7652 * @reply: reply message frame(lower 32bit addr)
7653 * Context: interrupt.
7655 * This function merely adds a new work task into ioc->firmware_event_thread.
7656 * The tasks are worked from _firmware_event_work in user context.
7658 * Return 1 meaning mf should be freed from _base_interrupt
7659 * 0 means the mf is freed from this function.
7662 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7665 struct fw_event_work *fw_event;
7666 Mpi2EventNotificationReply_t *mpi_reply;
7670 /* events turned off due to host reset or driver unloading */
7671 if (ioc->remove_host || ioc->pci_error_recovery)
7674 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7676 if (unlikely(!mpi_reply)) {
7677 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7678 ioc->name, __FILE__, __LINE__, __func__);
7682 event = le16_to_cpu(mpi_reply->Event);
7684 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7685 mpt3sas_trigger_event(ioc, event, 0);
7689 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7691 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7692 (Mpi2EventDataSasBroadcastPrimitive_t *)
7693 mpi_reply->EventData;
7695 if (baen_data->Primitive !=
7696 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7699 if (ioc->broadcast_aen_busy) {
7700 ioc->broadcast_aen_pending++;
7703 ioc->broadcast_aen_busy = 1;
7707 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7708 _scsih_check_topo_delete_events(ioc,
7709 (Mpi2EventDataSasTopologyChangeList_t *)
7710 mpi_reply->EventData);
7712 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7713 _scsih_check_ir_config_unhide_events(ioc,
7714 (Mpi2EventDataIrConfigChangeList_t *)
7715 mpi_reply->EventData);
7717 case MPI2_EVENT_IR_VOLUME:
7718 _scsih_check_volume_delete_events(ioc,
7719 (Mpi2EventDataIrVolume_t *)
7720 mpi_reply->EventData);
7722 case MPI2_EVENT_LOG_ENTRY_ADDED:
7724 Mpi2EventDataLogEntryAdded_t *log_entry;
7727 if (!ioc->is_warpdrive)
7730 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7731 mpi_reply->EventData;
7732 log_code = (u32 *)log_entry->LogData;
7734 if (le16_to_cpu(log_entry->LogEntryQualifier)
7735 != MPT2_WARPDRIVE_LOGENTRY)
7738 switch (le32_to_cpu(*log_code)) {
7739 case MPT2_WARPDRIVE_LC_SSDT:
7740 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7741 "IO Throttling has occurred in the WarpDrive "
7742 "subsystem. Check WarpDrive documentation for "
7743 "additional details.\n", ioc->name);
7745 case MPT2_WARPDRIVE_LC_SSDLW:
7746 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7747 "Program/Erase Cycles for the WarpDrive subsystem "
7748 "in degraded range. Check WarpDrive documentation "
7749 "for additional details.\n", ioc->name);
7751 case MPT2_WARPDRIVE_LC_SSDLF:
7752 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7753 "There are no Program/Erase Cycles for the "
7754 "WarpDrive subsystem. The storage device will be "
7755 "in read-only mode. Check WarpDrive documentation "
7756 "for additional details.\n", ioc->name);
7758 case MPT2_WARPDRIVE_LC_BRMF:
7759 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7760 "The Backup Rail Monitor has failed on the "
7761 "WarpDrive subsystem. Check WarpDrive "
7762 "documentation for additional details.\n",
7769 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7770 case MPI2_EVENT_IR_OPERATION_STATUS:
7771 case MPI2_EVENT_SAS_DISCOVERY:
7772 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7773 case MPI2_EVENT_IR_PHYSICAL_DISK:
7776 case MPI2_EVENT_TEMP_THRESHOLD:
7777 _scsih_temp_threshold_events(ioc,
7778 (Mpi2EventDataTemperature_t *)
7779 mpi_reply->EventData);
7782 default: /* ignore the rest */
7786 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7787 fw_event = alloc_fw_event_work(sz);
7789 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7790 ioc->name, __FILE__, __LINE__, __func__);
7794 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7795 fw_event->ioc = ioc;
7796 fw_event->VF_ID = mpi_reply->VF_ID;
7797 fw_event->VP_ID = mpi_reply->VP_ID;
7798 fw_event->event = event;
7799 _scsih_fw_event_add(ioc, fw_event);
7800 fw_event_work_put(fw_event);
7805 * _scsih_expander_node_remove - removing expander device from list.
7806 * @ioc: per adapter object
7807 * @sas_expander: the sas_device object
7808 * Context: Calling function should acquire ioc->sas_node_lock.
7810 * Removing object and freeing associated memory from the
7811 * ioc->sas_expander_list.
7816 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7817 struct _sas_node *sas_expander)
7819 struct _sas_port *mpt3sas_port, *next;
7821 /* remove sibling ports attached to this expander */
7822 list_for_each_entry_safe(mpt3sas_port, next,
7823 &sas_expander->sas_port_list, port_list) {
7824 if (ioc->shost_recovery)
7826 if (mpt3sas_port->remote_identify.device_type ==
7828 mpt3sas_device_remove_by_sas_address(ioc,
7829 mpt3sas_port->remote_identify.sas_address);
7830 else if (mpt3sas_port->remote_identify.device_type ==
7831 SAS_EDGE_EXPANDER_DEVICE ||
7832 mpt3sas_port->remote_identify.device_type ==
7833 SAS_FANOUT_EXPANDER_DEVICE)
7834 mpt3sas_expander_remove(ioc,
7835 mpt3sas_port->remote_identify.sas_address);
7838 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7839 sas_expander->sas_address_parent);
7842 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7844 sas_expander->handle, (unsigned long long)
7845 sas_expander->sas_address);
7847 kfree(sas_expander->phy);
7848 kfree(sas_expander);
7852 * _scsih_ir_shutdown - IR shutdown notification
7853 * @ioc: per adapter object
7855 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7856 * the host system is shutting down.
7861 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7863 Mpi2RaidActionRequest_t *mpi_request;
7864 Mpi2RaidActionReply_t *mpi_reply;
7867 /* is IR firmware build loaded ? */
7868 if (!ioc->ir_firmware)
7871 /* are there any volumes ? */
7872 if (list_empty(&ioc->raid_device_list))
7875 mutex_lock(&ioc->scsih_cmds.mutex);
7877 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7878 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7879 ioc->name, __func__);
7882 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7884 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7886 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7887 ioc->name, __func__);
7888 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7892 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7893 ioc->scsih_cmds.smid = smid;
7894 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7896 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7897 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7899 if (!ioc->hide_ir_msg)
7900 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7901 init_completion(&ioc->scsih_cmds.done);
7902 mpt3sas_base_put_smid_default(ioc, smid);
7903 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7905 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7906 pr_err(MPT3SAS_FMT "%s: timeout\n",
7907 ioc->name, __func__);
7911 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7912 mpi_reply = ioc->scsih_cmds.reply;
7913 if (!ioc->hide_ir_msg)
7914 pr_info(MPT3SAS_FMT "IR shutdown "
7915 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7916 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7917 le32_to_cpu(mpi_reply->IOCLogInfo));
7921 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7922 mutex_unlock(&ioc->scsih_cmds.mutex);
7926 * scsih_remove - detach and remove add host
7927 * @pdev: PCI device struct
7929 * Routine called when unloading the driver.
7932 void scsih_remove(struct pci_dev *pdev)
7934 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7935 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7936 struct _sas_port *mpt3sas_port, *next_port;
7937 struct _raid_device *raid_device, *next;
7938 struct MPT3SAS_TARGET *sas_target_priv_data;
7939 struct workqueue_struct *wq;
7940 unsigned long flags;
7942 ioc->remove_host = 1;
7943 _scsih_fw_event_cleanup_queue(ioc);
7945 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7946 wq = ioc->firmware_event_thread;
7947 ioc->firmware_event_thread = NULL;
7948 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7950 destroy_workqueue(wq);
7952 /* release all the volumes */
7953 _scsih_ir_shutdown(ioc);
7954 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7956 if (raid_device->starget) {
7957 sas_target_priv_data =
7958 raid_device->starget->hostdata;
7959 sas_target_priv_data->deleted = 1;
7960 scsi_remove_target(&raid_device->starget->dev);
7962 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7963 ioc->name, raid_device->handle,
7964 (unsigned long long) raid_device->wwid);
7965 _scsih_raid_device_remove(ioc, raid_device);
7968 /* free ports attached to the sas_host */
7969 list_for_each_entry_safe(mpt3sas_port, next_port,
7970 &ioc->sas_hba.sas_port_list, port_list) {
7971 if (mpt3sas_port->remote_identify.device_type ==
7973 mpt3sas_device_remove_by_sas_address(ioc,
7974 mpt3sas_port->remote_identify.sas_address);
7975 else if (mpt3sas_port->remote_identify.device_type ==
7976 SAS_EDGE_EXPANDER_DEVICE ||
7977 mpt3sas_port->remote_identify.device_type ==
7978 SAS_FANOUT_EXPANDER_DEVICE)
7979 mpt3sas_expander_remove(ioc,
7980 mpt3sas_port->remote_identify.sas_address);
7983 /* free phys attached to the sas_host */
7984 if (ioc->sas_hba.num_phys) {
7985 kfree(ioc->sas_hba.phy);
7986 ioc->sas_hba.phy = NULL;
7987 ioc->sas_hba.num_phys = 0;
7990 sas_remove_host(shost);
7991 scsi_remove_host(shost);
7992 mpt3sas_base_detach(ioc);
7993 spin_lock(&gioc_lock);
7994 list_del(&ioc->list);
7995 spin_unlock(&gioc_lock);
7996 scsi_host_put(shost);
8000 * scsih_shutdown - routine call during system shutdown
8001 * @pdev: PCI device struct
8006 scsih_shutdown(struct pci_dev *pdev)
8008 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8009 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8010 struct workqueue_struct *wq;
8011 unsigned long flags;
8013 ioc->remove_host = 1;
8014 _scsih_fw_event_cleanup_queue(ioc);
8016 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8017 wq = ioc->firmware_event_thread;
8018 ioc->firmware_event_thread = NULL;
8019 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8021 destroy_workqueue(wq);
8023 _scsih_ir_shutdown(ioc);
8024 mpt3sas_base_detach(ioc);
8029 * _scsih_probe_boot_devices - reports 1st device
8030 * @ioc: per adapter object
8032 * If specified in bios page 2, this routine reports the 1st
8033 * device scsi-ml or sas transport for persistent boot device
8034 * purposes. Please refer to function _scsih_determine_boot_device()
8037 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
8041 struct _sas_device *sas_device;
8042 struct _raid_device *raid_device;
8044 u64 sas_address_parent;
8046 unsigned long flags;
8049 /* no Bios, return immediately */
8050 if (!ioc->bios_pg3.BiosVersion)
8055 if (ioc->req_boot_device.device) {
8056 device = ioc->req_boot_device.device;
8057 is_raid = ioc->req_boot_device.is_raid;
8058 } else if (ioc->req_alt_boot_device.device) {
8059 device = ioc->req_alt_boot_device.device;
8060 is_raid = ioc->req_alt_boot_device.is_raid;
8061 } else if (ioc->current_boot_device.device) {
8062 device = ioc->current_boot_device.device;
8063 is_raid = ioc->current_boot_device.is_raid;
8070 raid_device = device;
8071 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8072 raid_device->id, 0);
8074 _scsih_raid_device_remove(ioc, raid_device);
8076 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8077 sas_device = device;
8078 handle = sas_device->handle;
8079 sas_address_parent = sas_device->sas_address_parent;
8080 sas_address = sas_device->sas_address;
8081 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8082 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8084 if (ioc->hide_drives)
8086 if (!mpt3sas_transport_port_add(ioc, handle,
8087 sas_address_parent)) {
8088 _scsih_sas_device_remove(ioc, sas_device);
8089 } else if (!sas_device->starget) {
8090 if (!ioc->is_driver_loading) {
8091 mpt3sas_transport_port_remove(ioc,
8093 sas_address_parent);
8094 _scsih_sas_device_remove(ioc, sas_device);
8101 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8102 * @ioc: per adapter object
8104 * Called during initial loading of the driver.
8107 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
8109 struct _raid_device *raid_device, *raid_next;
8112 list_for_each_entry_safe(raid_device, raid_next,
8113 &ioc->raid_device_list, list) {
8114 if (raid_device->starget)
8116 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8117 raid_device->id, 0);
8119 _scsih_raid_device_remove(ioc, raid_device);
8123 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8125 struct _sas_device *sas_device = NULL;
8126 unsigned long flags;
8128 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8129 if (!list_empty(&ioc->sas_device_init_list)) {
8130 sas_device = list_first_entry(&ioc->sas_device_init_list,
8131 struct _sas_device, list);
8132 sas_device_get(sas_device);
8134 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8139 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8140 struct _sas_device *sas_device)
8142 unsigned long flags;
8144 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8147 * Since we dropped the lock during the call to port_add(), we need to
8148 * be careful here that somebody else didn't move or delete this item
8149 * while we were busy with other things.
8151 * If it was on the list, we need a put() for the reference the list
8152 * had. Either way, we need a get() for the destination list.
8154 if (!list_empty(&sas_device->list)) {
8155 list_del_init(&sas_device->list);
8156 sas_device_put(sas_device);
8159 sas_device_get(sas_device);
8160 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8162 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8166 * _scsih_probe_sas - reporting sas devices to sas transport
8167 * @ioc: per adapter object
8169 * Called during initial loading of the driver.
8172 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
8174 struct _sas_device *sas_device;
8176 if (ioc->hide_drives)
8179 while ((sas_device = get_next_sas_device(ioc))) {
8180 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
8181 sas_device->sas_address_parent)) {
8182 _scsih_sas_device_remove(ioc, sas_device);
8183 sas_device_put(sas_device);
8185 } else if (!sas_device->starget) {
8187 * When asyn scanning is enabled, its not possible to
8188 * remove devices while scanning is turned on due to an
8189 * oops in scsi_sysfs_add_sdev()->add_device()->
8190 * sysfs_addrm_start()
8192 if (!ioc->is_driver_loading) {
8193 mpt3sas_transport_port_remove(ioc,
8194 sas_device->sas_address,
8195 sas_device->sas_address_parent);
8196 _scsih_sas_device_remove(ioc, sas_device);
8197 sas_device_put(sas_device);
8201 sas_device_make_active(ioc, sas_device);
8202 sas_device_put(sas_device);
8207 * _scsih_probe_devices - probing for devices
8208 * @ioc: per adapter object
8210 * Called during initial loading of the driver.
8213 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
8215 u16 volume_mapping_flags;
8217 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8218 return; /* return when IOC doesn't support initiator mode */
8220 _scsih_probe_boot_devices(ioc);
8222 if (ioc->ir_firmware) {
8223 volume_mapping_flags =
8224 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8225 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8226 if (volume_mapping_flags ==
8227 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8228 _scsih_probe_raid(ioc);
8229 _scsih_probe_sas(ioc);
8231 _scsih_probe_sas(ioc);
8232 _scsih_probe_raid(ioc);
8235 _scsih_probe_sas(ioc);
8239 * scsih_scan_start - scsi lld callback for .scan_start
8240 * @shost: SCSI host pointer
8242 * The shost has the ability to discover targets on its own instead
8243 * of scanning the entire bus. In our implemention, we will kick off
8244 * firmware discovery.
8247 scsih_scan_start(struct Scsi_Host *shost)
8249 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8251 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8252 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
8254 if (disable_discovery > 0)
8257 ioc->start_scan = 1;
8258 rc = mpt3sas_port_enable(ioc);
8261 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
8265 * scsih_scan_finished - scsi lld callback for .scan_finished
8266 * @shost: SCSI host pointer
8267 * @time: elapsed time of the scan in jiffies
8269 * This function will be called periodicallyn until it returns 1 with the
8270 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8271 * we wait for firmware discovery to complete, then return 1.
8274 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8276 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8278 if (disable_discovery > 0) {
8279 ioc->is_driver_loading = 0;
8280 ioc->wait_for_discovery_to_complete = 0;
8284 if (time >= (300 * HZ)) {
8285 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8287 "port enable: FAILED with timeout (timeout=300s)\n",
8289 ioc->is_driver_loading = 0;
8293 if (ioc->start_scan)
8296 if (ioc->start_scan_failed) {
8298 "port enable: FAILED with (ioc_status=0x%08x)\n",
8299 ioc->name, ioc->start_scan_failed);
8300 ioc->is_driver_loading = 0;
8301 ioc->wait_for_discovery_to_complete = 0;
8302 ioc->remove_host = 1;
8306 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
8307 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8309 if (ioc->wait_for_discovery_to_complete) {
8310 ioc->wait_for_discovery_to_complete = 0;
8311 _scsih_probe_devices(ioc);
8313 mpt3sas_base_start_watchdog(ioc);
8314 ioc->is_driver_loading = 0;
8318 /* shost template for SAS 2.0 HBA devices */
8319 static struct scsi_host_template mpt2sas_driver_template = {
8320 .module = THIS_MODULE,
8321 .name = "Fusion MPT SAS Host",
8322 .proc_name = MPT2SAS_DRIVER_NAME,
8323 .queuecommand = scsih_qcmd,
8324 .target_alloc = scsih_target_alloc,
8325 .slave_alloc = scsih_slave_alloc,
8326 .slave_configure = scsih_slave_configure,
8327 .target_destroy = scsih_target_destroy,
8328 .slave_destroy = scsih_slave_destroy,
8329 .scan_finished = scsih_scan_finished,
8330 .scan_start = scsih_scan_start,
8331 .change_queue_depth = scsih_change_queue_depth,
8332 .eh_abort_handler = scsih_abort,
8333 .eh_device_reset_handler = scsih_dev_reset,
8334 .eh_target_reset_handler = scsih_target_reset,
8335 .eh_host_reset_handler = scsih_host_reset,
8336 .bios_param = scsih_bios_param,
8339 .sg_tablesize = MPT2SAS_SG_DEPTH,
8340 .max_sectors = 32767,
8342 .use_clustering = ENABLE_CLUSTERING,
8343 .shost_attrs = mpt3sas_host_attrs,
8344 .sdev_attrs = mpt3sas_dev_attrs,
8345 .track_queue_depth = 1,
8348 /* raid transport support for SAS 2.0 HBA devices */
8349 static struct raid_function_template mpt2sas_raid_functions = {
8350 .cookie = &mpt2sas_driver_template,
8351 .is_raid = scsih_is_raid,
8352 .get_resync = scsih_get_resync,
8353 .get_state = scsih_get_state,
8356 /* shost template for SAS 3.0 HBA devices */
8357 static struct scsi_host_template mpt3sas_driver_template = {
8358 .module = THIS_MODULE,
8359 .name = "Fusion MPT SAS Host",
8360 .proc_name = MPT3SAS_DRIVER_NAME,
8361 .queuecommand = scsih_qcmd,
8362 .target_alloc = scsih_target_alloc,
8363 .slave_alloc = scsih_slave_alloc,
8364 .slave_configure = scsih_slave_configure,
8365 .target_destroy = scsih_target_destroy,
8366 .slave_destroy = scsih_slave_destroy,
8367 .scan_finished = scsih_scan_finished,
8368 .scan_start = scsih_scan_start,
8369 .change_queue_depth = scsih_change_queue_depth,
8370 .eh_abort_handler = scsih_abort,
8371 .eh_device_reset_handler = scsih_dev_reset,
8372 .eh_target_reset_handler = scsih_target_reset,
8373 .eh_host_reset_handler = scsih_host_reset,
8374 .bios_param = scsih_bios_param,
8377 .sg_tablesize = MPT3SAS_SG_DEPTH,
8378 .max_sectors = 32767,
8380 .use_clustering = ENABLE_CLUSTERING,
8381 .shost_attrs = mpt3sas_host_attrs,
8382 .sdev_attrs = mpt3sas_dev_attrs,
8383 .track_queue_depth = 1,
8386 /* raid transport support for SAS 3.0 HBA devices */
8387 static struct raid_function_template mpt3sas_raid_functions = {
8388 .cookie = &mpt3sas_driver_template,
8389 .is_raid = scsih_is_raid,
8390 .get_resync = scsih_get_resync,
8391 .get_state = scsih_get_state,
8395 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8396 * this device belongs to.
8397 * @pdev: PCI device struct
8399 * return MPI2_VERSION for SAS 2.0 HBA devices,
8400 * MPI25_VERSION for SAS 3.0 HBA devices.
8403 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8406 switch (pdev->device) {
8407 case MPI2_MFGPAGE_DEVID_SSS6200:
8408 case MPI2_MFGPAGE_DEVID_SAS2004:
8409 case MPI2_MFGPAGE_DEVID_SAS2008:
8410 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8411 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8412 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8413 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8414 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8415 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8416 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8417 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8418 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8419 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8420 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8421 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8422 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8423 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8424 return MPI2_VERSION;
8425 case MPI25_MFGPAGE_DEVID_SAS3004:
8426 case MPI25_MFGPAGE_DEVID_SAS3008:
8427 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8428 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8429 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8430 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8431 return MPI25_VERSION;
8437 * _scsih_probe - attach and add scsi host
8438 * @pdev: PCI device struct
8439 * @id: pci device id
8441 * Returns 0 success, anything else error.
8444 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8446 struct MPT3SAS_ADAPTER *ioc;
8447 struct Scsi_Host *shost = NULL;
8449 u16 hba_mpi_version;
8451 /* Determine in which MPI version class this pci device belongs */
8452 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8453 if (hba_mpi_version == 0)
8456 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8457 * for other generation HBA's return with -ENODEV
8459 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8462 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8463 * for other generation HBA's return with -ENODEV
8465 if ((hbas_to_enumerate == 2) && (hba_mpi_version != MPI25_VERSION))
8468 switch (hba_mpi_version) {
8470 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8471 shost = scsi_host_alloc(&mpt2sas_driver_template,
8472 sizeof(struct MPT3SAS_ADAPTER));
8475 ioc = shost_priv(shost);
8476 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8477 ioc->hba_mpi_version_belonged = hba_mpi_version;
8478 ioc->id = mpt2_ids++;
8479 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8480 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8481 ioc->is_warpdrive = 1;
8482 ioc->hide_ir_msg = 1;
8484 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8487 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8488 shost = scsi_host_alloc(&mpt3sas_driver_template,
8489 sizeof(struct MPT3SAS_ADAPTER));
8492 ioc = shost_priv(shost);
8493 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8494 ioc->hba_mpi_version_belonged = hba_mpi_version;
8495 ioc->id = mpt3_ids++;
8496 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8497 if (pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION)
8498 ioc->msix96_vector = 1;
8504 INIT_LIST_HEAD(&ioc->list);
8505 spin_lock(&gioc_lock);
8506 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8507 spin_unlock(&gioc_lock);
8510 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8511 ioc->tm_cb_idx = tm_cb_idx;
8512 ioc->ctl_cb_idx = ctl_cb_idx;
8513 ioc->base_cb_idx = base_cb_idx;
8514 ioc->port_enable_cb_idx = port_enable_cb_idx;
8515 ioc->transport_cb_idx = transport_cb_idx;
8516 ioc->scsih_cb_idx = scsih_cb_idx;
8517 ioc->config_cb_idx = config_cb_idx;
8518 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8519 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8520 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8521 ioc->logging_level = logging_level;
8522 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8523 /* misc semaphores and spin locks */
8524 mutex_init(&ioc->reset_in_progress_mutex);
8525 /* initializing pci_access_mutex lock */
8526 mutex_init(&ioc->pci_access_mutex);
8527 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8528 spin_lock_init(&ioc->scsi_lookup_lock);
8529 spin_lock_init(&ioc->sas_device_lock);
8530 spin_lock_init(&ioc->sas_node_lock);
8531 spin_lock_init(&ioc->fw_event_lock);
8532 spin_lock_init(&ioc->raid_device_lock);
8533 spin_lock_init(&ioc->diag_trigger_lock);
8535 INIT_LIST_HEAD(&ioc->sas_device_list);
8536 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8537 INIT_LIST_HEAD(&ioc->sas_expander_list);
8538 INIT_LIST_HEAD(&ioc->fw_event_list);
8539 INIT_LIST_HEAD(&ioc->raid_device_list);
8540 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8541 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8542 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8543 INIT_LIST_HEAD(&ioc->reply_queue_list);
8545 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8547 /* init shost parameters */
8548 shost->max_cmd_len = 32;
8549 shost->max_lun = max_lun;
8550 shost->transportt = mpt3sas_transport_template;
8551 shost->unique_id = ioc->id;
8553 if (max_sectors != 0xFFFF) {
8554 if (max_sectors < 64) {
8555 shost->max_sectors = 64;
8556 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8557 "for max_sectors, range is 64 to 32767. Assigning "
8558 "value of 64.\n", ioc->name, max_sectors);
8559 } else if (max_sectors > 32767) {
8560 shost->max_sectors = 32767;
8561 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8562 "for max_sectors, range is 64 to 32767. Assigning "
8563 "default value of 32767.\n", ioc->name,
8566 shost->max_sectors = max_sectors & 0xFFFE;
8568 "The max_sectors value is set to %d\n",
8569 ioc->name, shost->max_sectors);
8573 /* register EEDP capabilities with SCSI layer */
8575 scsi_host_set_prot(shost, prot_mask);
8577 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8578 | SHOST_DIF_TYPE2_PROTECTION
8579 | SHOST_DIF_TYPE3_PROTECTION);
8581 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8584 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8585 "fw_event_%s%d", ioc->driver_name, ioc->id);
8586 ioc->firmware_event_thread = alloc_ordered_workqueue(
8587 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8588 if (!ioc->firmware_event_thread) {
8589 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8590 ioc->name, __FILE__, __LINE__, __func__);
8592 goto out_thread_fail;
8595 ioc->is_driver_loading = 1;
8596 if ((mpt3sas_base_attach(ioc))) {
8597 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8598 ioc->name, __FILE__, __LINE__, __func__);
8600 goto out_attach_fail;
8603 if (ioc->is_warpdrive) {
8604 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8605 ioc->hide_drives = 0;
8606 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8607 ioc->hide_drives = 1;
8609 if (mpt3sas_get_num_volumes(ioc))
8610 ioc->hide_drives = 1;
8612 ioc->hide_drives = 0;
8615 ioc->hide_drives = 0;
8617 rv = scsi_add_host(shost, &pdev->dev);
8619 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8620 ioc->name, __FILE__, __LINE__, __func__);
8621 goto out_add_shost_fail;
8624 scsi_scan_host(shost);
8627 mpt3sas_base_detach(ioc);
8629 destroy_workqueue(ioc->firmware_event_thread);
8631 spin_lock(&gioc_lock);
8632 list_del(&ioc->list);
8633 spin_unlock(&gioc_lock);
8634 scsi_host_put(shost);
8640 * scsih_suspend - power management suspend main entry point
8641 * @pdev: PCI device struct
8642 * @state: PM state change to (usually PCI_D3)
8644 * Returns 0 success, anything else error.
8647 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8649 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8650 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8651 pci_power_t device_state;
8653 mpt3sas_base_stop_watchdog(ioc);
8654 flush_scheduled_work();
8655 scsi_block_requests(shost);
8656 device_state = pci_choose_state(pdev, state);
8658 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8659 ioc->name, pdev, pci_name(pdev), device_state);
8661 pci_save_state(pdev);
8662 mpt3sas_base_free_resources(ioc);
8663 pci_set_power_state(pdev, device_state);
8668 * scsih_resume - power management resume main entry point
8669 * @pdev: PCI device struct
8671 * Returns 0 success, anything else error.
8674 scsih_resume(struct pci_dev *pdev)
8676 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8677 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8678 pci_power_t device_state = pdev->current_state;
8682 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8683 ioc->name, pdev, pci_name(pdev), device_state);
8685 pci_set_power_state(pdev, PCI_D0);
8686 pci_enable_wake(pdev, PCI_D0, 0);
8687 pci_restore_state(pdev);
8689 r = mpt3sas_base_map_resources(ioc);
8693 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8694 scsi_unblock_requests(shost);
8695 mpt3sas_base_start_watchdog(ioc);
8698 #endif /* CONFIG_PM */
8701 * scsih_pci_error_detected - Called when a PCI error is detected.
8702 * @pdev: PCI device struct
8703 * @state: PCI channel state
8705 * Description: Called when a PCI error is detected.
8708 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8711 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8713 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8714 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8716 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
8720 case pci_channel_io_normal:
8721 return PCI_ERS_RESULT_CAN_RECOVER;
8722 case pci_channel_io_frozen:
8723 /* Fatal error, prepare for slot reset */
8724 ioc->pci_error_recovery = 1;
8725 scsi_block_requests(ioc->shost);
8726 mpt3sas_base_stop_watchdog(ioc);
8727 mpt3sas_base_free_resources(ioc);
8728 return PCI_ERS_RESULT_NEED_RESET;
8729 case pci_channel_io_perm_failure:
8730 /* Permanent error, prepare for device removal */
8731 ioc->pci_error_recovery = 1;
8732 mpt3sas_base_stop_watchdog(ioc);
8733 _scsih_flush_running_cmds(ioc);
8734 return PCI_ERS_RESULT_DISCONNECT;
8736 return PCI_ERS_RESULT_NEED_RESET;
8740 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8741 * @pdev: PCI device struct
8743 * Description: This routine is called by the pci error recovery
8744 * code after the PCI slot has been reset, just before we
8745 * should resume normal operations.
8748 scsih_pci_slot_reset(struct pci_dev *pdev)
8750 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8751 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8754 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8757 ioc->pci_error_recovery = 0;
8759 pci_restore_state(pdev);
8760 rc = mpt3sas_base_map_resources(ioc);
8762 return PCI_ERS_RESULT_DISCONNECT;
8764 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8767 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8768 (rc == 0) ? "success" : "failed");
8771 return PCI_ERS_RESULT_RECOVERED;
8773 return PCI_ERS_RESULT_DISCONNECT;
8777 * scsih_pci_resume() - resume normal ops after PCI reset
8778 * @pdev: pointer to PCI device
8780 * Called when the error recovery driver tells us that its
8781 * OK to resume normal operation. Use completion to allow
8782 * halted scsi ops to resume.
8785 scsih_pci_resume(struct pci_dev *pdev)
8787 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8788 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8790 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8792 pci_cleanup_aer_uncorrect_error_status(pdev);
8793 mpt3sas_base_start_watchdog(ioc);
8794 scsi_unblock_requests(ioc->shost);
8798 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8799 * @pdev: pointer to PCI device
8802 scsih_pci_mmio_enabled(struct pci_dev *pdev)
8804 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8805 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8807 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8810 /* TODO - dump whatever for debugging purposes */
8812 /* Request a slot reset. */
8813 return PCI_ERS_RESULT_NEED_RESET;
8817 * The pci device ids are defined in mpi/mpi2_cnfg.h.
8819 static const struct pci_device_id mpt3sas_pci_table[] = {
8820 /* Spitfire ~ 2004 */
8821 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
8822 PCI_ANY_ID, PCI_ANY_ID },
8824 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
8825 PCI_ANY_ID, PCI_ANY_ID },
8826 /* Liberator ~ 2108 */
8827 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
8828 PCI_ANY_ID, PCI_ANY_ID },
8829 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
8830 PCI_ANY_ID, PCI_ANY_ID },
8831 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
8832 PCI_ANY_ID, PCI_ANY_ID },
8834 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
8835 PCI_ANY_ID, PCI_ANY_ID },
8836 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
8837 PCI_ANY_ID, PCI_ANY_ID },
8838 /* Thunderbolt ~ 2208 */
8839 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
8840 PCI_ANY_ID, PCI_ANY_ID },
8841 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
8842 PCI_ANY_ID, PCI_ANY_ID },
8843 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
8844 PCI_ANY_ID, PCI_ANY_ID },
8845 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
8846 PCI_ANY_ID, PCI_ANY_ID },
8847 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
8848 PCI_ANY_ID, PCI_ANY_ID },
8849 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
8850 PCI_ANY_ID, PCI_ANY_ID },
8851 /* Mustang ~ 2308 */
8852 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
8853 PCI_ANY_ID, PCI_ANY_ID },
8854 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
8855 PCI_ANY_ID, PCI_ANY_ID },
8856 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
8857 PCI_ANY_ID, PCI_ANY_ID },
8859 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
8860 PCI_ANY_ID, PCI_ANY_ID },
8861 /* Fury ~ 3004 and 3008 */
8862 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
8863 PCI_ANY_ID, PCI_ANY_ID },
8864 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
8865 PCI_ANY_ID, PCI_ANY_ID },
8866 /* Invader ~ 3108 */
8867 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
8868 PCI_ANY_ID, PCI_ANY_ID },
8869 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
8870 PCI_ANY_ID, PCI_ANY_ID },
8871 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
8872 PCI_ANY_ID, PCI_ANY_ID },
8873 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
8874 PCI_ANY_ID, PCI_ANY_ID },
8875 {0} /* Terminating entry */
8877 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
8879 static struct pci_error_handlers _mpt3sas_err_handler = {
8880 .error_detected = scsih_pci_error_detected,
8881 .mmio_enabled = scsih_pci_mmio_enabled,
8882 .slot_reset = scsih_pci_slot_reset,
8883 .resume = scsih_pci_resume,
8886 static struct pci_driver mpt3sas_driver = {
8887 .name = MPT3SAS_DRIVER_NAME,
8888 .id_table = mpt3sas_pci_table,
8889 .probe = _scsih_probe,
8890 .remove = scsih_remove,
8891 .shutdown = scsih_shutdown,
8892 .err_handler = &_mpt3sas_err_handler,
8894 .suspend = scsih_suspend,
8895 .resume = scsih_resume,
8900 * scsih_init - main entry point for this driver.
8902 * Returns 0 success, anything else error.
8910 mpt3sas_base_initialize_callback_handler();
8912 /* queuecommand callback hander */
8913 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8915 /* task managment callback handler */
8916 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8918 /* base internal commands callback handler */
8919 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8920 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8921 mpt3sas_port_enable_done);
8923 /* transport internal commands callback handler */
8924 transport_cb_idx = mpt3sas_base_register_callback_handler(
8925 mpt3sas_transport_done);
8927 /* scsih internal commands callback handler */
8928 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8930 /* configuration page API internal commands callback handler */
8931 config_cb_idx = mpt3sas_base_register_callback_handler(
8932 mpt3sas_config_done);
8934 /* ctl module callback handler */
8935 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8937 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8938 _scsih_tm_tr_complete);
8940 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8941 _scsih_tm_volume_tr_complete);
8943 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8944 _scsih_sas_control_complete);
8950 * scsih_exit - exit point for this driver (when it is a module).
8952 * Returns 0 success, anything else error.
8958 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8959 mpt3sas_base_release_callback_handler(tm_cb_idx);
8960 mpt3sas_base_release_callback_handler(base_cb_idx);
8961 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8962 mpt3sas_base_release_callback_handler(transport_cb_idx);
8963 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8964 mpt3sas_base_release_callback_handler(config_cb_idx);
8965 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8967 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8968 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8969 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8971 /* raid transport support */
8972 if (hbas_to_enumerate != 1)
8973 raid_class_release(mpt3sas_raid_template);
8974 if (hbas_to_enumerate != 2)
8975 raid_class_release(mpt2sas_raid_template);
8976 sas_release_transport(mpt3sas_transport_template);
8980 * _mpt3sas_init - main entry point for this driver.
8982 * Returns 0 success, anything else error.
8989 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8990 MPT3SAS_DRIVER_VERSION);
8992 mpt3sas_transport_template =
8993 sas_attach_transport(&mpt3sas_transport_functions);
8994 if (!mpt3sas_transport_template)
8997 /* No need attach mpt3sas raid functions template
8998 * if hbas_to_enumarate value is one.
9000 if (hbas_to_enumerate != 1) {
9001 mpt3sas_raid_template =
9002 raid_class_attach(&mpt3sas_raid_functions);
9003 if (!mpt3sas_raid_template) {
9004 sas_release_transport(mpt3sas_transport_template);
9009 /* No need to attach mpt2sas raid functions template
9010 * if hbas_to_enumarate value is two
9012 if (hbas_to_enumerate != 2) {
9013 mpt2sas_raid_template =
9014 raid_class_attach(&mpt2sas_raid_functions);
9015 if (!mpt2sas_raid_template) {
9016 sas_release_transport(mpt3sas_transport_template);
9021 error = scsih_init();
9027 mpt3sas_ctl_init(hbas_to_enumerate);
9029 error = pci_register_driver(&mpt3sas_driver);
9037 * _mpt3sas_exit - exit point for this driver (when it is a module).
9043 pr_info("mpt3sas version %s unloading\n",
9044 MPT3SAS_DRIVER_VERSION);
9046 pci_unregister_driver(&mpt3sas_driver);
9048 mpt3sas_ctl_exit(hbas_to_enumerate);
9053 module_init(_mpt3sas_init);
9054 module_exit(_mpt3sas_exit);