2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
58 #include "mpt3sas_base.h"
60 MODULE_AUTHOR(MPT3SAS_AUTHOR);
61 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
65 #define RAID_CHANNEL 1
67 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
68 struct _sas_node *sas_expander);
69 static void _firmware_event_work(struct work_struct *work);
71 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
72 struct _sas_device *sas_device);
73 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
74 u8 retry_count, u8 is_pd);
76 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
78 static void _scsih_scan_start(struct Scsi_Host *shost);
79 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
81 /* global parameters */
82 LIST_HEAD(mpt3sas_ioc_list);
84 /* local parameters */
85 static u8 scsi_io_cb_idx = -1;
86 static u8 tm_cb_idx = -1;
87 static u8 ctl_cb_idx = -1;
88 static u8 base_cb_idx = -1;
89 static u8 port_enable_cb_idx = -1;
90 static u8 transport_cb_idx = -1;
91 static u8 scsih_cb_idx = -1;
92 static u8 config_cb_idx = -1;
95 static u8 tm_tr_cb_idx = -1 ;
96 static u8 tm_tr_volume_cb_idx = -1 ;
97 static u8 tm_sas_control_cb_idx = -1;
99 /* command line options */
100 static u32 logging_level;
101 MODULE_PARM_DESC(logging_level,
102 " bits for enabling additional logging info (default=0)");
105 static ushort max_sectors = 0xFFFF;
106 module_param(max_sectors, ushort, 0);
107 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
110 static int missing_delay[2] = {-1, -1};
111 module_param_array(missing_delay, int, NULL, 0);
112 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
114 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
115 #define MPT3SAS_MAX_LUN (16895)
116 static u64 max_lun = MPT3SAS_MAX_LUN;
117 module_param(max_lun, ullong, 0);
118 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
123 /* diag_buffer_enable is bitwise
125 * bit 1 set = SNAPSHOT
126 * bit 2 set = EXTENDED
128 * Either bit can be set, or both
130 static int diag_buffer_enable = -1;
131 module_param(diag_buffer_enable, int, 0);
132 MODULE_PARM_DESC(diag_buffer_enable,
133 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
134 static int disable_discovery = -1;
135 module_param(disable_discovery, int, 0);
136 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
139 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
140 static int prot_mask = -1;
141 module_param(prot_mask, int, 0);
142 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
145 /* raid transport support */
147 static struct raid_template *mpt3sas_raid_template;
151 * struct sense_info - common structure for obtaining sense keys
153 * @asc: additional sense code
154 * @ascq: additional sense code qualifier
162 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
163 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
164 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
165 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
166 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
168 * struct fw_event_work - firmware event struct
169 * @list: link list framework
170 * @work: work object (ioc->fault_reset_work_q)
171 * @cancel_pending_work: flag set during reset handling
172 * @ioc: per adapter object
173 * @device_handle: device handle
174 * @VF_ID: virtual function id
175 * @VP_ID: virtual port id
176 * @ignore: flag meaning this event has been marked to ignore
177 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
178 * @event_data: reply event data payload follows
180 * This object stored on ioc->fw_event_list.
182 struct fw_event_work {
183 struct list_head list;
184 struct work_struct work;
185 u8 cancel_pending_work;
186 struct delayed_work delayed_work;
188 struct MPT3SAS_ADAPTER *ioc;
194 char event_data[0] __aligned(4);
197 /* raid transport support */
198 static struct raid_template *mpt3sas_raid_template;
201 * struct _scsi_io_transfer - scsi io transfer
202 * @handle: sas device handle (assigned by firmware)
203 * @is_raid: flag set for hidden raid components
204 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
205 * @data_length: data transfer length
206 * @data_dma: dma pointer to data
209 * @cdb_length: cdb length
211 * @timeout: timeout for this command
212 * @VF_ID: virtual function id
213 * @VP_ID: virtual port id
214 * @valid_reply: flag set for reply message
215 * @sense_length: sense length
216 * @ioc_status: ioc status
217 * @scsi_state: scsi state
218 * @scsi_status: scsi staus
219 * @log_info: log information
220 * @transfer_length: data length transfer when there is a reply message
222 * Used for sending internal scsi commands to devices within this module.
223 * Refer to _scsi_send_scsi_io().
225 struct _scsi_io_transfer {
228 enum dma_data_direction dir;
231 u8 sense[SCSI_SENSE_BUFFERSIZE];
239 /* the following bits are only valid when 'valid_reply = 1' */
249 * The pci device ids are defined in mpi/mpi2_cnfg.h.
251 static const struct pci_device_id scsih_pci_table[] = {
252 /* Fury ~ 3004 and 3008 */
253 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
254 PCI_ANY_ID, PCI_ANY_ID },
255 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
256 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
265 PCI_ANY_ID, PCI_ANY_ID },
266 {0} /* Terminating entry */
268 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
271 * _scsih_set_debug_level - global setting of ioc->logging_level.
273 * Note: The logging levels are defined in mpt3sas_debug.h.
276 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
278 int ret = param_set_int(val, kp);
279 struct MPT3SAS_ADAPTER *ioc;
284 pr_info("setting logging_level(0x%08x)\n", logging_level);
285 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
286 ioc->logging_level = logging_level;
289 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
290 &logging_level, 0644);
293 * _scsih_srch_boot_sas_address - search based on sas_address
294 * @sas_address: sas address
295 * @boot_device: boot device object from bios page 2
297 * Returns 1 when there's a match, 0 means no match.
300 _scsih_srch_boot_sas_address(u64 sas_address,
301 Mpi2BootDeviceSasWwid_t *boot_device)
303 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
307 * _scsih_srch_boot_device_name - search based on device name
308 * @device_name: device name specified in INDENTIFY fram
309 * @boot_device: boot device object from bios page 2
311 * Returns 1 when there's a match, 0 means no match.
314 _scsih_srch_boot_device_name(u64 device_name,
315 Mpi2BootDeviceDeviceName_t *boot_device)
317 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
321 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
322 * @enclosure_logical_id: enclosure logical id
323 * @slot_number: slot number
324 * @boot_device: boot device object from bios page 2
326 * Returns 1 when there's a match, 0 means no match.
329 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
330 Mpi2BootDeviceEnclosureSlot_t *boot_device)
332 return (enclosure_logical_id == le64_to_cpu(boot_device->
333 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
334 SlotNumber)) ? 1 : 0;
338 * _scsih_is_boot_device - search for matching boot device.
339 * @sas_address: sas address
340 * @device_name: device name specified in INDENTIFY fram
341 * @enclosure_logical_id: enclosure logical id
342 * @slot_number: slot number
343 * @form: specifies boot device form
344 * @boot_device: boot device object from bios page 2
346 * Returns 1 when there's a match, 0 means no match.
349 _scsih_is_boot_device(u64 sas_address, u64 device_name,
350 u64 enclosure_logical_id, u16 slot, u8 form,
351 Mpi2BiosPage2BootDevice_t *boot_device)
356 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
359 rc = _scsih_srch_boot_sas_address(
360 sas_address, &boot_device->SasWwid);
362 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
363 if (!enclosure_logical_id)
365 rc = _scsih_srch_boot_encl_slot(
366 enclosure_logical_id,
367 slot, &boot_device->EnclosureSlot);
369 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
372 rc = _scsih_srch_boot_device_name(
373 device_name, &boot_device->DeviceName);
375 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
383 * _scsih_get_sas_address - set the sas_address for given device handle
384 * @handle: device handle
385 * @sas_address: sas address
387 * Returns 0 success, non-zero when failure
390 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
393 Mpi2SasDevicePage0_t sas_device_pg0;
394 Mpi2ConfigReply_t mpi_reply;
399 if (handle <= ioc->sas_hba.num_phys) {
400 *sas_address = ioc->sas_hba.sas_address;
404 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
405 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
406 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
407 __FILE__, __LINE__, __func__);
411 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
412 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
413 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
417 /* we hit this becuase the given parent handle doesn't exist */
418 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
421 /* else error case */
423 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
424 ioc->name, handle, ioc_status,
425 __FILE__, __LINE__, __func__);
430 * _scsih_determine_boot_device - determine boot device.
431 * @ioc: per adapter object
432 * @device: either sas_device or raid_device object
433 * @is_raid: [flag] 1 = raid object, 0 = sas object
435 * Determines whether this device should be first reported device to
436 * to scsi-ml or sas transport, this purpose is for persistent boot device.
437 * There are primary, alternate, and current entries in bios page 2. The order
438 * priority is primary, alternate, then current. This routine saves
439 * the corresponding device object and is_raid flag in the ioc object.
440 * The saved data to be used later in _scsih_probe_boot_devices().
443 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
444 void *device, u8 is_raid)
446 struct _sas_device *sas_device;
447 struct _raid_device *raid_device;
450 u64 enclosure_logical_id;
453 /* only process this function when driver loads */
454 if (!ioc->is_driver_loading)
457 /* no Bios, return immediately */
458 if (!ioc->bios_pg3.BiosVersion)
463 sas_address = sas_device->sas_address;
464 device_name = sas_device->device_name;
465 enclosure_logical_id = sas_device->enclosure_logical_id;
466 slot = sas_device->slot;
468 raid_device = device;
469 sas_address = raid_device->wwid;
471 enclosure_logical_id = 0;
475 if (!ioc->req_boot_device.device) {
476 if (_scsih_is_boot_device(sas_address, device_name,
477 enclosure_logical_id, slot,
478 (ioc->bios_pg2.ReqBootDeviceForm &
479 MPI2_BIOSPAGE2_FORM_MASK),
480 &ioc->bios_pg2.RequestedBootDevice)) {
481 dinitprintk(ioc, pr_info(MPT3SAS_FMT
482 "%s: req_boot_device(0x%016llx)\n",
484 (unsigned long long)sas_address));
485 ioc->req_boot_device.device = device;
486 ioc->req_boot_device.is_raid = is_raid;
490 if (!ioc->req_alt_boot_device.device) {
491 if (_scsih_is_boot_device(sas_address, device_name,
492 enclosure_logical_id, slot,
493 (ioc->bios_pg2.ReqAltBootDeviceForm &
494 MPI2_BIOSPAGE2_FORM_MASK),
495 &ioc->bios_pg2.RequestedAltBootDevice)) {
496 dinitprintk(ioc, pr_info(MPT3SAS_FMT
497 "%s: req_alt_boot_device(0x%016llx)\n",
499 (unsigned long long)sas_address));
500 ioc->req_alt_boot_device.device = device;
501 ioc->req_alt_boot_device.is_raid = is_raid;
505 if (!ioc->current_boot_device.device) {
506 if (_scsih_is_boot_device(sas_address, device_name,
507 enclosure_logical_id, slot,
508 (ioc->bios_pg2.CurrentBootDeviceForm &
509 MPI2_BIOSPAGE2_FORM_MASK),
510 &ioc->bios_pg2.CurrentBootDevice)) {
511 dinitprintk(ioc, pr_info(MPT3SAS_FMT
512 "%s: current_boot_device(0x%016llx)\n",
514 (unsigned long long)sas_address));
515 ioc->current_boot_device.device = device;
516 ioc->current_boot_device.is_raid = is_raid;
522 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
523 * @ioc: per adapter object
524 * @sas_address: sas address
525 * Context: Calling function should acquire ioc->sas_device_lock
527 * This searches for sas_device based on sas_address, then return sas_device
531 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
534 struct _sas_device *sas_device;
536 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
537 if (sas_device->sas_address == sas_address)
540 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
541 if (sas_device->sas_address == sas_address)
548 * _scsih_sas_device_find_by_handle - sas device search
549 * @ioc: per adapter object
550 * @handle: sas device handle (assigned by firmware)
551 * Context: Calling function should acquire ioc->sas_device_lock
553 * This searches for sas_device based on sas_address, then return sas_device
556 static struct _sas_device *
557 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
559 struct _sas_device *sas_device;
561 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
562 if (sas_device->handle == handle)
565 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
566 if (sas_device->handle == handle)
573 * _scsih_sas_device_remove - remove sas_device from list.
574 * @ioc: per adapter object
575 * @sas_device: the sas_device object
576 * Context: This function will acquire ioc->sas_device_lock.
578 * Removing object and freeing associated memory from the ioc->sas_device_list.
581 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
582 struct _sas_device *sas_device)
589 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
590 ioc->name, sas_device->handle,
591 (unsigned long long) sas_device->sas_address);
593 if (sas_device->enclosure_handle != 0)
595 "removing enclosure logical id(0x%016llx), slot(%d)\n",
596 ioc->name, (unsigned long long)
597 sas_device->enclosure_logical_id, sas_device->slot);
599 if (sas_device->connector_name[0] != '\0')
601 "removing enclosure level(0x%04x), connector name( %s)\n",
602 ioc->name, sas_device->enclosure_level,
603 sas_device->connector_name);
605 spin_lock_irqsave(&ioc->sas_device_lock, flags);
606 list_del(&sas_device->list);
608 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
612 * _scsih_device_remove_by_handle - removing device object by handle
613 * @ioc: per adapter object
614 * @handle: device handle
619 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
621 struct _sas_device *sas_device;
624 if (ioc->shost_recovery)
627 spin_lock_irqsave(&ioc->sas_device_lock, flags);
628 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
630 list_del(&sas_device->list);
631 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
633 _scsih_remove_device(ioc, sas_device);
637 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
638 * @ioc: per adapter object
639 * @sas_address: device sas_address
644 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
647 struct _sas_device *sas_device;
650 if (ioc->shost_recovery)
653 spin_lock_irqsave(&ioc->sas_device_lock, flags);
654 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
657 list_del(&sas_device->list);
658 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
660 _scsih_remove_device(ioc, sas_device);
664 * _scsih_sas_device_add - insert sas_device to the list.
665 * @ioc: per adapter object
666 * @sas_device: the sas_device object
667 * Context: This function will acquire ioc->sas_device_lock.
669 * Adding new object to the ioc->sas_device_list.
672 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
673 struct _sas_device *sas_device)
677 dewtprintk(ioc, pr_info(MPT3SAS_FMT
678 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
679 ioc->name, __func__, sas_device->handle,
680 (unsigned long long)sas_device->sas_address));
682 if (sas_device->enclosure_handle != 0)
683 dewtprintk(ioc, pr_info(MPT3SAS_FMT
684 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
685 ioc->name, __func__, (unsigned long long)
686 sas_device->enclosure_logical_id, sas_device->slot));
688 if (sas_device->connector_name[0] != '\0')
689 dewtprintk(ioc, pr_info(MPT3SAS_FMT
690 "%s: enclosure level(0x%04x), connector name( %s)\n",
692 sas_device->enclosure_level, sas_device->connector_name));
694 spin_lock_irqsave(&ioc->sas_device_lock, flags);
695 list_add_tail(&sas_device->list, &ioc->sas_device_list);
696 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
698 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
699 sas_device->sas_address_parent)) {
700 _scsih_sas_device_remove(ioc, sas_device);
701 } else if (!sas_device->starget) {
703 * When asyn scanning is enabled, its not possible to remove
704 * devices while scanning is turned on due to an oops in
705 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
707 if (!ioc->is_driver_loading) {
708 mpt3sas_transport_port_remove(ioc,
709 sas_device->sas_address,
710 sas_device->sas_address_parent);
711 _scsih_sas_device_remove(ioc, sas_device);
717 * _scsih_sas_device_init_add - insert sas_device to the list.
718 * @ioc: per adapter object
719 * @sas_device: the sas_device object
720 * Context: This function will acquire ioc->sas_device_lock.
722 * Adding new object at driver load time to the ioc->sas_device_init_list.
725 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
726 struct _sas_device *sas_device)
730 dewtprintk(ioc, pr_info(MPT3SAS_FMT
731 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
732 __func__, sas_device->handle,
733 (unsigned long long)sas_device->sas_address));
735 if (sas_device->enclosure_handle != 0)
736 dewtprintk(ioc, pr_info(MPT3SAS_FMT
737 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
738 ioc->name, __func__, (unsigned long long)
739 sas_device->enclosure_logical_id, sas_device->slot));
741 if (sas_device->connector_name[0] != '\0')
742 dewtprintk(ioc, pr_info(MPT3SAS_FMT
743 "%s: enclosure level(0x%04x), connector name( %s)\n",
744 ioc->name, __func__, sas_device->enclosure_level,
745 sas_device->connector_name));
747 spin_lock_irqsave(&ioc->sas_device_lock, flags);
748 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
749 _scsih_determine_boot_device(ioc, sas_device, 0);
750 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
754 * _scsih_raid_device_find_by_id - raid device search
755 * @ioc: per adapter object
756 * @id: sas device target id
757 * @channel: sas device channel
758 * Context: Calling function should acquire ioc->raid_device_lock
760 * This searches for raid_device based on target id, then return raid_device
763 static struct _raid_device *
764 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
766 struct _raid_device *raid_device, *r;
769 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
770 if (raid_device->id == id && raid_device->channel == channel) {
781 * _scsih_raid_device_find_by_handle - raid device search
782 * @ioc: per adapter object
783 * @handle: sas device handle (assigned by firmware)
784 * Context: Calling function should acquire ioc->raid_device_lock
786 * This searches for raid_device based on handle, then return raid_device
789 static struct _raid_device *
790 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
792 struct _raid_device *raid_device, *r;
795 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
796 if (raid_device->handle != handle)
807 * _scsih_raid_device_find_by_wwid - raid device search
808 * @ioc: per adapter object
809 * @handle: sas device handle (assigned by firmware)
810 * Context: Calling function should acquire ioc->raid_device_lock
812 * This searches for raid_device based on wwid, then return raid_device
815 static struct _raid_device *
816 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
818 struct _raid_device *raid_device, *r;
821 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
822 if (raid_device->wwid != wwid)
833 * _scsih_raid_device_add - add raid_device object
834 * @ioc: per adapter object
835 * @raid_device: raid_device object
837 * This is added to the raid_device_list link list.
840 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
841 struct _raid_device *raid_device)
845 dewtprintk(ioc, pr_info(MPT3SAS_FMT
846 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
847 raid_device->handle, (unsigned long long)raid_device->wwid));
849 spin_lock_irqsave(&ioc->raid_device_lock, flags);
850 list_add_tail(&raid_device->list, &ioc->raid_device_list);
851 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
855 * _scsih_raid_device_remove - delete raid_device object
856 * @ioc: per adapter object
857 * @raid_device: raid_device object
861 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
862 struct _raid_device *raid_device)
866 spin_lock_irqsave(&ioc->raid_device_lock, flags);
867 list_del(&raid_device->list);
869 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
873 * mpt3sas_scsih_expander_find_by_handle - expander device search
874 * @ioc: per adapter object
875 * @handle: expander handle (assigned by firmware)
876 * Context: Calling function should acquire ioc->sas_device_lock
878 * This searches for expander device based on handle, then returns the
882 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
884 struct _sas_node *sas_expander, *r;
887 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
888 if (sas_expander->handle != handle)
898 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
899 * @ioc: per adapter object
900 * @sas_address: sas address
901 * Context: Calling function should acquire ioc->sas_node_lock.
903 * This searches for expander device based on sas_address, then returns the
907 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
910 struct _sas_node *sas_expander, *r;
913 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
914 if (sas_expander->sas_address != sas_address)
924 * _scsih_expander_node_add - insert expander device to the list.
925 * @ioc: per adapter object
926 * @sas_expander: the sas_device object
927 * Context: This function will acquire ioc->sas_node_lock.
929 * Adding new object to the ioc->sas_expander_list.
934 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
935 struct _sas_node *sas_expander)
939 spin_lock_irqsave(&ioc->sas_node_lock, flags);
940 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
941 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
945 * _scsih_is_end_device - determines if device is an end device
946 * @device_info: bitfield providing information about the device.
949 * Returns 1 if end device.
952 _scsih_is_end_device(u32 device_info)
954 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
955 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
956 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
957 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
964 * _scsih_scsi_lookup_get - returns scmd entry
965 * @ioc: per adapter object
966 * @smid: system request message index
968 * Returns the smid stored scmd pointer.
970 static struct scsi_cmnd *
971 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
973 return ioc->scsi_lookup[smid - 1].scmd;
977 * _scsih_scsi_lookup_get_clear - returns scmd entry
978 * @ioc: per adapter object
979 * @smid: system request message index
981 * Returns the smid stored scmd pointer.
982 * Then will derefrence the stored scmd pointer.
984 static inline struct scsi_cmnd *
985 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
988 struct scsi_cmnd *scmd;
990 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
991 scmd = ioc->scsi_lookup[smid - 1].scmd;
992 ioc->scsi_lookup[smid - 1].scmd = NULL;
993 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
999 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1000 * @ioc: per adapter object
1001 * @smid: system request message index
1002 * @scmd: pointer to scsi command object
1003 * Context: This function will acquire ioc->scsi_lookup_lock.
1005 * This will search for a scmd pointer in the scsi_lookup array,
1006 * returning the revelent smid. A returned value of zero means invalid.
1009 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
1013 unsigned long flags;
1016 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1018 for (i = 0; i < ioc->scsiio_depth; i++) {
1019 if (ioc->scsi_lookup[i].scmd == scmd) {
1020 smid = ioc->scsi_lookup[i].smid;
1025 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1030 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1031 * @ioc: per adapter object
1034 * Context: This function will acquire ioc->scsi_lookup_lock.
1036 * This will search for a matching channel:id in the scsi_lookup array,
1037 * returning 1 if found.
1040 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1044 unsigned long flags;
1047 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1049 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1050 if (ioc->scsi_lookup[i].scmd &&
1051 (ioc->scsi_lookup[i].scmd->device->id == id &&
1052 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1058 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1063 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1064 * @ioc: per adapter object
1068 * Context: This function will acquire ioc->scsi_lookup_lock.
1070 * This will search for a matching channel:id:lun in the scsi_lookup array,
1071 * returning 1 if found.
1074 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1075 unsigned int lun, int channel)
1078 unsigned long flags;
1081 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1083 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1084 if (ioc->scsi_lookup[i].scmd &&
1085 (ioc->scsi_lookup[i].scmd->device->id == id &&
1086 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1087 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1093 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1098 * _scsih_change_queue_depth - setting device queue depth
1099 * @sdev: scsi device struct
1100 * @qdepth: requested queue depth
1102 * Returns queue depth.
1105 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1107 struct Scsi_Host *shost = sdev->host;
1109 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1110 struct MPT3SAS_DEVICE *sas_device_priv_data;
1111 struct MPT3SAS_TARGET *sas_target_priv_data;
1112 struct _sas_device *sas_device;
1113 unsigned long flags;
1115 max_depth = shost->can_queue;
1117 /* limit max device queue for SATA to 32 */
1118 sas_device_priv_data = sdev->hostdata;
1119 if (!sas_device_priv_data)
1121 sas_target_priv_data = sas_device_priv_data->sas_target;
1122 if (!sas_target_priv_data)
1124 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1126 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1127 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1128 sas_device_priv_data->sas_target->sas_address);
1129 if (sas_device && sas_device->device_info &
1130 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1131 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1132 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1136 if (!sdev->tagged_supported)
1138 if (qdepth > max_depth)
1140 return scsi_change_queue_depth(sdev, qdepth);
1144 * _scsih_target_alloc - target add routine
1145 * @starget: scsi target struct
1147 * Returns 0 if ok. Any other return is assumed to be an error and
1148 * the device is ignored.
1151 _scsih_target_alloc(struct scsi_target *starget)
1153 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1154 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1155 struct MPT3SAS_TARGET *sas_target_priv_data;
1156 struct _sas_device *sas_device;
1157 struct _raid_device *raid_device;
1158 unsigned long flags;
1159 struct sas_rphy *rphy;
1161 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1163 if (!sas_target_priv_data)
1166 starget->hostdata = sas_target_priv_data;
1167 sas_target_priv_data->starget = starget;
1168 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1171 if (starget->channel == RAID_CHANNEL) {
1172 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1173 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1176 sas_target_priv_data->handle = raid_device->handle;
1177 sas_target_priv_data->sas_address = raid_device->wwid;
1178 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1179 raid_device->starget = starget;
1181 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1185 /* sas/sata devices */
1186 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1187 rphy = dev_to_rphy(starget->dev.parent);
1188 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1189 rphy->identify.sas_address);
1192 sas_target_priv_data->handle = sas_device->handle;
1193 sas_target_priv_data->sas_address = sas_device->sas_address;
1194 sas_device->starget = starget;
1195 sas_device->id = starget->id;
1196 sas_device->channel = starget->channel;
1197 if (test_bit(sas_device->handle, ioc->pd_handles))
1198 sas_target_priv_data->flags |=
1199 MPT_TARGET_FLAGS_RAID_COMPONENT;
1200 if (sas_device->fast_path)
1201 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1203 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1209 * _scsih_target_destroy - target destroy routine
1210 * @starget: scsi target struct
1215 _scsih_target_destroy(struct scsi_target *starget)
1217 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1218 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1219 struct MPT3SAS_TARGET *sas_target_priv_data;
1220 struct _sas_device *sas_device;
1221 struct _raid_device *raid_device;
1222 unsigned long flags;
1223 struct sas_rphy *rphy;
1225 sas_target_priv_data = starget->hostdata;
1226 if (!sas_target_priv_data)
1229 if (starget->channel == RAID_CHANNEL) {
1230 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1231 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1234 raid_device->starget = NULL;
1235 raid_device->sdev = NULL;
1237 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1241 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1242 rphy = dev_to_rphy(starget->dev.parent);
1243 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1244 rphy->identify.sas_address);
1245 if (sas_device && (sas_device->starget == starget) &&
1246 (sas_device->id == starget->id) &&
1247 (sas_device->channel == starget->channel))
1248 sas_device->starget = NULL;
1250 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1253 kfree(sas_target_priv_data);
1254 starget->hostdata = NULL;
1258 * _scsih_slave_alloc - device add routine
1259 * @sdev: scsi device struct
1261 * Returns 0 if ok. Any other return is assumed to be an error and
1262 * the device is ignored.
1265 _scsih_slave_alloc(struct scsi_device *sdev)
1267 struct Scsi_Host *shost;
1268 struct MPT3SAS_ADAPTER *ioc;
1269 struct MPT3SAS_TARGET *sas_target_priv_data;
1270 struct MPT3SAS_DEVICE *sas_device_priv_data;
1271 struct scsi_target *starget;
1272 struct _raid_device *raid_device;
1273 struct _sas_device *sas_device;
1274 unsigned long flags;
1276 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1278 if (!sas_device_priv_data)
1281 sas_device_priv_data->lun = sdev->lun;
1282 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1284 starget = scsi_target(sdev);
1285 sas_target_priv_data = starget->hostdata;
1286 sas_target_priv_data->num_luns++;
1287 sas_device_priv_data->sas_target = sas_target_priv_data;
1288 sdev->hostdata = sas_device_priv_data;
1289 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1290 sdev->no_uld_attach = 1;
1292 shost = dev_to_shost(&starget->dev);
1293 ioc = shost_priv(shost);
1294 if (starget->channel == RAID_CHANNEL) {
1295 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1296 raid_device = _scsih_raid_device_find_by_id(ioc,
1297 starget->id, starget->channel);
1299 raid_device->sdev = sdev; /* raid is single lun */
1300 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1303 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1304 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1305 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1306 sas_target_priv_data->sas_address);
1307 if (sas_device && (sas_device->starget == NULL)) {
1308 sdev_printk(KERN_INFO, sdev,
1309 "%s : sas_device->starget set to starget @ %d\n",
1310 __func__, __LINE__);
1311 sas_device->starget = starget;
1313 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1320 * _scsih_slave_destroy - device destroy routine
1321 * @sdev: scsi device struct
1326 _scsih_slave_destroy(struct scsi_device *sdev)
1328 struct MPT3SAS_TARGET *sas_target_priv_data;
1329 struct scsi_target *starget;
1330 struct Scsi_Host *shost;
1331 struct MPT3SAS_ADAPTER *ioc;
1332 struct _sas_device *sas_device;
1333 unsigned long flags;
1335 if (!sdev->hostdata)
1338 starget = scsi_target(sdev);
1339 sas_target_priv_data = starget->hostdata;
1340 sas_target_priv_data->num_luns--;
1342 shost = dev_to_shost(&starget->dev);
1343 ioc = shost_priv(shost);
1345 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1346 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1347 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1348 sas_target_priv_data->sas_address);
1349 if (sas_device && !sas_target_priv_data->num_luns)
1350 sas_device->starget = NULL;
1351 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1354 kfree(sdev->hostdata);
1355 sdev->hostdata = NULL;
1359 * _scsih_display_sata_capabilities - sata capabilities
1360 * @ioc: per adapter object
1361 * @handle: device handle
1362 * @sdev: scsi device struct
1365 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1366 u16 handle, struct scsi_device *sdev)
1368 Mpi2ConfigReply_t mpi_reply;
1369 Mpi2SasDevicePage0_t sas_device_pg0;
1374 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1375 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1376 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1377 ioc->name, __FILE__, __LINE__, __func__);
1381 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1382 MPI2_IOCSTATUS_MASK;
1383 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1384 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1385 ioc->name, __FILE__, __LINE__, __func__);
1389 flags = le16_to_cpu(sas_device_pg0.Flags);
1390 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1392 sdev_printk(KERN_INFO, sdev,
1393 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1394 "sw_preserve(%s)\n",
1395 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1396 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1397 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1399 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1400 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1401 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1405 * raid transport support -
1406 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1407 * unloading the driver followed by a load - I beleive that the subroutine
1408 * raid_class_release() is not cleaning up properly.
1412 * _scsih_is_raid - return boolean indicating device is raid volume
1413 * @dev the device struct object
1416 _scsih_is_raid(struct device *dev)
1418 struct scsi_device *sdev = to_scsi_device(dev);
1420 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1424 * _scsih_get_resync - get raid volume resync percent complete
1425 * @dev the device struct object
1428 _scsih_get_resync(struct device *dev)
1430 struct scsi_device *sdev = to_scsi_device(dev);
1431 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1432 static struct _raid_device *raid_device;
1433 unsigned long flags;
1434 Mpi2RaidVolPage0_t vol_pg0;
1435 Mpi2ConfigReply_t mpi_reply;
1436 u32 volume_status_flags;
1437 u8 percent_complete;
1440 percent_complete = 0;
1442 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1443 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1446 handle = raid_device->handle;
1447 percent_complete = raid_device->percent_complete;
1449 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1454 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1455 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1456 sizeof(Mpi2RaidVolPage0_t))) {
1457 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1458 ioc->name, __FILE__, __LINE__, __func__);
1459 percent_complete = 0;
1463 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1464 if (!(volume_status_flags &
1465 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1466 percent_complete = 0;
1469 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1473 * _scsih_get_state - get raid volume level
1474 * @dev the device struct object
1477 _scsih_get_state(struct device *dev)
1479 struct scsi_device *sdev = to_scsi_device(dev);
1480 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1481 static struct _raid_device *raid_device;
1482 unsigned long flags;
1483 Mpi2RaidVolPage0_t vol_pg0;
1484 Mpi2ConfigReply_t mpi_reply;
1486 enum raid_state state = RAID_STATE_UNKNOWN;
1489 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1490 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1493 handle = raid_device->handle;
1494 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1499 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1500 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1501 sizeof(Mpi2RaidVolPage0_t))) {
1502 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1503 ioc->name, __FILE__, __LINE__, __func__);
1507 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1508 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1509 state = RAID_STATE_RESYNCING;
1513 switch (vol_pg0.VolumeState) {
1514 case MPI2_RAID_VOL_STATE_OPTIMAL:
1515 case MPI2_RAID_VOL_STATE_ONLINE:
1516 state = RAID_STATE_ACTIVE;
1518 case MPI2_RAID_VOL_STATE_DEGRADED:
1519 state = RAID_STATE_DEGRADED;
1521 case MPI2_RAID_VOL_STATE_FAILED:
1522 case MPI2_RAID_VOL_STATE_MISSING:
1523 state = RAID_STATE_OFFLINE;
1527 raid_set_state(mpt3sas_raid_template, dev, state);
1531 * _scsih_set_level - set raid level
1532 * @sdev: scsi device struct
1533 * @volume_type: volume type
1536 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1538 enum raid_level level = RAID_LEVEL_UNKNOWN;
1540 switch (volume_type) {
1541 case MPI2_RAID_VOL_TYPE_RAID0:
1542 level = RAID_LEVEL_0;
1544 case MPI2_RAID_VOL_TYPE_RAID10:
1545 level = RAID_LEVEL_10;
1547 case MPI2_RAID_VOL_TYPE_RAID1E:
1548 level = RAID_LEVEL_1E;
1550 case MPI2_RAID_VOL_TYPE_RAID1:
1551 level = RAID_LEVEL_1;
1555 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1560 * _scsih_get_volume_capabilities - volume capabilities
1561 * @ioc: per adapter object
1562 * @sas_device: the raid_device object
1564 * Returns 0 for success, else 1
1567 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1568 struct _raid_device *raid_device)
1570 Mpi2RaidVolPage0_t *vol_pg0;
1571 Mpi2RaidPhysDiskPage0_t pd_pg0;
1572 Mpi2SasDevicePage0_t sas_device_pg0;
1573 Mpi2ConfigReply_t mpi_reply;
1577 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1578 &num_pds)) || !num_pds) {
1579 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1580 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1585 raid_device->num_pds = num_pds;
1586 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1587 sizeof(Mpi2RaidVol0PhysDisk_t));
1588 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1590 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1591 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1596 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1597 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1598 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1599 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1605 raid_device->volume_type = vol_pg0->VolumeType;
1607 /* figure out what the underlying devices are by
1608 * obtaining the device_info bits for the 1st device
1610 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1611 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1612 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1613 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1614 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1615 le16_to_cpu(pd_pg0.DevHandle)))) {
1616 raid_device->device_info =
1617 le32_to_cpu(sas_device_pg0.DeviceInfo);
1628 * _scsih_enable_tlr - setting TLR flags
1629 * @ioc: per adapter object
1630 * @sdev: scsi device struct
1632 * Enabling Transaction Layer Retries for tape devices when
1633 * vpd page 0x90 is present
1637 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1641 if (sdev->type != TYPE_TAPE)
1644 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1647 sas_enable_tlr(sdev);
1648 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1649 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1655 * _scsih_slave_configure - device configure routine.
1656 * @sdev: scsi device struct
1658 * Returns 0 if ok. Any other return is assumed to be an error and
1659 * the device is ignored.
1662 _scsih_slave_configure(struct scsi_device *sdev)
1664 struct Scsi_Host *shost = sdev->host;
1665 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1666 struct MPT3SAS_DEVICE *sas_device_priv_data;
1667 struct MPT3SAS_TARGET *sas_target_priv_data;
1668 struct _sas_device *sas_device;
1669 struct _raid_device *raid_device;
1670 unsigned long flags;
1675 u16 handle, volume_handle = 0;
1676 u64 volume_wwid = 0;
1679 sas_device_priv_data = sdev->hostdata;
1680 sas_device_priv_data->configured_lun = 1;
1681 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1682 sas_target_priv_data = sas_device_priv_data->sas_target;
1683 handle = sas_target_priv_data->handle;
1685 /* raid volume handling */
1686 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1688 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1689 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1690 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1692 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1693 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1694 __LINE__, __func__));
1698 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1699 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1700 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1701 __LINE__, __func__));
1706 /* RAID Queue Depth Support
1707 * IS volume = underlying qdepth of drive type, either
1708 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1709 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1711 if (raid_device->device_info &
1712 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1713 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1716 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1717 if (raid_device->device_info &
1718 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1724 switch (raid_device->volume_type) {
1725 case MPI2_RAID_VOL_TYPE_RAID0:
1728 case MPI2_RAID_VOL_TYPE_RAID1E:
1729 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1730 if (ioc->manu_pg10.OEMIdentifier &&
1731 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1732 MFG10_GF0_R10_DISPLAY) &&
1733 !(raid_device->num_pds % 2))
1738 case MPI2_RAID_VOL_TYPE_RAID1:
1739 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1742 case MPI2_RAID_VOL_TYPE_RAID10:
1743 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1746 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1748 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1753 sdev_printk(KERN_INFO, sdev,
1754 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1755 r_level, raid_device->handle,
1756 (unsigned long long)raid_device->wwid,
1757 raid_device->num_pds, ds);
1760 _scsih_change_queue_depth(sdev, qdepth);
1762 /* raid transport support */
1763 _scsih_set_level(sdev, raid_device->volume_type);
1767 /* non-raid handling */
1768 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1769 if (mpt3sas_config_get_volume_handle(ioc, handle,
1771 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1772 "failure at %s:%d/%s()!\n", ioc->name,
1773 __FILE__, __LINE__, __func__));
1776 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1777 volume_handle, &volume_wwid)) {
1778 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1779 "failure at %s:%d/%s()!\n", ioc->name,
1780 __FILE__, __LINE__, __func__));
1785 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1786 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1787 sas_device_priv_data->sas_target->sas_address);
1789 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1790 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1791 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1796 sas_device->volume_handle = volume_handle;
1797 sas_device->volume_wwid = volume_wwid;
1798 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1799 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1803 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1804 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1806 else if (sas_device->device_info &
1807 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1811 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1812 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1813 ds, handle, (unsigned long long)sas_device->sas_address,
1814 sas_device->phy, (unsigned long long)sas_device->device_name);
1815 if (sas_device->enclosure_handle != 0)
1816 sdev_printk(KERN_INFO, sdev,
1817 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1818 ds, (unsigned long long)
1819 sas_device->enclosure_logical_id, sas_device->slot);
1820 if (sas_device->connector_name[0] != '\0')
1821 sdev_printk(KERN_INFO, sdev,
1822 "%s: enclosure level(0x%04x), connector name( %s)\n",
1823 ds, sas_device->enclosure_level,
1824 sas_device->connector_name);
1826 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1829 _scsih_display_sata_capabilities(ioc, handle, sdev);
1832 _scsih_change_queue_depth(sdev, qdepth);
1835 sas_read_port_mode_page(sdev);
1836 _scsih_enable_tlr(ioc, sdev);
1843 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1844 * @sdev: scsi device struct
1845 * @bdev: pointer to block device context
1846 * @capacity: device size (in 512 byte sectors)
1847 * @params: three element array to place output:
1848 * params[0] number of heads (max 255)
1849 * params[1] number of sectors (max 63)
1850 * params[2] number of cylinders
1855 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1856 sector_t capacity, int params[])
1866 dummy = heads * sectors;
1867 cylinders = capacity;
1868 sector_div(cylinders, dummy);
1871 * Handle extended translation size for logical drives
1874 if ((ulong)capacity >= 0x200000) {
1877 dummy = heads * sectors;
1878 cylinders = capacity;
1879 sector_div(cylinders, dummy);
1884 params[1] = sectors;
1885 params[2] = cylinders;
1891 * _scsih_response_code - translation of device response code
1892 * @ioc: per adapter object
1893 * @response_code: response code returned by the device
1898 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1902 switch (response_code) {
1903 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1904 desc = "task management request completed";
1906 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1907 desc = "invalid frame";
1909 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1910 desc = "task management request not supported";
1912 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1913 desc = "task management request failed";
1915 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1916 desc = "task management request succeeded";
1918 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1919 desc = "invalid lun";
1922 desc = "overlapped tag attempted";
1924 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1925 desc = "task queued, however not sent to target";
1931 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1932 ioc->name, response_code, desc);
1936 * _scsih_tm_done - tm completion routine
1937 * @ioc: per adapter object
1938 * @smid: system request message index
1939 * @msix_index: MSIX table index supplied by the OS
1940 * @reply: reply message frame(lower 32bit addr)
1943 * The callback handler when using scsih_issue_tm.
1945 * Return 1 meaning mf should be freed from _base_interrupt
1946 * 0 means the mf is freed from this function.
1949 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1951 MPI2DefaultReply_t *mpi_reply;
1953 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1955 if (ioc->tm_cmds.smid != smid)
1957 mpt3sas_base_flush_reply_queues(ioc);
1958 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1959 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1961 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1962 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1964 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1965 complete(&ioc->tm_cmds.done);
1970 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1971 * @ioc: per adapter object
1972 * @handle: device handle
1974 * During taskmangement request, we need to freeze the device queue.
1977 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1979 struct MPT3SAS_DEVICE *sas_device_priv_data;
1980 struct scsi_device *sdev;
1983 shost_for_each_device(sdev, ioc->shost) {
1986 sas_device_priv_data = sdev->hostdata;
1987 if (!sas_device_priv_data)
1989 if (sas_device_priv_data->sas_target->handle == handle) {
1990 sas_device_priv_data->sas_target->tm_busy = 1;
1992 ioc->ignore_loginfos = 1;
1998 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1999 * @ioc: per adapter object
2000 * @handle: device handle
2002 * During taskmangement request, we need to freeze the device queue.
2005 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2007 struct MPT3SAS_DEVICE *sas_device_priv_data;
2008 struct scsi_device *sdev;
2011 shost_for_each_device(sdev, ioc->shost) {
2014 sas_device_priv_data = sdev->hostdata;
2015 if (!sas_device_priv_data)
2017 if (sas_device_priv_data->sas_target->handle == handle) {
2018 sas_device_priv_data->sas_target->tm_busy = 0;
2020 ioc->ignore_loginfos = 0;
2026 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2027 * @ioc: per adapter struct
2028 * @device_handle: device handle
2029 * @channel: the channel assigned by the OS
2030 * @id: the id assigned by the OS
2032 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2033 * @smid_task: smid assigned to the task
2034 * @timeout: timeout in seconds
2035 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2038 * A generic API for sending task management requests to firmware.
2040 * The callback index is set inside `ioc->tm_cb_idx`.
2042 * Return SUCCESS or FAILED.
2045 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2046 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2047 enum mutex_type m_type)
2049 Mpi2SCSITaskManagementRequest_t *mpi_request;
2050 Mpi2SCSITaskManagementReply_t *mpi_reply;
2053 unsigned long timeleft;
2054 struct scsiio_tracker *scsi_lookup = NULL;
2057 if (m_type == TM_MUTEX_ON)
2058 mutex_lock(&ioc->tm_cmds.mutex);
2059 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2060 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2061 __func__, ioc->name);
2066 if (ioc->shost_recovery || ioc->remove_host ||
2067 ioc->pci_error_recovery) {
2068 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2069 __func__, ioc->name);
2074 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2075 if (ioc_state & MPI2_DOORBELL_USED) {
2076 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2077 "unexpected doorbell active!\n", ioc->name));
2078 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2080 rc = (!rc) ? SUCCESS : FAILED;
2084 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2085 mpt3sas_base_fault_info(ioc, ioc_state &
2086 MPI2_DOORBELL_DATA_MASK);
2087 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2089 rc = (!rc) ? SUCCESS : FAILED;
2093 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2095 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2096 ioc->name, __func__);
2101 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2102 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2104 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2105 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2106 ioc->name, handle, type, smid_task));
2107 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2108 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2109 ioc->tm_cmds.smid = smid;
2110 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2111 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2112 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2113 mpi_request->DevHandle = cpu_to_le16(handle);
2114 mpi_request->TaskType = type;
2115 mpi_request->TaskMID = cpu_to_le16(smid_task);
2116 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2117 mpt3sas_scsih_set_tm_flag(ioc, handle);
2118 init_completion(&ioc->tm_cmds.done);
2119 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2120 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2121 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2122 pr_err(MPT3SAS_FMT "%s: timeout\n",
2123 ioc->name, __func__);
2124 _debug_dump_mf(mpi_request,
2125 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2126 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2127 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2129 rc = (!rc) ? SUCCESS : FAILED;
2130 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2131 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2136 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2137 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2138 mpi_reply = ioc->tm_cmds.reply;
2139 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2140 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2141 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2142 le32_to_cpu(mpi_reply->IOCLogInfo),
2143 le32_to_cpu(mpi_reply->TerminationCount)));
2144 if (ioc->logging_level & MPT_DEBUG_TM) {
2145 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2146 if (mpi_reply->IOCStatus)
2147 _debug_dump_mf(mpi_request,
2148 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2153 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2155 if (scsi_lookup->scmd == NULL)
2160 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2161 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2166 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2167 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2168 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2173 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2181 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2182 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2183 if (m_type == TM_MUTEX_ON)
2184 mutex_unlock(&ioc->tm_cmds.mutex);
2189 if (m_type == TM_MUTEX_ON)
2190 mutex_unlock(&ioc->tm_cmds.mutex);
2195 * _scsih_tm_display_info - displays info about the device
2196 * @ioc: per adapter struct
2197 * @scmd: pointer to scsi command object
2199 * Called by task management callback handlers.
2202 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2204 struct scsi_target *starget = scmd->device->sdev_target;
2205 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2206 struct _sas_device *sas_device = NULL;
2207 unsigned long flags;
2208 char *device_str = NULL;
2212 device_str = "volume";
2214 scsi_print_command(scmd);
2215 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2216 starget_printk(KERN_INFO, starget,
2217 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2218 device_str, priv_target->handle,
2219 device_str, (unsigned long long)priv_target->sas_address);
2221 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2222 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2223 priv_target->sas_address);
2225 if (priv_target->flags &
2226 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2227 starget_printk(KERN_INFO, starget,
2228 "volume handle(0x%04x), "
2229 "volume wwid(0x%016llx)\n",
2230 sas_device->volume_handle,
2231 (unsigned long long)sas_device->volume_wwid);
2233 starget_printk(KERN_INFO, starget,
2234 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2236 (unsigned long long)sas_device->sas_address,
2238 if (sas_device->enclosure_handle != 0)
2239 starget_printk(KERN_INFO, starget,
2240 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2241 (unsigned long long)
2242 sas_device->enclosure_logical_id,
2244 if (sas_device->connector_name)
2245 starget_printk(KERN_INFO, starget,
2246 "enclosure level(0x%04x),connector name(%s)\n",
2247 sas_device->enclosure_level,
2248 sas_device->connector_name);
2250 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2255 * _scsih_abort - eh threads main abort routine
2256 * @scmd: pointer to scsi command object
2258 * Returns SUCCESS if command aborted else FAILED
2261 _scsih_abort(struct scsi_cmnd *scmd)
2263 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2264 struct MPT3SAS_DEVICE *sas_device_priv_data;
2269 sdev_printk(KERN_INFO, scmd->device,
2270 "attempting task abort! scmd(%p)\n", scmd);
2271 _scsih_tm_display_info(ioc, scmd);
2273 sas_device_priv_data = scmd->device->hostdata;
2274 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2275 sdev_printk(KERN_INFO, scmd->device,
2276 "device been deleted! scmd(%p)\n", scmd);
2277 scmd->result = DID_NO_CONNECT << 16;
2278 scmd->scsi_done(scmd);
2283 /* search for the command */
2284 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2286 scmd->result = DID_RESET << 16;
2291 /* for hidden raid components and volumes this is not supported */
2292 if (sas_device_priv_data->sas_target->flags &
2293 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2294 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2295 scmd->result = DID_RESET << 16;
2300 mpt3sas_halt_firmware(ioc);
2302 handle = sas_device_priv_data->sas_target->handle;
2303 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2304 scmd->device->id, scmd->device->lun,
2305 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2308 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2309 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2314 * _scsih_dev_reset - eh threads main device reset routine
2315 * @scmd: pointer to scsi command object
2317 * Returns SUCCESS if command aborted else FAILED
2320 _scsih_dev_reset(struct scsi_cmnd *scmd)
2322 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2323 struct MPT3SAS_DEVICE *sas_device_priv_data;
2324 struct _sas_device *sas_device;
2325 unsigned long flags;
2329 sdev_printk(KERN_INFO, scmd->device,
2330 "attempting device reset! scmd(%p)\n", scmd);
2331 _scsih_tm_display_info(ioc, scmd);
2333 sas_device_priv_data = scmd->device->hostdata;
2334 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2335 sdev_printk(KERN_INFO, scmd->device,
2336 "device been deleted! scmd(%p)\n", scmd);
2337 scmd->result = DID_NO_CONNECT << 16;
2338 scmd->scsi_done(scmd);
2343 /* for hidden raid components obtain the volume_handle */
2345 if (sas_device_priv_data->sas_target->flags &
2346 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2347 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2348 sas_device = _scsih_sas_device_find_by_handle(ioc,
2349 sas_device_priv_data->sas_target->handle);
2351 handle = sas_device->volume_handle;
2352 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2354 handle = sas_device_priv_data->sas_target->handle;
2357 scmd->result = DID_RESET << 16;
2362 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2363 scmd->device->id, scmd->device->lun,
2364 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2367 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2368 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2373 * _scsih_target_reset - eh threads main target reset routine
2374 * @scmd: pointer to scsi command object
2376 * Returns SUCCESS if command aborted else FAILED
2379 _scsih_target_reset(struct scsi_cmnd *scmd)
2381 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2382 struct MPT3SAS_DEVICE *sas_device_priv_data;
2383 struct _sas_device *sas_device;
2384 unsigned long flags;
2387 struct scsi_target *starget = scmd->device->sdev_target;
2389 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2391 _scsih_tm_display_info(ioc, scmd);
2393 sas_device_priv_data = scmd->device->hostdata;
2394 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2395 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2397 scmd->result = DID_NO_CONNECT << 16;
2398 scmd->scsi_done(scmd);
2403 /* for hidden raid components obtain the volume_handle */
2405 if (sas_device_priv_data->sas_target->flags &
2406 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2407 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2408 sas_device = _scsih_sas_device_find_by_handle(ioc,
2409 sas_device_priv_data->sas_target->handle);
2411 handle = sas_device->volume_handle;
2412 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2414 handle = sas_device_priv_data->sas_target->handle;
2417 scmd->result = DID_RESET << 16;
2422 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2423 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2427 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2428 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2434 * _scsih_host_reset - eh threads main host reset routine
2435 * @scmd: pointer to scsi command object
2437 * Returns SUCCESS if command aborted else FAILED
2440 _scsih_host_reset(struct scsi_cmnd *scmd)
2442 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2445 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2447 scsi_print_command(scmd);
2449 if (ioc->is_driver_loading) {
2450 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2456 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2458 r = (retval < 0) ? FAILED : SUCCESS;
2460 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2461 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2467 * _scsih_fw_event_add - insert and queue up fw_event
2468 * @ioc: per adapter object
2469 * @fw_event: object describing the event
2470 * Context: This function will acquire ioc->fw_event_lock.
2472 * This adds the firmware event object into link list, then queues it up to
2473 * be processed from user context.
2478 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2480 unsigned long flags;
2482 if (ioc->firmware_event_thread == NULL)
2485 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2486 INIT_LIST_HEAD(&fw_event->list);
2487 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2488 INIT_WORK(&fw_event->work, _firmware_event_work);
2489 queue_work(ioc->firmware_event_thread, &fw_event->work);
2490 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2494 * _scsih_fw_event_free - delete fw_event
2495 * @ioc: per adapter object
2496 * @fw_event: object describing the event
2497 * Context: This function will acquire ioc->fw_event_lock.
2499 * This removes firmware event object from link list, frees associated memory.
2504 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2507 unsigned long flags;
2509 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2510 list_del(&fw_event->list);
2512 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2517 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2518 * @ioc: per adapter object
2519 * @event_data: trigger event data
2524 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2525 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2527 struct fw_event_work *fw_event;
2529 if (ioc->is_driver_loading)
2531 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2535 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2536 fw_event->ioc = ioc;
2537 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2538 _scsih_fw_event_add(ioc, fw_event);
2542 * _scsih_error_recovery_delete_devices - remove devices not responding
2543 * @ioc: per adapter object
2548 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2550 struct fw_event_work *fw_event;
2552 if (ioc->is_driver_loading)
2554 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2557 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2558 fw_event->ioc = ioc;
2559 _scsih_fw_event_add(ioc, fw_event);
2563 * mpt3sas_port_enable_complete - port enable completed (fake event)
2564 * @ioc: per adapter object
2569 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2571 struct fw_event_work *fw_event;
2573 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2576 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2577 fw_event->ioc = ioc;
2578 _scsih_fw_event_add(ioc, fw_event);
2582 * _scsih_fw_event_cleanup_queue - cleanup event queue
2583 * @ioc: per adapter object
2585 * Walk the firmware event queue, either killing timers, or waiting
2586 * for outstanding events to complete
2591 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2593 struct fw_event_work *fw_event, *next;
2595 if (list_empty(&ioc->fw_event_list) ||
2596 !ioc->firmware_event_thread || in_interrupt())
2599 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2600 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2601 _scsih_fw_event_free(ioc, fw_event);
2608 * _scsih_internal_device_block - block the sdev device
2609 * @sdev: per device object
2610 * @sas_device_priv_data : per device driver private data
2612 * make sure device is blocked without error, if not
2616 _scsih_internal_device_block(struct scsi_device *sdev,
2617 struct MPT3SAS_DEVICE *sas_device_priv_data)
2621 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2622 sas_device_priv_data->sas_target->handle);
2623 sas_device_priv_data->block = 1;
2625 r = scsi_internal_device_block(sdev);
2627 sdev_printk(KERN_WARNING, sdev,
2628 "device_block failed with return(%d) for handle(0x%04x)\n",
2629 sas_device_priv_data->sas_target->handle, r);
2633 * _scsih_internal_device_unblock - unblock the sdev device
2634 * @sdev: per device object
2635 * @sas_device_priv_data : per device driver private data
2636 * make sure device is unblocked without error, if not retry
2637 * by blocking and then unblocking
2641 _scsih_internal_device_unblock(struct scsi_device *sdev,
2642 struct MPT3SAS_DEVICE *sas_device_priv_data)
2646 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2647 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2648 sas_device_priv_data->block = 0;
2649 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2651 /* The device has been set to SDEV_RUNNING by SD layer during
2652 * device addition but the request queue is still stopped by
2653 * our earlier block call. We need to perform a block again
2654 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2656 sdev_printk(KERN_WARNING, sdev,
2657 "device_unblock failed with return(%d) for handle(0x%04x) "
2658 "performing a block followed by an unblock\n",
2659 sas_device_priv_data->sas_target->handle, r);
2660 sas_device_priv_data->block = 1;
2661 r = scsi_internal_device_block(sdev);
2663 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2664 "failed with return(%d) for handle(0x%04x)\n",
2665 sas_device_priv_data->sas_target->handle, r);
2667 sas_device_priv_data->block = 0;
2668 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2670 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2671 " failed with return(%d) for handle(0x%04x)\n",
2672 sas_device_priv_data->sas_target->handle, r);
2677 * _scsih_ublock_io_all_device - unblock every device
2678 * @ioc: per adapter object
2680 * change the device state from block to running
2683 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2685 struct MPT3SAS_DEVICE *sas_device_priv_data;
2686 struct scsi_device *sdev;
2688 shost_for_each_device(sdev, ioc->shost) {
2689 sas_device_priv_data = sdev->hostdata;
2690 if (!sas_device_priv_data)
2692 if (!sas_device_priv_data->block)
2695 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2696 "device_running, handle(0x%04x)\n",
2697 sas_device_priv_data->sas_target->handle));
2698 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2704 * _scsih_ublock_io_device - prepare device to be deleted
2705 * @ioc: per adapter object
2706 * @sas_addr: sas address
2708 * unblock then put device in offline state
2711 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2713 struct MPT3SAS_DEVICE *sas_device_priv_data;
2714 struct scsi_device *sdev;
2716 shost_for_each_device(sdev, ioc->shost) {
2717 sas_device_priv_data = sdev->hostdata;
2718 if (!sas_device_priv_data)
2720 if (sas_device_priv_data->sas_target->sas_address
2723 if (sas_device_priv_data->block)
2724 _scsih_internal_device_unblock(sdev,
2725 sas_device_priv_data);
2730 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2731 * @ioc: per adapter object
2732 * @handle: device handle
2734 * During device pull we need to appropiately set the sdev state.
2737 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2739 struct MPT3SAS_DEVICE *sas_device_priv_data;
2740 struct scsi_device *sdev;
2742 shost_for_each_device(sdev, ioc->shost) {
2743 sas_device_priv_data = sdev->hostdata;
2744 if (!sas_device_priv_data)
2746 if (sas_device_priv_data->block)
2748 _scsih_internal_device_block(sdev, sas_device_priv_data);
2753 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2754 * @ioc: per adapter object
2755 * @handle: device handle
2757 * During device pull we need to appropiately set the sdev state.
2760 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2762 struct MPT3SAS_DEVICE *sas_device_priv_data;
2763 struct scsi_device *sdev;
2764 struct _sas_device *sas_device;
2766 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2770 shost_for_each_device(sdev, ioc->shost) {
2771 sas_device_priv_data = sdev->hostdata;
2772 if (!sas_device_priv_data)
2774 if (sas_device_priv_data->sas_target->handle != handle)
2776 if (sas_device_priv_data->block)
2778 if (sas_device->pend_sas_rphy_add)
2780 _scsih_internal_device_block(sdev, sas_device_priv_data);
2785 * _scsih_block_io_to_children_attached_to_ex
2786 * @ioc: per adapter object
2787 * @sas_expander: the sas_device object
2789 * This routine set sdev state to SDEV_BLOCK for all devices
2790 * attached to this expander. This function called when expander is
2794 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2795 struct _sas_node *sas_expander)
2797 struct _sas_port *mpt3sas_port;
2798 struct _sas_device *sas_device;
2799 struct _sas_node *expander_sibling;
2800 unsigned long flags;
2805 list_for_each_entry(mpt3sas_port,
2806 &sas_expander->sas_port_list, port_list) {
2807 if (mpt3sas_port->remote_identify.device_type ==
2809 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2811 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2812 mpt3sas_port->remote_identify.sas_address);
2814 set_bit(sas_device->handle,
2815 ioc->blocking_handles);
2816 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2820 list_for_each_entry(mpt3sas_port,
2821 &sas_expander->sas_port_list, port_list) {
2823 if (mpt3sas_port->remote_identify.device_type ==
2824 SAS_EDGE_EXPANDER_DEVICE ||
2825 mpt3sas_port->remote_identify.device_type ==
2826 SAS_FANOUT_EXPANDER_DEVICE) {
2828 mpt3sas_scsih_expander_find_by_sas_address(
2829 ioc, mpt3sas_port->remote_identify.sas_address);
2830 _scsih_block_io_to_children_attached_to_ex(ioc,
2837 * _scsih_block_io_to_children_attached_directly
2838 * @ioc: per adapter object
2839 * @event_data: topology change event data
2841 * This routine set sdev state to SDEV_BLOCK for all devices
2842 * direct attached during device pull.
2845 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2846 Mpi2EventDataSasTopologyChangeList_t *event_data)
2852 for (i = 0; i < event_data->NumEntries; i++) {
2853 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2856 reason_code = event_data->PHY[i].PhyStatus &
2857 MPI2_EVENT_SAS_TOPO_RC_MASK;
2858 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2859 _scsih_block_io_device(ioc, handle);
2864 * _scsih_tm_tr_send - send task management request
2865 * @ioc: per adapter object
2866 * @handle: device handle
2867 * Context: interrupt time.
2869 * This code is to initiate the device removal handshake protocol
2870 * with controller firmware. This function will issue target reset
2871 * using high priority request queue. It will send a sas iounit
2872 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2874 * This is designed to send muliple task management request at the same
2875 * time to the fifo. If the fifo is full, we will append the request,
2876 * and process it in a future completion.
2879 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2881 Mpi2SCSITaskManagementRequest_t *mpi_request;
2883 struct _sas_device *sas_device;
2884 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2885 u64 sas_address = 0;
2886 unsigned long flags;
2887 struct _tr_list *delayed_tr;
2890 if (ioc->remove_host) {
2891 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2892 "%s: host has been removed: handle(0x%04x)\n",
2893 __func__, ioc->name, handle));
2895 } else if (ioc->pci_error_recovery) {
2896 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2897 "%s: host in pci error recovery: handle(0x%04x)\n",
2898 __func__, ioc->name,
2902 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2903 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2904 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2905 "%s: host is not operational: handle(0x%04x)\n",
2906 __func__, ioc->name,
2911 /* if PD, then return */
2912 if (test_bit(handle, ioc->pd_handles))
2915 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2916 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2917 if (sas_device && sas_device->starget &&
2918 sas_device->starget->hostdata) {
2919 sas_target_priv_data = sas_device->starget->hostdata;
2920 sas_target_priv_data->deleted = 1;
2921 sas_address = sas_device->sas_address;
2923 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2925 if (sas_target_priv_data) {
2926 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2927 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2929 (unsigned long long)sas_address));
2930 if (sas_device->enclosure_handle != 0)
2931 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2932 "setting delete flag:enclosure logical id(0x%016llx),"
2933 " slot(%d)\n", ioc->name, (unsigned long long)
2934 sas_device->enclosure_logical_id,
2936 if (sas_device->connector_name)
2937 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2938 "setting delete flag: enclosure level(0x%04x),"
2939 " connector name( %s)\n", ioc->name,
2940 sas_device->enclosure_level,
2941 sas_device->connector_name));
2942 _scsih_ublock_io_device(ioc, sas_address);
2943 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2946 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2948 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2951 INIT_LIST_HEAD(&delayed_tr->list);
2952 delayed_tr->handle = handle;
2953 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2954 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2955 "DELAYED:tr:handle(0x%04x), (open)\n",
2956 ioc->name, handle));
2960 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2961 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2962 ioc->name, handle, smid,
2963 ioc->tm_tr_cb_idx));
2964 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2965 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2966 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2967 mpi_request->DevHandle = cpu_to_le16(handle);
2968 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2969 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2970 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2974 * _scsih_tm_tr_complete -
2975 * @ioc: per adapter object
2976 * @smid: system request message index
2977 * @msix_index: MSIX table index supplied by the OS
2978 * @reply: reply message frame(lower 32bit addr)
2979 * Context: interrupt time.
2981 * This is the target reset completion routine.
2982 * This code is part of the code to initiate the device removal
2983 * handshake protocol with controller firmware.
2984 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2986 * Return 1 meaning mf should be freed from _base_interrupt
2987 * 0 means the mf is freed from this function.
2990 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2994 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2995 Mpi2SCSITaskManagementReply_t *mpi_reply =
2996 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2997 Mpi2SasIoUnitControlRequest_t *mpi_request;
3001 if (ioc->remove_host) {
3002 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3003 "%s: host has been removed\n", __func__, ioc->name));
3005 } else if (ioc->pci_error_recovery) {
3006 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3007 "%s: host in pci error recovery\n", __func__,
3011 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3012 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3013 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3014 "%s: host is not operational\n", __func__, ioc->name));
3017 if (unlikely(!mpi_reply)) {
3018 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3019 ioc->name, __FILE__, __LINE__, __func__);
3022 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3023 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3024 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3025 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3026 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3028 le16_to_cpu(mpi_reply->DevHandle), smid));
3032 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3033 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3034 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3035 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3036 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3037 le32_to_cpu(mpi_reply->IOCLogInfo),
3038 le32_to_cpu(mpi_reply->TerminationCount)));
3040 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3041 if (!smid_sas_ctrl) {
3042 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3043 ioc->name, __func__);
3047 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3048 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3049 ioc->name, handle, smid_sas_ctrl,
3050 ioc->tm_sas_control_cb_idx));
3051 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3052 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3053 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3054 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3055 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3056 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3058 return _scsih_check_for_pending_tm(ioc, smid);
3063 * _scsih_sas_control_complete - completion routine
3064 * @ioc: per adapter object
3065 * @smid: system request message index
3066 * @msix_index: MSIX table index supplied by the OS
3067 * @reply: reply message frame(lower 32bit addr)
3068 * Context: interrupt time.
3070 * This is the sas iounit control completion routine.
3071 * This code is part of the code to initiate the device removal
3072 * handshake protocol with controller firmware.
3074 * Return 1 meaning mf should be freed from _base_interrupt
3075 * 0 means the mf is freed from this function.
3078 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3079 u8 msix_index, u32 reply)
3081 Mpi2SasIoUnitControlReply_t *mpi_reply =
3082 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3084 if (likely(mpi_reply)) {
3085 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3086 "sc_complete:handle(0x%04x), (open) "
3087 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3088 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3089 le16_to_cpu(mpi_reply->IOCStatus),
3090 le32_to_cpu(mpi_reply->IOCLogInfo)));
3092 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3093 ioc->name, __FILE__, __LINE__, __func__);
3099 * _scsih_tm_tr_volume_send - send target reset request for volumes
3100 * @ioc: per adapter object
3101 * @handle: device handle
3102 * Context: interrupt time.
3104 * This is designed to send muliple task management request at the same
3105 * time to the fifo. If the fifo is full, we will append the request,
3106 * and process it in a future completion.
3109 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3111 Mpi2SCSITaskManagementRequest_t *mpi_request;
3113 struct _tr_list *delayed_tr;
3115 if (ioc->shost_recovery || ioc->remove_host ||
3116 ioc->pci_error_recovery) {
3117 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3118 "%s: host reset in progress!\n",
3119 __func__, ioc->name));
3123 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3125 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3128 INIT_LIST_HEAD(&delayed_tr->list);
3129 delayed_tr->handle = handle;
3130 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3131 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3132 "DELAYED:tr:handle(0x%04x), (open)\n",
3133 ioc->name, handle));
3137 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3138 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3139 ioc->name, handle, smid,
3140 ioc->tm_tr_volume_cb_idx));
3141 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3142 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3143 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3144 mpi_request->DevHandle = cpu_to_le16(handle);
3145 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3146 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3150 * _scsih_tm_volume_tr_complete - target reset completion
3151 * @ioc: per adapter object
3152 * @smid: system request message index
3153 * @msix_index: MSIX table index supplied by the OS
3154 * @reply: reply message frame(lower 32bit addr)
3155 * Context: interrupt time.
3157 * Return 1 meaning mf should be freed from _base_interrupt
3158 * 0 means the mf is freed from this function.
3161 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3162 u8 msix_index, u32 reply)
3165 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3166 Mpi2SCSITaskManagementReply_t *mpi_reply =
3167 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3169 if (ioc->shost_recovery || ioc->remove_host ||
3170 ioc->pci_error_recovery) {
3171 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3172 "%s: host reset in progress!\n",
3173 __func__, ioc->name));
3176 if (unlikely(!mpi_reply)) {
3177 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3178 ioc->name, __FILE__, __LINE__, __func__);
3182 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3183 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3184 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3185 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3186 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3188 le16_to_cpu(mpi_reply->DevHandle), smid));
3192 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3193 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3194 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3195 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3196 le32_to_cpu(mpi_reply->IOCLogInfo),
3197 le32_to_cpu(mpi_reply->TerminationCount)));
3199 return _scsih_check_for_pending_tm(ioc, smid);
3204 * _scsih_check_for_pending_tm - check for pending task management
3205 * @ioc: per adapter object
3206 * @smid: system request message index
3208 * This will check delayed target reset list, and feed the
3211 * Return 1 meaning mf should be freed from _base_interrupt
3212 * 0 means the mf is freed from this function.
3215 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3217 struct _tr_list *delayed_tr;
3219 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3220 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3221 struct _tr_list, list);
3222 mpt3sas_base_free_smid(ioc, smid);
3223 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3224 list_del(&delayed_tr->list);
3229 if (!list_empty(&ioc->delayed_tr_list)) {
3230 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3231 struct _tr_list, list);
3232 mpt3sas_base_free_smid(ioc, smid);
3233 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3234 list_del(&delayed_tr->list);
3243 * _scsih_check_topo_delete_events - sanity check on topo events
3244 * @ioc: per adapter object
3245 * @event_data: the event data payload
3247 * This routine added to better handle cable breaker.
3249 * This handles the case where driver receives multiple expander
3250 * add and delete events in a single shot. When there is a delete event
3251 * the routine will void any pending add events waiting in the event queue.
3256 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3257 Mpi2EventDataSasTopologyChangeList_t *event_data)
3259 struct fw_event_work *fw_event;
3260 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3261 u16 expander_handle;
3262 struct _sas_node *sas_expander;
3263 unsigned long flags;
3267 for (i = 0 ; i < event_data->NumEntries; i++) {
3268 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3271 reason_code = event_data->PHY[i].PhyStatus &
3272 MPI2_EVENT_SAS_TOPO_RC_MASK;
3273 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3274 _scsih_tm_tr_send(ioc, handle);
3277 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3278 if (expander_handle < ioc->sas_hba.num_phys) {
3279 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3282 if (event_data->ExpStatus ==
3283 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3284 /* put expander attached devices into blocking state */
3285 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3286 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3288 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3289 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3291 handle = find_first_bit(ioc->blocking_handles,
3292 ioc->facts.MaxDevHandle);
3293 if (handle < ioc->facts.MaxDevHandle)
3294 _scsih_block_io_device(ioc, handle);
3295 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3296 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3297 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3299 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3302 /* mark ignore flag for pending events */
3303 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3304 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3305 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3308 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3309 fw_event->event_data;
3310 if (local_event_data->ExpStatus ==
3311 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3312 local_event_data->ExpStatus ==
3313 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3314 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3316 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3317 "setting ignoring flag\n", ioc->name));
3318 fw_event->ignore = 1;
3322 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3326 * _scsih_set_volume_delete_flag - setting volume delete flag
3327 * @ioc: per adapter object
3328 * @handle: device handle
3330 * This returns nothing.
3333 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3335 struct _raid_device *raid_device;
3336 struct MPT3SAS_TARGET *sas_target_priv_data;
3337 unsigned long flags;
3339 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3340 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3341 if (raid_device && raid_device->starget &&
3342 raid_device->starget->hostdata) {
3343 sas_target_priv_data =
3344 raid_device->starget->hostdata;
3345 sas_target_priv_data->deleted = 1;
3346 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3347 "setting delete flag: handle(0x%04x), "
3348 "wwid(0x%016llx)\n", ioc->name, handle,
3349 (unsigned long long) raid_device->wwid));
3351 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3355 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3356 * @handle: input handle
3357 * @a: handle for volume a
3358 * @b: handle for volume b
3360 * IR firmware only supports two raid volumes. The purpose of this
3361 * routine is to set the volume handle in either a or b. When the given
3362 * input handle is non-zero, or when a and b have not been set before.
3365 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3367 if (!handle || handle == *a || handle == *b)
3376 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3377 * @ioc: per adapter object
3378 * @event_data: the event data payload
3379 * Context: interrupt time.
3381 * This routine will send target reset to volume, followed by target
3382 * resets to the PDs. This is called when a PD has been removed, or
3383 * volume has been deleted or removed. When the target reset is sent
3384 * to volume, the PD target resets need to be queued to start upon
3385 * completion of the volume target reset.
3390 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3391 Mpi2EventDataIrConfigChangeList_t *event_data)
3393 Mpi2EventIrConfigElement_t *element;
3395 u16 handle, volume_handle, a, b;
3396 struct _tr_list *delayed_tr;
3401 /* Volume Resets for Deleted or Removed */
3402 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3403 for (i = 0; i < event_data->NumElements; i++, element++) {
3404 if (le32_to_cpu(event_data->Flags) &
3405 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3407 if (element->ReasonCode ==
3408 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3409 element->ReasonCode ==
3410 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3411 volume_handle = le16_to_cpu(element->VolDevHandle);
3412 _scsih_set_volume_delete_flag(ioc, volume_handle);
3413 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3417 /* Volume Resets for UNHIDE events */
3418 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3419 for (i = 0; i < event_data->NumElements; i++, element++) {
3420 if (le32_to_cpu(event_data->Flags) &
3421 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3423 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3424 volume_handle = le16_to_cpu(element->VolDevHandle);
3425 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3430 _scsih_tm_tr_volume_send(ioc, a);
3432 _scsih_tm_tr_volume_send(ioc, b);
3434 /* PD target resets */
3435 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3436 for (i = 0; i < event_data->NumElements; i++, element++) {
3437 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3439 handle = le16_to_cpu(element->PhysDiskDevHandle);
3440 volume_handle = le16_to_cpu(element->VolDevHandle);
3441 clear_bit(handle, ioc->pd_handles);
3443 _scsih_tm_tr_send(ioc, handle);
3444 else if (volume_handle == a || volume_handle == b) {
3445 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3446 BUG_ON(!delayed_tr);
3447 INIT_LIST_HEAD(&delayed_tr->list);
3448 delayed_tr->handle = handle;
3449 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3450 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3451 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3454 _scsih_tm_tr_send(ioc, handle);
3460 * _scsih_check_volume_delete_events - set delete flag for volumes
3461 * @ioc: per adapter object
3462 * @event_data: the event data payload
3463 * Context: interrupt time.
3465 * This will handle the case when the cable connected to entire volume is
3466 * pulled. We will take care of setting the deleted flag so normal IO will
3472 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3473 Mpi2EventDataIrVolume_t *event_data)
3477 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3479 state = le32_to_cpu(event_data->NewValue);
3480 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3481 MPI2_RAID_VOL_STATE_FAILED)
3482 _scsih_set_volume_delete_flag(ioc,
3483 le16_to_cpu(event_data->VolDevHandle));
3487 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3488 * @ioc: per adapter object
3489 * @event_data: the temp threshold event data
3490 * Context: interrupt time.
3495 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3496 Mpi2EventDataTemperature_t *event_data)
3498 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3499 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3500 " exceeded for Sensor: %d !!!\n", ioc->name,
3501 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3502 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3503 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3504 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3505 event_data->SensorNum);
3506 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3507 ioc->name, event_data->CurrentTemperature);
3512 * _scsih_flush_running_cmds - completing outstanding commands.
3513 * @ioc: per adapter object
3515 * The flushing out of all pending scmd commands following host reset,
3516 * where all IO is dropped to the floor.
3521 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3523 struct scsi_cmnd *scmd;
3527 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3528 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3532 mpt3sas_base_free_smid(ioc, smid);
3533 scsi_dma_unmap(scmd);
3534 if (ioc->pci_error_recovery)
3535 scmd->result = DID_NO_CONNECT << 16;
3537 scmd->result = DID_RESET << 16;
3538 scmd->scsi_done(scmd);
3540 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3545 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3546 * @ioc: per adapter object
3547 * @scmd: pointer to scsi command object
3548 * @mpi_request: pointer to the SCSI_IO reqest message frame
3550 * Supporting protection 1 and 3.
3555 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3556 Mpi2SCSIIORequest_t *mpi_request)
3559 unsigned char prot_op = scsi_get_prot_op(scmd);
3560 unsigned char prot_type = scsi_get_prot_type(scmd);
3561 Mpi25SCSIIORequest_t *mpi_request_3v =
3562 (Mpi25SCSIIORequest_t *)mpi_request;
3564 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3567 if (prot_op == SCSI_PROT_READ_STRIP)
3568 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3569 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3570 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3574 switch (prot_type) {
3575 case SCSI_PROT_DIF_TYPE1:
3576 case SCSI_PROT_DIF_TYPE2:
3579 * enable ref/guard checking
3580 * auto increment ref tag
3582 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3583 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3584 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3585 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3586 cpu_to_be32(scsi_get_lba(scmd));
3589 case SCSI_PROT_DIF_TYPE3:
3592 * enable guard checking
3594 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3599 mpi_request_3v->EEDPBlockSize =
3600 cpu_to_le16(scmd->device->sector_size);
3601 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3605 * _scsih_eedp_error_handling - return sense code for EEDP errors
3606 * @scmd: pointer to scsi command object
3607 * @ioc_status: ioc status
3612 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3616 switch (ioc_status) {
3617 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3620 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3623 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3630 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3632 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3633 SAM_STAT_CHECK_CONDITION;
3638 * _scsih_qcmd - main scsi request entry point
3639 * @scmd: pointer to scsi command object
3640 * @done: function pointer to be invoked on completion
3642 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3644 * Returns 0 on success. If there's a failure, return either:
3645 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3646 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3649 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3651 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3652 struct MPT3SAS_DEVICE *sas_device_priv_data;
3653 struct MPT3SAS_TARGET *sas_target_priv_data;
3654 Mpi2SCSIIORequest_t *mpi_request;
3659 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3660 if (ioc->logging_level & MPT_DEBUG_SCSI)
3661 scsi_print_command(scmd);
3664 sas_device_priv_data = scmd->device->hostdata;
3665 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3666 scmd->result = DID_NO_CONNECT << 16;
3667 scmd->scsi_done(scmd);
3671 if (ioc->pci_error_recovery || ioc->remove_host) {
3672 scmd->result = DID_NO_CONNECT << 16;
3673 scmd->scsi_done(scmd);
3677 sas_target_priv_data = sas_device_priv_data->sas_target;
3679 /* invalid device handle */
3680 handle = sas_target_priv_data->handle;
3681 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3682 scmd->result = DID_NO_CONNECT << 16;
3683 scmd->scsi_done(scmd);
3688 /* host recovery or link resets sent via IOCTLs */
3689 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3690 return SCSI_MLQUEUE_HOST_BUSY;
3692 /* device has been deleted */
3693 else if (sas_target_priv_data->deleted) {
3694 scmd->result = DID_NO_CONNECT << 16;
3695 scmd->scsi_done(scmd);
3697 /* device busy with task managment */
3698 } else if (sas_target_priv_data->tm_busy ||
3699 sas_device_priv_data->block)
3700 return SCSI_MLQUEUE_DEVICE_BUSY;
3702 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3703 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3704 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3705 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3707 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3710 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3712 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3713 scmd->cmd_len != 32)
3714 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3716 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3718 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3719 ioc->name, __func__);
3722 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3723 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3724 _scsih_setup_eedp(ioc, scmd, mpi_request);
3726 if (scmd->cmd_len == 32)
3727 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3728 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3729 if (sas_device_priv_data->sas_target->flags &
3730 MPT_TARGET_FLAGS_RAID_COMPONENT)
3731 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3733 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3734 mpi_request->DevHandle = cpu_to_le16(handle);
3735 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3736 mpi_request->Control = cpu_to_le32(mpi_control);
3737 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3738 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3739 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3740 mpi_request->SenseBufferLowAddress =
3741 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3742 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3743 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3745 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3747 if (mpi_request->DataLength) {
3748 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3749 mpt3sas_base_free_smid(ioc, smid);
3753 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3755 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3756 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3757 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3758 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3759 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3761 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3763 mpt3sas_base_put_smid_default(ioc, smid);
3767 return SCSI_MLQUEUE_HOST_BUSY;
3771 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3772 * @sense_buffer: sense data returned by target
3773 * @data: normalized skey/asc/ascq
3778 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3780 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3781 /* descriptor format */
3782 data->skey = sense_buffer[1] & 0x0F;
3783 data->asc = sense_buffer[2];
3784 data->ascq = sense_buffer[3];
3787 data->skey = sense_buffer[2] & 0x0F;
3788 data->asc = sense_buffer[12];
3789 data->ascq = sense_buffer[13];
3793 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
3795 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3796 * @ioc: per adapter object
3797 * @scmd: pointer to scsi command object
3798 * @mpi_reply: reply mf payload returned from firmware
3800 * scsi_status - SCSI Status code returned from target device
3801 * scsi_state - state info associated with SCSI_IO determined by ioc
3802 * ioc_status - ioc supplied status info
3807 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3808 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3812 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3813 MPI2_IOCSTATUS_MASK;
3814 u8 scsi_state = mpi_reply->SCSIState;
3815 u8 scsi_status = mpi_reply->SCSIStatus;
3816 char *desc_ioc_state = NULL;
3817 char *desc_scsi_status = NULL;
3818 char *desc_scsi_state = ioc->tmp_string;
3819 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3820 struct _sas_device *sas_device = NULL;
3821 unsigned long flags;
3822 struct scsi_target *starget = scmd->device->sdev_target;
3823 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3824 char *device_str = NULL;
3828 device_str = "volume";
3830 if (log_info == 0x31170000)
3833 switch (ioc_status) {
3834 case MPI2_IOCSTATUS_SUCCESS:
3835 desc_ioc_state = "success";
3837 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3838 desc_ioc_state = "invalid function";
3840 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3841 desc_ioc_state = "scsi recovered error";
3843 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3844 desc_ioc_state = "scsi invalid dev handle";
3846 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3847 desc_ioc_state = "scsi device not there";
3849 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3850 desc_ioc_state = "scsi data overrun";
3852 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3853 desc_ioc_state = "scsi data underrun";
3855 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3856 desc_ioc_state = "scsi io data error";
3858 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3859 desc_ioc_state = "scsi protocol error";
3861 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3862 desc_ioc_state = "scsi task terminated";
3864 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3865 desc_ioc_state = "scsi residual mismatch";
3867 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3868 desc_ioc_state = "scsi task mgmt failed";
3870 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3871 desc_ioc_state = "scsi ioc terminated";
3873 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3874 desc_ioc_state = "scsi ext terminated";
3876 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3877 desc_ioc_state = "eedp guard error";
3879 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3880 desc_ioc_state = "eedp ref tag error";
3882 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3883 desc_ioc_state = "eedp app tag error";
3886 desc_ioc_state = "unknown";
3890 switch (scsi_status) {
3891 case MPI2_SCSI_STATUS_GOOD:
3892 desc_scsi_status = "good";
3894 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3895 desc_scsi_status = "check condition";
3897 case MPI2_SCSI_STATUS_CONDITION_MET:
3898 desc_scsi_status = "condition met";
3900 case MPI2_SCSI_STATUS_BUSY:
3901 desc_scsi_status = "busy";
3903 case MPI2_SCSI_STATUS_INTERMEDIATE:
3904 desc_scsi_status = "intermediate";
3906 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3907 desc_scsi_status = "intermediate condmet";
3909 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3910 desc_scsi_status = "reservation conflict";
3912 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3913 desc_scsi_status = "command terminated";
3915 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3916 desc_scsi_status = "task set full";
3918 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3919 desc_scsi_status = "aca active";
3921 case MPI2_SCSI_STATUS_TASK_ABORTED:
3922 desc_scsi_status = "task aborted";
3925 desc_scsi_status = "unknown";
3929 desc_scsi_state[0] = '\0';
3931 desc_scsi_state = " ";
3932 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3933 strcat(desc_scsi_state, "response info ");
3934 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3935 strcat(desc_scsi_state, "state terminated ");
3936 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3937 strcat(desc_scsi_state, "no status ");
3938 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3939 strcat(desc_scsi_state, "autosense failed ");
3940 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3941 strcat(desc_scsi_state, "autosense valid ");
3943 scsi_print_command(scmd);
3945 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3946 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3947 device_str, (unsigned long long)priv_target->sas_address);
3949 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3950 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3951 priv_target->sas_address);
3954 "\tsas_address(0x%016llx), phy(%d)\n",
3955 ioc->name, (unsigned long long)
3956 sas_device->sas_address, sas_device->phy);
3957 if (sas_device->enclosure_handle != 0)
3959 "\tenclosure_logical_id(0x%016llx),"
3960 "slot(%d)\n", ioc->name,
3961 (unsigned long long)
3962 sas_device->enclosure_logical_id,
3964 if (sas_device->connector_name[0])
3966 "\tenclosure level(0x%04x),"
3967 " connector name( %s)\n", ioc->name,
3968 sas_device->enclosure_level,
3969 sas_device->connector_name);
3971 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3975 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3976 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3977 desc_ioc_state, ioc_status, smid);
3979 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3980 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3981 scsi_get_resid(scmd));
3983 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3984 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3985 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3987 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3988 ioc->name, desc_scsi_status,
3989 scsi_status, desc_scsi_state, scsi_state);
3991 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3992 struct sense_info data;
3993 _scsih_normalize_sense(scmd->sense_buffer, &data);
3995 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3996 ioc->name, data.skey,
3997 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4000 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4001 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4002 response_bytes = (u8 *)&response_info;
4003 _scsih_response_code(ioc, response_bytes[0]);
4009 * _scsih_turn_on_pfa_led - illuminate PFA LED
4010 * @ioc: per adapter object
4011 * @handle: device handle
4017 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4019 Mpi2SepReply_t mpi_reply;
4020 Mpi2SepRequest_t mpi_request;
4021 struct _sas_device *sas_device;
4023 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4027 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4028 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4029 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4030 mpi_request.SlotStatus =
4031 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4032 mpi_request.DevHandle = cpu_to_le16(handle);
4033 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4034 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4035 &mpi_request)) != 0) {
4036 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4037 __FILE__, __LINE__, __func__);
4040 sas_device->pfa_led_on = 1;
4042 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4043 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4044 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4045 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4046 le32_to_cpu(mpi_reply.IOCLogInfo)));
4051 * _scsih_turn_off_pfa_led - turn off Fault LED
4052 * @ioc: per adapter object
4053 * @sas_device: sas device whose PFA LED has to turned off
4059 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4060 struct _sas_device *sas_device)
4062 Mpi2SepReply_t mpi_reply;
4063 Mpi2SepRequest_t mpi_request;
4065 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4066 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4067 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4068 mpi_request.SlotStatus = 0;
4069 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4070 mpi_request.DevHandle = 0;
4071 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4072 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4073 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4074 &mpi_request)) != 0) {
4075 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4076 __FILE__, __LINE__, __func__);
4080 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4081 dewtprintk(ioc, printk(MPT3SAS_FMT
4082 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4083 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4084 le32_to_cpu(mpi_reply.IOCLogInfo)));
4089 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4090 * @ioc: per adapter object
4091 * @handle: device handle
4092 * Context: interrupt.
4097 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4099 struct fw_event_work *fw_event;
4101 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4104 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4105 fw_event->device_handle = handle;
4106 fw_event->ioc = ioc;
4107 _scsih_fw_event_add(ioc, fw_event);
4111 * _scsih_smart_predicted_fault - process smart errors
4112 * @ioc: per adapter object
4113 * @handle: device handle
4114 * Context: interrupt.
4119 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4121 struct scsi_target *starget;
4122 struct MPT3SAS_TARGET *sas_target_priv_data;
4123 Mpi2EventNotificationReply_t *event_reply;
4124 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4125 struct _sas_device *sas_device;
4127 unsigned long flags;
4129 /* only handle non-raid devices */
4130 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4131 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4133 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4136 starget = sas_device->starget;
4137 sas_target_priv_data = starget->hostdata;
4139 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4140 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4141 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4144 if (sas_device->enclosure_handle != 0)
4145 starget_printk(KERN_INFO, starget, "predicted fault, "
4146 "enclosure logical id(0x%016llx), slot(%d)\n",
4147 (unsigned long long)sas_device->enclosure_logical_id,
4149 if (sas_device->connector_name[0] != '\0')
4150 starget_printk(KERN_WARNING, starget, "predicted fault, "
4151 "enclosure level(0x%04x), connector name( %s)\n",
4152 sas_device->enclosure_level,
4153 sas_device->connector_name);
4154 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4156 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4157 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4159 /* insert into event log */
4160 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4161 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4162 event_reply = kzalloc(sz, GFP_KERNEL);
4164 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4165 ioc->name, __FILE__, __LINE__, __func__);
4169 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4170 event_reply->Event =
4171 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4172 event_reply->MsgLength = sz/4;
4173 event_reply->EventDataLength =
4174 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4175 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4176 event_reply->EventData;
4177 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4178 event_data->ASC = 0x5D;
4179 event_data->DevHandle = cpu_to_le16(handle);
4180 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4181 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4186 * _scsih_io_done - scsi request callback
4187 * @ioc: per adapter object
4188 * @smid: system request message index
4189 * @msix_index: MSIX table index supplied by the OS
4190 * @reply: reply message frame(lower 32bit addr)
4192 * Callback handler when using _scsih_qcmd.
4194 * Return 1 meaning mf should be freed from _base_interrupt
4195 * 0 means the mf is freed from this function.
4198 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4200 Mpi2SCSIIORequest_t *mpi_request;
4201 Mpi2SCSIIOReply_t *mpi_reply;
4202 struct scsi_cmnd *scmd;
4208 struct MPT3SAS_DEVICE *sas_device_priv_data;
4209 u32 response_code = 0;
4211 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4212 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4216 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4218 if (mpi_reply == NULL) {
4219 scmd->result = DID_OK << 16;
4223 sas_device_priv_data = scmd->device->hostdata;
4224 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4225 sas_device_priv_data->sas_target->deleted) {
4226 scmd->result = DID_NO_CONNECT << 16;
4229 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4231 /* turning off TLR */
4232 scsi_state = mpi_reply->SCSIState;
4233 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4235 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4236 if (!sas_device_priv_data->tlr_snoop_check) {
4237 sas_device_priv_data->tlr_snoop_check++;
4238 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4239 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4240 sas_device_priv_data->flags &=
4244 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4245 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4246 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4247 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4250 ioc_status &= MPI2_IOCSTATUS_MASK;
4251 scsi_status = mpi_reply->SCSIStatus;
4253 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4254 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4255 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4256 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4257 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4260 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4261 struct sense_info data;
4262 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4264 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4265 le32_to_cpu(mpi_reply->SenseCount));
4266 memcpy(scmd->sense_buffer, sense_data, sz);
4267 _scsih_normalize_sense(scmd->sense_buffer, &data);
4268 /* failure prediction threshold exceeded */
4269 if (data.asc == 0x5D)
4270 _scsih_smart_predicted_fault(ioc,
4271 le16_to_cpu(mpi_reply->DevHandle));
4272 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4274 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4275 if (!(ioc->logging_level & MPT_DEBUG_REPLY) &&
4276 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4277 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4278 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4279 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4282 switch (ioc_status) {
4283 case MPI2_IOCSTATUS_BUSY:
4284 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4285 scmd->result = SAM_STAT_BUSY;
4288 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4289 scmd->result = DID_NO_CONNECT << 16;
4292 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4293 if (sas_device_priv_data->block) {
4294 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4297 if (log_info == 0x31110630) {
4298 if (scmd->retries > 2) {
4299 scmd->result = DID_NO_CONNECT << 16;
4300 scsi_device_set_state(scmd->device,
4303 scmd->result = DID_SOFT_ERROR << 16;
4304 scmd->device->expecting_cc_ua = 1;
4307 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4308 scmd->result = DID_RESET << 16;
4311 scmd->result = DID_SOFT_ERROR << 16;
4313 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4314 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4315 scmd->result = DID_RESET << 16;
4318 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4319 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4320 scmd->result = DID_SOFT_ERROR << 16;
4322 scmd->result = (DID_OK << 16) | scsi_status;
4325 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4326 scmd->result = (DID_OK << 16) | scsi_status;
4328 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4331 if (xfer_cnt < scmd->underflow) {
4332 if (scsi_status == SAM_STAT_BUSY)
4333 scmd->result = SAM_STAT_BUSY;
4335 scmd->result = DID_SOFT_ERROR << 16;
4336 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4337 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4338 scmd->result = DID_SOFT_ERROR << 16;
4339 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4340 scmd->result = DID_RESET << 16;
4341 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4342 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4343 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4344 scmd->result = (DRIVER_SENSE << 24) |
4345 SAM_STAT_CHECK_CONDITION;
4346 scmd->sense_buffer[0] = 0x70;
4347 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4348 scmd->sense_buffer[12] = 0x20;
4349 scmd->sense_buffer[13] = 0;
4353 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4354 scsi_set_resid(scmd, 0);
4355 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4356 case MPI2_IOCSTATUS_SUCCESS:
4357 scmd->result = (DID_OK << 16) | scsi_status;
4358 if (response_code ==
4359 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4360 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4361 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4362 scmd->result = DID_SOFT_ERROR << 16;
4363 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4364 scmd->result = DID_RESET << 16;
4367 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4368 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4369 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4370 _scsih_eedp_error_handling(scmd, ioc_status);
4373 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4374 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4375 case MPI2_IOCSTATUS_INVALID_SGL:
4376 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4377 case MPI2_IOCSTATUS_INVALID_FIELD:
4378 case MPI2_IOCSTATUS_INVALID_STATE:
4379 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4380 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4382 scmd->result = DID_SOFT_ERROR << 16;
4387 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
4388 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4389 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4394 scsi_dma_unmap(scmd);
4396 scmd->scsi_done(scmd);
4401 * _scsih_sas_host_refresh - refreshing sas host object contents
4402 * @ioc: per adapter object
4405 * During port enable, fw will send topology events for every device. Its
4406 * possible that the handles may change from the previous setting, so this
4407 * code keeping handles updating if changed.
4412 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4417 Mpi2ConfigReply_t mpi_reply;
4418 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4419 u16 attached_handle;
4422 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4423 "updating handles for sas_host(0x%016llx)\n",
4424 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4426 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4427 * sizeof(Mpi2SasIOUnit0PhyData_t));
4428 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4429 if (!sas_iounit_pg0) {
4430 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4431 ioc->name, __FILE__, __LINE__, __func__);
4435 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4436 sas_iounit_pg0, sz)) != 0)
4438 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4439 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4441 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4442 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4444 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4445 PhyData[0].ControllerDevHandle);
4446 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4447 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4449 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4450 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4451 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4452 attached_handle, i, link_rate);
4455 kfree(sas_iounit_pg0);
4459 * _scsih_sas_host_add - create sas host object
4460 * @ioc: per adapter object
4462 * Creating host side data object, stored in ioc->sas_hba
4467 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4470 Mpi2ConfigReply_t mpi_reply;
4471 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4472 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4473 Mpi2SasPhyPage0_t phy_pg0;
4474 Mpi2SasDevicePage0_t sas_device_pg0;
4475 Mpi2SasEnclosurePage0_t enclosure_pg0;
4478 u8 device_missing_delay;
4480 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4481 if (!ioc->sas_hba.num_phys) {
4482 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4483 ioc->name, __FILE__, __LINE__, __func__);
4487 /* sas_iounit page 0 */
4488 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4489 sizeof(Mpi2SasIOUnit0PhyData_t));
4490 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4491 if (!sas_iounit_pg0) {
4492 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4493 ioc->name, __FILE__, __LINE__, __func__);
4496 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4497 sas_iounit_pg0, sz))) {
4498 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4499 ioc->name, __FILE__, __LINE__, __func__);
4502 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4503 MPI2_IOCSTATUS_MASK;
4504 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4505 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4506 ioc->name, __FILE__, __LINE__, __func__);
4510 /* sas_iounit page 1 */
4511 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4512 sizeof(Mpi2SasIOUnit1PhyData_t));
4513 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4514 if (!sas_iounit_pg1) {
4515 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4516 ioc->name, __FILE__, __LINE__, __func__);
4519 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4520 sas_iounit_pg1, sz))) {
4521 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4522 ioc->name, __FILE__, __LINE__, __func__);
4525 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4526 MPI2_IOCSTATUS_MASK;
4527 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4528 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4529 ioc->name, __FILE__, __LINE__, __func__);
4533 ioc->io_missing_delay =
4534 sas_iounit_pg1->IODeviceMissingDelay;
4535 device_missing_delay =
4536 sas_iounit_pg1->ReportDeviceMissingDelay;
4537 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4538 ioc->device_missing_delay = (device_missing_delay &
4539 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4541 ioc->device_missing_delay = device_missing_delay &
4542 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4544 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4545 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4546 sizeof(struct _sas_phy), GFP_KERNEL);
4547 if (!ioc->sas_hba.phy) {
4548 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4549 ioc->name, __FILE__, __LINE__, __func__);
4552 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4553 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4555 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4556 ioc->name, __FILE__, __LINE__, __func__);
4559 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4560 MPI2_IOCSTATUS_MASK;
4561 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4562 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4563 ioc->name, __FILE__, __LINE__, __func__);
4568 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4569 PhyData[0].ControllerDevHandle);
4570 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4571 ioc->sas_hba.phy[i].phy_id = i;
4572 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4573 phy_pg0, ioc->sas_hba.parent_dev);
4575 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4576 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4577 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4578 ioc->name, __FILE__, __LINE__, __func__);
4581 ioc->sas_hba.enclosure_handle =
4582 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4583 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4585 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4586 ioc->name, ioc->sas_hba.handle,
4587 (unsigned long long) ioc->sas_hba.sas_address,
4588 ioc->sas_hba.num_phys) ;
4590 if (ioc->sas_hba.enclosure_handle) {
4591 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4592 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4593 ioc->sas_hba.enclosure_handle)))
4594 ioc->sas_hba.enclosure_logical_id =
4595 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4599 kfree(sas_iounit_pg1);
4600 kfree(sas_iounit_pg0);
4604 * _scsih_expander_add - creating expander object
4605 * @ioc: per adapter object
4606 * @handle: expander handle
4608 * Creating expander object, stored in ioc->sas_expander_list.
4610 * Return 0 for success, else error.
4613 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4615 struct _sas_node *sas_expander;
4616 Mpi2ConfigReply_t mpi_reply;
4617 Mpi2ExpanderPage0_t expander_pg0;
4618 Mpi2ExpanderPage1_t expander_pg1;
4619 Mpi2SasEnclosurePage0_t enclosure_pg0;
4622 u64 sas_address, sas_address_parent = 0;
4624 unsigned long flags;
4625 struct _sas_port *mpt3sas_port = NULL;
4632 if (ioc->shost_recovery || ioc->pci_error_recovery)
4635 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4636 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4637 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4638 ioc->name, __FILE__, __LINE__, __func__);
4642 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4643 MPI2_IOCSTATUS_MASK;
4644 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4645 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4646 ioc->name, __FILE__, __LINE__, __func__);
4650 /* handle out of order topology events */
4651 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4652 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4654 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4655 ioc->name, __FILE__, __LINE__, __func__);
4658 if (sas_address_parent != ioc->sas_hba.sas_address) {
4659 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4660 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4661 sas_address_parent);
4662 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4663 if (!sas_expander) {
4664 rc = _scsih_expander_add(ioc, parent_handle);
4670 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4671 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4672 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4674 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4679 sas_expander = kzalloc(sizeof(struct _sas_node),
4681 if (!sas_expander) {
4682 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4683 ioc->name, __FILE__, __LINE__, __func__);
4687 sas_expander->handle = handle;
4688 sas_expander->num_phys = expander_pg0.NumPhys;
4689 sas_expander->sas_address_parent = sas_address_parent;
4690 sas_expander->sas_address = sas_address;
4692 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4693 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4694 handle, parent_handle, (unsigned long long)
4695 sas_expander->sas_address, sas_expander->num_phys);
4697 if (!sas_expander->num_phys)
4699 sas_expander->phy = kcalloc(sas_expander->num_phys,
4700 sizeof(struct _sas_phy), GFP_KERNEL);
4701 if (!sas_expander->phy) {
4702 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4703 ioc->name, __FILE__, __LINE__, __func__);
4708 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4709 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4710 sas_address_parent);
4711 if (!mpt3sas_port) {
4712 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4713 ioc->name, __FILE__, __LINE__, __func__);
4717 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4719 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4720 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4721 &expander_pg1, i, handle))) {
4722 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4723 ioc->name, __FILE__, __LINE__, __func__);
4727 sas_expander->phy[i].handle = handle;
4728 sas_expander->phy[i].phy_id = i;
4730 if ((mpt3sas_transport_add_expander_phy(ioc,
4731 &sas_expander->phy[i], expander_pg1,
4732 sas_expander->parent_dev))) {
4733 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4734 ioc->name, __FILE__, __LINE__, __func__);
4740 if (sas_expander->enclosure_handle) {
4741 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4742 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4743 sas_expander->enclosure_handle)))
4744 sas_expander->enclosure_logical_id =
4745 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4748 _scsih_expander_node_add(ioc, sas_expander);
4754 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4755 sas_address_parent);
4756 kfree(sas_expander);
4761 * mpt3sas_expander_remove - removing expander object
4762 * @ioc: per adapter object
4763 * @sas_address: expander sas_address
4768 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4770 struct _sas_node *sas_expander;
4771 unsigned long flags;
4773 if (ioc->shost_recovery)
4776 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4777 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4780 list_del(&sas_expander->list);
4781 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4783 _scsih_expander_node_remove(ioc, sas_expander);
4787 * _scsih_done - internal SCSI_IO callback handler.
4788 * @ioc: per adapter object
4789 * @smid: system request message index
4790 * @msix_index: MSIX table index supplied by the OS
4791 * @reply: reply message frame(lower 32bit addr)
4793 * Callback handler when sending internal generated SCSI_IO.
4794 * The callback index passed is `ioc->scsih_cb_idx`
4796 * Return 1 meaning mf should be freed from _base_interrupt
4797 * 0 means the mf is freed from this function.
4800 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4802 MPI2DefaultReply_t *mpi_reply;
4804 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4805 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4807 if (ioc->scsih_cmds.smid != smid)
4809 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4811 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4812 mpi_reply->MsgLength*4);
4813 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4815 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4816 complete(&ioc->scsih_cmds.done);
4823 #define MPT3_MAX_LUNS (255)
4827 * _scsih_check_access_status - check access flags
4828 * @ioc: per adapter object
4829 * @sas_address: sas address
4830 * @handle: sas device handle
4831 * @access_flags: errors returned during discovery of the device
4833 * Return 0 for success, else failure
4836 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4837 u16 handle, u8 access_status)
4842 switch (access_status) {
4843 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4844 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4847 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4848 desc = "sata capability failed";
4850 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4851 desc = "sata affiliation conflict";
4853 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4854 desc = "route not addressable";
4856 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4857 desc = "smp error not addressable";
4859 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4860 desc = "device blocked";
4862 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4863 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4864 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4865 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4866 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4867 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4868 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4869 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4870 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4871 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4872 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4873 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4874 desc = "sata initialization failed";
4885 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4886 ioc->name, desc, (unsigned long long)sas_address, handle);
4891 * _scsih_check_device - checking device responsiveness
4892 * @ioc: per adapter object
4893 * @parent_sas_address: sas address of parent expander or sas host
4894 * @handle: attached device handle
4895 * @phy_numberv: phy number
4896 * @link_rate: new link rate
4901 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4902 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4904 Mpi2ConfigReply_t mpi_reply;
4905 Mpi2SasDevicePage0_t sas_device_pg0;
4906 struct _sas_device *sas_device;
4908 unsigned long flags;
4910 struct scsi_target *starget;
4911 struct MPT3SAS_TARGET *sas_target_priv_data;
4915 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4916 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4919 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4920 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4923 /* wide port handling ~ we need only handle device once for the phy that
4924 * is matched in sas device page zero
4926 if (phy_number != sas_device_pg0.PhyNum)
4929 /* check if this is end device */
4930 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4931 if (!(_scsih_is_end_device(device_info)))
4934 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4935 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4936 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4940 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4944 if (unlikely(sas_device->handle != handle)) {
4945 starget = sas_device->starget;
4946 sas_target_priv_data = starget->hostdata;
4947 starget_printk(KERN_INFO, starget,
4948 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4949 sas_device->handle, handle);
4950 sas_target_priv_data->handle = handle;
4951 sas_device->handle = handle;
4952 if (sas_device_pg0.Flags &
4953 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
4954 sas_device->enclosure_level =
4955 le16_to_cpu(sas_device_pg0.EnclosureLevel);
4956 memcpy(&sas_device->connector_name[0],
4957 &sas_device_pg0.ConnectorName[0], 4);
4959 sas_device->enclosure_level = 0;
4960 sas_device->connector_name[0] = '\0';
4964 /* check if device is present */
4965 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4966 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4968 "device is not present handle(0x%04x), flags!!!\n",
4970 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4974 /* check if there were any issues with discovery */
4975 if (_scsih_check_access_status(ioc, sas_address, handle,
4976 sas_device_pg0.AccessStatus)) {
4977 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4981 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4982 _scsih_ublock_io_device(ioc, sas_address);
4987 * _scsih_add_device - creating sas device object
4988 * @ioc: per adapter object
4989 * @handle: sas device handle
4990 * @phy_num: phy number end device attached to
4991 * @is_pd: is this hidden raid component
4993 * Creating end device object, stored in ioc->sas_device_list.
4995 * Returns 0 for success, non-zero for failure.
4998 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5001 Mpi2ConfigReply_t mpi_reply;
5002 Mpi2SasDevicePage0_t sas_device_pg0;
5003 Mpi2SasEnclosurePage0_t enclosure_pg0;
5004 struct _sas_device *sas_device;
5008 unsigned long flags;
5010 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5011 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5012 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5013 ioc->name, __FILE__, __LINE__, __func__);
5017 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5018 MPI2_IOCSTATUS_MASK;
5019 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5020 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5021 ioc->name, __FILE__, __LINE__, __func__);
5025 /* check if this is end device */
5026 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5027 if (!(_scsih_is_end_device(device_info)))
5029 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5031 /* check if device is present */
5032 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5033 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5034 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5039 /* check if there were any issues with discovery */
5040 if (_scsih_check_access_status(ioc, sas_address, handle,
5041 sas_device_pg0.AccessStatus))
5044 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5045 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5047 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5052 sas_device = kzalloc(sizeof(struct _sas_device),
5055 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5056 ioc->name, __FILE__, __LINE__, __func__);
5060 sas_device->handle = handle;
5061 if (_scsih_get_sas_address(ioc,
5062 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5063 &sas_device->sas_address_parent) != 0)
5064 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5065 ioc->name, __FILE__, __LINE__, __func__);
5066 sas_device->enclosure_handle =
5067 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5068 if (sas_device->enclosure_handle != 0)
5070 le16_to_cpu(sas_device_pg0.Slot);
5071 sas_device->device_info = device_info;
5072 sas_device->sas_address = sas_address;
5073 sas_device->phy = sas_device_pg0.PhyNum;
5074 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5075 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5077 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5078 sas_device->enclosure_level =
5079 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5080 memcpy(&sas_device->connector_name[0],
5081 &sas_device_pg0.ConnectorName[0], 4);
5083 sas_device->enclosure_level = 0;
5084 sas_device->connector_name[0] = '\0';
5086 /* get enclosure_logical_id */
5087 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5088 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5089 sas_device->enclosure_handle)))
5090 sas_device->enclosure_logical_id =
5091 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5093 /* get device name */
5094 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5096 if (ioc->wait_for_discovery_to_complete)
5097 _scsih_sas_device_init_add(ioc, sas_device);
5099 _scsih_sas_device_add(ioc, sas_device);
5105 * _scsih_remove_device - removing sas device object
5106 * @ioc: per adapter object
5107 * @sas_device_delete: the sas_device object
5112 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5113 struct _sas_device *sas_device)
5115 struct MPT3SAS_TARGET *sas_target_priv_data;
5117 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5118 (sas_device->pfa_led_on)) {
5119 _scsih_turn_off_pfa_led(ioc, sas_device);
5120 sas_device->pfa_led_on = 0;
5122 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5123 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5124 ioc->name, __func__,
5125 sas_device->handle, (unsigned long long)
5126 sas_device->sas_address));
5127 if (sas_device->enclosure_handle != 0)
5128 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5129 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5130 ioc->name, __func__,
5131 (unsigned long long)sas_device->enclosure_logical_id,
5133 if (sas_device->connector_name[0] != '\0')
5134 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5135 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5136 ioc->name, __func__,
5137 sas_device->enclosure_level,
5138 sas_device->connector_name));
5140 if (sas_device->starget && sas_device->starget->hostdata) {
5141 sas_target_priv_data = sas_device->starget->hostdata;
5142 sas_target_priv_data->deleted = 1;
5143 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5144 sas_target_priv_data->handle =
5145 MPT3SAS_INVALID_DEVICE_HANDLE;
5147 mpt3sas_transport_port_remove(ioc,
5148 sas_device->sas_address,
5149 sas_device->sas_address_parent);
5152 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5153 ioc->name, sas_device->handle,
5154 (unsigned long long) sas_device->sas_address);
5155 if (sas_device->enclosure_handle != 0)
5157 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5159 (unsigned long long)sas_device->enclosure_logical_id,
5161 if (sas_device->connector_name[0] != '\0')
5163 "removing enclosure level(0x%04x), connector name( %s)\n",
5164 ioc->name, sas_device->enclosure_level,
5165 sas_device->connector_name);
5167 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5168 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5169 ioc->name, __func__,
5170 sas_device->handle, (unsigned long long)
5171 sas_device->sas_address));
5172 if (sas_device->enclosure_handle != 0)
5173 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5174 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5175 ioc->name, __func__,
5176 (unsigned long long)sas_device->enclosure_logical_id,
5178 if (sas_device->connector_name[0] != '\0')
5179 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5180 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5181 ioc->name, __func__, sas_device->enclosure_level,
5182 sas_device->connector_name));
5187 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5189 * _scsih_sas_topology_change_event_debug - debug for topology event
5190 * @ioc: per adapter object
5191 * @event_data: event data payload
5195 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5196 Mpi2EventDataSasTopologyChangeList_t *event_data)
5202 char *status_str = NULL;
5203 u8 link_rate, prev_link_rate;
5205 switch (event_data->ExpStatus) {
5206 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5209 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5210 status_str = "remove";
5212 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5214 status_str = "responding";
5216 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5217 status_str = "remove delay";
5220 status_str = "unknown status";
5223 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5224 ioc->name, status_str);
5225 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5226 "start_phy(%02d), count(%d)\n",
5227 le16_to_cpu(event_data->ExpanderDevHandle),
5228 le16_to_cpu(event_data->EnclosureHandle),
5229 event_data->StartPhyNum, event_data->NumEntries);
5230 for (i = 0; i < event_data->NumEntries; i++) {
5231 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5234 phy_number = event_data->StartPhyNum + i;
5235 reason_code = event_data->PHY[i].PhyStatus &
5236 MPI2_EVENT_SAS_TOPO_RC_MASK;
5237 switch (reason_code) {
5238 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5239 status_str = "target add";
5241 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5242 status_str = "target remove";
5244 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5245 status_str = "delay target remove";
5247 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5248 status_str = "link rate change";
5250 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5251 status_str = "target responding";
5254 status_str = "unknown";
5257 link_rate = event_data->PHY[i].LinkRate >> 4;
5258 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5259 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5260 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5261 handle, status_str, link_rate, prev_link_rate);
5268 * _scsih_sas_topology_change_event - handle topology changes
5269 * @ioc: per adapter object
5270 * @fw_event: The fw_event_work object
5275 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5276 struct fw_event_work *fw_event)
5279 u16 parent_handle, handle;
5281 u8 phy_number, max_phys;
5282 struct _sas_node *sas_expander;
5284 unsigned long flags;
5285 u8 link_rate, prev_link_rate;
5286 Mpi2EventDataSasTopologyChangeList_t *event_data =
5287 (Mpi2EventDataSasTopologyChangeList_t *)
5288 fw_event->event_data;
5290 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5291 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5292 _scsih_sas_topology_change_event_debug(ioc, event_data);
5295 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5298 if (!ioc->sas_hba.num_phys)
5299 _scsih_sas_host_add(ioc);
5301 _scsih_sas_host_refresh(ioc);
5303 if (fw_event->ignore) {
5304 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5305 "ignoring expander event\n", ioc->name));
5309 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5311 /* handle expander add */
5312 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5313 if (_scsih_expander_add(ioc, parent_handle) != 0)
5316 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5317 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5320 sas_address = sas_expander->sas_address;
5321 max_phys = sas_expander->num_phys;
5322 } else if (parent_handle < ioc->sas_hba.num_phys) {
5323 sas_address = ioc->sas_hba.sas_address;
5324 max_phys = ioc->sas_hba.num_phys;
5326 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5329 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5331 /* handle siblings events */
5332 for (i = 0; i < event_data->NumEntries; i++) {
5333 if (fw_event->ignore) {
5334 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5335 "ignoring expander event\n", ioc->name));
5338 if (ioc->remove_host || ioc->pci_error_recovery)
5340 phy_number = event_data->StartPhyNum + i;
5341 if (phy_number >= max_phys)
5343 reason_code = event_data->PHY[i].PhyStatus &
5344 MPI2_EVENT_SAS_TOPO_RC_MASK;
5345 if ((event_data->PHY[i].PhyStatus &
5346 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5347 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5349 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5352 link_rate = event_data->PHY[i].LinkRate >> 4;
5353 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5354 switch (reason_code) {
5355 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5357 if (ioc->shost_recovery)
5360 if (link_rate == prev_link_rate)
5363 mpt3sas_transport_update_links(ioc, sas_address,
5364 handle, phy_number, link_rate);
5366 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5369 _scsih_check_device(ioc, sas_address, handle,
5370 phy_number, link_rate);
5373 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5375 if (ioc->shost_recovery)
5378 mpt3sas_transport_update_links(ioc, sas_address,
5379 handle, phy_number, link_rate);
5381 _scsih_add_device(ioc, handle, phy_number, 0);
5384 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5386 _scsih_device_remove_by_handle(ioc, handle);
5391 /* handle expander removal */
5392 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5394 mpt3sas_expander_remove(ioc, sas_address);
5399 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5401 * _scsih_sas_device_status_change_event_debug - debug for device event
5402 * @event_data: event data payload
5408 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5409 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5411 char *reason_str = NULL;
5413 switch (event_data->ReasonCode) {
5414 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5415 reason_str = "smart data";
5417 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5418 reason_str = "unsupported device discovered";
5420 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5421 reason_str = "internal device reset";
5423 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5424 reason_str = "internal task abort";
5426 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5427 reason_str = "internal task abort set";
5429 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5430 reason_str = "internal clear task set";
5432 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5433 reason_str = "internal query task";
5435 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5436 reason_str = "sata init failure";
5438 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5439 reason_str = "internal device reset complete";
5441 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5442 reason_str = "internal task abort complete";
5444 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5445 reason_str = "internal async notification";
5447 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5448 reason_str = "expander reduced functionality";
5450 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5451 reason_str = "expander reduced functionality complete";
5454 reason_str = "unknown reason";
5457 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5458 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5459 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5460 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5461 le16_to_cpu(event_data->TaskTag));
5462 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5463 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5464 event_data->ASC, event_data->ASCQ);
5470 * _scsih_sas_device_status_change_event - handle device status change
5471 * @ioc: per adapter object
5472 * @fw_event: The fw_event_work object
5478 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5479 struct fw_event_work *fw_event)
5481 struct MPT3SAS_TARGET *target_priv_data;
5482 struct _sas_device *sas_device;
5484 unsigned long flags;
5485 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5486 (Mpi2EventDataSasDeviceStatusChange_t *)
5487 fw_event->event_data;
5489 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5490 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5491 _scsih_sas_device_status_change_event_debug(ioc,
5495 /* In MPI Revision K (0xC), the internal device reset complete was
5496 * implemented, so avoid setting tm_busy flag for older firmware.
5498 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5501 if (event_data->ReasonCode !=
5502 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5503 event_data->ReasonCode !=
5504 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5507 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5508 sas_address = le64_to_cpu(event_data->SASAddress);
5509 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5512 if (!sas_device || !sas_device->starget) {
5513 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5517 target_priv_data = sas_device->starget->hostdata;
5518 if (!target_priv_data) {
5519 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5523 if (event_data->ReasonCode ==
5524 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5525 target_priv_data->tm_busy = 1;
5527 target_priv_data->tm_busy = 0;
5528 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5531 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5533 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5535 * @ioc: per adapter object
5536 * @event_data: event data payload
5542 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5543 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5545 char *reason_str = NULL;
5547 switch (event_data->ReasonCode) {
5548 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5549 reason_str = "enclosure add";
5551 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5552 reason_str = "enclosure remove";
5555 reason_str = "unknown reason";
5559 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5560 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5561 " number slots(%d)\n", ioc->name, reason_str,
5562 le16_to_cpu(event_data->EnclosureHandle),
5563 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5564 le16_to_cpu(event_data->StartSlot));
5569 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5570 * @ioc: per adapter object
5571 * @fw_event: The fw_event_work object
5577 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5578 struct fw_event_work *fw_event)
5580 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5581 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5582 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5583 (Mpi2EventDataSasEnclDevStatusChange_t *)
5584 fw_event->event_data);
5589 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5590 * @ioc: per adapter object
5591 * @fw_event: The fw_event_work object
5597 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5598 struct fw_event_work *fw_event)
5600 struct scsi_cmnd *scmd;
5601 struct scsi_device *sdev;
5604 struct MPT3SAS_DEVICE *sas_device_priv_data;
5605 u32 termination_count;
5607 Mpi2SCSITaskManagementReply_t *mpi_reply;
5608 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5609 (Mpi2EventDataSasBroadcastPrimitive_t *)
5610 fw_event->event_data;
5612 unsigned long flags;
5615 u8 task_abort_retries;
5617 mutex_lock(&ioc->tm_cmds.mutex);
5619 "%s: enter: phy number(%d), width(%d)\n",
5620 ioc->name, __func__, event_data->PhyNum,
5621 event_data->PortWidth);
5623 _scsih_block_io_all_device(ioc);
5625 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5626 mpi_reply = ioc->tm_cmds.reply;
5627 broadcast_aen_retry:
5629 /* sanity checks for retrying this loop */
5630 if (max_retries++ == 5) {
5631 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5632 ioc->name, __func__));
5634 } else if (max_retries > 1)
5635 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5636 ioc->name, __func__, max_retries - 1));
5638 termination_count = 0;
5640 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5641 if (ioc->shost_recovery)
5643 scmd = _scsih_scsi_lookup_get(ioc, smid);
5646 sdev = scmd->device;
5647 sas_device_priv_data = sdev->hostdata;
5648 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5650 /* skip hidden raid components */
5651 if (sas_device_priv_data->sas_target->flags &
5652 MPT_TARGET_FLAGS_RAID_COMPONENT)
5655 if (sas_device_priv_data->sas_target->flags &
5656 MPT_TARGET_FLAGS_VOLUME)
5659 handle = sas_device_priv_data->sas_target->handle;
5660 lun = sas_device_priv_data->lun;
5663 if (ioc->shost_recovery)
5666 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5667 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5668 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5671 sdev_printk(KERN_WARNING, sdev,
5672 "mpt3sas_scsih_issue_tm: FAILED when sending "
5673 "QUERY_TASK: scmd(%p)\n", scmd);
5674 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5675 goto broadcast_aen_retry;
5677 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5678 & MPI2_IOCSTATUS_MASK;
5679 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5680 sdev_printk(KERN_WARNING, sdev,
5681 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5683 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5684 goto broadcast_aen_retry;
5687 /* see if IO is still owned by IOC and target */
5688 if (mpi_reply->ResponseCode ==
5689 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5690 mpi_reply->ResponseCode ==
5691 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5692 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5695 task_abort_retries = 0;
5697 if (task_abort_retries++ == 60) {
5698 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5699 "%s: ABORT_TASK: giving up\n", ioc->name,
5701 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5702 goto broadcast_aen_retry;
5705 if (ioc->shost_recovery)
5708 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5709 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5712 sdev_printk(KERN_WARNING, sdev,
5713 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5714 "scmd(%p)\n", scmd);
5718 if (task_abort_retries > 1)
5719 sdev_printk(KERN_WARNING, sdev,
5720 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5722 task_abort_retries - 1, scmd);
5724 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5725 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5728 if (ioc->broadcast_aen_pending) {
5729 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5730 "%s: loop back due to pending AEN\n",
5731 ioc->name, __func__));
5732 ioc->broadcast_aen_pending = 0;
5733 goto broadcast_aen_retry;
5737 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5740 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5741 "%s - exit, query_count = %d termination_count = %d\n",
5742 ioc->name, __func__, query_count, termination_count));
5744 ioc->broadcast_aen_busy = 0;
5745 if (!ioc->shost_recovery)
5746 _scsih_ublock_io_all_device(ioc);
5747 mutex_unlock(&ioc->tm_cmds.mutex);
5751 * _scsih_sas_discovery_event - handle discovery events
5752 * @ioc: per adapter object
5753 * @fw_event: The fw_event_work object
5759 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5760 struct fw_event_work *fw_event)
5762 Mpi2EventDataSasDiscovery_t *event_data =
5763 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5765 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
5766 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5767 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5768 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5770 if (event_data->DiscoveryStatus)
5771 pr_info("discovery_status(0x%08x)",
5772 le32_to_cpu(event_data->DiscoveryStatus));
5777 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5778 !ioc->sas_hba.num_phys) {
5779 if (disable_discovery > 0 && ioc->shost_recovery) {
5780 /* Wait for the reset to complete */
5781 while (ioc->shost_recovery)
5784 _scsih_sas_host_add(ioc);
5789 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5790 * @ioc: per adapter object
5791 * @handle: device handle for physical disk
5792 * @phys_disk_num: physical disk number
5794 * Return 0 for success, else failure.
5797 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5799 Mpi2RaidActionRequest_t *mpi_request;
5800 Mpi2RaidActionReply_t *mpi_reply;
5808 mutex_lock(&ioc->scsih_cmds.mutex);
5810 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5811 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5812 ioc->name, __func__);
5816 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5818 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5820 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5821 ioc->name, __func__);
5822 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5827 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5828 ioc->scsih_cmds.smid = smid;
5829 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5831 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5832 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5833 mpi_request->PhysDiskNum = phys_disk_num;
5835 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5836 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5837 handle, phys_disk_num));
5839 init_completion(&ioc->scsih_cmds.done);
5840 mpt3sas_base_put_smid_default(ioc, smid);
5841 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5843 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5844 pr_err(MPT3SAS_FMT "%s: timeout\n",
5845 ioc->name, __func__);
5846 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5852 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5854 mpi_reply = ioc->scsih_cmds.reply;
5855 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5856 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5857 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5860 ioc_status &= MPI2_IOCSTATUS_MASK;
5861 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5862 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5863 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5864 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5868 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5869 "IR RAID_ACTION: completed successfully\n",
5874 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5875 mutex_unlock(&ioc->scsih_cmds.mutex);
5878 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5884 * _scsih_reprobe_lun - reprobing lun
5885 * @sdev: scsi device struct
5886 * @no_uld_attach: sdev->no_uld_attach flag setting
5890 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5893 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5894 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5895 sdev->no_uld_attach ? "hidding" : "exposing");
5896 rc = scsi_device_reprobe(sdev);
5900 * _scsih_sas_volume_add - add new volume
5901 * @ioc: per adapter object
5902 * @element: IR config element data
5908 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5909 Mpi2EventIrConfigElement_t *element)
5911 struct _raid_device *raid_device;
5912 unsigned long flags;
5914 u16 handle = le16_to_cpu(element->VolDevHandle);
5917 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5920 "failure at %s:%d/%s()!\n", ioc->name,
5921 __FILE__, __LINE__, __func__);
5925 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5926 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5927 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5932 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5935 "failure at %s:%d/%s()!\n", ioc->name,
5936 __FILE__, __LINE__, __func__);
5940 raid_device->id = ioc->sas_id++;
5941 raid_device->channel = RAID_CHANNEL;
5942 raid_device->handle = handle;
5943 raid_device->wwid = wwid;
5944 _scsih_raid_device_add(ioc, raid_device);
5945 if (!ioc->wait_for_discovery_to_complete) {
5946 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5947 raid_device->id, 0);
5949 _scsih_raid_device_remove(ioc, raid_device);
5951 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5952 _scsih_determine_boot_device(ioc, raid_device, 1);
5953 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5958 * _scsih_sas_volume_delete - delete volume
5959 * @ioc: per adapter object
5960 * @handle: volume device handle
5966 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5968 struct _raid_device *raid_device;
5969 unsigned long flags;
5970 struct MPT3SAS_TARGET *sas_target_priv_data;
5971 struct scsi_target *starget = NULL;
5973 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5974 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5976 if (raid_device->starget) {
5977 starget = raid_device->starget;
5978 sas_target_priv_data = starget->hostdata;
5979 sas_target_priv_data->deleted = 1;
5981 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5982 ioc->name, raid_device->handle,
5983 (unsigned long long) raid_device->wwid);
5984 list_del(&raid_device->list);
5987 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5989 scsi_remove_target(&starget->dev);
5993 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5994 * @ioc: per adapter object
5995 * @element: IR config element data
6001 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6002 Mpi2EventIrConfigElement_t *element)
6004 struct _sas_device *sas_device;
6005 struct scsi_target *starget = NULL;
6006 struct MPT3SAS_TARGET *sas_target_priv_data;
6007 unsigned long flags;
6008 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6010 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6011 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6013 sas_device->volume_handle = 0;
6014 sas_device->volume_wwid = 0;
6015 clear_bit(handle, ioc->pd_handles);
6016 if (sas_device->starget && sas_device->starget->hostdata) {
6017 starget = sas_device->starget;
6018 sas_target_priv_data = starget->hostdata;
6019 sas_target_priv_data->flags &=
6020 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6023 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6027 /* exposing raid component */
6029 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6033 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6034 * @ioc: per adapter object
6035 * @element: IR config element data
6041 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6042 Mpi2EventIrConfigElement_t *element)
6044 struct _sas_device *sas_device;
6045 struct scsi_target *starget = NULL;
6046 struct MPT3SAS_TARGET *sas_target_priv_data;
6047 unsigned long flags;
6048 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6049 u16 volume_handle = 0;
6050 u64 volume_wwid = 0;
6052 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6054 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6057 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6058 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6060 set_bit(handle, ioc->pd_handles);
6061 if (sas_device->starget && sas_device->starget->hostdata) {
6062 starget = sas_device->starget;
6063 sas_target_priv_data = starget->hostdata;
6064 sas_target_priv_data->flags |=
6065 MPT_TARGET_FLAGS_RAID_COMPONENT;
6066 sas_device->volume_handle = volume_handle;
6067 sas_device->volume_wwid = volume_wwid;
6070 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6074 /* hiding raid component */
6075 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6077 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6081 * _scsih_sas_pd_delete - delete pd component
6082 * @ioc: per adapter object
6083 * @element: IR config element data
6089 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6090 Mpi2EventIrConfigElement_t *element)
6092 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6094 _scsih_device_remove_by_handle(ioc, handle);
6098 * _scsih_sas_pd_add - remove pd component
6099 * @ioc: per adapter object
6100 * @element: IR config element data
6106 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6107 Mpi2EventIrConfigElement_t *element)
6109 struct _sas_device *sas_device;
6110 unsigned long flags;
6111 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6112 Mpi2ConfigReply_t mpi_reply;
6113 Mpi2SasDevicePage0_t sas_device_pg0;
6118 set_bit(handle, ioc->pd_handles);
6120 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6121 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6122 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6124 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6128 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6129 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6130 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6131 ioc->name, __FILE__, __LINE__, __func__);
6135 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6136 MPI2_IOCSTATUS_MASK;
6137 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6138 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6139 ioc->name, __FILE__, __LINE__, __func__);
6143 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6144 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6145 mpt3sas_transport_update_links(ioc, sas_address, handle,
6146 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6148 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6149 _scsih_add_device(ioc, handle, 0, 1);
6152 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6154 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6155 * @ioc: per adapter object
6156 * @event_data: event data payload
6162 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6163 Mpi2EventDataIrConfigChangeList_t *event_data)
6165 Mpi2EventIrConfigElement_t *element;
6168 char *reason_str = NULL, *element_str = NULL;
6170 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6172 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6173 ioc->name, (le32_to_cpu(event_data->Flags) &
6174 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6175 "foreign" : "native", event_data->NumElements);
6176 for (i = 0; i < event_data->NumElements; i++, element++) {
6177 switch (element->ReasonCode) {
6178 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6181 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6182 reason_str = "remove";
6184 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6185 reason_str = "no change";
6187 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6188 reason_str = "hide";
6190 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6191 reason_str = "unhide";
6193 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6194 reason_str = "volume_created";
6196 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6197 reason_str = "volume_deleted";
6199 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6200 reason_str = "pd_created";
6202 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6203 reason_str = "pd_deleted";
6206 reason_str = "unknown reason";
6209 element_type = le16_to_cpu(element->ElementFlags) &
6210 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6211 switch (element_type) {
6212 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6213 element_str = "volume";
6215 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6216 element_str = "phys disk";
6218 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6219 element_str = "hot spare";
6222 element_str = "unknown element";
6225 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6226 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6227 reason_str, le16_to_cpu(element->VolDevHandle),
6228 le16_to_cpu(element->PhysDiskDevHandle),
6229 element->PhysDiskNum);
6235 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6236 * @ioc: per adapter object
6237 * @fw_event: The fw_event_work object
6243 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6244 struct fw_event_work *fw_event)
6246 Mpi2EventIrConfigElement_t *element;
6249 Mpi2EventDataIrConfigChangeList_t *event_data =
6250 (Mpi2EventDataIrConfigChangeList_t *)
6251 fw_event->event_data;
6253 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6254 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6255 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6259 foreign_config = (le32_to_cpu(event_data->Flags) &
6260 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6262 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6263 if (ioc->shost_recovery) {
6265 for (i = 0; i < event_data->NumElements; i++, element++) {
6266 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6267 _scsih_ir_fastpath(ioc,
6268 le16_to_cpu(element->PhysDiskDevHandle),
6269 element->PhysDiskNum);
6273 for (i = 0; i < event_data->NumElements; i++, element++) {
6275 switch (element->ReasonCode) {
6276 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6277 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6278 if (!foreign_config)
6279 _scsih_sas_volume_add(ioc, element);
6281 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6282 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6283 if (!foreign_config)
6284 _scsih_sas_volume_delete(ioc,
6285 le16_to_cpu(element->VolDevHandle));
6287 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6288 _scsih_sas_pd_hide(ioc, element);
6290 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6291 _scsih_sas_pd_expose(ioc, element);
6293 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6294 _scsih_sas_pd_add(ioc, element);
6296 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6297 _scsih_sas_pd_delete(ioc, element);
6304 * _scsih_sas_ir_volume_event - IR volume event
6305 * @ioc: per adapter object
6306 * @fw_event: The fw_event_work object
6312 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6313 struct fw_event_work *fw_event)
6316 unsigned long flags;
6317 struct _raid_device *raid_device;
6321 Mpi2EventDataIrVolume_t *event_data =
6322 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6324 if (ioc->shost_recovery)
6327 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6330 handle = le16_to_cpu(event_data->VolDevHandle);
6331 state = le32_to_cpu(event_data->NewValue);
6332 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6333 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6334 ioc->name, __func__, handle,
6335 le32_to_cpu(event_data->PreviousValue), state));
6337 case MPI2_RAID_VOL_STATE_MISSING:
6338 case MPI2_RAID_VOL_STATE_FAILED:
6339 _scsih_sas_volume_delete(ioc, handle);
6342 case MPI2_RAID_VOL_STATE_ONLINE:
6343 case MPI2_RAID_VOL_STATE_DEGRADED:
6344 case MPI2_RAID_VOL_STATE_OPTIMAL:
6346 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6347 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6348 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6353 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6356 "failure at %s:%d/%s()!\n", ioc->name,
6357 __FILE__, __LINE__, __func__);
6361 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6364 "failure at %s:%d/%s()!\n", ioc->name,
6365 __FILE__, __LINE__, __func__);
6369 raid_device->id = ioc->sas_id++;
6370 raid_device->channel = RAID_CHANNEL;
6371 raid_device->handle = handle;
6372 raid_device->wwid = wwid;
6373 _scsih_raid_device_add(ioc, raid_device);
6374 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6375 raid_device->id, 0);
6377 _scsih_raid_device_remove(ioc, raid_device);
6380 case MPI2_RAID_VOL_STATE_INITIALIZING:
6387 * _scsih_sas_ir_physical_disk_event - PD event
6388 * @ioc: per adapter object
6389 * @fw_event: The fw_event_work object
6395 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6396 struct fw_event_work *fw_event)
6398 u16 handle, parent_handle;
6400 struct _sas_device *sas_device;
6401 unsigned long flags;
6402 Mpi2ConfigReply_t mpi_reply;
6403 Mpi2SasDevicePage0_t sas_device_pg0;
6405 Mpi2EventDataIrPhysicalDisk_t *event_data =
6406 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6409 if (ioc->shost_recovery)
6412 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6415 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6416 state = le32_to_cpu(event_data->NewValue);
6418 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6419 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6420 ioc->name, __func__, handle,
6421 le32_to_cpu(event_data->PreviousValue), state));
6423 case MPI2_RAID_PD_STATE_ONLINE:
6424 case MPI2_RAID_PD_STATE_DEGRADED:
6425 case MPI2_RAID_PD_STATE_REBUILDING:
6426 case MPI2_RAID_PD_STATE_OPTIMAL:
6427 case MPI2_RAID_PD_STATE_HOT_SPARE:
6429 set_bit(handle, ioc->pd_handles);
6430 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6431 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6432 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6437 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6438 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6440 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6441 ioc->name, __FILE__, __LINE__, __func__);
6445 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6446 MPI2_IOCSTATUS_MASK;
6447 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6448 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6449 ioc->name, __FILE__, __LINE__, __func__);
6453 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6454 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6455 mpt3sas_transport_update_links(ioc, sas_address, handle,
6456 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6458 _scsih_add_device(ioc, handle, 0, 1);
6462 case MPI2_RAID_PD_STATE_OFFLINE:
6463 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6464 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6470 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6472 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6473 * @ioc: per adapter object
6474 * @event_data: event data payload
6480 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6481 Mpi2EventDataIrOperationStatus_t *event_data)
6483 char *reason_str = NULL;
6485 switch (event_data->RAIDOperation) {
6486 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6487 reason_str = "resync";
6489 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6490 reason_str = "online capacity expansion";
6492 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6493 reason_str = "consistency check";
6495 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6496 reason_str = "background init";
6498 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6499 reason_str = "make data consistent";
6506 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6507 "\thandle(0x%04x), percent complete(%d)\n",
6508 ioc->name, reason_str,
6509 le16_to_cpu(event_data->VolDevHandle),
6510 event_data->PercentComplete);
6515 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6516 * @ioc: per adapter object
6517 * @fw_event: The fw_event_work object
6523 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6524 struct fw_event_work *fw_event)
6526 Mpi2EventDataIrOperationStatus_t *event_data =
6527 (Mpi2EventDataIrOperationStatus_t *)
6528 fw_event->event_data;
6529 static struct _raid_device *raid_device;
6530 unsigned long flags;
6533 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
6534 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6535 _scsih_sas_ir_operation_status_event_debug(ioc,
6539 /* code added for raid transport support */
6540 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6542 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6543 handle = le16_to_cpu(event_data->VolDevHandle);
6544 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6546 raid_device->percent_complete =
6547 event_data->PercentComplete;
6548 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6553 * _scsih_prep_device_scan - initialize parameters prior to device scan
6554 * @ioc: per adapter object
6556 * Set the deleted flag prior to device scan. If the device is found during
6557 * the scan, then we clear the deleted flag.
6560 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6562 struct MPT3SAS_DEVICE *sas_device_priv_data;
6563 struct scsi_device *sdev;
6565 shost_for_each_device(sdev, ioc->shost) {
6566 sas_device_priv_data = sdev->hostdata;
6567 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6568 sas_device_priv_data->sas_target->deleted = 1;
6573 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6574 * @ioc: per adapter object
6575 * @sas_device_pg0: SAS Device page 0
6577 * After host reset, find out whether devices are still responding.
6578 * Used in _scsih_remove_unresponsive_sas_devices.
6583 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
6584 Mpi2SasDevicePage0_t *sas_device_pg0)
6586 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6587 struct scsi_target *starget;
6588 struct _sas_device *sas_device;
6589 unsigned long flags;
6591 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6592 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6593 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
6594 (sas_device->slot == sas_device_pg0->Slot)) {
6595 sas_device->responding = 1;
6596 starget = sas_device->starget;
6597 if (starget && starget->hostdata) {
6598 sas_target_priv_data = starget->hostdata;
6599 sas_target_priv_data->tm_busy = 0;
6600 sas_target_priv_data->deleted = 0;
6602 sas_target_priv_data = NULL;
6604 starget_printk(KERN_INFO, starget,
6605 "handle(0x%04x), sas_addr(0x%016llx)\n",
6606 sas_device_pg0->DevHandle,
6607 (unsigned long long)
6608 sas_device->sas_address);
6610 if (sas_device->enclosure_handle != 0)
6611 starget_printk(KERN_INFO, starget,
6612 "enclosure logical id(0x%016llx),"
6614 (unsigned long long)
6615 sas_device->enclosure_logical_id,
6618 if (sas_device_pg0->Flags &
6619 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6620 sas_device->enclosure_level =
6621 le16_to_cpu(sas_device_pg0->EnclosureLevel);
6622 memcpy(&sas_device->connector_name[0],
6623 &sas_device_pg0->ConnectorName[0], 4);
6625 sas_device->enclosure_level = 0;
6626 sas_device->connector_name[0] = '\0';
6629 if (sas_device->handle == sas_device_pg0->DevHandle)
6631 pr_info("\thandle changed from(0x%04x)!!!\n",
6632 sas_device->handle);
6633 sas_device->handle = sas_device_pg0->DevHandle;
6634 if (sas_target_priv_data)
6635 sas_target_priv_data->handle =
6636 sas_device_pg0->DevHandle;
6641 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6645 * _scsih_search_responding_sas_devices -
6646 * @ioc: per adapter object
6648 * After host reset, find out whether devices are still responding.
6654 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6656 Mpi2SasDevicePage0_t sas_device_pg0;
6657 Mpi2ConfigReply_t mpi_reply;
6662 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6664 if (list_empty(&ioc->sas_device_list))
6668 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6669 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6671 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6672 MPI2_IOCSTATUS_MASK;
6673 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6675 handle = sas_device_pg0.DevHandle =
6676 le16_to_cpu(sas_device_pg0.DevHandle);
6677 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6678 if (!(_scsih_is_end_device(device_info)))
6680 sas_device_pg0.SASAddress =
6681 le64_to_cpu(sas_device_pg0.SASAddress);
6682 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
6683 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
6687 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6692 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6693 * @ioc: per adapter object
6694 * @wwid: world wide identifier for raid volume
6695 * @handle: device handle
6697 * After host reset, find out whether devices are still responding.
6698 * Used in _scsih_remove_unresponsive_raid_devices.
6703 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6706 struct MPT3SAS_TARGET *sas_target_priv_data;
6707 struct scsi_target *starget;
6708 struct _raid_device *raid_device;
6709 unsigned long flags;
6711 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6712 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6713 if (raid_device->wwid == wwid && raid_device->starget) {
6714 starget = raid_device->starget;
6715 if (starget && starget->hostdata) {
6716 sas_target_priv_data = starget->hostdata;
6717 sas_target_priv_data->deleted = 0;
6719 sas_target_priv_data = NULL;
6720 raid_device->responding = 1;
6721 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6722 starget_printk(KERN_INFO, raid_device->starget,
6723 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6724 (unsigned long long)raid_device->wwid);
6725 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6726 if (raid_device->handle == handle) {
6727 spin_unlock_irqrestore(&ioc->raid_device_lock,
6731 pr_info("\thandle changed from(0x%04x)!!!\n",
6732 raid_device->handle);
6733 raid_device->handle = handle;
6734 if (sas_target_priv_data)
6735 sas_target_priv_data->handle = handle;
6736 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6740 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6744 * _scsih_search_responding_raid_devices -
6745 * @ioc: per adapter object
6747 * After host reset, find out whether devices are still responding.
6753 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6755 Mpi2RaidVolPage1_t volume_pg1;
6756 Mpi2RaidVolPage0_t volume_pg0;
6757 Mpi2RaidPhysDiskPage0_t pd_pg0;
6758 Mpi2ConfigReply_t mpi_reply;
6763 if (!ioc->ir_firmware)
6766 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6769 if (list_empty(&ioc->raid_device_list))
6773 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6774 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6775 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6776 MPI2_IOCSTATUS_MASK;
6777 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6779 handle = le16_to_cpu(volume_pg1.DevHandle);
6781 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6782 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6783 sizeof(Mpi2RaidVolPage0_t)))
6786 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6787 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6788 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6789 _scsih_mark_responding_raid_device(ioc,
6790 le64_to_cpu(volume_pg1.WWID), handle);
6793 /* refresh the pd_handles */
6794 phys_disk_num = 0xFF;
6795 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6796 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6797 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6799 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6800 MPI2_IOCSTATUS_MASK;
6801 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6803 phys_disk_num = pd_pg0.PhysDiskNum;
6804 handle = le16_to_cpu(pd_pg0.DevHandle);
6805 set_bit(handle, ioc->pd_handles);
6808 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6813 * _scsih_mark_responding_expander - mark a expander as responding
6814 * @ioc: per adapter object
6815 * @sas_address: sas address
6818 * After host reset, find out whether devices are still responding.
6819 * Used in _scsih_remove_unresponsive_expanders.
6824 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6827 struct _sas_node *sas_expander;
6828 unsigned long flags;
6831 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6832 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6833 if (sas_expander->sas_address != sas_address)
6835 sas_expander->responding = 1;
6836 if (sas_expander->handle == handle)
6838 pr_info("\texpander(0x%016llx): handle changed" \
6839 " from(0x%04x) to (0x%04x)!!!\n",
6840 (unsigned long long)sas_expander->sas_address,
6841 sas_expander->handle, handle);
6842 sas_expander->handle = handle;
6843 for (i = 0 ; i < sas_expander->num_phys ; i++)
6844 sas_expander->phy[i].handle = handle;
6848 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6852 * _scsih_search_responding_expanders -
6853 * @ioc: per adapter object
6855 * After host reset, find out whether devices are still responding.
6861 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6863 Mpi2ExpanderPage0_t expander_pg0;
6864 Mpi2ConfigReply_t mpi_reply;
6869 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6871 if (list_empty(&ioc->sas_expander_list))
6875 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6876 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6878 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6879 MPI2_IOCSTATUS_MASK;
6880 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6883 handle = le16_to_cpu(expander_pg0.DevHandle);
6884 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6885 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6887 (unsigned long long)sas_address);
6888 _scsih_mark_responding_expander(ioc, sas_address, handle);
6892 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6896 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6897 * @ioc: per adapter object
6902 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6904 struct _sas_device *sas_device, *sas_device_next;
6905 struct _sas_node *sas_expander, *sas_expander_next;
6906 struct _raid_device *raid_device, *raid_device_next;
6907 struct list_head tmp_list;
6908 unsigned long flags;
6910 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6913 /* removing unresponding end devices */
6914 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6916 list_for_each_entry_safe(sas_device, sas_device_next,
6917 &ioc->sas_device_list, list) {
6918 if (!sas_device->responding)
6919 mpt3sas_device_remove_by_sas_address(ioc,
6920 sas_device->sas_address);
6922 sas_device->responding = 0;
6925 /* removing unresponding volumes */
6926 if (ioc->ir_firmware) {
6927 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6929 list_for_each_entry_safe(raid_device, raid_device_next,
6930 &ioc->raid_device_list, list) {
6931 if (!raid_device->responding)
6932 _scsih_sas_volume_delete(ioc,
6933 raid_device->handle);
6935 raid_device->responding = 0;
6939 /* removing unresponding expanders */
6940 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6942 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6943 INIT_LIST_HEAD(&tmp_list);
6944 list_for_each_entry_safe(sas_expander, sas_expander_next,
6945 &ioc->sas_expander_list, list) {
6946 if (!sas_expander->responding)
6947 list_move_tail(&sas_expander->list, &tmp_list);
6949 sas_expander->responding = 0;
6951 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6952 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6954 list_del(&sas_expander->list);
6955 _scsih_expander_node_remove(ioc, sas_expander);
6958 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6961 /* unblock devices */
6962 _scsih_ublock_io_all_device(ioc);
6966 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6967 struct _sas_node *sas_expander, u16 handle)
6969 Mpi2ExpanderPage1_t expander_pg1;
6970 Mpi2ConfigReply_t mpi_reply;
6973 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6974 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6975 &expander_pg1, i, handle))) {
6976 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6977 ioc->name, __FILE__, __LINE__, __func__);
6981 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6982 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6983 expander_pg1.NegotiatedLinkRate >> 4);
6988 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6989 * @ioc: per adapter object
6994 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6996 Mpi2ExpanderPage0_t expander_pg0;
6997 Mpi2SasDevicePage0_t sas_device_pg0;
6998 Mpi2RaidVolPage1_t volume_pg1;
6999 Mpi2RaidVolPage0_t volume_pg0;
7000 Mpi2RaidPhysDiskPage0_t pd_pg0;
7001 Mpi2EventIrConfigElement_t element;
7002 Mpi2ConfigReply_t mpi_reply;
7005 u16 handle, parent_handle;
7007 struct _sas_device *sas_device;
7008 struct _sas_node *expander_device;
7009 static struct _raid_device *raid_device;
7011 unsigned long flags;
7013 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7015 _scsih_sas_host_refresh(ioc);
7017 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7021 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7022 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7023 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7024 MPI2_IOCSTATUS_MASK;
7025 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7026 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7027 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7028 ioc->name, ioc_status,
7029 le32_to_cpu(mpi_reply.IOCLogInfo));
7032 handle = le16_to_cpu(expander_pg0.DevHandle);
7033 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7034 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7035 ioc, le64_to_cpu(expander_pg0.SASAddress));
7036 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7037 if (expander_device)
7038 _scsih_refresh_expander_links(ioc, expander_device,
7041 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7042 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7043 handle, (unsigned long long)
7044 le64_to_cpu(expander_pg0.SASAddress));
7045 _scsih_expander_add(ioc, handle);
7046 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7047 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7048 handle, (unsigned long long)
7049 le64_to_cpu(expander_pg0.SASAddress));
7053 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7056 if (!ioc->ir_firmware)
7059 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7062 phys_disk_num = 0xFF;
7063 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7064 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7066 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7067 MPI2_IOCSTATUS_MASK;
7068 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7069 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7070 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7071 ioc->name, ioc_status,
7072 le32_to_cpu(mpi_reply.IOCLogInfo));
7075 phys_disk_num = pd_pg0.PhysDiskNum;
7076 handle = le16_to_cpu(pd_pg0.DevHandle);
7077 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7078 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7079 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7082 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7083 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7086 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7087 MPI2_IOCSTATUS_MASK;
7088 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7089 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7090 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7091 ioc->name, ioc_status,
7092 le32_to_cpu(mpi_reply.IOCLogInfo));
7095 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7096 if (!_scsih_get_sas_address(ioc, parent_handle,
7098 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7099 " handle (0x%04x), sas_addr(0x%016llx)\n",
7100 ioc->name, handle, (unsigned long long)
7101 le64_to_cpu(sas_device_pg0.SASAddress));
7102 mpt3sas_transport_update_links(ioc, sas_address,
7103 handle, sas_device_pg0.PhyNum,
7104 MPI2_SAS_NEG_LINK_RATE_1_5);
7105 set_bit(handle, ioc->pd_handles);
7107 /* This will retry adding the end device.
7108 * _scsih_add_device() will decide on retries and
7109 * return "1" when it should be retried
7111 while (_scsih_add_device(ioc, handle, retry_count++,
7115 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7116 " handle (0x%04x), sas_addr(0x%016llx)\n",
7117 ioc->name, handle, (unsigned long long)
7118 le64_to_cpu(sas_device_pg0.SASAddress));
7122 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7125 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7129 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7130 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7131 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7132 MPI2_IOCSTATUS_MASK;
7133 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7134 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7135 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7136 ioc->name, ioc_status,
7137 le32_to_cpu(mpi_reply.IOCLogInfo));
7140 handle = le16_to_cpu(volume_pg1.DevHandle);
7141 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7142 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7143 le64_to_cpu(volume_pg1.WWID));
7144 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7147 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7148 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7149 sizeof(Mpi2RaidVolPage0_t)))
7151 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7152 MPI2_IOCSTATUS_MASK;
7153 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7154 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7155 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7156 ioc->name, ioc_status,
7157 le32_to_cpu(mpi_reply.IOCLogInfo));
7160 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7161 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7162 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7163 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7164 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7165 element.VolDevHandle = volume_pg1.DevHandle;
7167 "\tBEFORE adding volume: handle (0x%04x)\n",
7168 ioc->name, volume_pg1.DevHandle);
7169 _scsih_sas_volume_add(ioc, &element);
7171 "\tAFTER adding volume: handle (0x%04x)\n",
7172 ioc->name, volume_pg1.DevHandle);
7176 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7181 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7186 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7187 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7189 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7190 MPI2_IOCSTATUS_MASK;
7191 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7192 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7193 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7194 ioc->name, ioc_status,
7195 le32_to_cpu(mpi_reply.IOCLogInfo));
7198 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7199 if (!(_scsih_is_end_device(
7200 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7202 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7203 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
7204 le64_to_cpu(sas_device_pg0.SASAddress));
7205 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7208 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7209 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7210 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7211 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7212 handle, (unsigned long long)
7213 le64_to_cpu(sas_device_pg0.SASAddress));
7214 mpt3sas_transport_update_links(ioc, sas_address, handle,
7215 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7217 /* This will retry adding the end device.
7218 * _scsih_add_device() will decide on retries and
7219 * return "1" when it should be retried
7221 while (_scsih_add_device(ioc, handle, retry_count++,
7225 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7226 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7227 handle, (unsigned long long)
7228 le64_to_cpu(sas_device_pg0.SASAddress));
7231 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7234 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7237 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7238 * @ioc: per adapter object
7239 * @reset_phase: phase
7241 * The handler for doing any required cleanup or initialization.
7243 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7244 * MPT3_IOC_DONE_RESET
7249 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7251 switch (reset_phase) {
7252 case MPT3_IOC_PRE_RESET:
7253 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7254 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7256 case MPT3_IOC_AFTER_RESET:
7257 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7258 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7259 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7260 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7261 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7262 complete(&ioc->scsih_cmds.done);
7264 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7265 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7266 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7267 complete(&ioc->tm_cmds.done);
7270 _scsih_fw_event_cleanup_queue(ioc);
7271 _scsih_flush_running_cmds(ioc);
7273 case MPT3_IOC_DONE_RESET:
7274 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7275 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7276 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7277 !ioc->sas_hba.num_phys)) {
7278 _scsih_prep_device_scan(ioc);
7279 _scsih_search_responding_sas_devices(ioc);
7280 _scsih_search_responding_raid_devices(ioc);
7281 _scsih_search_responding_expanders(ioc);
7282 _scsih_error_recovery_delete_devices(ioc);
7289 * _mpt3sas_fw_work - delayed task for processing firmware events
7290 * @ioc: per adapter object
7291 * @fw_event: The fw_event_work object
7297 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7299 /* the queue is being flushed so ignore this event */
7300 if (ioc->remove_host ||
7301 ioc->pci_error_recovery) {
7302 _scsih_fw_event_free(ioc, fw_event);
7306 switch (fw_event->event) {
7307 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7308 mpt3sas_process_trigger_data(ioc,
7309 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7310 fw_event->event_data);
7312 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7313 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7315 _scsih_remove_unresponding_sas_devices(ioc);
7316 _scsih_scan_for_devices_after_reset(ioc);
7318 case MPT3SAS_PORT_ENABLE_COMPLETE:
7319 ioc->start_scan = 0;
7320 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7321 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7323 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7324 "port enable: complete from worker thread\n",
7327 case MPT3SAS_TURN_ON_PFA_LED:
7328 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7330 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7331 _scsih_sas_topology_change_event(ioc, fw_event);
7333 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7334 _scsih_sas_device_status_change_event(ioc, fw_event);
7336 case MPI2_EVENT_SAS_DISCOVERY:
7337 _scsih_sas_discovery_event(ioc, fw_event);
7339 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7340 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7342 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7343 _scsih_sas_enclosure_dev_status_change_event(ioc,
7346 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7347 _scsih_sas_ir_config_change_event(ioc, fw_event);
7349 case MPI2_EVENT_IR_VOLUME:
7350 _scsih_sas_ir_volume_event(ioc, fw_event);
7352 case MPI2_EVENT_IR_PHYSICAL_DISK:
7353 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7355 case MPI2_EVENT_IR_OPERATION_STATUS:
7356 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7359 _scsih_fw_event_free(ioc, fw_event);
7363 * _firmware_event_work
7364 * @ioc: per adapter object
7365 * @work: The fw_event_work object
7368 * wrappers for the work thread handling firmware events
7374 _firmware_event_work(struct work_struct *work)
7376 struct fw_event_work *fw_event = container_of(work,
7377 struct fw_event_work, work);
7379 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7383 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7384 * @ioc: per adapter object
7385 * @msix_index: MSIX table index supplied by the OS
7386 * @reply: reply message frame(lower 32bit addr)
7387 * Context: interrupt.
7389 * This function merely adds a new work task into ioc->firmware_event_thread.
7390 * The tasks are worked from _firmware_event_work in user context.
7392 * Return 1 meaning mf should be freed from _base_interrupt
7393 * 0 means the mf is freed from this function.
7396 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7399 struct fw_event_work *fw_event;
7400 Mpi2EventNotificationReply_t *mpi_reply;
7404 /* events turned off due to host reset or driver unloading */
7405 if (ioc->remove_host || ioc->pci_error_recovery)
7408 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7410 if (unlikely(!mpi_reply)) {
7411 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7412 ioc->name, __FILE__, __LINE__, __func__);
7416 event = le16_to_cpu(mpi_reply->Event);
7418 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7419 mpt3sas_trigger_event(ioc, event, 0);
7423 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7425 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7426 (Mpi2EventDataSasBroadcastPrimitive_t *)
7427 mpi_reply->EventData;
7429 if (baen_data->Primitive !=
7430 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7433 if (ioc->broadcast_aen_busy) {
7434 ioc->broadcast_aen_pending++;
7437 ioc->broadcast_aen_busy = 1;
7441 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7442 _scsih_check_topo_delete_events(ioc,
7443 (Mpi2EventDataSasTopologyChangeList_t *)
7444 mpi_reply->EventData);
7446 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7447 _scsih_check_ir_config_unhide_events(ioc,
7448 (Mpi2EventDataIrConfigChangeList_t *)
7449 mpi_reply->EventData);
7451 case MPI2_EVENT_IR_VOLUME:
7452 _scsih_check_volume_delete_events(ioc,
7453 (Mpi2EventDataIrVolume_t *)
7454 mpi_reply->EventData);
7457 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7458 case MPI2_EVENT_IR_OPERATION_STATUS:
7459 case MPI2_EVENT_SAS_DISCOVERY:
7460 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7461 case MPI2_EVENT_IR_PHYSICAL_DISK:
7464 case MPI2_EVENT_TEMP_THRESHOLD:
7465 _scsih_temp_threshold_events(ioc,
7466 (Mpi2EventDataTemperature_t *)
7467 mpi_reply->EventData);
7470 default: /* ignore the rest */
7474 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7475 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7477 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7478 ioc->name, __FILE__, __LINE__, __func__);
7482 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7483 fw_event->ioc = ioc;
7484 fw_event->VF_ID = mpi_reply->VF_ID;
7485 fw_event->VP_ID = mpi_reply->VP_ID;
7486 fw_event->event = event;
7487 _scsih_fw_event_add(ioc, fw_event);
7491 /* shost template */
7492 static struct scsi_host_template scsih_driver_template = {
7493 .module = THIS_MODULE,
7494 .name = "Fusion MPT SAS Host",
7495 .proc_name = MPT3SAS_DRIVER_NAME,
7496 .queuecommand = _scsih_qcmd,
7497 .target_alloc = _scsih_target_alloc,
7498 .slave_alloc = _scsih_slave_alloc,
7499 .slave_configure = _scsih_slave_configure,
7500 .target_destroy = _scsih_target_destroy,
7501 .slave_destroy = _scsih_slave_destroy,
7502 .scan_finished = _scsih_scan_finished,
7503 .scan_start = _scsih_scan_start,
7504 .change_queue_depth = _scsih_change_queue_depth,
7505 .eh_abort_handler = _scsih_abort,
7506 .eh_device_reset_handler = _scsih_dev_reset,
7507 .eh_target_reset_handler = _scsih_target_reset,
7508 .eh_host_reset_handler = _scsih_host_reset,
7509 .bios_param = _scsih_bios_param,
7512 .sg_tablesize = MPT3SAS_SG_DEPTH,
7513 .max_sectors = 32767,
7515 .use_clustering = ENABLE_CLUSTERING,
7516 .shost_attrs = mpt3sas_host_attrs,
7517 .sdev_attrs = mpt3sas_dev_attrs,
7518 .track_queue_depth = 1,
7522 * _scsih_expander_node_remove - removing expander device from list.
7523 * @ioc: per adapter object
7524 * @sas_expander: the sas_device object
7525 * Context: Calling function should acquire ioc->sas_node_lock.
7527 * Removing object and freeing associated memory from the
7528 * ioc->sas_expander_list.
7533 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7534 struct _sas_node *sas_expander)
7536 struct _sas_port *mpt3sas_port, *next;
7538 /* remove sibling ports attached to this expander */
7539 list_for_each_entry_safe(mpt3sas_port, next,
7540 &sas_expander->sas_port_list, port_list) {
7541 if (ioc->shost_recovery)
7543 if (mpt3sas_port->remote_identify.device_type ==
7545 mpt3sas_device_remove_by_sas_address(ioc,
7546 mpt3sas_port->remote_identify.sas_address);
7547 else if (mpt3sas_port->remote_identify.device_type ==
7548 SAS_EDGE_EXPANDER_DEVICE ||
7549 mpt3sas_port->remote_identify.device_type ==
7550 SAS_FANOUT_EXPANDER_DEVICE)
7551 mpt3sas_expander_remove(ioc,
7552 mpt3sas_port->remote_identify.sas_address);
7555 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7556 sas_expander->sas_address_parent);
7559 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7561 sas_expander->handle, (unsigned long long)
7562 sas_expander->sas_address);
7564 kfree(sas_expander->phy);
7565 kfree(sas_expander);
7569 * _scsih_ir_shutdown - IR shutdown notification
7570 * @ioc: per adapter object
7572 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7573 * the host system is shutting down.
7578 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7580 Mpi2RaidActionRequest_t *mpi_request;
7581 Mpi2RaidActionReply_t *mpi_reply;
7584 /* is IR firmware build loaded ? */
7585 if (!ioc->ir_firmware)
7588 /* are there any volumes ? */
7589 if (list_empty(&ioc->raid_device_list))
7592 mutex_lock(&ioc->scsih_cmds.mutex);
7594 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7595 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7596 ioc->name, __func__);
7599 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7601 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7603 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7604 ioc->name, __func__);
7605 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7609 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7610 ioc->scsih_cmds.smid = smid;
7611 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7613 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7614 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7616 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7617 init_completion(&ioc->scsih_cmds.done);
7618 mpt3sas_base_put_smid_default(ioc, smid);
7619 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7621 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7622 pr_err(MPT3SAS_FMT "%s: timeout\n",
7623 ioc->name, __func__);
7627 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7628 mpi_reply = ioc->scsih_cmds.reply;
7630 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7631 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7632 le32_to_cpu(mpi_reply->IOCLogInfo));
7636 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7637 mutex_unlock(&ioc->scsih_cmds.mutex);
7641 * _scsih_remove - detach and remove add host
7642 * @pdev: PCI device struct
7644 * Routine called when unloading the driver.
7647 static void _scsih_remove(struct pci_dev *pdev)
7649 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7650 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7651 struct _sas_port *mpt3sas_port, *next_port;
7652 struct _raid_device *raid_device, *next;
7653 struct MPT3SAS_TARGET *sas_target_priv_data;
7654 struct workqueue_struct *wq;
7655 unsigned long flags;
7657 ioc->remove_host = 1;
7658 _scsih_fw_event_cleanup_queue(ioc);
7660 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7661 wq = ioc->firmware_event_thread;
7662 ioc->firmware_event_thread = NULL;
7663 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7665 destroy_workqueue(wq);
7667 /* release all the volumes */
7668 _scsih_ir_shutdown(ioc);
7669 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7671 if (raid_device->starget) {
7672 sas_target_priv_data =
7673 raid_device->starget->hostdata;
7674 sas_target_priv_data->deleted = 1;
7675 scsi_remove_target(&raid_device->starget->dev);
7677 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7678 ioc->name, raid_device->handle,
7679 (unsigned long long) raid_device->wwid);
7680 _scsih_raid_device_remove(ioc, raid_device);
7683 /* free ports attached to the sas_host */
7684 list_for_each_entry_safe(mpt3sas_port, next_port,
7685 &ioc->sas_hba.sas_port_list, port_list) {
7686 if (mpt3sas_port->remote_identify.device_type ==
7688 mpt3sas_device_remove_by_sas_address(ioc,
7689 mpt3sas_port->remote_identify.sas_address);
7690 else if (mpt3sas_port->remote_identify.device_type ==
7691 SAS_EDGE_EXPANDER_DEVICE ||
7692 mpt3sas_port->remote_identify.device_type ==
7693 SAS_FANOUT_EXPANDER_DEVICE)
7694 mpt3sas_expander_remove(ioc,
7695 mpt3sas_port->remote_identify.sas_address);
7698 /* free phys attached to the sas_host */
7699 if (ioc->sas_hba.num_phys) {
7700 kfree(ioc->sas_hba.phy);
7701 ioc->sas_hba.phy = NULL;
7702 ioc->sas_hba.num_phys = 0;
7705 sas_remove_host(shost);
7706 scsi_remove_host(shost);
7707 mpt3sas_base_detach(ioc);
7708 list_del(&ioc->list);
7709 scsi_host_put(shost);
7713 * _scsih_shutdown - routine call during system shutdown
7714 * @pdev: PCI device struct
7719 _scsih_shutdown(struct pci_dev *pdev)
7721 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7722 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7723 struct workqueue_struct *wq;
7724 unsigned long flags;
7726 ioc->remove_host = 1;
7727 _scsih_fw_event_cleanup_queue(ioc);
7729 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7730 wq = ioc->firmware_event_thread;
7731 ioc->firmware_event_thread = NULL;
7732 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7734 destroy_workqueue(wq);
7736 _scsih_ir_shutdown(ioc);
7737 mpt3sas_base_detach(ioc);
7742 * _scsih_probe_boot_devices - reports 1st device
7743 * @ioc: per adapter object
7745 * If specified in bios page 2, this routine reports the 1st
7746 * device scsi-ml or sas transport for persistent boot device
7747 * purposes. Please refer to function _scsih_determine_boot_device()
7750 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7754 struct _sas_device *sas_device;
7755 struct _raid_device *raid_device;
7757 u64 sas_address_parent;
7759 unsigned long flags;
7762 /* no Bios, return immediately */
7763 if (!ioc->bios_pg3.BiosVersion)
7768 if (ioc->req_boot_device.device) {
7769 device = ioc->req_boot_device.device;
7770 is_raid = ioc->req_boot_device.is_raid;
7771 } else if (ioc->req_alt_boot_device.device) {
7772 device = ioc->req_alt_boot_device.device;
7773 is_raid = ioc->req_alt_boot_device.is_raid;
7774 } else if (ioc->current_boot_device.device) {
7775 device = ioc->current_boot_device.device;
7776 is_raid = ioc->current_boot_device.is_raid;
7783 raid_device = device;
7784 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7785 raid_device->id, 0);
7787 _scsih_raid_device_remove(ioc, raid_device);
7789 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7790 sas_device = device;
7791 handle = sas_device->handle;
7792 sas_address_parent = sas_device->sas_address_parent;
7793 sas_address = sas_device->sas_address;
7794 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7795 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7797 if (!mpt3sas_transport_port_add(ioc, handle,
7798 sas_address_parent)) {
7799 _scsih_sas_device_remove(ioc, sas_device);
7800 } else if (!sas_device->starget) {
7801 if (!ioc->is_driver_loading) {
7802 mpt3sas_transport_port_remove(ioc,
7804 sas_address_parent);
7805 _scsih_sas_device_remove(ioc, sas_device);
7812 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7813 * @ioc: per adapter object
7815 * Called during initial loading of the driver.
7818 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7820 struct _raid_device *raid_device, *raid_next;
7823 list_for_each_entry_safe(raid_device, raid_next,
7824 &ioc->raid_device_list, list) {
7825 if (raid_device->starget)
7827 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7828 raid_device->id, 0);
7830 _scsih_raid_device_remove(ioc, raid_device);
7835 * _scsih_probe_sas - reporting sas devices to sas transport
7836 * @ioc: per adapter object
7838 * Called during initial loading of the driver.
7841 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7843 struct _sas_device *sas_device, *next;
7844 unsigned long flags;
7846 /* SAS Device List */
7847 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7850 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7851 sas_device->sas_address_parent)) {
7852 list_del(&sas_device->list);
7855 } else if (!sas_device->starget) {
7857 * When asyn scanning is enabled, its not possible to
7858 * remove devices while scanning is turned on due to an
7859 * oops in scsi_sysfs_add_sdev()->add_device()->
7860 * sysfs_addrm_start()
7862 if (!ioc->is_driver_loading) {
7863 mpt3sas_transport_port_remove(ioc,
7864 sas_device->sas_address,
7865 sas_device->sas_address_parent);
7866 list_del(&sas_device->list);
7872 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7873 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7874 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7879 * _scsih_probe_devices - probing for devices
7880 * @ioc: per adapter object
7882 * Called during initial loading of the driver.
7885 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7887 u16 volume_mapping_flags;
7889 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7890 return; /* return when IOC doesn't support initiator mode */
7892 _scsih_probe_boot_devices(ioc);
7894 if (ioc->ir_firmware) {
7895 volume_mapping_flags =
7896 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7897 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7898 if (volume_mapping_flags ==
7899 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7900 _scsih_probe_raid(ioc);
7901 _scsih_probe_sas(ioc);
7903 _scsih_probe_sas(ioc);
7904 _scsih_probe_raid(ioc);
7907 _scsih_probe_sas(ioc);
7911 * _scsih_scan_start - scsi lld callback for .scan_start
7912 * @shost: SCSI host pointer
7914 * The shost has the ability to discover targets on its own instead
7915 * of scanning the entire bus. In our implemention, we will kick off
7916 * firmware discovery.
7919 _scsih_scan_start(struct Scsi_Host *shost)
7921 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7923 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7924 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7926 if (disable_discovery > 0)
7929 ioc->start_scan = 1;
7930 rc = mpt3sas_port_enable(ioc);
7933 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7937 * _scsih_scan_finished - scsi lld callback for .scan_finished
7938 * @shost: SCSI host pointer
7939 * @time: elapsed time of the scan in jiffies
7941 * This function will be called periodicallyn until it returns 1 with the
7942 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7943 * we wait for firmware discovery to complete, then return 1.
7946 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7948 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7950 if (disable_discovery > 0) {
7951 ioc->is_driver_loading = 0;
7952 ioc->wait_for_discovery_to_complete = 0;
7956 if (time >= (300 * HZ)) {
7957 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7959 "port enable: FAILED with timeout (timeout=300s)\n",
7961 ioc->is_driver_loading = 0;
7965 if (ioc->start_scan)
7968 if (ioc->start_scan_failed) {
7970 "port enable: FAILED with (ioc_status=0x%08x)\n",
7971 ioc->name, ioc->start_scan_failed);
7972 ioc->is_driver_loading = 0;
7973 ioc->wait_for_discovery_to_complete = 0;
7974 ioc->remove_host = 1;
7978 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7979 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7981 if (ioc->wait_for_discovery_to_complete) {
7982 ioc->wait_for_discovery_to_complete = 0;
7983 _scsih_probe_devices(ioc);
7985 mpt3sas_base_start_watchdog(ioc);
7986 ioc->is_driver_loading = 0;
7991 * _scsih_probe - attach and add scsi host
7992 * @pdev: PCI device struct
7993 * @id: pci device id
7995 * Returns 0 success, anything else error.
7998 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8000 struct MPT3SAS_ADAPTER *ioc;
8001 struct Scsi_Host *shost;
8004 shost = scsi_host_alloc(&scsih_driver_template,
8005 sizeof(struct MPT3SAS_ADAPTER));
8009 /* init local params */
8010 ioc = shost_priv(shost);
8011 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8012 INIT_LIST_HEAD(&ioc->list);
8013 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8015 ioc->id = mpt_ids++;
8016 sprintf(ioc->name, "%s%d", MPT3SAS_DRIVER_NAME, ioc->id);
8018 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8019 ioc->tm_cb_idx = tm_cb_idx;
8020 ioc->ctl_cb_idx = ctl_cb_idx;
8021 ioc->base_cb_idx = base_cb_idx;
8022 ioc->port_enable_cb_idx = port_enable_cb_idx;
8023 ioc->transport_cb_idx = transport_cb_idx;
8024 ioc->scsih_cb_idx = scsih_cb_idx;
8025 ioc->config_cb_idx = config_cb_idx;
8026 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8027 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8028 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8029 ioc->logging_level = logging_level;
8030 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8031 /* misc semaphores and spin locks */
8032 mutex_init(&ioc->reset_in_progress_mutex);
8033 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8034 spin_lock_init(&ioc->scsi_lookup_lock);
8035 spin_lock_init(&ioc->sas_device_lock);
8036 spin_lock_init(&ioc->sas_node_lock);
8037 spin_lock_init(&ioc->fw_event_lock);
8038 spin_lock_init(&ioc->raid_device_lock);
8039 spin_lock_init(&ioc->diag_trigger_lock);
8041 INIT_LIST_HEAD(&ioc->sas_device_list);
8042 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8043 INIT_LIST_HEAD(&ioc->sas_expander_list);
8044 INIT_LIST_HEAD(&ioc->fw_event_list);
8045 INIT_LIST_HEAD(&ioc->raid_device_list);
8046 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8047 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8048 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8049 INIT_LIST_HEAD(&ioc->reply_queue_list);
8051 /* init shost parameters */
8052 shost->max_cmd_len = 32;
8053 shost->max_lun = max_lun;
8054 shost->transportt = mpt3sas_transport_template;
8055 shost->unique_id = ioc->id;
8057 if (max_sectors != 0xFFFF) {
8058 if (max_sectors < 64) {
8059 shost->max_sectors = 64;
8060 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8061 "for max_sectors, range is 64 to 32767. Assigning "
8062 "value of 64.\n", ioc->name, max_sectors);
8063 } else if (max_sectors > 32767) {
8064 shost->max_sectors = 32767;
8065 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8066 "for max_sectors, range is 64 to 32767. Assigning "
8067 "default value of 32767.\n", ioc->name,
8070 shost->max_sectors = max_sectors & 0xFFFE;
8072 "The max_sectors value is set to %d\n",
8073 ioc->name, shost->max_sectors);
8077 /* register EEDP capabilities with SCSI layer */
8079 scsi_host_set_prot(shost, prot_mask);
8081 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8082 | SHOST_DIF_TYPE2_PROTECTION
8083 | SHOST_DIF_TYPE3_PROTECTION);
8085 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8088 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8089 "fw_event%d", ioc->id);
8090 ioc->firmware_event_thread = alloc_ordered_workqueue(
8091 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8092 if (!ioc->firmware_event_thread) {
8093 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8094 ioc->name, __FILE__, __LINE__, __func__);
8096 goto out_thread_fail;
8099 ioc->is_driver_loading = 1;
8100 if ((mpt3sas_base_attach(ioc))) {
8101 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8102 ioc->name, __FILE__, __LINE__, __func__);
8104 goto out_attach_fail;
8106 rv = scsi_add_host(shost, &pdev->dev);
8108 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8109 ioc->name, __FILE__, __LINE__, __func__);
8110 goto out_add_shost_fail;
8113 scsi_scan_host(shost);
8116 mpt3sas_base_detach(ioc);
8118 destroy_workqueue(ioc->firmware_event_thread);
8120 list_del(&ioc->list);
8121 scsi_host_put(shost);
8127 * _scsih_suspend - power management suspend main entry point
8128 * @pdev: PCI device struct
8129 * @state: PM state change to (usually PCI_D3)
8131 * Returns 0 success, anything else error.
8134 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8136 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8137 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8138 pci_power_t device_state;
8140 mpt3sas_base_stop_watchdog(ioc);
8141 flush_scheduled_work();
8142 scsi_block_requests(shost);
8143 device_state = pci_choose_state(pdev, state);
8145 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8146 ioc->name, pdev, pci_name(pdev), device_state);
8148 pci_save_state(pdev);
8149 mpt3sas_base_free_resources(ioc);
8150 pci_set_power_state(pdev, device_state);
8155 * _scsih_resume - power management resume main entry point
8156 * @pdev: PCI device struct
8158 * Returns 0 success, anything else error.
8161 _scsih_resume(struct pci_dev *pdev)
8163 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8164 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8165 pci_power_t device_state = pdev->current_state;
8169 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8170 ioc->name, pdev, pci_name(pdev), device_state);
8172 pci_set_power_state(pdev, PCI_D0);
8173 pci_enable_wake(pdev, PCI_D0, 0);
8174 pci_restore_state(pdev);
8176 r = mpt3sas_base_map_resources(ioc);
8180 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8181 scsi_unblock_requests(shost);
8182 mpt3sas_base_start_watchdog(ioc);
8185 #endif /* CONFIG_PM */
8188 * _scsih_pci_error_detected - Called when a PCI error is detected.
8189 * @pdev: PCI device struct
8190 * @state: PCI channel state
8192 * Description: Called when a PCI error is detected.
8195 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8197 static pci_ers_result_t
8198 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8200 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8201 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8203 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
8207 case pci_channel_io_normal:
8208 return PCI_ERS_RESULT_CAN_RECOVER;
8209 case pci_channel_io_frozen:
8210 /* Fatal error, prepare for slot reset */
8211 ioc->pci_error_recovery = 1;
8212 scsi_block_requests(ioc->shost);
8213 mpt3sas_base_stop_watchdog(ioc);
8214 mpt3sas_base_free_resources(ioc);
8215 return PCI_ERS_RESULT_NEED_RESET;
8216 case pci_channel_io_perm_failure:
8217 /* Permanent error, prepare for device removal */
8218 ioc->pci_error_recovery = 1;
8219 mpt3sas_base_stop_watchdog(ioc);
8220 _scsih_flush_running_cmds(ioc);
8221 return PCI_ERS_RESULT_DISCONNECT;
8223 return PCI_ERS_RESULT_NEED_RESET;
8227 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8228 * @pdev: PCI device struct
8230 * Description: This routine is called by the pci error recovery
8231 * code after the PCI slot has been reset, just before we
8232 * should resume normal operations.
8234 static pci_ers_result_t
8235 _scsih_pci_slot_reset(struct pci_dev *pdev)
8237 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8238 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8241 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8244 ioc->pci_error_recovery = 0;
8246 pci_restore_state(pdev);
8247 rc = mpt3sas_base_map_resources(ioc);
8249 return PCI_ERS_RESULT_DISCONNECT;
8251 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8254 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8255 (rc == 0) ? "success" : "failed");
8258 return PCI_ERS_RESULT_RECOVERED;
8260 return PCI_ERS_RESULT_DISCONNECT;
8264 * _scsih_pci_resume() - resume normal ops after PCI reset
8265 * @pdev: pointer to PCI device
8267 * Called when the error recovery driver tells us that its
8268 * OK to resume normal operation. Use completion to allow
8269 * halted scsi ops to resume.
8272 _scsih_pci_resume(struct pci_dev *pdev)
8274 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8275 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8277 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8279 pci_cleanup_aer_uncorrect_error_status(pdev);
8280 mpt3sas_base_start_watchdog(ioc);
8281 scsi_unblock_requests(ioc->shost);
8285 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8286 * @pdev: pointer to PCI device
8288 static pci_ers_result_t
8289 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8291 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8292 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8294 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8297 /* TODO - dump whatever for debugging purposes */
8299 /* Request a slot reset. */
8300 return PCI_ERS_RESULT_NEED_RESET;
8303 /* raid transport support */
8304 static struct raid_function_template mpt3sas_raid_functions = {
8305 .cookie = &scsih_driver_template,
8306 .is_raid = _scsih_is_raid,
8307 .get_resync = _scsih_get_resync,
8308 .get_state = _scsih_get_state,
8311 static struct pci_error_handlers _scsih_err_handler = {
8312 .error_detected = _scsih_pci_error_detected,
8313 .mmio_enabled = _scsih_pci_mmio_enabled,
8314 .slot_reset = _scsih_pci_slot_reset,
8315 .resume = _scsih_pci_resume,
8318 static struct pci_driver scsih_driver = {
8319 .name = MPT3SAS_DRIVER_NAME,
8320 .id_table = scsih_pci_table,
8321 .probe = _scsih_probe,
8322 .remove = _scsih_remove,
8323 .shutdown = _scsih_shutdown,
8324 .err_handler = &_scsih_err_handler,
8326 .suspend = _scsih_suspend,
8327 .resume = _scsih_resume,
8333 * _scsih_init - main entry point for this driver.
8335 * Returns 0 success, anything else error.
8344 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
8345 MPT3SAS_DRIVER_VERSION);
8347 mpt3sas_transport_template =
8348 sas_attach_transport(&mpt3sas_transport_functions);
8349 if (!mpt3sas_transport_template)
8352 /* raid transport support */
8353 mpt3sas_raid_template = raid_class_attach(&mpt3sas_raid_functions);
8354 if (!mpt3sas_raid_template) {
8355 sas_release_transport(mpt3sas_transport_template);
8359 mpt3sas_base_initialize_callback_handler();
8361 /* queuecommand callback hander */
8362 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8364 /* task managment callback handler */
8365 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8367 /* base internal commands callback handler */
8368 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8369 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8370 mpt3sas_port_enable_done);
8372 /* transport internal commands callback handler */
8373 transport_cb_idx = mpt3sas_base_register_callback_handler(
8374 mpt3sas_transport_done);
8376 /* scsih internal commands callback handler */
8377 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8379 /* configuration page API internal commands callback handler */
8380 config_cb_idx = mpt3sas_base_register_callback_handler(
8381 mpt3sas_config_done);
8383 /* ctl module callback handler */
8384 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8386 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8387 _scsih_tm_tr_complete);
8389 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8390 _scsih_tm_volume_tr_complete);
8392 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8393 _scsih_sas_control_complete);
8397 error = pci_register_driver(&scsih_driver);
8399 /* raid transport support */
8400 raid_class_release(mpt3sas_raid_template);
8401 sas_release_transport(mpt3sas_transport_template);
8408 * _scsih_exit - exit point for this driver (when it is a module).
8410 * Returns 0 success, anything else error.
8415 pr_info("mpt3sas version %s unloading\n",
8416 MPT3SAS_DRIVER_VERSION);
8420 pci_unregister_driver(&scsih_driver);
8423 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8424 mpt3sas_base_release_callback_handler(tm_cb_idx);
8425 mpt3sas_base_release_callback_handler(base_cb_idx);
8426 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8427 mpt3sas_base_release_callback_handler(transport_cb_idx);
8428 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8429 mpt3sas_base_release_callback_handler(config_cb_idx);
8430 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8432 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8433 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8434 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8436 /* raid transport support */
8437 raid_class_release(mpt3sas_raid_template);
8438 sas_release_transport(mpt3sas_transport_template);
8441 module_init(_scsih_init);
8442 module_exit(_scsih_exit);