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 #define RAID_CHANNEL 1
62 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
63 struct _sas_node *sas_expander);
64 static void _firmware_event_work(struct work_struct *work);
66 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
67 struct _sas_device *sas_device);
68 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
69 u8 retry_count, u8 is_pd);
71 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
74 /* global parameters */
75 LIST_HEAD(mpt3sas_ioc_list);
76 char driver_name[MPT_NAME_LENGTH];
78 /* local parameters */
79 static u8 scsi_io_cb_idx = -1;
80 static u8 tm_cb_idx = -1;
81 static u8 ctl_cb_idx = -1;
82 static u8 base_cb_idx = -1;
83 static u8 port_enable_cb_idx = -1;
84 static u8 transport_cb_idx = -1;
85 static u8 scsih_cb_idx = -1;
86 static u8 config_cb_idx = -1;
89 static u8 tm_tr_cb_idx = -1 ;
90 static u8 tm_tr_volume_cb_idx = -1 ;
91 static u8 tm_sas_control_cb_idx = -1;
93 /* command line options */
94 static u32 logging_level;
95 MODULE_PARM_DESC(logging_level,
96 " bits for enabling additional logging info (default=0)");
99 static ushort max_sectors = 0xFFFF;
100 module_param(max_sectors, ushort, 0);
101 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
104 static int missing_delay[2] = {-1, -1};
105 module_param_array(missing_delay, int, NULL, 0);
106 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
108 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
109 #define MPT3SAS_MAX_LUN (16895)
110 static u64 max_lun = MPT3SAS_MAX_LUN;
111 module_param(max_lun, ullong, 0);
112 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
117 /* diag_buffer_enable is bitwise
119 * bit 1 set = SNAPSHOT
120 * bit 2 set = EXTENDED
122 * Either bit can be set, or both
124 static int diag_buffer_enable = -1;
125 module_param(diag_buffer_enable, int, 0);
126 MODULE_PARM_DESC(diag_buffer_enable,
127 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
128 static int disable_discovery = -1;
129 module_param(disable_discovery, int, 0);
130 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
133 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
134 static int prot_mask = -1;
135 module_param(prot_mask, int, 0);
136 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
139 /* raid transport support */
140 struct raid_template *mpt3sas_raid_template;
144 * struct sense_info - common structure for obtaining sense keys
146 * @asc: additional sense code
147 * @ascq: additional sense code qualifier
155 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
156 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
157 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
158 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
159 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
161 * struct fw_event_work - firmware event struct
162 * @list: link list framework
163 * @work: work object (ioc->fault_reset_work_q)
164 * @cancel_pending_work: flag set during reset handling
165 * @ioc: per adapter object
166 * @device_handle: device handle
167 * @VF_ID: virtual function id
168 * @VP_ID: virtual port id
169 * @ignore: flag meaning this event has been marked to ignore
170 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
171 * @event_data: reply event data payload follows
173 * This object stored on ioc->fw_event_list.
175 struct fw_event_work {
176 struct list_head list;
177 struct work_struct work;
178 u8 cancel_pending_work;
179 struct delayed_work delayed_work;
181 struct MPT3SAS_ADAPTER *ioc;
187 char event_data[0] __aligned(4);
191 * struct _scsi_io_transfer - scsi io transfer
192 * @handle: sas device handle (assigned by firmware)
193 * @is_raid: flag set for hidden raid components
194 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
195 * @data_length: data transfer length
196 * @data_dma: dma pointer to data
199 * @cdb_length: cdb length
201 * @timeout: timeout for this command
202 * @VF_ID: virtual function id
203 * @VP_ID: virtual port id
204 * @valid_reply: flag set for reply message
205 * @sense_length: sense length
206 * @ioc_status: ioc status
207 * @scsi_state: scsi state
208 * @scsi_status: scsi staus
209 * @log_info: log information
210 * @transfer_length: data length transfer when there is a reply message
212 * Used for sending internal scsi commands to devices within this module.
213 * Refer to _scsi_send_scsi_io().
215 struct _scsi_io_transfer {
218 enum dma_data_direction dir;
221 u8 sense[SCSI_SENSE_BUFFERSIZE];
229 /* the following bits are only valid when 'valid_reply = 1' */
239 * _scsih_set_debug_level - global setting of ioc->logging_level.
241 * Note: The logging levels are defined in mpt3sas_debug.h.
244 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
246 int ret = param_set_int(val, kp);
247 struct MPT3SAS_ADAPTER *ioc;
252 pr_info("setting logging_level(0x%08x)\n", logging_level);
253 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
254 ioc->logging_level = logging_level;
257 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
258 &logging_level, 0644);
261 * _scsih_srch_boot_sas_address - search based on sas_address
262 * @sas_address: sas address
263 * @boot_device: boot device object from bios page 2
265 * Returns 1 when there's a match, 0 means no match.
268 _scsih_srch_boot_sas_address(u64 sas_address,
269 Mpi2BootDeviceSasWwid_t *boot_device)
271 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
275 * _scsih_srch_boot_device_name - search based on device name
276 * @device_name: device name specified in INDENTIFY fram
277 * @boot_device: boot device object from bios page 2
279 * Returns 1 when there's a match, 0 means no match.
282 _scsih_srch_boot_device_name(u64 device_name,
283 Mpi2BootDeviceDeviceName_t *boot_device)
285 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
289 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
290 * @enclosure_logical_id: enclosure logical id
291 * @slot_number: slot number
292 * @boot_device: boot device object from bios page 2
294 * Returns 1 when there's a match, 0 means no match.
297 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
298 Mpi2BootDeviceEnclosureSlot_t *boot_device)
300 return (enclosure_logical_id == le64_to_cpu(boot_device->
301 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
302 SlotNumber)) ? 1 : 0;
306 * _scsih_is_boot_device - search for matching boot device.
307 * @sas_address: sas address
308 * @device_name: device name specified in INDENTIFY fram
309 * @enclosure_logical_id: enclosure logical id
310 * @slot_number: slot number
311 * @form: specifies boot device form
312 * @boot_device: boot device object from bios page 2
314 * Returns 1 when there's a match, 0 means no match.
317 _scsih_is_boot_device(u64 sas_address, u64 device_name,
318 u64 enclosure_logical_id, u16 slot, u8 form,
319 Mpi2BiosPage2BootDevice_t *boot_device)
324 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
327 rc = _scsih_srch_boot_sas_address(
328 sas_address, &boot_device->SasWwid);
330 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
331 if (!enclosure_logical_id)
333 rc = _scsih_srch_boot_encl_slot(
334 enclosure_logical_id,
335 slot, &boot_device->EnclosureSlot);
337 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
340 rc = _scsih_srch_boot_device_name(
341 device_name, &boot_device->DeviceName);
343 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
351 * _scsih_get_sas_address - set the sas_address for given device handle
352 * @handle: device handle
353 * @sas_address: sas address
355 * Returns 0 success, non-zero when failure
358 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
361 Mpi2SasDevicePage0_t sas_device_pg0;
362 Mpi2ConfigReply_t mpi_reply;
367 if (handle <= ioc->sas_hba.num_phys) {
368 *sas_address = ioc->sas_hba.sas_address;
372 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
373 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
374 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
375 __FILE__, __LINE__, __func__);
379 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
380 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
381 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
385 /* we hit this becuase the given parent handle doesn't exist */
386 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
389 /* else error case */
391 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
392 ioc->name, handle, ioc_status,
393 __FILE__, __LINE__, __func__);
398 * _scsih_determine_boot_device - determine boot device.
399 * @ioc: per adapter object
400 * @device: either sas_device or raid_device object
401 * @is_raid: [flag] 1 = raid object, 0 = sas object
403 * Determines whether this device should be first reported device to
404 * to scsi-ml or sas transport, this purpose is for persistent boot device.
405 * There are primary, alternate, and current entries in bios page 2. The order
406 * priority is primary, alternate, then current. This routine saves
407 * the corresponding device object and is_raid flag in the ioc object.
408 * The saved data to be used later in _scsih_probe_boot_devices().
411 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
412 void *device, u8 is_raid)
414 struct _sas_device *sas_device;
415 struct _raid_device *raid_device;
418 u64 enclosure_logical_id;
421 /* only process this function when driver loads */
422 if (!ioc->is_driver_loading)
425 /* no Bios, return immediately */
426 if (!ioc->bios_pg3.BiosVersion)
431 sas_address = sas_device->sas_address;
432 device_name = sas_device->device_name;
433 enclosure_logical_id = sas_device->enclosure_logical_id;
434 slot = sas_device->slot;
436 raid_device = device;
437 sas_address = raid_device->wwid;
439 enclosure_logical_id = 0;
443 if (!ioc->req_boot_device.device) {
444 if (_scsih_is_boot_device(sas_address, device_name,
445 enclosure_logical_id, slot,
446 (ioc->bios_pg2.ReqBootDeviceForm &
447 MPI2_BIOSPAGE2_FORM_MASK),
448 &ioc->bios_pg2.RequestedBootDevice)) {
449 dinitprintk(ioc, pr_info(MPT3SAS_FMT
450 "%s: req_boot_device(0x%016llx)\n",
452 (unsigned long long)sas_address));
453 ioc->req_boot_device.device = device;
454 ioc->req_boot_device.is_raid = is_raid;
458 if (!ioc->req_alt_boot_device.device) {
459 if (_scsih_is_boot_device(sas_address, device_name,
460 enclosure_logical_id, slot,
461 (ioc->bios_pg2.ReqAltBootDeviceForm &
462 MPI2_BIOSPAGE2_FORM_MASK),
463 &ioc->bios_pg2.RequestedAltBootDevice)) {
464 dinitprintk(ioc, pr_info(MPT3SAS_FMT
465 "%s: req_alt_boot_device(0x%016llx)\n",
467 (unsigned long long)sas_address));
468 ioc->req_alt_boot_device.device = device;
469 ioc->req_alt_boot_device.is_raid = is_raid;
473 if (!ioc->current_boot_device.device) {
474 if (_scsih_is_boot_device(sas_address, device_name,
475 enclosure_logical_id, slot,
476 (ioc->bios_pg2.CurrentBootDeviceForm &
477 MPI2_BIOSPAGE2_FORM_MASK),
478 &ioc->bios_pg2.CurrentBootDevice)) {
479 dinitprintk(ioc, pr_info(MPT3SAS_FMT
480 "%s: current_boot_device(0x%016llx)\n",
482 (unsigned long long)sas_address));
483 ioc->current_boot_device.device = device;
484 ioc->current_boot_device.is_raid = is_raid;
490 * mpt3sas_scsih_sas_device_find_by_sas_address - sas device search
491 * @ioc: per adapter object
492 * @sas_address: sas address
493 * Context: Calling function should acquire ioc->sas_device_lock
495 * This searches for sas_device based on sas_address, then return sas_device
499 mpt3sas_scsih_sas_device_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
502 struct _sas_device *sas_device;
504 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
505 if (sas_device->sas_address == sas_address)
508 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
509 if (sas_device->sas_address == sas_address)
516 * _scsih_sas_device_find_by_handle - sas device search
517 * @ioc: per adapter object
518 * @handle: sas device handle (assigned by firmware)
519 * Context: Calling function should acquire ioc->sas_device_lock
521 * This searches for sas_device based on sas_address, then return sas_device
524 static struct _sas_device *
525 _scsih_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
527 struct _sas_device *sas_device;
529 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
530 if (sas_device->handle == handle)
533 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
534 if (sas_device->handle == handle)
541 * _scsih_sas_device_remove - remove sas_device from list.
542 * @ioc: per adapter object
543 * @sas_device: the sas_device object
544 * Context: This function will acquire ioc->sas_device_lock.
546 * Removing object and freeing associated memory from the ioc->sas_device_list.
549 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
550 struct _sas_device *sas_device)
557 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
558 ioc->name, sas_device->handle,
559 (unsigned long long) sas_device->sas_address);
561 if (sas_device->enclosure_handle != 0)
563 "removing enclosure logical id(0x%016llx), slot(%d)\n",
564 ioc->name, (unsigned long long)
565 sas_device->enclosure_logical_id, sas_device->slot);
567 if (sas_device->connector_name[0] != '\0')
569 "removing enclosure level(0x%04x), connector name( %s)\n",
570 ioc->name, sas_device->enclosure_level,
571 sas_device->connector_name);
573 spin_lock_irqsave(&ioc->sas_device_lock, flags);
574 list_del(&sas_device->list);
576 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
580 * _scsih_device_remove_by_handle - removing device object by handle
581 * @ioc: per adapter object
582 * @handle: device handle
587 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
589 struct _sas_device *sas_device;
592 if (ioc->shost_recovery)
595 spin_lock_irqsave(&ioc->sas_device_lock, flags);
596 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
598 list_del(&sas_device->list);
599 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
601 _scsih_remove_device(ioc, sas_device);
605 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
606 * @ioc: per adapter object
607 * @sas_address: device sas_address
612 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
615 struct _sas_device *sas_device;
618 if (ioc->shost_recovery)
621 spin_lock_irqsave(&ioc->sas_device_lock, flags);
622 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
625 list_del(&sas_device->list);
626 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
628 _scsih_remove_device(ioc, sas_device);
632 * _scsih_sas_device_add - insert sas_device to the list.
633 * @ioc: per adapter object
634 * @sas_device: the sas_device object
635 * Context: This function will acquire ioc->sas_device_lock.
637 * Adding new object to the ioc->sas_device_list.
640 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
641 struct _sas_device *sas_device)
645 dewtprintk(ioc, pr_info(MPT3SAS_FMT
646 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
647 ioc->name, __func__, sas_device->handle,
648 (unsigned long long)sas_device->sas_address));
650 if (sas_device->enclosure_handle != 0)
651 dewtprintk(ioc, pr_info(MPT3SAS_FMT
652 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
653 ioc->name, __func__, (unsigned long long)
654 sas_device->enclosure_logical_id, sas_device->slot));
656 if (sas_device->connector_name[0] != '\0')
657 dewtprintk(ioc, pr_info(MPT3SAS_FMT
658 "%s: enclosure level(0x%04x), connector name( %s)\n",
660 sas_device->enclosure_level, sas_device->connector_name));
662 spin_lock_irqsave(&ioc->sas_device_lock, flags);
663 list_add_tail(&sas_device->list, &ioc->sas_device_list);
664 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
666 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
667 sas_device->sas_address_parent)) {
668 _scsih_sas_device_remove(ioc, sas_device);
669 } else if (!sas_device->starget) {
671 * When asyn scanning is enabled, its not possible to remove
672 * devices while scanning is turned on due to an oops in
673 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
675 if (!ioc->is_driver_loading) {
676 mpt3sas_transport_port_remove(ioc,
677 sas_device->sas_address,
678 sas_device->sas_address_parent);
679 _scsih_sas_device_remove(ioc, sas_device);
685 * _scsih_sas_device_init_add - insert sas_device to the list.
686 * @ioc: per adapter object
687 * @sas_device: the sas_device object
688 * Context: This function will acquire ioc->sas_device_lock.
690 * Adding new object at driver load time to the ioc->sas_device_init_list.
693 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
694 struct _sas_device *sas_device)
698 dewtprintk(ioc, pr_info(MPT3SAS_FMT
699 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
700 __func__, sas_device->handle,
701 (unsigned long long)sas_device->sas_address));
703 if (sas_device->enclosure_handle != 0)
704 dewtprintk(ioc, pr_info(MPT3SAS_FMT
705 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
706 ioc->name, __func__, (unsigned long long)
707 sas_device->enclosure_logical_id, sas_device->slot));
709 if (sas_device->connector_name[0] != '\0')
710 dewtprintk(ioc, pr_info(MPT3SAS_FMT
711 "%s: enclosure level(0x%04x), connector name( %s)\n",
712 ioc->name, __func__, sas_device->enclosure_level,
713 sas_device->connector_name));
715 spin_lock_irqsave(&ioc->sas_device_lock, flags);
716 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
717 _scsih_determine_boot_device(ioc, sas_device, 0);
718 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
722 * _scsih_raid_device_find_by_id - raid device search
723 * @ioc: per adapter object
724 * @id: sas device target id
725 * @channel: sas device channel
726 * Context: Calling function should acquire ioc->raid_device_lock
728 * This searches for raid_device based on target id, then return raid_device
731 static struct _raid_device *
732 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
734 struct _raid_device *raid_device, *r;
737 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
738 if (raid_device->id == id && raid_device->channel == channel) {
749 * _scsih_raid_device_find_by_handle - raid device search
750 * @ioc: per adapter object
751 * @handle: sas device handle (assigned by firmware)
752 * Context: Calling function should acquire ioc->raid_device_lock
754 * This searches for raid_device based on handle, then return raid_device
757 static struct _raid_device *
758 _scsih_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
760 struct _raid_device *raid_device, *r;
763 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
764 if (raid_device->handle != handle)
775 * _scsih_raid_device_find_by_wwid - raid device search
776 * @ioc: per adapter object
777 * @handle: sas device handle (assigned by firmware)
778 * Context: Calling function should acquire ioc->raid_device_lock
780 * This searches for raid_device based on wwid, then return raid_device
783 static struct _raid_device *
784 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
786 struct _raid_device *raid_device, *r;
789 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
790 if (raid_device->wwid != wwid)
801 * _scsih_raid_device_add - add raid_device object
802 * @ioc: per adapter object
803 * @raid_device: raid_device object
805 * This is added to the raid_device_list link list.
808 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
809 struct _raid_device *raid_device)
813 dewtprintk(ioc, pr_info(MPT3SAS_FMT
814 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
815 raid_device->handle, (unsigned long long)raid_device->wwid));
817 spin_lock_irqsave(&ioc->raid_device_lock, flags);
818 list_add_tail(&raid_device->list, &ioc->raid_device_list);
819 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
823 * _scsih_raid_device_remove - delete raid_device object
824 * @ioc: per adapter object
825 * @raid_device: raid_device object
829 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
830 struct _raid_device *raid_device)
834 spin_lock_irqsave(&ioc->raid_device_lock, flags);
835 list_del(&raid_device->list);
837 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
841 * mpt3sas_scsih_expander_find_by_handle - expander device search
842 * @ioc: per adapter object
843 * @handle: expander handle (assigned by firmware)
844 * Context: Calling function should acquire ioc->sas_device_lock
846 * This searches for expander device based on handle, then returns the
850 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
852 struct _sas_node *sas_expander, *r;
855 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
856 if (sas_expander->handle != handle)
866 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
867 * @ioc: per adapter object
868 * @sas_address: sas address
869 * Context: Calling function should acquire ioc->sas_node_lock.
871 * This searches for expander device based on sas_address, then returns the
875 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
878 struct _sas_node *sas_expander, *r;
881 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
882 if (sas_expander->sas_address != sas_address)
892 * _scsih_expander_node_add - insert expander device to the list.
893 * @ioc: per adapter object
894 * @sas_expander: the sas_device object
895 * Context: This function will acquire ioc->sas_node_lock.
897 * Adding new object to the ioc->sas_expander_list.
902 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
903 struct _sas_node *sas_expander)
907 spin_lock_irqsave(&ioc->sas_node_lock, flags);
908 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
909 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
913 * _scsih_is_end_device - determines if device is an end device
914 * @device_info: bitfield providing information about the device.
917 * Returns 1 if end device.
920 _scsih_is_end_device(u32 device_info)
922 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
923 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
924 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
925 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
932 * _scsih_scsi_lookup_get - returns scmd entry
933 * @ioc: per adapter object
934 * @smid: system request message index
936 * Returns the smid stored scmd pointer.
938 static struct scsi_cmnd *
939 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
941 return ioc->scsi_lookup[smid - 1].scmd;
945 * _scsih_scsi_lookup_get_clear - returns scmd entry
946 * @ioc: per adapter object
947 * @smid: system request message index
949 * Returns the smid stored scmd pointer.
950 * Then will derefrence the stored scmd pointer.
952 static inline struct scsi_cmnd *
953 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
956 struct scsi_cmnd *scmd;
958 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
959 scmd = ioc->scsi_lookup[smid - 1].scmd;
960 ioc->scsi_lookup[smid - 1].scmd = NULL;
961 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
967 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
968 * @ioc: per adapter object
969 * @smid: system request message index
970 * @scmd: pointer to scsi command object
971 * Context: This function will acquire ioc->scsi_lookup_lock.
973 * This will search for a scmd pointer in the scsi_lookup array,
974 * returning the revelent smid. A returned value of zero means invalid.
977 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
984 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
986 for (i = 0; i < ioc->scsiio_depth; i++) {
987 if (ioc->scsi_lookup[i].scmd == scmd) {
988 smid = ioc->scsi_lookup[i].smid;
993 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
998 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
999 * @ioc: per adapter object
1002 * Context: This function will acquire ioc->scsi_lookup_lock.
1004 * This will search for a matching channel:id in the scsi_lookup array,
1005 * returning 1 if found.
1008 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1012 unsigned long flags;
1015 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1017 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1018 if (ioc->scsi_lookup[i].scmd &&
1019 (ioc->scsi_lookup[i].scmd->device->id == id &&
1020 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1026 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1031 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1032 * @ioc: per adapter object
1036 * Context: This function will acquire ioc->scsi_lookup_lock.
1038 * This will search for a matching channel:id:lun in the scsi_lookup array,
1039 * returning 1 if found.
1042 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1043 unsigned int lun, int channel)
1046 unsigned long flags;
1049 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1051 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1052 if (ioc->scsi_lookup[i].scmd &&
1053 (ioc->scsi_lookup[i].scmd->device->id == id &&
1054 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1055 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1061 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1066 * scsih_change_queue_depth - setting device queue depth
1067 * @sdev: scsi device struct
1068 * @qdepth: requested queue depth
1070 * Returns queue depth.
1073 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1075 struct Scsi_Host *shost = sdev->host;
1077 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1078 struct MPT3SAS_DEVICE *sas_device_priv_data;
1079 struct MPT3SAS_TARGET *sas_target_priv_data;
1080 struct _sas_device *sas_device;
1081 unsigned long flags;
1083 max_depth = shost->can_queue;
1085 /* limit max device queue for SATA to 32 */
1086 sas_device_priv_data = sdev->hostdata;
1087 if (!sas_device_priv_data)
1089 sas_target_priv_data = sas_device_priv_data->sas_target;
1090 if (!sas_target_priv_data)
1092 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1094 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1095 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1096 sas_device_priv_data->sas_target->sas_address);
1097 if (sas_device && sas_device->device_info &
1098 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1099 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1100 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1104 if (!sdev->tagged_supported)
1106 if (qdepth > max_depth)
1108 return scsi_change_queue_depth(sdev, qdepth);
1112 * scsih_target_alloc - target add routine
1113 * @starget: scsi target struct
1115 * Returns 0 if ok. Any other return is assumed to be an error and
1116 * the device is ignored.
1119 scsih_target_alloc(struct scsi_target *starget)
1121 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1122 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1123 struct MPT3SAS_TARGET *sas_target_priv_data;
1124 struct _sas_device *sas_device;
1125 struct _raid_device *raid_device;
1126 unsigned long flags;
1127 struct sas_rphy *rphy;
1129 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1131 if (!sas_target_priv_data)
1134 starget->hostdata = sas_target_priv_data;
1135 sas_target_priv_data->starget = starget;
1136 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1139 if (starget->channel == RAID_CHANNEL) {
1140 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1141 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1144 sas_target_priv_data->handle = raid_device->handle;
1145 sas_target_priv_data->sas_address = raid_device->wwid;
1146 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1147 raid_device->starget = starget;
1149 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1153 /* sas/sata devices */
1154 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1155 rphy = dev_to_rphy(starget->dev.parent);
1156 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1157 rphy->identify.sas_address);
1160 sas_target_priv_data->handle = sas_device->handle;
1161 sas_target_priv_data->sas_address = sas_device->sas_address;
1162 sas_device->starget = starget;
1163 sas_device->id = starget->id;
1164 sas_device->channel = starget->channel;
1165 if (test_bit(sas_device->handle, ioc->pd_handles))
1166 sas_target_priv_data->flags |=
1167 MPT_TARGET_FLAGS_RAID_COMPONENT;
1168 if (sas_device->fast_path)
1169 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1171 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1177 * scsih_target_destroy - target destroy routine
1178 * @starget: scsi target struct
1183 scsih_target_destroy(struct scsi_target *starget)
1185 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1186 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1187 struct MPT3SAS_TARGET *sas_target_priv_data;
1188 struct _sas_device *sas_device;
1189 struct _raid_device *raid_device;
1190 unsigned long flags;
1191 struct sas_rphy *rphy;
1193 sas_target_priv_data = starget->hostdata;
1194 if (!sas_target_priv_data)
1197 if (starget->channel == RAID_CHANNEL) {
1198 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1199 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1202 raid_device->starget = NULL;
1203 raid_device->sdev = NULL;
1205 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1209 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1210 rphy = dev_to_rphy(starget->dev.parent);
1211 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1212 rphy->identify.sas_address);
1213 if (sas_device && (sas_device->starget == starget) &&
1214 (sas_device->id == starget->id) &&
1215 (sas_device->channel == starget->channel))
1216 sas_device->starget = NULL;
1218 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1221 kfree(sas_target_priv_data);
1222 starget->hostdata = NULL;
1226 * scsih_slave_alloc - device add routine
1227 * @sdev: scsi device struct
1229 * Returns 0 if ok. Any other return is assumed to be an error and
1230 * the device is ignored.
1233 scsih_slave_alloc(struct scsi_device *sdev)
1235 struct Scsi_Host *shost;
1236 struct MPT3SAS_ADAPTER *ioc;
1237 struct MPT3SAS_TARGET *sas_target_priv_data;
1238 struct MPT3SAS_DEVICE *sas_device_priv_data;
1239 struct scsi_target *starget;
1240 struct _raid_device *raid_device;
1241 struct _sas_device *sas_device;
1242 unsigned long flags;
1244 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1246 if (!sas_device_priv_data)
1249 sas_device_priv_data->lun = sdev->lun;
1250 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1252 starget = scsi_target(sdev);
1253 sas_target_priv_data = starget->hostdata;
1254 sas_target_priv_data->num_luns++;
1255 sas_device_priv_data->sas_target = sas_target_priv_data;
1256 sdev->hostdata = sas_device_priv_data;
1257 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1258 sdev->no_uld_attach = 1;
1260 shost = dev_to_shost(&starget->dev);
1261 ioc = shost_priv(shost);
1262 if (starget->channel == RAID_CHANNEL) {
1263 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1264 raid_device = _scsih_raid_device_find_by_id(ioc,
1265 starget->id, starget->channel);
1267 raid_device->sdev = sdev; /* raid is single lun */
1268 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1271 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1272 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1273 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1274 sas_target_priv_data->sas_address);
1275 if (sas_device && (sas_device->starget == NULL)) {
1276 sdev_printk(KERN_INFO, sdev,
1277 "%s : sas_device->starget set to starget @ %d\n",
1278 __func__, __LINE__);
1279 sas_device->starget = starget;
1281 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1288 * scsih_slave_destroy - device destroy routine
1289 * @sdev: scsi device struct
1294 scsih_slave_destroy(struct scsi_device *sdev)
1296 struct MPT3SAS_TARGET *sas_target_priv_data;
1297 struct scsi_target *starget;
1298 struct Scsi_Host *shost;
1299 struct MPT3SAS_ADAPTER *ioc;
1300 struct _sas_device *sas_device;
1301 unsigned long flags;
1303 if (!sdev->hostdata)
1306 starget = scsi_target(sdev);
1307 sas_target_priv_data = starget->hostdata;
1308 sas_target_priv_data->num_luns--;
1310 shost = dev_to_shost(&starget->dev);
1311 ioc = shost_priv(shost);
1313 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1314 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1315 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1316 sas_target_priv_data->sas_address);
1317 if (sas_device && !sas_target_priv_data->num_luns)
1318 sas_device->starget = NULL;
1319 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1322 kfree(sdev->hostdata);
1323 sdev->hostdata = NULL;
1327 * _scsih_display_sata_capabilities - sata capabilities
1328 * @ioc: per adapter object
1329 * @handle: device handle
1330 * @sdev: scsi device struct
1333 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1334 u16 handle, struct scsi_device *sdev)
1336 Mpi2ConfigReply_t mpi_reply;
1337 Mpi2SasDevicePage0_t sas_device_pg0;
1342 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1343 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1344 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1345 ioc->name, __FILE__, __LINE__, __func__);
1349 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1350 MPI2_IOCSTATUS_MASK;
1351 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1352 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1353 ioc->name, __FILE__, __LINE__, __func__);
1357 flags = le16_to_cpu(sas_device_pg0.Flags);
1358 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1360 sdev_printk(KERN_INFO, sdev,
1361 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1362 "sw_preserve(%s)\n",
1363 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1364 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1365 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1367 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1368 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1369 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1373 * raid transport support -
1374 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1375 * unloading the driver followed by a load - I beleive that the subroutine
1376 * raid_class_release() is not cleaning up properly.
1380 * scsih_is_raid - return boolean indicating device is raid volume
1381 * @dev the device struct object
1384 scsih_is_raid(struct device *dev)
1386 struct scsi_device *sdev = to_scsi_device(dev);
1388 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1392 * scsih_get_resync - get raid volume resync percent complete
1393 * @dev the device struct object
1396 scsih_get_resync(struct device *dev)
1398 struct scsi_device *sdev = to_scsi_device(dev);
1399 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1400 static struct _raid_device *raid_device;
1401 unsigned long flags;
1402 Mpi2RaidVolPage0_t vol_pg0;
1403 Mpi2ConfigReply_t mpi_reply;
1404 u32 volume_status_flags;
1405 u8 percent_complete;
1408 percent_complete = 0;
1410 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1411 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1414 handle = raid_device->handle;
1415 percent_complete = raid_device->percent_complete;
1417 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1422 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1423 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1424 sizeof(Mpi2RaidVolPage0_t))) {
1425 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1426 ioc->name, __FILE__, __LINE__, __func__);
1427 percent_complete = 0;
1431 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1432 if (!(volume_status_flags &
1433 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1434 percent_complete = 0;
1437 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1441 * scsih_get_state - get raid volume level
1442 * @dev the device struct object
1445 scsih_get_state(struct device *dev)
1447 struct scsi_device *sdev = to_scsi_device(dev);
1448 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1449 static struct _raid_device *raid_device;
1450 unsigned long flags;
1451 Mpi2RaidVolPage0_t vol_pg0;
1452 Mpi2ConfigReply_t mpi_reply;
1454 enum raid_state state = RAID_STATE_UNKNOWN;
1457 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1458 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1461 handle = raid_device->handle;
1462 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1467 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1468 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1469 sizeof(Mpi2RaidVolPage0_t))) {
1470 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1471 ioc->name, __FILE__, __LINE__, __func__);
1475 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1476 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1477 state = RAID_STATE_RESYNCING;
1481 switch (vol_pg0.VolumeState) {
1482 case MPI2_RAID_VOL_STATE_OPTIMAL:
1483 case MPI2_RAID_VOL_STATE_ONLINE:
1484 state = RAID_STATE_ACTIVE;
1486 case MPI2_RAID_VOL_STATE_DEGRADED:
1487 state = RAID_STATE_DEGRADED;
1489 case MPI2_RAID_VOL_STATE_FAILED:
1490 case MPI2_RAID_VOL_STATE_MISSING:
1491 state = RAID_STATE_OFFLINE;
1495 raid_set_state(mpt3sas_raid_template, dev, state);
1499 * _scsih_set_level - set raid level
1500 * @sdev: scsi device struct
1501 * @volume_type: volume type
1504 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1506 enum raid_level level = RAID_LEVEL_UNKNOWN;
1508 switch (volume_type) {
1509 case MPI2_RAID_VOL_TYPE_RAID0:
1510 level = RAID_LEVEL_0;
1512 case MPI2_RAID_VOL_TYPE_RAID10:
1513 level = RAID_LEVEL_10;
1515 case MPI2_RAID_VOL_TYPE_RAID1E:
1516 level = RAID_LEVEL_1E;
1518 case MPI2_RAID_VOL_TYPE_RAID1:
1519 level = RAID_LEVEL_1;
1523 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1528 * _scsih_get_volume_capabilities - volume capabilities
1529 * @ioc: per adapter object
1530 * @sas_device: the raid_device object
1532 * Returns 0 for success, else 1
1535 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1536 struct _raid_device *raid_device)
1538 Mpi2RaidVolPage0_t *vol_pg0;
1539 Mpi2RaidPhysDiskPage0_t pd_pg0;
1540 Mpi2SasDevicePage0_t sas_device_pg0;
1541 Mpi2ConfigReply_t mpi_reply;
1545 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1546 &num_pds)) || !num_pds) {
1547 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1548 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1553 raid_device->num_pds = num_pds;
1554 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1555 sizeof(Mpi2RaidVol0PhysDisk_t));
1556 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1558 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1559 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1564 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1565 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1566 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1567 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1573 raid_device->volume_type = vol_pg0->VolumeType;
1575 /* figure out what the underlying devices are by
1576 * obtaining the device_info bits for the 1st device
1578 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1579 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1580 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1581 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1582 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1583 le16_to_cpu(pd_pg0.DevHandle)))) {
1584 raid_device->device_info =
1585 le32_to_cpu(sas_device_pg0.DeviceInfo);
1596 * _scsih_enable_tlr - setting TLR flags
1597 * @ioc: per adapter object
1598 * @sdev: scsi device struct
1600 * Enabling Transaction Layer Retries for tape devices when
1601 * vpd page 0x90 is present
1605 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1609 if (sdev->type != TYPE_TAPE)
1612 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1615 sas_enable_tlr(sdev);
1616 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1617 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1623 * scsih_slave_configure - device configure routine.
1624 * @sdev: scsi device struct
1626 * Returns 0 if ok. Any other return is assumed to be an error and
1627 * the device is ignored.
1630 scsih_slave_configure(struct scsi_device *sdev)
1632 struct Scsi_Host *shost = sdev->host;
1633 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1634 struct MPT3SAS_DEVICE *sas_device_priv_data;
1635 struct MPT3SAS_TARGET *sas_target_priv_data;
1636 struct _sas_device *sas_device;
1637 struct _raid_device *raid_device;
1638 unsigned long flags;
1643 u16 handle, volume_handle = 0;
1644 u64 volume_wwid = 0;
1647 sas_device_priv_data = sdev->hostdata;
1648 sas_device_priv_data->configured_lun = 1;
1649 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1650 sas_target_priv_data = sas_device_priv_data->sas_target;
1651 handle = sas_target_priv_data->handle;
1653 /* raid volume handling */
1654 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1656 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1657 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1658 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1660 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1661 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1662 __LINE__, __func__));
1666 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1667 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1668 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1669 __LINE__, __func__));
1674 /* RAID Queue Depth Support
1675 * IS volume = underlying qdepth of drive type, either
1676 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1677 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1679 if (raid_device->device_info &
1680 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1681 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1684 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1685 if (raid_device->device_info &
1686 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1692 switch (raid_device->volume_type) {
1693 case MPI2_RAID_VOL_TYPE_RAID0:
1696 case MPI2_RAID_VOL_TYPE_RAID1E:
1697 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1698 if (ioc->manu_pg10.OEMIdentifier &&
1699 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1700 MFG10_GF0_R10_DISPLAY) &&
1701 !(raid_device->num_pds % 2))
1706 case MPI2_RAID_VOL_TYPE_RAID1:
1707 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1710 case MPI2_RAID_VOL_TYPE_RAID10:
1711 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1714 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1716 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1721 sdev_printk(KERN_INFO, sdev,
1722 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1723 r_level, raid_device->handle,
1724 (unsigned long long)raid_device->wwid,
1725 raid_device->num_pds, ds);
1728 scsih_change_queue_depth(sdev, qdepth);
1730 /* raid transport support */
1731 _scsih_set_level(sdev, raid_device->volume_type);
1735 /* non-raid handling */
1736 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1737 if (mpt3sas_config_get_volume_handle(ioc, handle,
1739 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1740 "failure at %s:%d/%s()!\n", ioc->name,
1741 __FILE__, __LINE__, __func__));
1744 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1745 volume_handle, &volume_wwid)) {
1746 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1747 "failure at %s:%d/%s()!\n", ioc->name,
1748 __FILE__, __LINE__, __func__));
1753 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1754 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1755 sas_device_priv_data->sas_target->sas_address);
1757 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1758 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1759 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1764 sas_device->volume_handle = volume_handle;
1765 sas_device->volume_wwid = volume_wwid;
1766 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1767 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1771 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1772 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1774 else if (sas_device->device_info &
1775 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1779 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1780 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1781 ds, handle, (unsigned long long)sas_device->sas_address,
1782 sas_device->phy, (unsigned long long)sas_device->device_name);
1783 if (sas_device->enclosure_handle != 0)
1784 sdev_printk(KERN_INFO, sdev,
1785 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1786 ds, (unsigned long long)
1787 sas_device->enclosure_logical_id, sas_device->slot);
1788 if (sas_device->connector_name[0] != '\0')
1789 sdev_printk(KERN_INFO, sdev,
1790 "%s: enclosure level(0x%04x), connector name( %s)\n",
1791 ds, sas_device->enclosure_level,
1792 sas_device->connector_name);
1794 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1797 _scsih_display_sata_capabilities(ioc, handle, sdev);
1800 scsih_change_queue_depth(sdev, qdepth);
1803 sas_read_port_mode_page(sdev);
1804 _scsih_enable_tlr(ioc, sdev);
1811 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1812 * @sdev: scsi device struct
1813 * @bdev: pointer to block device context
1814 * @capacity: device size (in 512 byte sectors)
1815 * @params: three element array to place output:
1816 * params[0] number of heads (max 255)
1817 * params[1] number of sectors (max 63)
1818 * params[2] number of cylinders
1823 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1824 sector_t capacity, int params[])
1834 dummy = heads * sectors;
1835 cylinders = capacity;
1836 sector_div(cylinders, dummy);
1839 * Handle extended translation size for logical drives
1842 if ((ulong)capacity >= 0x200000) {
1845 dummy = heads * sectors;
1846 cylinders = capacity;
1847 sector_div(cylinders, dummy);
1852 params[1] = sectors;
1853 params[2] = cylinders;
1859 * _scsih_response_code - translation of device response code
1860 * @ioc: per adapter object
1861 * @response_code: response code returned by the device
1866 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1870 switch (response_code) {
1871 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1872 desc = "task management request completed";
1874 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1875 desc = "invalid frame";
1877 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1878 desc = "task management request not supported";
1880 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1881 desc = "task management request failed";
1883 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1884 desc = "task management request succeeded";
1886 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1887 desc = "invalid lun";
1890 desc = "overlapped tag attempted";
1892 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1893 desc = "task queued, however not sent to target";
1899 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1900 ioc->name, response_code, desc);
1904 * _scsih_tm_done - tm completion routine
1905 * @ioc: per adapter object
1906 * @smid: system request message index
1907 * @msix_index: MSIX table index supplied by the OS
1908 * @reply: reply message frame(lower 32bit addr)
1911 * The callback handler when using scsih_issue_tm.
1913 * Return 1 meaning mf should be freed from _base_interrupt
1914 * 0 means the mf is freed from this function.
1917 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1919 MPI2DefaultReply_t *mpi_reply;
1921 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1923 if (ioc->tm_cmds.smid != smid)
1925 mpt3sas_base_flush_reply_queues(ioc);
1926 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1927 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1929 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1930 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1932 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1933 complete(&ioc->tm_cmds.done);
1938 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1939 * @ioc: per adapter object
1940 * @handle: device handle
1942 * During taskmangement request, we need to freeze the device queue.
1945 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1947 struct MPT3SAS_DEVICE *sas_device_priv_data;
1948 struct scsi_device *sdev;
1951 shost_for_each_device(sdev, ioc->shost) {
1954 sas_device_priv_data = sdev->hostdata;
1955 if (!sas_device_priv_data)
1957 if (sas_device_priv_data->sas_target->handle == handle) {
1958 sas_device_priv_data->sas_target->tm_busy = 1;
1960 ioc->ignore_loginfos = 1;
1966 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1967 * @ioc: per adapter object
1968 * @handle: device handle
1970 * During taskmangement request, we need to freeze the device queue.
1973 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1975 struct MPT3SAS_DEVICE *sas_device_priv_data;
1976 struct scsi_device *sdev;
1979 shost_for_each_device(sdev, ioc->shost) {
1982 sas_device_priv_data = sdev->hostdata;
1983 if (!sas_device_priv_data)
1985 if (sas_device_priv_data->sas_target->handle == handle) {
1986 sas_device_priv_data->sas_target->tm_busy = 0;
1988 ioc->ignore_loginfos = 0;
1994 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
1995 * @ioc: per adapter struct
1996 * @device_handle: device handle
1997 * @channel: the channel assigned by the OS
1998 * @id: the id assigned by the OS
2000 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2001 * @smid_task: smid assigned to the task
2002 * @timeout: timeout in seconds
2003 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2006 * A generic API for sending task management requests to firmware.
2008 * The callback index is set inside `ioc->tm_cb_idx`.
2010 * Return SUCCESS or FAILED.
2013 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2014 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2015 enum mutex_type m_type)
2017 Mpi2SCSITaskManagementRequest_t *mpi_request;
2018 Mpi2SCSITaskManagementReply_t *mpi_reply;
2021 unsigned long timeleft;
2022 struct scsiio_tracker *scsi_lookup = NULL;
2025 if (m_type == TM_MUTEX_ON)
2026 mutex_lock(&ioc->tm_cmds.mutex);
2027 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2028 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2029 __func__, ioc->name);
2034 if (ioc->shost_recovery || ioc->remove_host ||
2035 ioc->pci_error_recovery) {
2036 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2037 __func__, ioc->name);
2042 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2043 if (ioc_state & MPI2_DOORBELL_USED) {
2044 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2045 "unexpected doorbell active!\n", ioc->name));
2046 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2048 rc = (!rc) ? SUCCESS : FAILED;
2052 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2053 mpt3sas_base_fault_info(ioc, ioc_state &
2054 MPI2_DOORBELL_DATA_MASK);
2055 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2057 rc = (!rc) ? SUCCESS : FAILED;
2061 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2063 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2064 ioc->name, __func__);
2069 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2070 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2072 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2073 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2074 ioc->name, handle, type, smid_task));
2075 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2076 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2077 ioc->tm_cmds.smid = smid;
2078 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2079 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2080 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2081 mpi_request->DevHandle = cpu_to_le16(handle);
2082 mpi_request->TaskType = type;
2083 mpi_request->TaskMID = cpu_to_le16(smid_task);
2084 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2085 mpt3sas_scsih_set_tm_flag(ioc, handle);
2086 init_completion(&ioc->tm_cmds.done);
2087 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2088 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2089 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2090 pr_err(MPT3SAS_FMT "%s: timeout\n",
2091 ioc->name, __func__);
2092 _debug_dump_mf(mpi_request,
2093 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2094 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2095 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2097 rc = (!rc) ? SUCCESS : FAILED;
2098 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2099 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2104 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2105 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2106 mpi_reply = ioc->tm_cmds.reply;
2107 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2108 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2109 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2110 le32_to_cpu(mpi_reply->IOCLogInfo),
2111 le32_to_cpu(mpi_reply->TerminationCount)));
2112 if (ioc->logging_level & MPT_DEBUG_TM) {
2113 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2114 if (mpi_reply->IOCStatus)
2115 _debug_dump_mf(mpi_request,
2116 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2121 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2123 if (scsi_lookup->scmd == NULL)
2128 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2129 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2134 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2135 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2136 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2141 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2149 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2150 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2151 if (m_type == TM_MUTEX_ON)
2152 mutex_unlock(&ioc->tm_cmds.mutex);
2157 if (m_type == TM_MUTEX_ON)
2158 mutex_unlock(&ioc->tm_cmds.mutex);
2163 * _scsih_tm_display_info - displays info about the device
2164 * @ioc: per adapter struct
2165 * @scmd: pointer to scsi command object
2167 * Called by task management callback handlers.
2170 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2172 struct scsi_target *starget = scmd->device->sdev_target;
2173 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2174 struct _sas_device *sas_device = NULL;
2175 unsigned long flags;
2176 char *device_str = NULL;
2180 device_str = "volume";
2182 scsi_print_command(scmd);
2183 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2184 starget_printk(KERN_INFO, starget,
2185 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2186 device_str, priv_target->handle,
2187 device_str, (unsigned long long)priv_target->sas_address);
2189 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2190 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2191 priv_target->sas_address);
2193 if (priv_target->flags &
2194 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2195 starget_printk(KERN_INFO, starget,
2196 "volume handle(0x%04x), "
2197 "volume wwid(0x%016llx)\n",
2198 sas_device->volume_handle,
2199 (unsigned long long)sas_device->volume_wwid);
2201 starget_printk(KERN_INFO, starget,
2202 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2204 (unsigned long long)sas_device->sas_address,
2206 if (sas_device->enclosure_handle != 0)
2207 starget_printk(KERN_INFO, starget,
2208 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2209 (unsigned long long)
2210 sas_device->enclosure_logical_id,
2212 if (sas_device->connector_name)
2213 starget_printk(KERN_INFO, starget,
2214 "enclosure level(0x%04x),connector name(%s)\n",
2215 sas_device->enclosure_level,
2216 sas_device->connector_name);
2218 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2223 * scsih_abort - eh threads main abort routine
2224 * @scmd: pointer to scsi command object
2226 * Returns SUCCESS if command aborted else FAILED
2229 scsih_abort(struct scsi_cmnd *scmd)
2231 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2232 struct MPT3SAS_DEVICE *sas_device_priv_data;
2237 sdev_printk(KERN_INFO, scmd->device,
2238 "attempting task abort! scmd(%p)\n", scmd);
2239 _scsih_tm_display_info(ioc, scmd);
2241 sas_device_priv_data = scmd->device->hostdata;
2242 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2243 sdev_printk(KERN_INFO, scmd->device,
2244 "device been deleted! scmd(%p)\n", scmd);
2245 scmd->result = DID_NO_CONNECT << 16;
2246 scmd->scsi_done(scmd);
2251 /* search for the command */
2252 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2254 scmd->result = DID_RESET << 16;
2259 /* for hidden raid components and volumes this is not supported */
2260 if (sas_device_priv_data->sas_target->flags &
2261 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2262 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2263 scmd->result = DID_RESET << 16;
2268 mpt3sas_halt_firmware(ioc);
2270 handle = sas_device_priv_data->sas_target->handle;
2271 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2272 scmd->device->id, scmd->device->lun,
2273 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2276 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2277 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2282 * scsih_dev_reset - eh threads main device reset routine
2283 * @scmd: pointer to scsi command object
2285 * Returns SUCCESS if command aborted else FAILED
2288 scsih_dev_reset(struct scsi_cmnd *scmd)
2290 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2291 struct MPT3SAS_DEVICE *sas_device_priv_data;
2292 struct _sas_device *sas_device;
2293 unsigned long flags;
2297 sdev_printk(KERN_INFO, scmd->device,
2298 "attempting device reset! scmd(%p)\n", scmd);
2299 _scsih_tm_display_info(ioc, scmd);
2301 sas_device_priv_data = scmd->device->hostdata;
2302 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2303 sdev_printk(KERN_INFO, scmd->device,
2304 "device been deleted! scmd(%p)\n", scmd);
2305 scmd->result = DID_NO_CONNECT << 16;
2306 scmd->scsi_done(scmd);
2311 /* for hidden raid components obtain the volume_handle */
2313 if (sas_device_priv_data->sas_target->flags &
2314 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2315 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2316 sas_device = _scsih_sas_device_find_by_handle(ioc,
2317 sas_device_priv_data->sas_target->handle);
2319 handle = sas_device->volume_handle;
2320 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2322 handle = sas_device_priv_data->sas_target->handle;
2325 scmd->result = DID_RESET << 16;
2330 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2331 scmd->device->id, scmd->device->lun,
2332 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2335 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2336 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2341 * scsih_target_reset - eh threads main target reset routine
2342 * @scmd: pointer to scsi command object
2344 * Returns SUCCESS if command aborted else FAILED
2347 scsih_target_reset(struct scsi_cmnd *scmd)
2349 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2350 struct MPT3SAS_DEVICE *sas_device_priv_data;
2351 struct _sas_device *sas_device;
2352 unsigned long flags;
2355 struct scsi_target *starget = scmd->device->sdev_target;
2357 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2359 _scsih_tm_display_info(ioc, scmd);
2361 sas_device_priv_data = scmd->device->hostdata;
2362 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2363 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2365 scmd->result = DID_NO_CONNECT << 16;
2366 scmd->scsi_done(scmd);
2371 /* for hidden raid components obtain the volume_handle */
2373 if (sas_device_priv_data->sas_target->flags &
2374 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2375 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2376 sas_device = _scsih_sas_device_find_by_handle(ioc,
2377 sas_device_priv_data->sas_target->handle);
2379 handle = sas_device->volume_handle;
2380 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2382 handle = sas_device_priv_data->sas_target->handle;
2385 scmd->result = DID_RESET << 16;
2390 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2391 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2395 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2396 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2402 * scsih_host_reset - eh threads main host reset routine
2403 * @scmd: pointer to scsi command object
2405 * Returns SUCCESS if command aborted else FAILED
2408 scsih_host_reset(struct scsi_cmnd *scmd)
2410 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2413 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2415 scsi_print_command(scmd);
2417 if (ioc->is_driver_loading) {
2418 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2424 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2426 r = (retval < 0) ? FAILED : SUCCESS;
2428 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2429 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2435 * _scsih_fw_event_add - insert and queue up fw_event
2436 * @ioc: per adapter object
2437 * @fw_event: object describing the event
2438 * Context: This function will acquire ioc->fw_event_lock.
2440 * This adds the firmware event object into link list, then queues it up to
2441 * be processed from user context.
2446 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2448 unsigned long flags;
2450 if (ioc->firmware_event_thread == NULL)
2453 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2454 INIT_LIST_HEAD(&fw_event->list);
2455 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2456 INIT_WORK(&fw_event->work, _firmware_event_work);
2457 queue_work(ioc->firmware_event_thread, &fw_event->work);
2458 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2462 * _scsih_fw_event_free - delete fw_event
2463 * @ioc: per adapter object
2464 * @fw_event: object describing the event
2465 * Context: This function will acquire ioc->fw_event_lock.
2467 * This removes firmware event object from link list, frees associated memory.
2472 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2475 unsigned long flags;
2477 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2478 list_del(&fw_event->list);
2480 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2485 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2486 * @ioc: per adapter object
2487 * @event_data: trigger event data
2492 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2493 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2495 struct fw_event_work *fw_event;
2497 if (ioc->is_driver_loading)
2499 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2503 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2504 fw_event->ioc = ioc;
2505 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2506 _scsih_fw_event_add(ioc, fw_event);
2510 * _scsih_error_recovery_delete_devices - remove devices not responding
2511 * @ioc: per adapter object
2516 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2518 struct fw_event_work *fw_event;
2520 if (ioc->is_driver_loading)
2522 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2525 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2526 fw_event->ioc = ioc;
2527 _scsih_fw_event_add(ioc, fw_event);
2531 * mpt3sas_port_enable_complete - port enable completed (fake event)
2532 * @ioc: per adapter object
2537 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2539 struct fw_event_work *fw_event;
2541 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2544 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2545 fw_event->ioc = ioc;
2546 _scsih_fw_event_add(ioc, fw_event);
2550 * _scsih_fw_event_cleanup_queue - cleanup event queue
2551 * @ioc: per adapter object
2553 * Walk the firmware event queue, either killing timers, or waiting
2554 * for outstanding events to complete
2559 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2561 struct fw_event_work *fw_event, *next;
2563 if (list_empty(&ioc->fw_event_list) ||
2564 !ioc->firmware_event_thread || in_interrupt())
2567 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2568 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2569 _scsih_fw_event_free(ioc, fw_event);
2576 * _scsih_internal_device_block - block the sdev device
2577 * @sdev: per device object
2578 * @sas_device_priv_data : per device driver private data
2580 * make sure device is blocked without error, if not
2584 _scsih_internal_device_block(struct scsi_device *sdev,
2585 struct MPT3SAS_DEVICE *sas_device_priv_data)
2589 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2590 sas_device_priv_data->sas_target->handle);
2591 sas_device_priv_data->block = 1;
2593 r = scsi_internal_device_block(sdev);
2595 sdev_printk(KERN_WARNING, sdev,
2596 "device_block failed with return(%d) for handle(0x%04x)\n",
2597 sas_device_priv_data->sas_target->handle, r);
2601 * _scsih_internal_device_unblock - unblock the sdev device
2602 * @sdev: per device object
2603 * @sas_device_priv_data : per device driver private data
2604 * make sure device is unblocked without error, if not retry
2605 * by blocking and then unblocking
2609 _scsih_internal_device_unblock(struct scsi_device *sdev,
2610 struct MPT3SAS_DEVICE *sas_device_priv_data)
2614 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2615 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2616 sas_device_priv_data->block = 0;
2617 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2619 /* The device has been set to SDEV_RUNNING by SD layer during
2620 * device addition but the request queue is still stopped by
2621 * our earlier block call. We need to perform a block again
2622 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2624 sdev_printk(KERN_WARNING, sdev,
2625 "device_unblock failed with return(%d) for handle(0x%04x) "
2626 "performing a block followed by an unblock\n",
2627 sas_device_priv_data->sas_target->handle, r);
2628 sas_device_priv_data->block = 1;
2629 r = scsi_internal_device_block(sdev);
2631 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2632 "failed with return(%d) for handle(0x%04x)\n",
2633 sas_device_priv_data->sas_target->handle, r);
2635 sas_device_priv_data->block = 0;
2636 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2638 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2639 " failed with return(%d) for handle(0x%04x)\n",
2640 sas_device_priv_data->sas_target->handle, r);
2645 * _scsih_ublock_io_all_device - unblock every device
2646 * @ioc: per adapter object
2648 * change the device state from block to running
2651 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2653 struct MPT3SAS_DEVICE *sas_device_priv_data;
2654 struct scsi_device *sdev;
2656 shost_for_each_device(sdev, ioc->shost) {
2657 sas_device_priv_data = sdev->hostdata;
2658 if (!sas_device_priv_data)
2660 if (!sas_device_priv_data->block)
2663 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2664 "device_running, handle(0x%04x)\n",
2665 sas_device_priv_data->sas_target->handle));
2666 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2672 * _scsih_ublock_io_device - prepare device to be deleted
2673 * @ioc: per adapter object
2674 * @sas_addr: sas address
2676 * unblock then put device in offline state
2679 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2681 struct MPT3SAS_DEVICE *sas_device_priv_data;
2682 struct scsi_device *sdev;
2684 shost_for_each_device(sdev, ioc->shost) {
2685 sas_device_priv_data = sdev->hostdata;
2686 if (!sas_device_priv_data)
2688 if (sas_device_priv_data->sas_target->sas_address
2691 if (sas_device_priv_data->block)
2692 _scsih_internal_device_unblock(sdev,
2693 sas_device_priv_data);
2698 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2699 * @ioc: per adapter object
2700 * @handle: device handle
2702 * During device pull we need to appropiately set the sdev state.
2705 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2707 struct MPT3SAS_DEVICE *sas_device_priv_data;
2708 struct scsi_device *sdev;
2710 shost_for_each_device(sdev, ioc->shost) {
2711 sas_device_priv_data = sdev->hostdata;
2712 if (!sas_device_priv_data)
2714 if (sas_device_priv_data->block)
2716 _scsih_internal_device_block(sdev, sas_device_priv_data);
2721 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2722 * @ioc: per adapter object
2723 * @handle: device handle
2725 * During device pull we need to appropiately set the sdev state.
2728 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2730 struct MPT3SAS_DEVICE *sas_device_priv_data;
2731 struct scsi_device *sdev;
2732 struct _sas_device *sas_device;
2734 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2738 shost_for_each_device(sdev, ioc->shost) {
2739 sas_device_priv_data = sdev->hostdata;
2740 if (!sas_device_priv_data)
2742 if (sas_device_priv_data->sas_target->handle != handle)
2744 if (sas_device_priv_data->block)
2746 if (sas_device->pend_sas_rphy_add)
2748 _scsih_internal_device_block(sdev, sas_device_priv_data);
2753 * _scsih_block_io_to_children_attached_to_ex
2754 * @ioc: per adapter object
2755 * @sas_expander: the sas_device object
2757 * This routine set sdev state to SDEV_BLOCK for all devices
2758 * attached to this expander. This function called when expander is
2762 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2763 struct _sas_node *sas_expander)
2765 struct _sas_port *mpt3sas_port;
2766 struct _sas_device *sas_device;
2767 struct _sas_node *expander_sibling;
2768 unsigned long flags;
2773 list_for_each_entry(mpt3sas_port,
2774 &sas_expander->sas_port_list, port_list) {
2775 if (mpt3sas_port->remote_identify.device_type ==
2777 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2779 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2780 mpt3sas_port->remote_identify.sas_address);
2782 set_bit(sas_device->handle,
2783 ioc->blocking_handles);
2784 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2788 list_for_each_entry(mpt3sas_port,
2789 &sas_expander->sas_port_list, port_list) {
2791 if (mpt3sas_port->remote_identify.device_type ==
2792 SAS_EDGE_EXPANDER_DEVICE ||
2793 mpt3sas_port->remote_identify.device_type ==
2794 SAS_FANOUT_EXPANDER_DEVICE) {
2796 mpt3sas_scsih_expander_find_by_sas_address(
2797 ioc, mpt3sas_port->remote_identify.sas_address);
2798 _scsih_block_io_to_children_attached_to_ex(ioc,
2805 * _scsih_block_io_to_children_attached_directly
2806 * @ioc: per adapter object
2807 * @event_data: topology change event data
2809 * This routine set sdev state to SDEV_BLOCK for all devices
2810 * direct attached during device pull.
2813 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2814 Mpi2EventDataSasTopologyChangeList_t *event_data)
2820 for (i = 0; i < event_data->NumEntries; i++) {
2821 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2824 reason_code = event_data->PHY[i].PhyStatus &
2825 MPI2_EVENT_SAS_TOPO_RC_MASK;
2826 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2827 _scsih_block_io_device(ioc, handle);
2832 * _scsih_tm_tr_send - send task management request
2833 * @ioc: per adapter object
2834 * @handle: device handle
2835 * Context: interrupt time.
2837 * This code is to initiate the device removal handshake protocol
2838 * with controller firmware. This function will issue target reset
2839 * using high priority request queue. It will send a sas iounit
2840 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2842 * This is designed to send muliple task management request at the same
2843 * time to the fifo. If the fifo is full, we will append the request,
2844 * and process it in a future completion.
2847 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2849 Mpi2SCSITaskManagementRequest_t *mpi_request;
2851 struct _sas_device *sas_device;
2852 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2853 u64 sas_address = 0;
2854 unsigned long flags;
2855 struct _tr_list *delayed_tr;
2858 if (ioc->remove_host) {
2859 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2860 "%s: host has been removed: handle(0x%04x)\n",
2861 __func__, ioc->name, handle));
2863 } else if (ioc->pci_error_recovery) {
2864 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2865 "%s: host in pci error recovery: handle(0x%04x)\n",
2866 __func__, ioc->name,
2870 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2871 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2872 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2873 "%s: host is not operational: handle(0x%04x)\n",
2874 __func__, ioc->name,
2879 /* if PD, then return */
2880 if (test_bit(handle, ioc->pd_handles))
2883 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2884 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2885 if (sas_device && sas_device->starget &&
2886 sas_device->starget->hostdata) {
2887 sas_target_priv_data = sas_device->starget->hostdata;
2888 sas_target_priv_data->deleted = 1;
2889 sas_address = sas_device->sas_address;
2891 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2893 if (sas_target_priv_data) {
2894 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2895 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2897 (unsigned long long)sas_address));
2898 if (sas_device->enclosure_handle != 0)
2899 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2900 "setting delete flag:enclosure logical id(0x%016llx),"
2901 " slot(%d)\n", ioc->name, (unsigned long long)
2902 sas_device->enclosure_logical_id,
2904 if (sas_device->connector_name)
2905 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2906 "setting delete flag: enclosure level(0x%04x),"
2907 " connector name( %s)\n", ioc->name,
2908 sas_device->enclosure_level,
2909 sas_device->connector_name));
2910 _scsih_ublock_io_device(ioc, sas_address);
2911 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2914 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2916 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2919 INIT_LIST_HEAD(&delayed_tr->list);
2920 delayed_tr->handle = handle;
2921 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2922 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2923 "DELAYED:tr:handle(0x%04x), (open)\n",
2924 ioc->name, handle));
2928 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2929 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2930 ioc->name, handle, smid,
2931 ioc->tm_tr_cb_idx));
2932 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2933 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2934 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2935 mpi_request->DevHandle = cpu_to_le16(handle);
2936 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2937 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2938 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2942 * _scsih_tm_tr_complete -
2943 * @ioc: per adapter object
2944 * @smid: system request message index
2945 * @msix_index: MSIX table index supplied by the OS
2946 * @reply: reply message frame(lower 32bit addr)
2947 * Context: interrupt time.
2949 * This is the target reset completion routine.
2950 * This code is part of the code to initiate the device removal
2951 * handshake protocol with controller firmware.
2952 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2954 * Return 1 meaning mf should be freed from _base_interrupt
2955 * 0 means the mf is freed from this function.
2958 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2962 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2963 Mpi2SCSITaskManagementReply_t *mpi_reply =
2964 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2965 Mpi2SasIoUnitControlRequest_t *mpi_request;
2969 if (ioc->remove_host) {
2970 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2971 "%s: host has been removed\n", __func__, ioc->name));
2973 } else if (ioc->pci_error_recovery) {
2974 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2975 "%s: host in pci error recovery\n", __func__,
2979 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2980 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2981 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2982 "%s: host is not operational\n", __func__, ioc->name));
2985 if (unlikely(!mpi_reply)) {
2986 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2987 ioc->name, __FILE__, __LINE__, __func__);
2990 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2991 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2992 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2993 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2994 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2996 le16_to_cpu(mpi_reply->DevHandle), smid));
3000 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3001 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3002 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3003 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3004 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3005 le32_to_cpu(mpi_reply->IOCLogInfo),
3006 le32_to_cpu(mpi_reply->TerminationCount)));
3008 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3009 if (!smid_sas_ctrl) {
3010 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3011 ioc->name, __func__);
3015 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3016 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3017 ioc->name, handle, smid_sas_ctrl,
3018 ioc->tm_sas_control_cb_idx));
3019 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3020 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3021 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3022 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3023 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3024 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3026 return _scsih_check_for_pending_tm(ioc, smid);
3031 * _scsih_sas_control_complete - completion routine
3032 * @ioc: per adapter object
3033 * @smid: system request message index
3034 * @msix_index: MSIX table index supplied by the OS
3035 * @reply: reply message frame(lower 32bit addr)
3036 * Context: interrupt time.
3038 * This is the sas iounit control completion routine.
3039 * This code is part of the code to initiate the device removal
3040 * handshake protocol with controller firmware.
3042 * Return 1 meaning mf should be freed from _base_interrupt
3043 * 0 means the mf is freed from this function.
3046 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3047 u8 msix_index, u32 reply)
3049 Mpi2SasIoUnitControlReply_t *mpi_reply =
3050 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3052 if (likely(mpi_reply)) {
3053 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3054 "sc_complete:handle(0x%04x), (open) "
3055 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3056 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3057 le16_to_cpu(mpi_reply->IOCStatus),
3058 le32_to_cpu(mpi_reply->IOCLogInfo)));
3060 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3061 ioc->name, __FILE__, __LINE__, __func__);
3067 * _scsih_tm_tr_volume_send - send target reset request for volumes
3068 * @ioc: per adapter object
3069 * @handle: device handle
3070 * Context: interrupt time.
3072 * This is designed to send muliple task management request at the same
3073 * time to the fifo. If the fifo is full, we will append the request,
3074 * and process it in a future completion.
3077 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3079 Mpi2SCSITaskManagementRequest_t *mpi_request;
3081 struct _tr_list *delayed_tr;
3083 if (ioc->shost_recovery || ioc->remove_host ||
3084 ioc->pci_error_recovery) {
3085 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3086 "%s: host reset in progress!\n",
3087 __func__, ioc->name));
3091 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3093 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3096 INIT_LIST_HEAD(&delayed_tr->list);
3097 delayed_tr->handle = handle;
3098 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3099 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3100 "DELAYED:tr:handle(0x%04x), (open)\n",
3101 ioc->name, handle));
3105 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3106 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3107 ioc->name, handle, smid,
3108 ioc->tm_tr_volume_cb_idx));
3109 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3110 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3111 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3112 mpi_request->DevHandle = cpu_to_le16(handle);
3113 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3114 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3118 * _scsih_tm_volume_tr_complete - target reset completion
3119 * @ioc: per adapter object
3120 * @smid: system request message index
3121 * @msix_index: MSIX table index supplied by the OS
3122 * @reply: reply message frame(lower 32bit addr)
3123 * Context: interrupt time.
3125 * Return 1 meaning mf should be freed from _base_interrupt
3126 * 0 means the mf is freed from this function.
3129 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3130 u8 msix_index, u32 reply)
3133 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3134 Mpi2SCSITaskManagementReply_t *mpi_reply =
3135 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3137 if (ioc->shost_recovery || ioc->remove_host ||
3138 ioc->pci_error_recovery) {
3139 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3140 "%s: host reset in progress!\n",
3141 __func__, ioc->name));
3144 if (unlikely(!mpi_reply)) {
3145 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3146 ioc->name, __FILE__, __LINE__, __func__);
3150 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3151 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3152 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3153 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3154 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3156 le16_to_cpu(mpi_reply->DevHandle), smid));
3160 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3161 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3162 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3163 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3164 le32_to_cpu(mpi_reply->IOCLogInfo),
3165 le32_to_cpu(mpi_reply->TerminationCount)));
3167 return _scsih_check_for_pending_tm(ioc, smid);
3172 * _scsih_check_for_pending_tm - check for pending task management
3173 * @ioc: per adapter object
3174 * @smid: system request message index
3176 * This will check delayed target reset list, and feed the
3179 * Return 1 meaning mf should be freed from _base_interrupt
3180 * 0 means the mf is freed from this function.
3183 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3185 struct _tr_list *delayed_tr;
3187 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3188 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3189 struct _tr_list, list);
3190 mpt3sas_base_free_smid(ioc, smid);
3191 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3192 list_del(&delayed_tr->list);
3197 if (!list_empty(&ioc->delayed_tr_list)) {
3198 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3199 struct _tr_list, list);
3200 mpt3sas_base_free_smid(ioc, smid);
3201 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3202 list_del(&delayed_tr->list);
3211 * _scsih_check_topo_delete_events - sanity check on topo events
3212 * @ioc: per adapter object
3213 * @event_data: the event data payload
3215 * This routine added to better handle cable breaker.
3217 * This handles the case where driver receives multiple expander
3218 * add and delete events in a single shot. When there is a delete event
3219 * the routine will void any pending add events waiting in the event queue.
3224 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3225 Mpi2EventDataSasTopologyChangeList_t *event_data)
3227 struct fw_event_work *fw_event;
3228 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3229 u16 expander_handle;
3230 struct _sas_node *sas_expander;
3231 unsigned long flags;
3235 for (i = 0 ; i < event_data->NumEntries; i++) {
3236 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3239 reason_code = event_data->PHY[i].PhyStatus &
3240 MPI2_EVENT_SAS_TOPO_RC_MASK;
3241 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3242 _scsih_tm_tr_send(ioc, handle);
3245 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3246 if (expander_handle < ioc->sas_hba.num_phys) {
3247 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3250 if (event_data->ExpStatus ==
3251 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3252 /* put expander attached devices into blocking state */
3253 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3254 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3256 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3257 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3259 handle = find_first_bit(ioc->blocking_handles,
3260 ioc->facts.MaxDevHandle);
3261 if (handle < ioc->facts.MaxDevHandle)
3262 _scsih_block_io_device(ioc, handle);
3263 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3264 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3265 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3267 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3270 /* mark ignore flag for pending events */
3271 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3272 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3273 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3276 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3277 fw_event->event_data;
3278 if (local_event_data->ExpStatus ==
3279 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3280 local_event_data->ExpStatus ==
3281 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3282 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3284 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3285 "setting ignoring flag\n", ioc->name));
3286 fw_event->ignore = 1;
3290 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3294 * _scsih_set_volume_delete_flag - setting volume delete flag
3295 * @ioc: per adapter object
3296 * @handle: device handle
3298 * This returns nothing.
3301 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3303 struct _raid_device *raid_device;
3304 struct MPT3SAS_TARGET *sas_target_priv_data;
3305 unsigned long flags;
3307 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3308 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3309 if (raid_device && raid_device->starget &&
3310 raid_device->starget->hostdata) {
3311 sas_target_priv_data =
3312 raid_device->starget->hostdata;
3313 sas_target_priv_data->deleted = 1;
3314 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3315 "setting delete flag: handle(0x%04x), "
3316 "wwid(0x%016llx)\n", ioc->name, handle,
3317 (unsigned long long) raid_device->wwid));
3319 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3323 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3324 * @handle: input handle
3325 * @a: handle for volume a
3326 * @b: handle for volume b
3328 * IR firmware only supports two raid volumes. The purpose of this
3329 * routine is to set the volume handle in either a or b. When the given
3330 * input handle is non-zero, or when a and b have not been set before.
3333 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3335 if (!handle || handle == *a || handle == *b)
3344 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3345 * @ioc: per adapter object
3346 * @event_data: the event data payload
3347 * Context: interrupt time.
3349 * This routine will send target reset to volume, followed by target
3350 * resets to the PDs. This is called when a PD has been removed, or
3351 * volume has been deleted or removed. When the target reset is sent
3352 * to volume, the PD target resets need to be queued to start upon
3353 * completion of the volume target reset.
3358 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3359 Mpi2EventDataIrConfigChangeList_t *event_data)
3361 Mpi2EventIrConfigElement_t *element;
3363 u16 handle, volume_handle, a, b;
3364 struct _tr_list *delayed_tr;
3369 /* Volume Resets for Deleted or Removed */
3370 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3371 for (i = 0; i < event_data->NumElements; i++, element++) {
3372 if (le32_to_cpu(event_data->Flags) &
3373 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3375 if (element->ReasonCode ==
3376 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3377 element->ReasonCode ==
3378 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3379 volume_handle = le16_to_cpu(element->VolDevHandle);
3380 _scsih_set_volume_delete_flag(ioc, volume_handle);
3381 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3385 /* Volume Resets for UNHIDE events */
3386 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3387 for (i = 0; i < event_data->NumElements; i++, element++) {
3388 if (le32_to_cpu(event_data->Flags) &
3389 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3391 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3392 volume_handle = le16_to_cpu(element->VolDevHandle);
3393 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3398 _scsih_tm_tr_volume_send(ioc, a);
3400 _scsih_tm_tr_volume_send(ioc, b);
3402 /* PD target resets */
3403 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3404 for (i = 0; i < event_data->NumElements; i++, element++) {
3405 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3407 handle = le16_to_cpu(element->PhysDiskDevHandle);
3408 volume_handle = le16_to_cpu(element->VolDevHandle);
3409 clear_bit(handle, ioc->pd_handles);
3411 _scsih_tm_tr_send(ioc, handle);
3412 else if (volume_handle == a || volume_handle == b) {
3413 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3414 BUG_ON(!delayed_tr);
3415 INIT_LIST_HEAD(&delayed_tr->list);
3416 delayed_tr->handle = handle;
3417 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3418 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3419 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3422 _scsih_tm_tr_send(ioc, handle);
3428 * _scsih_check_volume_delete_events - set delete flag for volumes
3429 * @ioc: per adapter object
3430 * @event_data: the event data payload
3431 * Context: interrupt time.
3433 * This will handle the case when the cable connected to entire volume is
3434 * pulled. We will take care of setting the deleted flag so normal IO will
3440 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3441 Mpi2EventDataIrVolume_t *event_data)
3445 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3447 state = le32_to_cpu(event_data->NewValue);
3448 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3449 MPI2_RAID_VOL_STATE_FAILED)
3450 _scsih_set_volume_delete_flag(ioc,
3451 le16_to_cpu(event_data->VolDevHandle));
3455 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3456 * @ioc: per adapter object
3457 * @event_data: the temp threshold event data
3458 * Context: interrupt time.
3463 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3464 Mpi2EventDataTemperature_t *event_data)
3466 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3467 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3468 " exceeded for Sensor: %d !!!\n", ioc->name,
3469 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3470 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3471 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3472 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3473 event_data->SensorNum);
3474 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3475 ioc->name, event_data->CurrentTemperature);
3480 * _scsih_flush_running_cmds - completing outstanding commands.
3481 * @ioc: per adapter object
3483 * The flushing out of all pending scmd commands following host reset,
3484 * where all IO is dropped to the floor.
3489 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3491 struct scsi_cmnd *scmd;
3495 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3496 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3500 mpt3sas_base_free_smid(ioc, smid);
3501 scsi_dma_unmap(scmd);
3502 if (ioc->pci_error_recovery)
3503 scmd->result = DID_NO_CONNECT << 16;
3505 scmd->result = DID_RESET << 16;
3506 scmd->scsi_done(scmd);
3508 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3513 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3514 * @ioc: per adapter object
3515 * @scmd: pointer to scsi command object
3516 * @mpi_request: pointer to the SCSI_IO reqest message frame
3518 * Supporting protection 1 and 3.
3523 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3524 Mpi2SCSIIORequest_t *mpi_request)
3527 unsigned char prot_op = scsi_get_prot_op(scmd);
3528 unsigned char prot_type = scsi_get_prot_type(scmd);
3529 Mpi25SCSIIORequest_t *mpi_request_3v =
3530 (Mpi25SCSIIORequest_t *)mpi_request;
3532 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3535 if (prot_op == SCSI_PROT_READ_STRIP)
3536 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3537 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3538 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3542 switch (prot_type) {
3543 case SCSI_PROT_DIF_TYPE1:
3544 case SCSI_PROT_DIF_TYPE2:
3547 * enable ref/guard checking
3548 * auto increment ref tag
3550 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3551 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3552 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3553 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3554 cpu_to_be32(scsi_get_lba(scmd));
3557 case SCSI_PROT_DIF_TYPE3:
3560 * enable guard checking
3562 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3567 mpi_request_3v->EEDPBlockSize =
3568 cpu_to_le16(scmd->device->sector_size);
3569 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3573 * _scsih_eedp_error_handling - return sense code for EEDP errors
3574 * @scmd: pointer to scsi command object
3575 * @ioc_status: ioc status
3580 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3584 switch (ioc_status) {
3585 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3588 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3591 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3598 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3600 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3601 SAM_STAT_CHECK_CONDITION;
3606 * scsih_qcmd - main scsi request entry point
3607 * @scmd: pointer to scsi command object
3608 * @done: function pointer to be invoked on completion
3610 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3612 * Returns 0 on success. If there's a failure, return either:
3613 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3614 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3617 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3619 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3620 struct MPT3SAS_DEVICE *sas_device_priv_data;
3621 struct MPT3SAS_TARGET *sas_target_priv_data;
3622 Mpi2SCSIIORequest_t *mpi_request;
3627 if (ioc->logging_level & MPT_DEBUG_SCSI)
3628 scsi_print_command(scmd);
3630 sas_device_priv_data = scmd->device->hostdata;
3631 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3632 scmd->result = DID_NO_CONNECT << 16;
3633 scmd->scsi_done(scmd);
3637 if (ioc->pci_error_recovery || ioc->remove_host) {
3638 scmd->result = DID_NO_CONNECT << 16;
3639 scmd->scsi_done(scmd);
3643 sas_target_priv_data = sas_device_priv_data->sas_target;
3645 /* invalid device handle */
3646 handle = sas_target_priv_data->handle;
3647 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3648 scmd->result = DID_NO_CONNECT << 16;
3649 scmd->scsi_done(scmd);
3654 /* host recovery or link resets sent via IOCTLs */
3655 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3656 return SCSI_MLQUEUE_HOST_BUSY;
3658 /* device has been deleted */
3659 else if (sas_target_priv_data->deleted) {
3660 scmd->result = DID_NO_CONNECT << 16;
3661 scmd->scsi_done(scmd);
3663 /* device busy with task managment */
3664 } else if (sas_target_priv_data->tm_busy ||
3665 sas_device_priv_data->block)
3666 return SCSI_MLQUEUE_DEVICE_BUSY;
3668 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3669 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3670 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3671 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3673 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3676 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3678 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3679 scmd->cmd_len != 32)
3680 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3682 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3684 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3685 ioc->name, __func__);
3688 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3689 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3690 _scsih_setup_eedp(ioc, scmd, mpi_request);
3692 if (scmd->cmd_len == 32)
3693 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3694 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3695 if (sas_device_priv_data->sas_target->flags &
3696 MPT_TARGET_FLAGS_RAID_COMPONENT)
3697 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3699 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3700 mpi_request->DevHandle = cpu_to_le16(handle);
3701 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3702 mpi_request->Control = cpu_to_le32(mpi_control);
3703 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3704 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3705 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3706 mpi_request->SenseBufferLowAddress =
3707 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3708 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3709 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3711 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3713 if (mpi_request->DataLength) {
3714 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3715 mpt3sas_base_free_smid(ioc, smid);
3719 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3721 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3722 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3723 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3724 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3725 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3727 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3729 mpt3sas_base_put_smid_default(ioc, smid);
3733 return SCSI_MLQUEUE_HOST_BUSY;
3737 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3738 * @sense_buffer: sense data returned by target
3739 * @data: normalized skey/asc/ascq
3744 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3746 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3747 /* descriptor format */
3748 data->skey = sense_buffer[1] & 0x0F;
3749 data->asc = sense_buffer[2];
3750 data->ascq = sense_buffer[3];
3753 data->skey = sense_buffer[2] & 0x0F;
3754 data->asc = sense_buffer[12];
3755 data->ascq = sense_buffer[13];
3760 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3761 * @ioc: per adapter object
3762 * @scmd: pointer to scsi command object
3763 * @mpi_reply: reply mf payload returned from firmware
3765 * scsi_status - SCSI Status code returned from target device
3766 * scsi_state - state info associated with SCSI_IO determined by ioc
3767 * ioc_status - ioc supplied status info
3772 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3773 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3777 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3778 MPI2_IOCSTATUS_MASK;
3779 u8 scsi_state = mpi_reply->SCSIState;
3780 u8 scsi_status = mpi_reply->SCSIStatus;
3781 char *desc_ioc_state = NULL;
3782 char *desc_scsi_status = NULL;
3783 char *desc_scsi_state = ioc->tmp_string;
3784 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3785 struct _sas_device *sas_device = NULL;
3786 unsigned long flags;
3787 struct scsi_target *starget = scmd->device->sdev_target;
3788 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3789 char *device_str = NULL;
3793 device_str = "volume";
3795 if (log_info == 0x31170000)
3798 switch (ioc_status) {
3799 case MPI2_IOCSTATUS_SUCCESS:
3800 desc_ioc_state = "success";
3802 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3803 desc_ioc_state = "invalid function";
3805 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3806 desc_ioc_state = "scsi recovered error";
3808 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3809 desc_ioc_state = "scsi invalid dev handle";
3811 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3812 desc_ioc_state = "scsi device not there";
3814 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3815 desc_ioc_state = "scsi data overrun";
3817 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3818 desc_ioc_state = "scsi data underrun";
3820 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3821 desc_ioc_state = "scsi io data error";
3823 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3824 desc_ioc_state = "scsi protocol error";
3826 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3827 desc_ioc_state = "scsi task terminated";
3829 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3830 desc_ioc_state = "scsi residual mismatch";
3832 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3833 desc_ioc_state = "scsi task mgmt failed";
3835 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3836 desc_ioc_state = "scsi ioc terminated";
3838 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3839 desc_ioc_state = "scsi ext terminated";
3841 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3842 desc_ioc_state = "eedp guard error";
3844 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3845 desc_ioc_state = "eedp ref tag error";
3847 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3848 desc_ioc_state = "eedp app tag error";
3851 desc_ioc_state = "unknown";
3855 switch (scsi_status) {
3856 case MPI2_SCSI_STATUS_GOOD:
3857 desc_scsi_status = "good";
3859 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3860 desc_scsi_status = "check condition";
3862 case MPI2_SCSI_STATUS_CONDITION_MET:
3863 desc_scsi_status = "condition met";
3865 case MPI2_SCSI_STATUS_BUSY:
3866 desc_scsi_status = "busy";
3868 case MPI2_SCSI_STATUS_INTERMEDIATE:
3869 desc_scsi_status = "intermediate";
3871 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3872 desc_scsi_status = "intermediate condmet";
3874 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3875 desc_scsi_status = "reservation conflict";
3877 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3878 desc_scsi_status = "command terminated";
3880 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3881 desc_scsi_status = "task set full";
3883 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3884 desc_scsi_status = "aca active";
3886 case MPI2_SCSI_STATUS_TASK_ABORTED:
3887 desc_scsi_status = "task aborted";
3890 desc_scsi_status = "unknown";
3894 desc_scsi_state[0] = '\0';
3896 desc_scsi_state = " ";
3897 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3898 strcat(desc_scsi_state, "response info ");
3899 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3900 strcat(desc_scsi_state, "state terminated ");
3901 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3902 strcat(desc_scsi_state, "no status ");
3903 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3904 strcat(desc_scsi_state, "autosense failed ");
3905 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3906 strcat(desc_scsi_state, "autosense valid ");
3908 scsi_print_command(scmd);
3910 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3911 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3912 device_str, (unsigned long long)priv_target->sas_address);
3914 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3915 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3916 priv_target->sas_address);
3919 "\tsas_address(0x%016llx), phy(%d)\n",
3920 ioc->name, (unsigned long long)
3921 sas_device->sas_address, sas_device->phy);
3922 if (sas_device->enclosure_handle != 0)
3924 "\tenclosure_logical_id(0x%016llx),"
3925 "slot(%d)\n", ioc->name,
3926 (unsigned long long)
3927 sas_device->enclosure_logical_id,
3929 if (sas_device->connector_name[0])
3931 "\tenclosure level(0x%04x),"
3932 " connector name( %s)\n", ioc->name,
3933 sas_device->enclosure_level,
3934 sas_device->connector_name);
3936 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3940 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3941 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3942 desc_ioc_state, ioc_status, smid);
3944 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3945 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3946 scsi_get_resid(scmd));
3948 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3949 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3950 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3952 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3953 ioc->name, desc_scsi_status,
3954 scsi_status, desc_scsi_state, scsi_state);
3956 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3957 struct sense_info data;
3958 _scsih_normalize_sense(scmd->sense_buffer, &data);
3960 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3961 ioc->name, data.skey,
3962 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3965 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3966 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3967 response_bytes = (u8 *)&response_info;
3968 _scsih_response_code(ioc, response_bytes[0]);
3973 * _scsih_turn_on_pfa_led - illuminate PFA LED
3974 * @ioc: per adapter object
3975 * @handle: device handle
3981 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3983 Mpi2SepReply_t mpi_reply;
3984 Mpi2SepRequest_t mpi_request;
3985 struct _sas_device *sas_device;
3987 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3991 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3992 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3993 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3994 mpi_request.SlotStatus =
3995 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
3996 mpi_request.DevHandle = cpu_to_le16(handle);
3997 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3998 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3999 &mpi_request)) != 0) {
4000 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4001 __FILE__, __LINE__, __func__);
4004 sas_device->pfa_led_on = 1;
4006 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4007 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4008 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4009 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4010 le32_to_cpu(mpi_reply.IOCLogInfo)));
4015 * _scsih_turn_off_pfa_led - turn off Fault LED
4016 * @ioc: per adapter object
4017 * @sas_device: sas device whose PFA LED has to turned off
4023 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4024 struct _sas_device *sas_device)
4026 Mpi2SepReply_t mpi_reply;
4027 Mpi2SepRequest_t mpi_request;
4029 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4030 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4031 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4032 mpi_request.SlotStatus = 0;
4033 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4034 mpi_request.DevHandle = 0;
4035 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4036 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4037 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4038 &mpi_request)) != 0) {
4039 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4040 __FILE__, __LINE__, __func__);
4044 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4045 dewtprintk(ioc, printk(MPT3SAS_FMT
4046 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4047 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4048 le32_to_cpu(mpi_reply.IOCLogInfo)));
4053 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4054 * @ioc: per adapter object
4055 * @handle: device handle
4056 * Context: interrupt.
4061 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4063 struct fw_event_work *fw_event;
4065 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4068 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4069 fw_event->device_handle = handle;
4070 fw_event->ioc = ioc;
4071 _scsih_fw_event_add(ioc, fw_event);
4075 * _scsih_smart_predicted_fault - process smart errors
4076 * @ioc: per adapter object
4077 * @handle: device handle
4078 * Context: interrupt.
4083 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4085 struct scsi_target *starget;
4086 struct MPT3SAS_TARGET *sas_target_priv_data;
4087 Mpi2EventNotificationReply_t *event_reply;
4088 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4089 struct _sas_device *sas_device;
4091 unsigned long flags;
4093 /* only handle non-raid devices */
4094 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4095 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4097 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4100 starget = sas_device->starget;
4101 sas_target_priv_data = starget->hostdata;
4103 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4104 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4105 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4108 if (sas_device->enclosure_handle != 0)
4109 starget_printk(KERN_INFO, starget, "predicted fault, "
4110 "enclosure logical id(0x%016llx), slot(%d)\n",
4111 (unsigned long long)sas_device->enclosure_logical_id,
4113 if (sas_device->connector_name[0] != '\0')
4114 starget_printk(KERN_WARNING, starget, "predicted fault, "
4115 "enclosure level(0x%04x), connector name( %s)\n",
4116 sas_device->enclosure_level,
4117 sas_device->connector_name);
4118 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4120 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4121 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4123 /* insert into event log */
4124 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4125 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4126 event_reply = kzalloc(sz, GFP_KERNEL);
4128 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4129 ioc->name, __FILE__, __LINE__, __func__);
4133 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4134 event_reply->Event =
4135 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4136 event_reply->MsgLength = sz/4;
4137 event_reply->EventDataLength =
4138 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4139 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4140 event_reply->EventData;
4141 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4142 event_data->ASC = 0x5D;
4143 event_data->DevHandle = cpu_to_le16(handle);
4144 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4145 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4150 * _scsih_io_done - scsi request callback
4151 * @ioc: per adapter object
4152 * @smid: system request message index
4153 * @msix_index: MSIX table index supplied by the OS
4154 * @reply: reply message frame(lower 32bit addr)
4156 * Callback handler when using _scsih_qcmd.
4158 * Return 1 meaning mf should be freed from _base_interrupt
4159 * 0 means the mf is freed from this function.
4162 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4164 Mpi2SCSIIORequest_t *mpi_request;
4165 Mpi2SCSIIOReply_t *mpi_reply;
4166 struct scsi_cmnd *scmd;
4172 struct MPT3SAS_DEVICE *sas_device_priv_data;
4173 u32 response_code = 0;
4175 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4176 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4180 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4182 if (mpi_reply == NULL) {
4183 scmd->result = DID_OK << 16;
4187 sas_device_priv_data = scmd->device->hostdata;
4188 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4189 sas_device_priv_data->sas_target->deleted) {
4190 scmd->result = DID_NO_CONNECT << 16;
4193 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4195 /* turning off TLR */
4196 scsi_state = mpi_reply->SCSIState;
4197 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4199 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4200 if (!sas_device_priv_data->tlr_snoop_check) {
4201 sas_device_priv_data->tlr_snoop_check++;
4202 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4203 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4204 sas_device_priv_data->flags &=
4208 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4209 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4210 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4211 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4214 ioc_status &= MPI2_IOCSTATUS_MASK;
4215 scsi_status = mpi_reply->SCSIStatus;
4217 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4218 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4219 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4220 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4221 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4224 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4225 struct sense_info data;
4226 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4228 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4229 le32_to_cpu(mpi_reply->SenseCount));
4230 memcpy(scmd->sense_buffer, sense_data, sz);
4231 _scsih_normalize_sense(scmd->sense_buffer, &data);
4232 /* failure prediction threshold exceeded */
4233 if (data.asc == 0x5D)
4234 _scsih_smart_predicted_fault(ioc,
4235 le16_to_cpu(mpi_reply->DevHandle));
4236 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4238 if (!(ioc->logging_level & MPT_DEBUG_REPLY) &&
4239 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4240 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4241 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4242 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4244 switch (ioc_status) {
4245 case MPI2_IOCSTATUS_BUSY:
4246 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4247 scmd->result = SAM_STAT_BUSY;
4250 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4251 scmd->result = DID_NO_CONNECT << 16;
4254 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4255 if (sas_device_priv_data->block) {
4256 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4259 if (log_info == 0x31110630) {
4260 if (scmd->retries > 2) {
4261 scmd->result = DID_NO_CONNECT << 16;
4262 scsi_device_set_state(scmd->device,
4265 scmd->result = DID_SOFT_ERROR << 16;
4266 scmd->device->expecting_cc_ua = 1;
4269 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4270 scmd->result = DID_RESET << 16;
4273 scmd->result = DID_SOFT_ERROR << 16;
4275 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4276 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4277 scmd->result = DID_RESET << 16;
4280 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4281 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4282 scmd->result = DID_SOFT_ERROR << 16;
4284 scmd->result = (DID_OK << 16) | scsi_status;
4287 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4288 scmd->result = (DID_OK << 16) | scsi_status;
4290 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4293 if (xfer_cnt < scmd->underflow) {
4294 if (scsi_status == SAM_STAT_BUSY)
4295 scmd->result = SAM_STAT_BUSY;
4297 scmd->result = DID_SOFT_ERROR << 16;
4298 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4299 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4300 scmd->result = DID_SOFT_ERROR << 16;
4301 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4302 scmd->result = DID_RESET << 16;
4303 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4304 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4305 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4306 scmd->result = (DRIVER_SENSE << 24) |
4307 SAM_STAT_CHECK_CONDITION;
4308 scmd->sense_buffer[0] = 0x70;
4309 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4310 scmd->sense_buffer[12] = 0x20;
4311 scmd->sense_buffer[13] = 0;
4315 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4316 scsi_set_resid(scmd, 0);
4317 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4318 case MPI2_IOCSTATUS_SUCCESS:
4319 scmd->result = (DID_OK << 16) | scsi_status;
4320 if (response_code ==
4321 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4322 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4323 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4324 scmd->result = DID_SOFT_ERROR << 16;
4325 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4326 scmd->result = DID_RESET << 16;
4329 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4330 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4331 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4332 _scsih_eedp_error_handling(scmd, ioc_status);
4335 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4336 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4337 case MPI2_IOCSTATUS_INVALID_SGL:
4338 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4339 case MPI2_IOCSTATUS_INVALID_FIELD:
4340 case MPI2_IOCSTATUS_INVALID_STATE:
4341 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4342 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4344 scmd->result = DID_SOFT_ERROR << 16;
4349 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4350 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4354 scsi_dma_unmap(scmd);
4356 scmd->scsi_done(scmd);
4361 * _scsih_sas_host_refresh - refreshing sas host object contents
4362 * @ioc: per adapter object
4365 * During port enable, fw will send topology events for every device. Its
4366 * possible that the handles may change from the previous setting, so this
4367 * code keeping handles updating if changed.
4372 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4377 Mpi2ConfigReply_t mpi_reply;
4378 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4379 u16 attached_handle;
4382 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4383 "updating handles for sas_host(0x%016llx)\n",
4384 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4386 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4387 * sizeof(Mpi2SasIOUnit0PhyData_t));
4388 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4389 if (!sas_iounit_pg0) {
4390 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4391 ioc->name, __FILE__, __LINE__, __func__);
4395 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4396 sas_iounit_pg0, sz)) != 0)
4398 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4399 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4401 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4402 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4404 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4405 PhyData[0].ControllerDevHandle);
4406 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4407 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4409 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4410 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4411 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4412 attached_handle, i, link_rate);
4415 kfree(sas_iounit_pg0);
4419 * _scsih_sas_host_add - create sas host object
4420 * @ioc: per adapter object
4422 * Creating host side data object, stored in ioc->sas_hba
4427 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4430 Mpi2ConfigReply_t mpi_reply;
4431 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4432 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4433 Mpi2SasPhyPage0_t phy_pg0;
4434 Mpi2SasDevicePage0_t sas_device_pg0;
4435 Mpi2SasEnclosurePage0_t enclosure_pg0;
4438 u8 device_missing_delay;
4440 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4441 if (!ioc->sas_hba.num_phys) {
4442 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4443 ioc->name, __FILE__, __LINE__, __func__);
4447 /* sas_iounit page 0 */
4448 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4449 sizeof(Mpi2SasIOUnit0PhyData_t));
4450 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4451 if (!sas_iounit_pg0) {
4452 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4453 ioc->name, __FILE__, __LINE__, __func__);
4456 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4457 sas_iounit_pg0, sz))) {
4458 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4459 ioc->name, __FILE__, __LINE__, __func__);
4462 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4463 MPI2_IOCSTATUS_MASK;
4464 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4465 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4466 ioc->name, __FILE__, __LINE__, __func__);
4470 /* sas_iounit page 1 */
4471 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4472 sizeof(Mpi2SasIOUnit1PhyData_t));
4473 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4474 if (!sas_iounit_pg1) {
4475 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4476 ioc->name, __FILE__, __LINE__, __func__);
4479 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4480 sas_iounit_pg1, sz))) {
4481 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4482 ioc->name, __FILE__, __LINE__, __func__);
4485 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4486 MPI2_IOCSTATUS_MASK;
4487 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4488 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4489 ioc->name, __FILE__, __LINE__, __func__);
4493 ioc->io_missing_delay =
4494 sas_iounit_pg1->IODeviceMissingDelay;
4495 device_missing_delay =
4496 sas_iounit_pg1->ReportDeviceMissingDelay;
4497 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4498 ioc->device_missing_delay = (device_missing_delay &
4499 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4501 ioc->device_missing_delay = device_missing_delay &
4502 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4504 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4505 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4506 sizeof(struct _sas_phy), GFP_KERNEL);
4507 if (!ioc->sas_hba.phy) {
4508 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4509 ioc->name, __FILE__, __LINE__, __func__);
4512 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4513 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4515 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4516 ioc->name, __FILE__, __LINE__, __func__);
4519 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4520 MPI2_IOCSTATUS_MASK;
4521 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4522 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4523 ioc->name, __FILE__, __LINE__, __func__);
4528 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4529 PhyData[0].ControllerDevHandle);
4530 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4531 ioc->sas_hba.phy[i].phy_id = i;
4532 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4533 phy_pg0, ioc->sas_hba.parent_dev);
4535 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4536 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4537 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4538 ioc->name, __FILE__, __LINE__, __func__);
4541 ioc->sas_hba.enclosure_handle =
4542 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4543 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4545 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4546 ioc->name, ioc->sas_hba.handle,
4547 (unsigned long long) ioc->sas_hba.sas_address,
4548 ioc->sas_hba.num_phys) ;
4550 if (ioc->sas_hba.enclosure_handle) {
4551 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4552 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4553 ioc->sas_hba.enclosure_handle)))
4554 ioc->sas_hba.enclosure_logical_id =
4555 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4559 kfree(sas_iounit_pg1);
4560 kfree(sas_iounit_pg0);
4564 * _scsih_expander_add - creating expander object
4565 * @ioc: per adapter object
4566 * @handle: expander handle
4568 * Creating expander object, stored in ioc->sas_expander_list.
4570 * Return 0 for success, else error.
4573 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4575 struct _sas_node *sas_expander;
4576 Mpi2ConfigReply_t mpi_reply;
4577 Mpi2ExpanderPage0_t expander_pg0;
4578 Mpi2ExpanderPage1_t expander_pg1;
4579 Mpi2SasEnclosurePage0_t enclosure_pg0;
4582 u64 sas_address, sas_address_parent = 0;
4584 unsigned long flags;
4585 struct _sas_port *mpt3sas_port = NULL;
4592 if (ioc->shost_recovery || ioc->pci_error_recovery)
4595 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4596 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4597 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4598 ioc->name, __FILE__, __LINE__, __func__);
4602 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4603 MPI2_IOCSTATUS_MASK;
4604 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4605 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4606 ioc->name, __FILE__, __LINE__, __func__);
4610 /* handle out of order topology events */
4611 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4612 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4614 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4615 ioc->name, __FILE__, __LINE__, __func__);
4618 if (sas_address_parent != ioc->sas_hba.sas_address) {
4619 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4620 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4621 sas_address_parent);
4622 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4623 if (!sas_expander) {
4624 rc = _scsih_expander_add(ioc, parent_handle);
4630 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4631 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4632 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4634 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4639 sas_expander = kzalloc(sizeof(struct _sas_node),
4641 if (!sas_expander) {
4642 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4643 ioc->name, __FILE__, __LINE__, __func__);
4647 sas_expander->handle = handle;
4648 sas_expander->num_phys = expander_pg0.NumPhys;
4649 sas_expander->sas_address_parent = sas_address_parent;
4650 sas_expander->sas_address = sas_address;
4652 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4653 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4654 handle, parent_handle, (unsigned long long)
4655 sas_expander->sas_address, sas_expander->num_phys);
4657 if (!sas_expander->num_phys)
4659 sas_expander->phy = kcalloc(sas_expander->num_phys,
4660 sizeof(struct _sas_phy), GFP_KERNEL);
4661 if (!sas_expander->phy) {
4662 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4663 ioc->name, __FILE__, __LINE__, __func__);
4668 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4669 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4670 sas_address_parent);
4671 if (!mpt3sas_port) {
4672 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4673 ioc->name, __FILE__, __LINE__, __func__);
4677 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4679 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4680 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4681 &expander_pg1, i, handle))) {
4682 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4683 ioc->name, __FILE__, __LINE__, __func__);
4687 sas_expander->phy[i].handle = handle;
4688 sas_expander->phy[i].phy_id = i;
4690 if ((mpt3sas_transport_add_expander_phy(ioc,
4691 &sas_expander->phy[i], expander_pg1,
4692 sas_expander->parent_dev))) {
4693 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4694 ioc->name, __FILE__, __LINE__, __func__);
4700 if (sas_expander->enclosure_handle) {
4701 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4702 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4703 sas_expander->enclosure_handle)))
4704 sas_expander->enclosure_logical_id =
4705 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4708 _scsih_expander_node_add(ioc, sas_expander);
4714 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4715 sas_address_parent);
4716 kfree(sas_expander);
4721 * mpt3sas_expander_remove - removing expander object
4722 * @ioc: per adapter object
4723 * @sas_address: expander sas_address
4728 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4730 struct _sas_node *sas_expander;
4731 unsigned long flags;
4733 if (ioc->shost_recovery)
4736 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4737 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4740 list_del(&sas_expander->list);
4741 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4743 _scsih_expander_node_remove(ioc, sas_expander);
4747 * _scsih_done - internal SCSI_IO callback handler.
4748 * @ioc: per adapter object
4749 * @smid: system request message index
4750 * @msix_index: MSIX table index supplied by the OS
4751 * @reply: reply message frame(lower 32bit addr)
4753 * Callback handler when sending internal generated SCSI_IO.
4754 * The callback index passed is `ioc->scsih_cb_idx`
4756 * Return 1 meaning mf should be freed from _base_interrupt
4757 * 0 means the mf is freed from this function.
4760 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4762 MPI2DefaultReply_t *mpi_reply;
4764 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4765 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4767 if (ioc->scsih_cmds.smid != smid)
4769 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4771 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4772 mpi_reply->MsgLength*4);
4773 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4775 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4776 complete(&ioc->scsih_cmds.done);
4783 #define MPT3_MAX_LUNS (255)
4787 * _scsih_check_access_status - check access flags
4788 * @ioc: per adapter object
4789 * @sas_address: sas address
4790 * @handle: sas device handle
4791 * @access_flags: errors returned during discovery of the device
4793 * Return 0 for success, else failure
4796 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4797 u16 handle, u8 access_status)
4802 switch (access_status) {
4803 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4804 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4807 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4808 desc = "sata capability failed";
4810 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4811 desc = "sata affiliation conflict";
4813 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4814 desc = "route not addressable";
4816 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4817 desc = "smp error not addressable";
4819 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4820 desc = "device blocked";
4822 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4823 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4824 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4825 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4826 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4827 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4828 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4829 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4830 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4831 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4832 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4833 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4834 desc = "sata initialization failed";
4845 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4846 ioc->name, desc, (unsigned long long)sas_address, handle);
4851 * _scsih_check_device - checking device responsiveness
4852 * @ioc: per adapter object
4853 * @parent_sas_address: sas address of parent expander or sas host
4854 * @handle: attached device handle
4855 * @phy_numberv: phy number
4856 * @link_rate: new link rate
4861 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4862 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4864 Mpi2ConfigReply_t mpi_reply;
4865 Mpi2SasDevicePage0_t sas_device_pg0;
4866 struct _sas_device *sas_device;
4868 unsigned long flags;
4870 struct scsi_target *starget;
4871 struct MPT3SAS_TARGET *sas_target_priv_data;
4875 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4876 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4879 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4880 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4883 /* wide port handling ~ we need only handle device once for the phy that
4884 * is matched in sas device page zero
4886 if (phy_number != sas_device_pg0.PhyNum)
4889 /* check if this is end device */
4890 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4891 if (!(_scsih_is_end_device(device_info)))
4894 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4895 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4896 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4900 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4904 if (unlikely(sas_device->handle != handle)) {
4905 starget = sas_device->starget;
4906 sas_target_priv_data = starget->hostdata;
4907 starget_printk(KERN_INFO, starget,
4908 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4909 sas_device->handle, handle);
4910 sas_target_priv_data->handle = handle;
4911 sas_device->handle = handle;
4912 if (sas_device_pg0.Flags &
4913 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
4914 sas_device->enclosure_level =
4915 le16_to_cpu(sas_device_pg0.EnclosureLevel);
4916 memcpy(&sas_device->connector_name[0],
4917 &sas_device_pg0.ConnectorName[0], 4);
4919 sas_device->enclosure_level = 0;
4920 sas_device->connector_name[0] = '\0';
4924 /* check if device is present */
4925 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4926 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4928 "device is not present handle(0x%04x), flags!!!\n",
4930 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4934 /* check if there were any issues with discovery */
4935 if (_scsih_check_access_status(ioc, sas_address, handle,
4936 sas_device_pg0.AccessStatus)) {
4937 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4941 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4942 _scsih_ublock_io_device(ioc, sas_address);
4947 * _scsih_add_device - creating sas device object
4948 * @ioc: per adapter object
4949 * @handle: sas device handle
4950 * @phy_num: phy number end device attached to
4951 * @is_pd: is this hidden raid component
4953 * Creating end device object, stored in ioc->sas_device_list.
4955 * Returns 0 for success, non-zero for failure.
4958 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4961 Mpi2ConfigReply_t mpi_reply;
4962 Mpi2SasDevicePage0_t sas_device_pg0;
4963 Mpi2SasEnclosurePage0_t enclosure_pg0;
4964 struct _sas_device *sas_device;
4968 unsigned long flags;
4970 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4971 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4972 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4973 ioc->name, __FILE__, __LINE__, __func__);
4977 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4978 MPI2_IOCSTATUS_MASK;
4979 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4980 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4981 ioc->name, __FILE__, __LINE__, __func__);
4985 /* check if this is end device */
4986 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4987 if (!(_scsih_is_end_device(device_info)))
4989 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4991 /* check if device is present */
4992 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4993 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4994 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
4999 /* check if there were any issues with discovery */
5000 if (_scsih_check_access_status(ioc, sas_address, handle,
5001 sas_device_pg0.AccessStatus))
5004 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5005 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5007 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5012 sas_device = kzalloc(sizeof(struct _sas_device),
5015 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5016 ioc->name, __FILE__, __LINE__, __func__);
5020 sas_device->handle = handle;
5021 if (_scsih_get_sas_address(ioc,
5022 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5023 &sas_device->sas_address_parent) != 0)
5024 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5025 ioc->name, __FILE__, __LINE__, __func__);
5026 sas_device->enclosure_handle =
5027 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5028 if (sas_device->enclosure_handle != 0)
5030 le16_to_cpu(sas_device_pg0.Slot);
5031 sas_device->device_info = device_info;
5032 sas_device->sas_address = sas_address;
5033 sas_device->phy = sas_device_pg0.PhyNum;
5034 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5035 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5037 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5038 sas_device->enclosure_level =
5039 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5040 memcpy(&sas_device->connector_name[0],
5041 &sas_device_pg0.ConnectorName[0], 4);
5043 sas_device->enclosure_level = 0;
5044 sas_device->connector_name[0] = '\0';
5046 /* get enclosure_logical_id */
5047 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5048 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5049 sas_device->enclosure_handle)))
5050 sas_device->enclosure_logical_id =
5051 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5053 /* get device name */
5054 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5056 if (ioc->wait_for_discovery_to_complete)
5057 _scsih_sas_device_init_add(ioc, sas_device);
5059 _scsih_sas_device_add(ioc, sas_device);
5065 * _scsih_remove_device - removing sas device object
5066 * @ioc: per adapter object
5067 * @sas_device_delete: the sas_device object
5072 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5073 struct _sas_device *sas_device)
5075 struct MPT3SAS_TARGET *sas_target_priv_data;
5077 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5078 (sas_device->pfa_led_on)) {
5079 _scsih_turn_off_pfa_led(ioc, sas_device);
5080 sas_device->pfa_led_on = 0;
5082 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5083 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5084 ioc->name, __func__,
5085 sas_device->handle, (unsigned long long)
5086 sas_device->sas_address));
5087 if (sas_device->enclosure_handle != 0)
5088 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5089 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5090 ioc->name, __func__,
5091 (unsigned long long)sas_device->enclosure_logical_id,
5093 if (sas_device->connector_name[0] != '\0')
5094 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5095 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5096 ioc->name, __func__,
5097 sas_device->enclosure_level,
5098 sas_device->connector_name));
5100 if (sas_device->starget && sas_device->starget->hostdata) {
5101 sas_target_priv_data = sas_device->starget->hostdata;
5102 sas_target_priv_data->deleted = 1;
5103 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5104 sas_target_priv_data->handle =
5105 MPT3SAS_INVALID_DEVICE_HANDLE;
5107 mpt3sas_transport_port_remove(ioc,
5108 sas_device->sas_address,
5109 sas_device->sas_address_parent);
5112 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5113 ioc->name, sas_device->handle,
5114 (unsigned long long) sas_device->sas_address);
5115 if (sas_device->enclosure_handle != 0)
5117 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5119 (unsigned long long)sas_device->enclosure_logical_id,
5121 if (sas_device->connector_name[0] != '\0')
5123 "removing enclosure level(0x%04x), connector name( %s)\n",
5124 ioc->name, sas_device->enclosure_level,
5125 sas_device->connector_name);
5127 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5128 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5129 ioc->name, __func__,
5130 sas_device->handle, (unsigned long long)
5131 sas_device->sas_address));
5132 if (sas_device->enclosure_handle != 0)
5133 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5134 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5135 ioc->name, __func__,
5136 (unsigned long long)sas_device->enclosure_logical_id,
5138 if (sas_device->connector_name[0] != '\0')
5139 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5140 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5141 ioc->name, __func__, sas_device->enclosure_level,
5142 sas_device->connector_name));
5148 * _scsih_sas_topology_change_event_debug - debug for topology event
5149 * @ioc: per adapter object
5150 * @event_data: event data payload
5154 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5155 Mpi2EventDataSasTopologyChangeList_t *event_data)
5161 char *status_str = NULL;
5162 u8 link_rate, prev_link_rate;
5164 switch (event_data->ExpStatus) {
5165 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5168 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5169 status_str = "remove";
5171 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5173 status_str = "responding";
5175 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5176 status_str = "remove delay";
5179 status_str = "unknown status";
5182 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5183 ioc->name, status_str);
5184 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5185 "start_phy(%02d), count(%d)\n",
5186 le16_to_cpu(event_data->ExpanderDevHandle),
5187 le16_to_cpu(event_data->EnclosureHandle),
5188 event_data->StartPhyNum, event_data->NumEntries);
5189 for (i = 0; i < event_data->NumEntries; i++) {
5190 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5193 phy_number = event_data->StartPhyNum + i;
5194 reason_code = event_data->PHY[i].PhyStatus &
5195 MPI2_EVENT_SAS_TOPO_RC_MASK;
5196 switch (reason_code) {
5197 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5198 status_str = "target add";
5200 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5201 status_str = "target remove";
5203 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5204 status_str = "delay target remove";
5206 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5207 status_str = "link rate change";
5209 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5210 status_str = "target responding";
5213 status_str = "unknown";
5216 link_rate = event_data->PHY[i].LinkRate >> 4;
5217 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5218 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5219 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5220 handle, status_str, link_rate, prev_link_rate);
5226 * _scsih_sas_topology_change_event - handle topology changes
5227 * @ioc: per adapter object
5228 * @fw_event: The fw_event_work object
5233 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5234 struct fw_event_work *fw_event)
5237 u16 parent_handle, handle;
5239 u8 phy_number, max_phys;
5240 struct _sas_node *sas_expander;
5242 unsigned long flags;
5243 u8 link_rate, prev_link_rate;
5244 Mpi2EventDataSasTopologyChangeList_t *event_data =
5245 (Mpi2EventDataSasTopologyChangeList_t *)
5246 fw_event->event_data;
5248 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5249 _scsih_sas_topology_change_event_debug(ioc, event_data);
5251 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5254 if (!ioc->sas_hba.num_phys)
5255 _scsih_sas_host_add(ioc);
5257 _scsih_sas_host_refresh(ioc);
5259 if (fw_event->ignore) {
5260 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5261 "ignoring expander event\n", ioc->name));
5265 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5267 /* handle expander add */
5268 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5269 if (_scsih_expander_add(ioc, parent_handle) != 0)
5272 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5273 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5276 sas_address = sas_expander->sas_address;
5277 max_phys = sas_expander->num_phys;
5278 } else if (parent_handle < ioc->sas_hba.num_phys) {
5279 sas_address = ioc->sas_hba.sas_address;
5280 max_phys = ioc->sas_hba.num_phys;
5282 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5285 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5287 /* handle siblings events */
5288 for (i = 0; i < event_data->NumEntries; i++) {
5289 if (fw_event->ignore) {
5290 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5291 "ignoring expander event\n", ioc->name));
5294 if (ioc->remove_host || ioc->pci_error_recovery)
5296 phy_number = event_data->StartPhyNum + i;
5297 if (phy_number >= max_phys)
5299 reason_code = event_data->PHY[i].PhyStatus &
5300 MPI2_EVENT_SAS_TOPO_RC_MASK;
5301 if ((event_data->PHY[i].PhyStatus &
5302 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5303 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5305 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5308 link_rate = event_data->PHY[i].LinkRate >> 4;
5309 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5310 switch (reason_code) {
5311 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5313 if (ioc->shost_recovery)
5316 if (link_rate == prev_link_rate)
5319 mpt3sas_transport_update_links(ioc, sas_address,
5320 handle, phy_number, link_rate);
5322 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5325 _scsih_check_device(ioc, sas_address, handle,
5326 phy_number, link_rate);
5329 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5331 if (ioc->shost_recovery)
5334 mpt3sas_transport_update_links(ioc, sas_address,
5335 handle, phy_number, link_rate);
5337 _scsih_add_device(ioc, handle, phy_number, 0);
5340 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5342 _scsih_device_remove_by_handle(ioc, handle);
5347 /* handle expander removal */
5348 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5350 mpt3sas_expander_remove(ioc, sas_address);
5356 * _scsih_sas_device_status_change_event_debug - debug for device event
5357 * @event_data: event data payload
5363 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5364 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5366 char *reason_str = NULL;
5368 switch (event_data->ReasonCode) {
5369 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5370 reason_str = "smart data";
5372 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5373 reason_str = "unsupported device discovered";
5375 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5376 reason_str = "internal device reset";
5378 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5379 reason_str = "internal task abort";
5381 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5382 reason_str = "internal task abort set";
5384 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5385 reason_str = "internal clear task set";
5387 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5388 reason_str = "internal query task";
5390 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5391 reason_str = "sata init failure";
5393 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5394 reason_str = "internal device reset complete";
5396 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5397 reason_str = "internal task abort complete";
5399 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5400 reason_str = "internal async notification";
5402 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5403 reason_str = "expander reduced functionality";
5405 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5406 reason_str = "expander reduced functionality complete";
5409 reason_str = "unknown reason";
5412 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5413 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5414 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5415 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5416 le16_to_cpu(event_data->TaskTag));
5417 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5418 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5419 event_data->ASC, event_data->ASCQ);
5424 * _scsih_sas_device_status_change_event - handle device status change
5425 * @ioc: per adapter object
5426 * @fw_event: The fw_event_work object
5432 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5433 struct fw_event_work *fw_event)
5435 struct MPT3SAS_TARGET *target_priv_data;
5436 struct _sas_device *sas_device;
5438 unsigned long flags;
5439 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5440 (Mpi2EventDataSasDeviceStatusChange_t *)
5441 fw_event->event_data;
5443 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5444 _scsih_sas_device_status_change_event_debug(ioc,
5447 /* In MPI Revision K (0xC), the internal device reset complete was
5448 * implemented, so avoid setting tm_busy flag for older firmware.
5450 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5453 if (event_data->ReasonCode !=
5454 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5455 event_data->ReasonCode !=
5456 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5459 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5460 sas_address = le64_to_cpu(event_data->SASAddress);
5461 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5464 if (!sas_device || !sas_device->starget) {
5465 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5469 target_priv_data = sas_device->starget->hostdata;
5470 if (!target_priv_data) {
5471 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5475 if (event_data->ReasonCode ==
5476 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5477 target_priv_data->tm_busy = 1;
5479 target_priv_data->tm_busy = 0;
5480 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5484 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5486 * @ioc: per adapter object
5487 * @event_data: event data payload
5493 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5494 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5496 char *reason_str = NULL;
5498 switch (event_data->ReasonCode) {
5499 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5500 reason_str = "enclosure add";
5502 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5503 reason_str = "enclosure remove";
5506 reason_str = "unknown reason";
5510 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5511 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5512 " number slots(%d)\n", ioc->name, reason_str,
5513 le16_to_cpu(event_data->EnclosureHandle),
5514 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5515 le16_to_cpu(event_data->StartSlot));
5519 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5520 * @ioc: per adapter object
5521 * @fw_event: The fw_event_work object
5527 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5528 struct fw_event_work *fw_event)
5530 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5531 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5532 (Mpi2EventDataSasEnclDevStatusChange_t *)
5533 fw_event->event_data);
5537 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5538 * @ioc: per adapter object
5539 * @fw_event: The fw_event_work object
5545 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5546 struct fw_event_work *fw_event)
5548 struct scsi_cmnd *scmd;
5549 struct scsi_device *sdev;
5552 struct MPT3SAS_DEVICE *sas_device_priv_data;
5553 u32 termination_count;
5555 Mpi2SCSITaskManagementReply_t *mpi_reply;
5556 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5557 (Mpi2EventDataSasBroadcastPrimitive_t *)
5558 fw_event->event_data;
5560 unsigned long flags;
5563 u8 task_abort_retries;
5565 mutex_lock(&ioc->tm_cmds.mutex);
5567 "%s: enter: phy number(%d), width(%d)\n",
5568 ioc->name, __func__, event_data->PhyNum,
5569 event_data->PortWidth);
5571 _scsih_block_io_all_device(ioc);
5573 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5574 mpi_reply = ioc->tm_cmds.reply;
5575 broadcast_aen_retry:
5577 /* sanity checks for retrying this loop */
5578 if (max_retries++ == 5) {
5579 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5580 ioc->name, __func__));
5582 } else if (max_retries > 1)
5583 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5584 ioc->name, __func__, max_retries - 1));
5586 termination_count = 0;
5588 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5589 if (ioc->shost_recovery)
5591 scmd = _scsih_scsi_lookup_get(ioc, smid);
5594 sdev = scmd->device;
5595 sas_device_priv_data = sdev->hostdata;
5596 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5598 /* skip hidden raid components */
5599 if (sas_device_priv_data->sas_target->flags &
5600 MPT_TARGET_FLAGS_RAID_COMPONENT)
5603 if (sas_device_priv_data->sas_target->flags &
5604 MPT_TARGET_FLAGS_VOLUME)
5607 handle = sas_device_priv_data->sas_target->handle;
5608 lun = sas_device_priv_data->lun;
5611 if (ioc->shost_recovery)
5614 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5615 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5616 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5619 sdev_printk(KERN_WARNING, sdev,
5620 "mpt3sas_scsih_issue_tm: FAILED when sending "
5621 "QUERY_TASK: scmd(%p)\n", scmd);
5622 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5623 goto broadcast_aen_retry;
5625 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5626 & MPI2_IOCSTATUS_MASK;
5627 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5628 sdev_printk(KERN_WARNING, sdev,
5629 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5631 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5632 goto broadcast_aen_retry;
5635 /* see if IO is still owned by IOC and target */
5636 if (mpi_reply->ResponseCode ==
5637 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5638 mpi_reply->ResponseCode ==
5639 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5640 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5643 task_abort_retries = 0;
5645 if (task_abort_retries++ == 60) {
5646 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5647 "%s: ABORT_TASK: giving up\n", ioc->name,
5649 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5650 goto broadcast_aen_retry;
5653 if (ioc->shost_recovery)
5656 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5657 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5660 sdev_printk(KERN_WARNING, sdev,
5661 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5662 "scmd(%p)\n", scmd);
5666 if (task_abort_retries > 1)
5667 sdev_printk(KERN_WARNING, sdev,
5668 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5670 task_abort_retries - 1, scmd);
5672 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5673 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5676 if (ioc->broadcast_aen_pending) {
5677 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5678 "%s: loop back due to pending AEN\n",
5679 ioc->name, __func__));
5680 ioc->broadcast_aen_pending = 0;
5681 goto broadcast_aen_retry;
5685 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5688 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5689 "%s - exit, query_count = %d termination_count = %d\n",
5690 ioc->name, __func__, query_count, termination_count));
5692 ioc->broadcast_aen_busy = 0;
5693 if (!ioc->shost_recovery)
5694 _scsih_ublock_io_all_device(ioc);
5695 mutex_unlock(&ioc->tm_cmds.mutex);
5699 * _scsih_sas_discovery_event - handle discovery events
5700 * @ioc: per adapter object
5701 * @fw_event: The fw_event_work object
5707 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5708 struct fw_event_work *fw_event)
5710 Mpi2EventDataSasDiscovery_t *event_data =
5711 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5713 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5714 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5715 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5717 if (event_data->DiscoveryStatus)
5718 pr_info("discovery_status(0x%08x)",
5719 le32_to_cpu(event_data->DiscoveryStatus));
5723 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5724 !ioc->sas_hba.num_phys) {
5725 if (disable_discovery > 0 && ioc->shost_recovery) {
5726 /* Wait for the reset to complete */
5727 while (ioc->shost_recovery)
5730 _scsih_sas_host_add(ioc);
5735 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5736 * @ioc: per adapter object
5737 * @handle: device handle for physical disk
5738 * @phys_disk_num: physical disk number
5740 * Return 0 for success, else failure.
5743 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5745 Mpi2RaidActionRequest_t *mpi_request;
5746 Mpi2RaidActionReply_t *mpi_reply;
5754 mutex_lock(&ioc->scsih_cmds.mutex);
5756 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5757 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5758 ioc->name, __func__);
5762 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5764 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5766 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5767 ioc->name, __func__);
5768 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5773 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5774 ioc->scsih_cmds.smid = smid;
5775 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5777 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5778 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5779 mpi_request->PhysDiskNum = phys_disk_num;
5781 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5782 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5783 handle, phys_disk_num));
5785 init_completion(&ioc->scsih_cmds.done);
5786 mpt3sas_base_put_smid_default(ioc, smid);
5787 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5789 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5790 pr_err(MPT3SAS_FMT "%s: timeout\n",
5791 ioc->name, __func__);
5792 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5798 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5800 mpi_reply = ioc->scsih_cmds.reply;
5801 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5802 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5803 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5806 ioc_status &= MPI2_IOCSTATUS_MASK;
5807 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5808 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5809 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5810 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5814 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5815 "IR RAID_ACTION: completed successfully\n",
5820 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5821 mutex_unlock(&ioc->scsih_cmds.mutex);
5824 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5830 * _scsih_reprobe_lun - reprobing lun
5831 * @sdev: scsi device struct
5832 * @no_uld_attach: sdev->no_uld_attach flag setting
5836 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5839 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5840 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5841 sdev->no_uld_attach ? "hidding" : "exposing");
5842 rc = scsi_device_reprobe(sdev);
5846 * _scsih_sas_volume_add - add new volume
5847 * @ioc: per adapter object
5848 * @element: IR config element data
5854 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5855 Mpi2EventIrConfigElement_t *element)
5857 struct _raid_device *raid_device;
5858 unsigned long flags;
5860 u16 handle = le16_to_cpu(element->VolDevHandle);
5863 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5866 "failure at %s:%d/%s()!\n", ioc->name,
5867 __FILE__, __LINE__, __func__);
5871 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5872 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5873 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5878 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5881 "failure at %s:%d/%s()!\n", ioc->name,
5882 __FILE__, __LINE__, __func__);
5886 raid_device->id = ioc->sas_id++;
5887 raid_device->channel = RAID_CHANNEL;
5888 raid_device->handle = handle;
5889 raid_device->wwid = wwid;
5890 _scsih_raid_device_add(ioc, raid_device);
5891 if (!ioc->wait_for_discovery_to_complete) {
5892 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5893 raid_device->id, 0);
5895 _scsih_raid_device_remove(ioc, raid_device);
5897 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5898 _scsih_determine_boot_device(ioc, raid_device, 1);
5899 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5904 * _scsih_sas_volume_delete - delete volume
5905 * @ioc: per adapter object
5906 * @handle: volume device handle
5912 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5914 struct _raid_device *raid_device;
5915 unsigned long flags;
5916 struct MPT3SAS_TARGET *sas_target_priv_data;
5917 struct scsi_target *starget = NULL;
5919 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5920 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5922 if (raid_device->starget) {
5923 starget = raid_device->starget;
5924 sas_target_priv_data = starget->hostdata;
5925 sas_target_priv_data->deleted = 1;
5927 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5928 ioc->name, raid_device->handle,
5929 (unsigned long long) raid_device->wwid);
5930 list_del(&raid_device->list);
5933 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5935 scsi_remove_target(&starget->dev);
5939 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5940 * @ioc: per adapter object
5941 * @element: IR config element data
5947 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5948 Mpi2EventIrConfigElement_t *element)
5950 struct _sas_device *sas_device;
5951 struct scsi_target *starget = NULL;
5952 struct MPT3SAS_TARGET *sas_target_priv_data;
5953 unsigned long flags;
5954 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5956 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5957 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5959 sas_device->volume_handle = 0;
5960 sas_device->volume_wwid = 0;
5961 clear_bit(handle, ioc->pd_handles);
5962 if (sas_device->starget && sas_device->starget->hostdata) {
5963 starget = sas_device->starget;
5964 sas_target_priv_data = starget->hostdata;
5965 sas_target_priv_data->flags &=
5966 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5969 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5973 /* exposing raid component */
5975 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5979 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5980 * @ioc: per adapter object
5981 * @element: IR config element data
5987 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5988 Mpi2EventIrConfigElement_t *element)
5990 struct _sas_device *sas_device;
5991 struct scsi_target *starget = NULL;
5992 struct MPT3SAS_TARGET *sas_target_priv_data;
5993 unsigned long flags;
5994 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5995 u16 volume_handle = 0;
5996 u64 volume_wwid = 0;
5998 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6000 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6003 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6004 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6006 set_bit(handle, ioc->pd_handles);
6007 if (sas_device->starget && sas_device->starget->hostdata) {
6008 starget = sas_device->starget;
6009 sas_target_priv_data = starget->hostdata;
6010 sas_target_priv_data->flags |=
6011 MPT_TARGET_FLAGS_RAID_COMPONENT;
6012 sas_device->volume_handle = volume_handle;
6013 sas_device->volume_wwid = volume_wwid;
6016 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6020 /* hiding raid component */
6021 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6023 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6027 * _scsih_sas_pd_delete - delete pd component
6028 * @ioc: per adapter object
6029 * @element: IR config element data
6035 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6036 Mpi2EventIrConfigElement_t *element)
6038 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6040 _scsih_device_remove_by_handle(ioc, handle);
6044 * _scsih_sas_pd_add - remove pd component
6045 * @ioc: per adapter object
6046 * @element: IR config element data
6052 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6053 Mpi2EventIrConfigElement_t *element)
6055 struct _sas_device *sas_device;
6056 unsigned long flags;
6057 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6058 Mpi2ConfigReply_t mpi_reply;
6059 Mpi2SasDevicePage0_t sas_device_pg0;
6064 set_bit(handle, ioc->pd_handles);
6066 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6067 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6068 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6070 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6074 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6075 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6076 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6077 ioc->name, __FILE__, __LINE__, __func__);
6081 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6082 MPI2_IOCSTATUS_MASK;
6083 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6084 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6085 ioc->name, __FILE__, __LINE__, __func__);
6089 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6090 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6091 mpt3sas_transport_update_links(ioc, sas_address, handle,
6092 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6094 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6095 _scsih_add_device(ioc, handle, 0, 1);
6099 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6100 * @ioc: per adapter object
6101 * @event_data: event data payload
6107 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6108 Mpi2EventDataIrConfigChangeList_t *event_data)
6110 Mpi2EventIrConfigElement_t *element;
6113 char *reason_str = NULL, *element_str = NULL;
6115 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6117 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6118 ioc->name, (le32_to_cpu(event_data->Flags) &
6119 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6120 "foreign" : "native", event_data->NumElements);
6121 for (i = 0; i < event_data->NumElements; i++, element++) {
6122 switch (element->ReasonCode) {
6123 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6126 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6127 reason_str = "remove";
6129 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6130 reason_str = "no change";
6132 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6133 reason_str = "hide";
6135 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6136 reason_str = "unhide";
6138 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6139 reason_str = "volume_created";
6141 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6142 reason_str = "volume_deleted";
6144 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6145 reason_str = "pd_created";
6147 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6148 reason_str = "pd_deleted";
6151 reason_str = "unknown reason";
6154 element_type = le16_to_cpu(element->ElementFlags) &
6155 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6156 switch (element_type) {
6157 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6158 element_str = "volume";
6160 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6161 element_str = "phys disk";
6163 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6164 element_str = "hot spare";
6167 element_str = "unknown element";
6170 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6171 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6172 reason_str, le16_to_cpu(element->VolDevHandle),
6173 le16_to_cpu(element->PhysDiskDevHandle),
6174 element->PhysDiskNum);
6179 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6180 * @ioc: per adapter object
6181 * @fw_event: The fw_event_work object
6187 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6188 struct fw_event_work *fw_event)
6190 Mpi2EventIrConfigElement_t *element;
6193 Mpi2EventDataIrConfigChangeList_t *event_data =
6194 (Mpi2EventDataIrConfigChangeList_t *)
6195 fw_event->event_data;
6197 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6198 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6200 foreign_config = (le32_to_cpu(event_data->Flags) &
6201 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6203 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6204 if (ioc->shost_recovery) {
6206 for (i = 0; i < event_data->NumElements; i++, element++) {
6207 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6208 _scsih_ir_fastpath(ioc,
6209 le16_to_cpu(element->PhysDiskDevHandle),
6210 element->PhysDiskNum);
6214 for (i = 0; i < event_data->NumElements; i++, element++) {
6216 switch (element->ReasonCode) {
6217 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6218 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6219 if (!foreign_config)
6220 _scsih_sas_volume_add(ioc, element);
6222 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6223 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6224 if (!foreign_config)
6225 _scsih_sas_volume_delete(ioc,
6226 le16_to_cpu(element->VolDevHandle));
6228 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6229 _scsih_sas_pd_hide(ioc, element);
6231 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6232 _scsih_sas_pd_expose(ioc, element);
6234 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6235 _scsih_sas_pd_add(ioc, element);
6237 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6238 _scsih_sas_pd_delete(ioc, element);
6245 * _scsih_sas_ir_volume_event - IR volume event
6246 * @ioc: per adapter object
6247 * @fw_event: The fw_event_work object
6253 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6254 struct fw_event_work *fw_event)
6257 unsigned long flags;
6258 struct _raid_device *raid_device;
6262 Mpi2EventDataIrVolume_t *event_data =
6263 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6265 if (ioc->shost_recovery)
6268 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6271 handle = le16_to_cpu(event_data->VolDevHandle);
6272 state = le32_to_cpu(event_data->NewValue);
6273 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6274 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6275 ioc->name, __func__, handle,
6276 le32_to_cpu(event_data->PreviousValue), state));
6278 case MPI2_RAID_VOL_STATE_MISSING:
6279 case MPI2_RAID_VOL_STATE_FAILED:
6280 _scsih_sas_volume_delete(ioc, handle);
6283 case MPI2_RAID_VOL_STATE_ONLINE:
6284 case MPI2_RAID_VOL_STATE_DEGRADED:
6285 case MPI2_RAID_VOL_STATE_OPTIMAL:
6287 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6288 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6289 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6294 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6297 "failure at %s:%d/%s()!\n", ioc->name,
6298 __FILE__, __LINE__, __func__);
6302 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6305 "failure at %s:%d/%s()!\n", ioc->name,
6306 __FILE__, __LINE__, __func__);
6310 raid_device->id = ioc->sas_id++;
6311 raid_device->channel = RAID_CHANNEL;
6312 raid_device->handle = handle;
6313 raid_device->wwid = wwid;
6314 _scsih_raid_device_add(ioc, raid_device);
6315 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6316 raid_device->id, 0);
6318 _scsih_raid_device_remove(ioc, raid_device);
6321 case MPI2_RAID_VOL_STATE_INITIALIZING:
6328 * _scsih_sas_ir_physical_disk_event - PD event
6329 * @ioc: per adapter object
6330 * @fw_event: The fw_event_work object
6336 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6337 struct fw_event_work *fw_event)
6339 u16 handle, parent_handle;
6341 struct _sas_device *sas_device;
6342 unsigned long flags;
6343 Mpi2ConfigReply_t mpi_reply;
6344 Mpi2SasDevicePage0_t sas_device_pg0;
6346 Mpi2EventDataIrPhysicalDisk_t *event_data =
6347 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6350 if (ioc->shost_recovery)
6353 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6356 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6357 state = le32_to_cpu(event_data->NewValue);
6359 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6360 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6361 ioc->name, __func__, handle,
6362 le32_to_cpu(event_data->PreviousValue), state));
6364 case MPI2_RAID_PD_STATE_ONLINE:
6365 case MPI2_RAID_PD_STATE_DEGRADED:
6366 case MPI2_RAID_PD_STATE_REBUILDING:
6367 case MPI2_RAID_PD_STATE_OPTIMAL:
6368 case MPI2_RAID_PD_STATE_HOT_SPARE:
6370 set_bit(handle, ioc->pd_handles);
6371 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6372 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6373 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6378 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6379 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6381 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6382 ioc->name, __FILE__, __LINE__, __func__);
6386 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6387 MPI2_IOCSTATUS_MASK;
6388 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6389 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6390 ioc->name, __FILE__, __LINE__, __func__);
6394 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6395 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6396 mpt3sas_transport_update_links(ioc, sas_address, handle,
6397 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6399 _scsih_add_device(ioc, handle, 0, 1);
6403 case MPI2_RAID_PD_STATE_OFFLINE:
6404 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6405 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6412 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6413 * @ioc: per adapter object
6414 * @event_data: event data payload
6420 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6421 Mpi2EventDataIrOperationStatus_t *event_data)
6423 char *reason_str = NULL;
6425 switch (event_data->RAIDOperation) {
6426 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6427 reason_str = "resync";
6429 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6430 reason_str = "online capacity expansion";
6432 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6433 reason_str = "consistency check";
6435 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6436 reason_str = "background init";
6438 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6439 reason_str = "make data consistent";
6446 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6447 "\thandle(0x%04x), percent complete(%d)\n",
6448 ioc->name, reason_str,
6449 le16_to_cpu(event_data->VolDevHandle),
6450 event_data->PercentComplete);
6454 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6455 * @ioc: per adapter object
6456 * @fw_event: The fw_event_work object
6462 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6463 struct fw_event_work *fw_event)
6465 Mpi2EventDataIrOperationStatus_t *event_data =
6466 (Mpi2EventDataIrOperationStatus_t *)
6467 fw_event->event_data;
6468 static struct _raid_device *raid_device;
6469 unsigned long flags;
6472 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6473 _scsih_sas_ir_operation_status_event_debug(ioc,
6476 /* code added for raid transport support */
6477 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6479 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6480 handle = le16_to_cpu(event_data->VolDevHandle);
6481 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6483 raid_device->percent_complete =
6484 event_data->PercentComplete;
6485 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6490 * _scsih_prep_device_scan - initialize parameters prior to device scan
6491 * @ioc: per adapter object
6493 * Set the deleted flag prior to device scan. If the device is found during
6494 * the scan, then we clear the deleted flag.
6497 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6499 struct MPT3SAS_DEVICE *sas_device_priv_data;
6500 struct scsi_device *sdev;
6502 shost_for_each_device(sdev, ioc->shost) {
6503 sas_device_priv_data = sdev->hostdata;
6504 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6505 sas_device_priv_data->sas_target->deleted = 1;
6510 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6511 * @ioc: per adapter object
6512 * @sas_device_pg0: SAS Device page 0
6514 * After host reset, find out whether devices are still responding.
6515 * Used in _scsih_remove_unresponsive_sas_devices.
6520 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
6521 Mpi2SasDevicePage0_t *sas_device_pg0)
6523 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6524 struct scsi_target *starget;
6525 struct _sas_device *sas_device;
6526 unsigned long flags;
6528 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6529 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6530 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
6531 (sas_device->slot == sas_device_pg0->Slot)) {
6532 sas_device->responding = 1;
6533 starget = sas_device->starget;
6534 if (starget && starget->hostdata) {
6535 sas_target_priv_data = starget->hostdata;
6536 sas_target_priv_data->tm_busy = 0;
6537 sas_target_priv_data->deleted = 0;
6539 sas_target_priv_data = NULL;
6541 starget_printk(KERN_INFO, starget,
6542 "handle(0x%04x), sas_addr(0x%016llx)\n",
6543 sas_device_pg0->DevHandle,
6544 (unsigned long long)
6545 sas_device->sas_address);
6547 if (sas_device->enclosure_handle != 0)
6548 starget_printk(KERN_INFO, starget,
6549 "enclosure logical id(0x%016llx),"
6551 (unsigned long long)
6552 sas_device->enclosure_logical_id,
6555 if (sas_device_pg0->Flags &
6556 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6557 sas_device->enclosure_level =
6558 le16_to_cpu(sas_device_pg0->EnclosureLevel);
6559 memcpy(&sas_device->connector_name[0],
6560 &sas_device_pg0->ConnectorName[0], 4);
6562 sas_device->enclosure_level = 0;
6563 sas_device->connector_name[0] = '\0';
6566 if (sas_device->handle == sas_device_pg0->DevHandle)
6568 pr_info("\thandle changed from(0x%04x)!!!\n",
6569 sas_device->handle);
6570 sas_device->handle = sas_device_pg0->DevHandle;
6571 if (sas_target_priv_data)
6572 sas_target_priv_data->handle =
6573 sas_device_pg0->DevHandle;
6578 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6582 * _scsih_search_responding_sas_devices -
6583 * @ioc: per adapter object
6585 * After host reset, find out whether devices are still responding.
6591 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6593 Mpi2SasDevicePage0_t sas_device_pg0;
6594 Mpi2ConfigReply_t mpi_reply;
6599 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6601 if (list_empty(&ioc->sas_device_list))
6605 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6606 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6608 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6609 MPI2_IOCSTATUS_MASK;
6610 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6612 handle = sas_device_pg0.DevHandle =
6613 le16_to_cpu(sas_device_pg0.DevHandle);
6614 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6615 if (!(_scsih_is_end_device(device_info)))
6617 sas_device_pg0.SASAddress =
6618 le64_to_cpu(sas_device_pg0.SASAddress);
6619 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
6620 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
6624 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6629 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6630 * @ioc: per adapter object
6631 * @wwid: world wide identifier for raid volume
6632 * @handle: device handle
6634 * After host reset, find out whether devices are still responding.
6635 * Used in _scsih_remove_unresponsive_raid_devices.
6640 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6643 struct MPT3SAS_TARGET *sas_target_priv_data;
6644 struct scsi_target *starget;
6645 struct _raid_device *raid_device;
6646 unsigned long flags;
6648 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6649 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6650 if (raid_device->wwid == wwid && raid_device->starget) {
6651 starget = raid_device->starget;
6652 if (starget && starget->hostdata) {
6653 sas_target_priv_data = starget->hostdata;
6654 sas_target_priv_data->deleted = 0;
6656 sas_target_priv_data = NULL;
6657 raid_device->responding = 1;
6658 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6659 starget_printk(KERN_INFO, raid_device->starget,
6660 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6661 (unsigned long long)raid_device->wwid);
6662 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6663 if (raid_device->handle == handle) {
6664 spin_unlock_irqrestore(&ioc->raid_device_lock,
6668 pr_info("\thandle changed from(0x%04x)!!!\n",
6669 raid_device->handle);
6670 raid_device->handle = handle;
6671 if (sas_target_priv_data)
6672 sas_target_priv_data->handle = handle;
6673 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6677 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6681 * _scsih_search_responding_raid_devices -
6682 * @ioc: per adapter object
6684 * After host reset, find out whether devices are still responding.
6690 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6692 Mpi2RaidVolPage1_t volume_pg1;
6693 Mpi2RaidVolPage0_t volume_pg0;
6694 Mpi2RaidPhysDiskPage0_t pd_pg0;
6695 Mpi2ConfigReply_t mpi_reply;
6700 if (!ioc->ir_firmware)
6703 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6706 if (list_empty(&ioc->raid_device_list))
6710 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6711 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6712 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6713 MPI2_IOCSTATUS_MASK;
6714 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6716 handle = le16_to_cpu(volume_pg1.DevHandle);
6718 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6719 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6720 sizeof(Mpi2RaidVolPage0_t)))
6723 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6724 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6725 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6726 _scsih_mark_responding_raid_device(ioc,
6727 le64_to_cpu(volume_pg1.WWID), handle);
6730 /* refresh the pd_handles */
6731 phys_disk_num = 0xFF;
6732 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6733 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6734 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6736 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6737 MPI2_IOCSTATUS_MASK;
6738 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6740 phys_disk_num = pd_pg0.PhysDiskNum;
6741 handle = le16_to_cpu(pd_pg0.DevHandle);
6742 set_bit(handle, ioc->pd_handles);
6745 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6750 * _scsih_mark_responding_expander - mark a expander as responding
6751 * @ioc: per adapter object
6752 * @sas_address: sas address
6755 * After host reset, find out whether devices are still responding.
6756 * Used in _scsih_remove_unresponsive_expanders.
6761 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6764 struct _sas_node *sas_expander;
6765 unsigned long flags;
6768 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6769 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6770 if (sas_expander->sas_address != sas_address)
6772 sas_expander->responding = 1;
6773 if (sas_expander->handle == handle)
6775 pr_info("\texpander(0x%016llx): handle changed" \
6776 " from(0x%04x) to (0x%04x)!!!\n",
6777 (unsigned long long)sas_expander->sas_address,
6778 sas_expander->handle, handle);
6779 sas_expander->handle = handle;
6780 for (i = 0 ; i < sas_expander->num_phys ; i++)
6781 sas_expander->phy[i].handle = handle;
6785 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6789 * _scsih_search_responding_expanders -
6790 * @ioc: per adapter object
6792 * After host reset, find out whether devices are still responding.
6798 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6800 Mpi2ExpanderPage0_t expander_pg0;
6801 Mpi2ConfigReply_t mpi_reply;
6806 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6808 if (list_empty(&ioc->sas_expander_list))
6812 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6813 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6815 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6816 MPI2_IOCSTATUS_MASK;
6817 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6820 handle = le16_to_cpu(expander_pg0.DevHandle);
6821 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6822 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6824 (unsigned long long)sas_address);
6825 _scsih_mark_responding_expander(ioc, sas_address, handle);
6829 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6833 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6834 * @ioc: per adapter object
6839 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6841 struct _sas_device *sas_device, *sas_device_next;
6842 struct _sas_node *sas_expander, *sas_expander_next;
6843 struct _raid_device *raid_device, *raid_device_next;
6844 struct list_head tmp_list;
6845 unsigned long flags;
6847 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6850 /* removing unresponding end devices */
6851 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6853 list_for_each_entry_safe(sas_device, sas_device_next,
6854 &ioc->sas_device_list, list) {
6855 if (!sas_device->responding)
6856 mpt3sas_device_remove_by_sas_address(ioc,
6857 sas_device->sas_address);
6859 sas_device->responding = 0;
6862 /* removing unresponding volumes */
6863 if (ioc->ir_firmware) {
6864 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6866 list_for_each_entry_safe(raid_device, raid_device_next,
6867 &ioc->raid_device_list, list) {
6868 if (!raid_device->responding)
6869 _scsih_sas_volume_delete(ioc,
6870 raid_device->handle);
6872 raid_device->responding = 0;
6876 /* removing unresponding expanders */
6877 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6879 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6880 INIT_LIST_HEAD(&tmp_list);
6881 list_for_each_entry_safe(sas_expander, sas_expander_next,
6882 &ioc->sas_expander_list, list) {
6883 if (!sas_expander->responding)
6884 list_move_tail(&sas_expander->list, &tmp_list);
6886 sas_expander->responding = 0;
6888 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6889 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6891 list_del(&sas_expander->list);
6892 _scsih_expander_node_remove(ioc, sas_expander);
6895 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6898 /* unblock devices */
6899 _scsih_ublock_io_all_device(ioc);
6903 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6904 struct _sas_node *sas_expander, u16 handle)
6906 Mpi2ExpanderPage1_t expander_pg1;
6907 Mpi2ConfigReply_t mpi_reply;
6910 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6911 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6912 &expander_pg1, i, handle))) {
6913 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6914 ioc->name, __FILE__, __LINE__, __func__);
6918 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6919 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6920 expander_pg1.NegotiatedLinkRate >> 4);
6925 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6926 * @ioc: per adapter object
6931 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6933 Mpi2ExpanderPage0_t expander_pg0;
6934 Mpi2SasDevicePage0_t sas_device_pg0;
6935 Mpi2RaidVolPage1_t volume_pg1;
6936 Mpi2RaidVolPage0_t volume_pg0;
6937 Mpi2RaidPhysDiskPage0_t pd_pg0;
6938 Mpi2EventIrConfigElement_t element;
6939 Mpi2ConfigReply_t mpi_reply;
6942 u16 handle, parent_handle;
6944 struct _sas_device *sas_device;
6945 struct _sas_node *expander_device;
6946 static struct _raid_device *raid_device;
6948 unsigned long flags;
6950 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6952 _scsih_sas_host_refresh(ioc);
6954 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6958 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6959 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6960 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6961 MPI2_IOCSTATUS_MASK;
6962 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6963 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6964 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6965 ioc->name, ioc_status,
6966 le32_to_cpu(mpi_reply.IOCLogInfo));
6969 handle = le16_to_cpu(expander_pg0.DevHandle);
6970 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6971 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6972 ioc, le64_to_cpu(expander_pg0.SASAddress));
6973 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6974 if (expander_device)
6975 _scsih_refresh_expander_links(ioc, expander_device,
6978 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6979 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6980 handle, (unsigned long long)
6981 le64_to_cpu(expander_pg0.SASAddress));
6982 _scsih_expander_add(ioc, handle);
6983 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6984 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6985 handle, (unsigned long long)
6986 le64_to_cpu(expander_pg0.SASAddress));
6990 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
6993 if (!ioc->ir_firmware)
6996 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
6999 phys_disk_num = 0xFF;
7000 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7001 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7003 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7004 MPI2_IOCSTATUS_MASK;
7005 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7006 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7007 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7008 ioc->name, ioc_status,
7009 le32_to_cpu(mpi_reply.IOCLogInfo));
7012 phys_disk_num = pd_pg0.PhysDiskNum;
7013 handle = le16_to_cpu(pd_pg0.DevHandle);
7014 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7015 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7016 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7019 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7020 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_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 phys disk scan " \
7027 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7028 ioc->name, ioc_status,
7029 le32_to_cpu(mpi_reply.IOCLogInfo));
7032 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7033 if (!_scsih_get_sas_address(ioc, parent_handle,
7035 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7036 " handle (0x%04x), sas_addr(0x%016llx)\n",
7037 ioc->name, handle, (unsigned long long)
7038 le64_to_cpu(sas_device_pg0.SASAddress));
7039 mpt3sas_transport_update_links(ioc, sas_address,
7040 handle, sas_device_pg0.PhyNum,
7041 MPI2_SAS_NEG_LINK_RATE_1_5);
7042 set_bit(handle, ioc->pd_handles);
7044 /* This will retry adding the end device.
7045 * _scsih_add_device() will decide on retries and
7046 * return "1" when it should be retried
7048 while (_scsih_add_device(ioc, handle, retry_count++,
7052 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7053 " handle (0x%04x), sas_addr(0x%016llx)\n",
7054 ioc->name, handle, (unsigned long long)
7055 le64_to_cpu(sas_device_pg0.SASAddress));
7059 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7062 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7066 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7067 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7068 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7069 MPI2_IOCSTATUS_MASK;
7070 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7071 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7072 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7073 ioc->name, ioc_status,
7074 le32_to_cpu(mpi_reply.IOCLogInfo));
7077 handle = le16_to_cpu(volume_pg1.DevHandle);
7078 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7079 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7080 le64_to_cpu(volume_pg1.WWID));
7081 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7084 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7085 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7086 sizeof(Mpi2RaidVolPage0_t)))
7088 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7089 MPI2_IOCSTATUS_MASK;
7090 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7091 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7092 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7093 ioc->name, ioc_status,
7094 le32_to_cpu(mpi_reply.IOCLogInfo));
7097 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7098 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7099 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7100 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7101 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7102 element.VolDevHandle = volume_pg1.DevHandle;
7104 "\tBEFORE adding volume: handle (0x%04x)\n",
7105 ioc->name, volume_pg1.DevHandle);
7106 _scsih_sas_volume_add(ioc, &element);
7108 "\tAFTER adding volume: handle (0x%04x)\n",
7109 ioc->name, volume_pg1.DevHandle);
7113 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7118 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7123 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7124 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7126 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7127 MPI2_IOCSTATUS_MASK;
7128 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7129 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7130 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7131 ioc->name, ioc_status,
7132 le32_to_cpu(mpi_reply.IOCLogInfo));
7135 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7136 if (!(_scsih_is_end_device(
7137 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7139 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7140 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
7141 le64_to_cpu(sas_device_pg0.SASAddress));
7142 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7145 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7146 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7147 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7148 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7149 handle, (unsigned long long)
7150 le64_to_cpu(sas_device_pg0.SASAddress));
7151 mpt3sas_transport_update_links(ioc, sas_address, handle,
7152 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7154 /* This will retry adding the end device.
7155 * _scsih_add_device() will decide on retries and
7156 * return "1" when it should be retried
7158 while (_scsih_add_device(ioc, handle, retry_count++,
7162 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7163 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7164 handle, (unsigned long long)
7165 le64_to_cpu(sas_device_pg0.SASAddress));
7168 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7171 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7174 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7175 * @ioc: per adapter object
7176 * @reset_phase: phase
7178 * The handler for doing any required cleanup or initialization.
7180 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7181 * MPT3_IOC_DONE_RESET
7186 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7188 switch (reset_phase) {
7189 case MPT3_IOC_PRE_RESET:
7190 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7191 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7193 case MPT3_IOC_AFTER_RESET:
7194 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7195 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7196 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7197 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7198 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7199 complete(&ioc->scsih_cmds.done);
7201 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7202 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7203 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7204 complete(&ioc->tm_cmds.done);
7207 _scsih_fw_event_cleanup_queue(ioc);
7208 _scsih_flush_running_cmds(ioc);
7210 case MPT3_IOC_DONE_RESET:
7211 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7212 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7213 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7214 !ioc->sas_hba.num_phys)) {
7215 _scsih_prep_device_scan(ioc);
7216 _scsih_search_responding_sas_devices(ioc);
7217 _scsih_search_responding_raid_devices(ioc);
7218 _scsih_search_responding_expanders(ioc);
7219 _scsih_error_recovery_delete_devices(ioc);
7226 * _mpt3sas_fw_work - delayed task for processing firmware events
7227 * @ioc: per adapter object
7228 * @fw_event: The fw_event_work object
7234 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7236 /* the queue is being flushed so ignore this event */
7237 if (ioc->remove_host ||
7238 ioc->pci_error_recovery) {
7239 _scsih_fw_event_free(ioc, fw_event);
7243 switch (fw_event->event) {
7244 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7245 mpt3sas_process_trigger_data(ioc,
7246 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7247 fw_event->event_data);
7249 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7250 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7252 _scsih_remove_unresponding_sas_devices(ioc);
7253 _scsih_scan_for_devices_after_reset(ioc);
7255 case MPT3SAS_PORT_ENABLE_COMPLETE:
7256 ioc->start_scan = 0;
7257 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7258 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7260 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7261 "port enable: complete from worker thread\n",
7264 case MPT3SAS_TURN_ON_PFA_LED:
7265 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7267 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7268 _scsih_sas_topology_change_event(ioc, fw_event);
7270 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7271 _scsih_sas_device_status_change_event(ioc, fw_event);
7273 case MPI2_EVENT_SAS_DISCOVERY:
7274 _scsih_sas_discovery_event(ioc, fw_event);
7276 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7277 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7279 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7280 _scsih_sas_enclosure_dev_status_change_event(ioc,
7283 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7284 _scsih_sas_ir_config_change_event(ioc, fw_event);
7286 case MPI2_EVENT_IR_VOLUME:
7287 _scsih_sas_ir_volume_event(ioc, fw_event);
7289 case MPI2_EVENT_IR_PHYSICAL_DISK:
7290 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7292 case MPI2_EVENT_IR_OPERATION_STATUS:
7293 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7296 _scsih_fw_event_free(ioc, fw_event);
7300 * _firmware_event_work
7301 * @ioc: per adapter object
7302 * @work: The fw_event_work object
7305 * wrappers for the work thread handling firmware events
7311 _firmware_event_work(struct work_struct *work)
7313 struct fw_event_work *fw_event = container_of(work,
7314 struct fw_event_work, work);
7316 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7320 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7321 * @ioc: per adapter object
7322 * @msix_index: MSIX table index supplied by the OS
7323 * @reply: reply message frame(lower 32bit addr)
7324 * Context: interrupt.
7326 * This function merely adds a new work task into ioc->firmware_event_thread.
7327 * The tasks are worked from _firmware_event_work in user context.
7329 * Return 1 meaning mf should be freed from _base_interrupt
7330 * 0 means the mf is freed from this function.
7333 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7336 struct fw_event_work *fw_event;
7337 Mpi2EventNotificationReply_t *mpi_reply;
7341 /* events turned off due to host reset or driver unloading */
7342 if (ioc->remove_host || ioc->pci_error_recovery)
7345 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7347 if (unlikely(!mpi_reply)) {
7348 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7349 ioc->name, __FILE__, __LINE__, __func__);
7353 event = le16_to_cpu(mpi_reply->Event);
7355 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7356 mpt3sas_trigger_event(ioc, event, 0);
7360 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7362 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7363 (Mpi2EventDataSasBroadcastPrimitive_t *)
7364 mpi_reply->EventData;
7366 if (baen_data->Primitive !=
7367 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7370 if (ioc->broadcast_aen_busy) {
7371 ioc->broadcast_aen_pending++;
7374 ioc->broadcast_aen_busy = 1;
7378 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7379 _scsih_check_topo_delete_events(ioc,
7380 (Mpi2EventDataSasTopologyChangeList_t *)
7381 mpi_reply->EventData);
7383 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7384 _scsih_check_ir_config_unhide_events(ioc,
7385 (Mpi2EventDataIrConfigChangeList_t *)
7386 mpi_reply->EventData);
7388 case MPI2_EVENT_IR_VOLUME:
7389 _scsih_check_volume_delete_events(ioc,
7390 (Mpi2EventDataIrVolume_t *)
7391 mpi_reply->EventData);
7394 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7395 case MPI2_EVENT_IR_OPERATION_STATUS:
7396 case MPI2_EVENT_SAS_DISCOVERY:
7397 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7398 case MPI2_EVENT_IR_PHYSICAL_DISK:
7401 case MPI2_EVENT_TEMP_THRESHOLD:
7402 _scsih_temp_threshold_events(ioc,
7403 (Mpi2EventDataTemperature_t *)
7404 mpi_reply->EventData);
7407 default: /* ignore the rest */
7411 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7412 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7414 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7415 ioc->name, __FILE__, __LINE__, __func__);
7419 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7420 fw_event->ioc = ioc;
7421 fw_event->VF_ID = mpi_reply->VF_ID;
7422 fw_event->VP_ID = mpi_reply->VP_ID;
7423 fw_event->event = event;
7424 _scsih_fw_event_add(ioc, fw_event);
7429 * _scsih_expander_node_remove - removing expander device from list.
7430 * @ioc: per adapter object
7431 * @sas_expander: the sas_device object
7432 * Context: Calling function should acquire ioc->sas_node_lock.
7434 * Removing object and freeing associated memory from the
7435 * ioc->sas_expander_list.
7440 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7441 struct _sas_node *sas_expander)
7443 struct _sas_port *mpt3sas_port, *next;
7445 /* remove sibling ports attached to this expander */
7446 list_for_each_entry_safe(mpt3sas_port, next,
7447 &sas_expander->sas_port_list, port_list) {
7448 if (ioc->shost_recovery)
7450 if (mpt3sas_port->remote_identify.device_type ==
7452 mpt3sas_device_remove_by_sas_address(ioc,
7453 mpt3sas_port->remote_identify.sas_address);
7454 else if (mpt3sas_port->remote_identify.device_type ==
7455 SAS_EDGE_EXPANDER_DEVICE ||
7456 mpt3sas_port->remote_identify.device_type ==
7457 SAS_FANOUT_EXPANDER_DEVICE)
7458 mpt3sas_expander_remove(ioc,
7459 mpt3sas_port->remote_identify.sas_address);
7462 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7463 sas_expander->sas_address_parent);
7466 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7468 sas_expander->handle, (unsigned long long)
7469 sas_expander->sas_address);
7471 kfree(sas_expander->phy);
7472 kfree(sas_expander);
7476 * _scsih_ir_shutdown - IR shutdown notification
7477 * @ioc: per adapter object
7479 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7480 * the host system is shutting down.
7485 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7487 Mpi2RaidActionRequest_t *mpi_request;
7488 Mpi2RaidActionReply_t *mpi_reply;
7491 /* is IR firmware build loaded ? */
7492 if (!ioc->ir_firmware)
7495 /* are there any volumes ? */
7496 if (list_empty(&ioc->raid_device_list))
7499 mutex_lock(&ioc->scsih_cmds.mutex);
7501 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7502 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7503 ioc->name, __func__);
7506 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7508 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7510 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7511 ioc->name, __func__);
7512 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7516 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7517 ioc->scsih_cmds.smid = smid;
7518 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7520 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7521 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7523 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7524 init_completion(&ioc->scsih_cmds.done);
7525 mpt3sas_base_put_smid_default(ioc, smid);
7526 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7528 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7529 pr_err(MPT3SAS_FMT "%s: timeout\n",
7530 ioc->name, __func__);
7534 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7535 mpi_reply = ioc->scsih_cmds.reply;
7537 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7538 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7539 le32_to_cpu(mpi_reply->IOCLogInfo));
7543 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7544 mutex_unlock(&ioc->scsih_cmds.mutex);
7548 * scsih_remove - detach and remove add host
7549 * @pdev: PCI device struct
7551 * Routine called when unloading the driver.
7554 void scsih_remove(struct pci_dev *pdev)
7556 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7557 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7558 struct _sas_port *mpt3sas_port, *next_port;
7559 struct _raid_device *raid_device, *next;
7560 struct MPT3SAS_TARGET *sas_target_priv_data;
7561 struct workqueue_struct *wq;
7562 unsigned long flags;
7564 ioc->remove_host = 1;
7565 _scsih_fw_event_cleanup_queue(ioc);
7567 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7568 wq = ioc->firmware_event_thread;
7569 ioc->firmware_event_thread = NULL;
7570 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7572 destroy_workqueue(wq);
7574 /* release all the volumes */
7575 _scsih_ir_shutdown(ioc);
7576 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7578 if (raid_device->starget) {
7579 sas_target_priv_data =
7580 raid_device->starget->hostdata;
7581 sas_target_priv_data->deleted = 1;
7582 scsi_remove_target(&raid_device->starget->dev);
7584 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7585 ioc->name, raid_device->handle,
7586 (unsigned long long) raid_device->wwid);
7587 _scsih_raid_device_remove(ioc, raid_device);
7590 /* free ports attached to the sas_host */
7591 list_for_each_entry_safe(mpt3sas_port, next_port,
7592 &ioc->sas_hba.sas_port_list, port_list) {
7593 if (mpt3sas_port->remote_identify.device_type ==
7595 mpt3sas_device_remove_by_sas_address(ioc,
7596 mpt3sas_port->remote_identify.sas_address);
7597 else if (mpt3sas_port->remote_identify.device_type ==
7598 SAS_EDGE_EXPANDER_DEVICE ||
7599 mpt3sas_port->remote_identify.device_type ==
7600 SAS_FANOUT_EXPANDER_DEVICE)
7601 mpt3sas_expander_remove(ioc,
7602 mpt3sas_port->remote_identify.sas_address);
7605 /* free phys attached to the sas_host */
7606 if (ioc->sas_hba.num_phys) {
7607 kfree(ioc->sas_hba.phy);
7608 ioc->sas_hba.phy = NULL;
7609 ioc->sas_hba.num_phys = 0;
7612 sas_remove_host(shost);
7613 scsi_remove_host(shost);
7614 mpt3sas_base_detach(ioc);
7615 list_del(&ioc->list);
7616 scsi_host_put(shost);
7620 * scsih_shutdown - routine call during system shutdown
7621 * @pdev: PCI device struct
7626 scsih_shutdown(struct pci_dev *pdev)
7628 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7629 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7630 struct workqueue_struct *wq;
7631 unsigned long flags;
7633 ioc->remove_host = 1;
7634 _scsih_fw_event_cleanup_queue(ioc);
7636 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7637 wq = ioc->firmware_event_thread;
7638 ioc->firmware_event_thread = NULL;
7639 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7641 destroy_workqueue(wq);
7643 _scsih_ir_shutdown(ioc);
7644 mpt3sas_base_detach(ioc);
7649 * _scsih_probe_boot_devices - reports 1st device
7650 * @ioc: per adapter object
7652 * If specified in bios page 2, this routine reports the 1st
7653 * device scsi-ml or sas transport for persistent boot device
7654 * purposes. Please refer to function _scsih_determine_boot_device()
7657 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7661 struct _sas_device *sas_device;
7662 struct _raid_device *raid_device;
7664 u64 sas_address_parent;
7666 unsigned long flags;
7669 /* no Bios, return immediately */
7670 if (!ioc->bios_pg3.BiosVersion)
7675 if (ioc->req_boot_device.device) {
7676 device = ioc->req_boot_device.device;
7677 is_raid = ioc->req_boot_device.is_raid;
7678 } else if (ioc->req_alt_boot_device.device) {
7679 device = ioc->req_alt_boot_device.device;
7680 is_raid = ioc->req_alt_boot_device.is_raid;
7681 } else if (ioc->current_boot_device.device) {
7682 device = ioc->current_boot_device.device;
7683 is_raid = ioc->current_boot_device.is_raid;
7690 raid_device = device;
7691 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7692 raid_device->id, 0);
7694 _scsih_raid_device_remove(ioc, raid_device);
7696 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7697 sas_device = device;
7698 handle = sas_device->handle;
7699 sas_address_parent = sas_device->sas_address_parent;
7700 sas_address = sas_device->sas_address;
7701 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7702 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7704 if (!mpt3sas_transport_port_add(ioc, handle,
7705 sas_address_parent)) {
7706 _scsih_sas_device_remove(ioc, sas_device);
7707 } else if (!sas_device->starget) {
7708 if (!ioc->is_driver_loading) {
7709 mpt3sas_transport_port_remove(ioc,
7711 sas_address_parent);
7712 _scsih_sas_device_remove(ioc, sas_device);
7719 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7720 * @ioc: per adapter object
7722 * Called during initial loading of the driver.
7725 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7727 struct _raid_device *raid_device, *raid_next;
7730 list_for_each_entry_safe(raid_device, raid_next,
7731 &ioc->raid_device_list, list) {
7732 if (raid_device->starget)
7734 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7735 raid_device->id, 0);
7737 _scsih_raid_device_remove(ioc, raid_device);
7742 * _scsih_probe_sas - reporting sas devices to sas transport
7743 * @ioc: per adapter object
7745 * Called during initial loading of the driver.
7748 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7750 struct _sas_device *sas_device, *next;
7751 unsigned long flags;
7753 /* SAS Device List */
7754 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7757 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7758 sas_device->sas_address_parent)) {
7759 list_del(&sas_device->list);
7762 } else if (!sas_device->starget) {
7764 * When asyn scanning is enabled, its not possible to
7765 * remove devices while scanning is turned on due to an
7766 * oops in scsi_sysfs_add_sdev()->add_device()->
7767 * sysfs_addrm_start()
7769 if (!ioc->is_driver_loading) {
7770 mpt3sas_transport_port_remove(ioc,
7771 sas_device->sas_address,
7772 sas_device->sas_address_parent);
7773 list_del(&sas_device->list);
7779 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7780 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7781 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7786 * _scsih_probe_devices - probing for devices
7787 * @ioc: per adapter object
7789 * Called during initial loading of the driver.
7792 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7794 u16 volume_mapping_flags;
7796 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7797 return; /* return when IOC doesn't support initiator mode */
7799 _scsih_probe_boot_devices(ioc);
7801 if (ioc->ir_firmware) {
7802 volume_mapping_flags =
7803 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7804 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7805 if (volume_mapping_flags ==
7806 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7807 _scsih_probe_raid(ioc);
7808 _scsih_probe_sas(ioc);
7810 _scsih_probe_sas(ioc);
7811 _scsih_probe_raid(ioc);
7814 _scsih_probe_sas(ioc);
7818 * scsih_scan_start - scsi lld callback for .scan_start
7819 * @shost: SCSI host pointer
7821 * The shost has the ability to discover targets on its own instead
7822 * of scanning the entire bus. In our implemention, we will kick off
7823 * firmware discovery.
7826 scsih_scan_start(struct Scsi_Host *shost)
7828 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7830 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7831 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7833 if (disable_discovery > 0)
7836 ioc->start_scan = 1;
7837 rc = mpt3sas_port_enable(ioc);
7840 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7844 * scsih_scan_finished - scsi lld callback for .scan_finished
7845 * @shost: SCSI host pointer
7846 * @time: elapsed time of the scan in jiffies
7848 * This function will be called periodicallyn until it returns 1 with the
7849 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7850 * we wait for firmware discovery to complete, then return 1.
7853 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7855 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7857 if (disable_discovery > 0) {
7858 ioc->is_driver_loading = 0;
7859 ioc->wait_for_discovery_to_complete = 0;
7863 if (time >= (300 * HZ)) {
7864 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7866 "port enable: FAILED with timeout (timeout=300s)\n",
7868 ioc->is_driver_loading = 0;
7872 if (ioc->start_scan)
7875 if (ioc->start_scan_failed) {
7877 "port enable: FAILED with (ioc_status=0x%08x)\n",
7878 ioc->name, ioc->start_scan_failed);
7879 ioc->is_driver_loading = 0;
7880 ioc->wait_for_discovery_to_complete = 0;
7881 ioc->remove_host = 1;
7885 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7886 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7888 if (ioc->wait_for_discovery_to_complete) {
7889 ioc->wait_for_discovery_to_complete = 0;
7890 _scsih_probe_devices(ioc);
7892 mpt3sas_base_start_watchdog(ioc);
7893 ioc->is_driver_loading = 0;
7898 _scsih_determine_hba_mpi_version(struct MPT3SAS_ADAPTER *ioc) {
7900 switch (ioc->pdev->device) {
7901 case MPI2_MFGPAGE_DEVID_SAS2004:
7902 case MPI2_MFGPAGE_DEVID_SAS2008:
7903 case MPI2_MFGPAGE_DEVID_SAS2108_1:
7904 case MPI2_MFGPAGE_DEVID_SAS2108_2:
7905 case MPI2_MFGPAGE_DEVID_SAS2108_3:
7906 case MPI2_MFGPAGE_DEVID_SAS2116_1:
7907 case MPI2_MFGPAGE_DEVID_SAS2116_2:
7908 case MPI2_MFGPAGE_DEVID_SAS2208_1:
7909 case MPI2_MFGPAGE_DEVID_SAS2208_2:
7910 case MPI2_MFGPAGE_DEVID_SAS2208_3:
7911 case MPI2_MFGPAGE_DEVID_SAS2208_4:
7912 case MPI2_MFGPAGE_DEVID_SAS2208_5:
7913 case MPI2_MFGPAGE_DEVID_SAS2208_6:
7914 case MPI2_MFGPAGE_DEVID_SAS2308_1:
7915 case MPI2_MFGPAGE_DEVID_SAS2308_2:
7916 case MPI2_MFGPAGE_DEVID_SAS2308_3:
7917 ioc->hba_mpi_version_belonged = MPI2_VERSION;
7919 case MPI25_MFGPAGE_DEVID_SAS3004:
7920 case MPI25_MFGPAGE_DEVID_SAS3008:
7921 case MPI25_MFGPAGE_DEVID_SAS3108_1:
7922 case MPI25_MFGPAGE_DEVID_SAS3108_2:
7923 case MPI25_MFGPAGE_DEVID_SAS3108_5:
7924 case MPI25_MFGPAGE_DEVID_SAS3108_6:
7925 ioc->hba_mpi_version_belonged = MPI25_VERSION;
7931 * scsih_probe - attach and add scsi host
7932 * @pdev: PCI device struct
7933 * @id: pci device id
7935 * Returns 0 success, anything else error.
7938 scsih_probe(struct pci_dev *pdev, struct Scsi_Host *shost)
7940 struct MPT3SAS_ADAPTER *ioc;
7943 /* init local params */
7944 ioc = shost_priv(shost);
7945 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7946 INIT_LIST_HEAD(&ioc->list);
7947 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7949 ioc->id = mpt_ids++;
7952 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7953 ioc->tm_cb_idx = tm_cb_idx;
7954 ioc->ctl_cb_idx = ctl_cb_idx;
7955 ioc->base_cb_idx = base_cb_idx;
7956 ioc->port_enable_cb_idx = port_enable_cb_idx;
7957 ioc->transport_cb_idx = transport_cb_idx;
7958 ioc->scsih_cb_idx = scsih_cb_idx;
7959 ioc->config_cb_idx = config_cb_idx;
7960 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7961 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7962 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7963 ioc->logging_level = logging_level;
7964 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7965 /* misc semaphores and spin locks */
7966 mutex_init(&ioc->reset_in_progress_mutex);
7967 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7968 spin_lock_init(&ioc->scsi_lookup_lock);
7969 spin_lock_init(&ioc->sas_device_lock);
7970 spin_lock_init(&ioc->sas_node_lock);
7971 spin_lock_init(&ioc->fw_event_lock);
7972 spin_lock_init(&ioc->raid_device_lock);
7973 spin_lock_init(&ioc->diag_trigger_lock);
7975 INIT_LIST_HEAD(&ioc->sas_device_list);
7976 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7977 INIT_LIST_HEAD(&ioc->sas_expander_list);
7978 INIT_LIST_HEAD(&ioc->fw_event_list);
7979 INIT_LIST_HEAD(&ioc->raid_device_list);
7980 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7981 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7982 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7983 INIT_LIST_HEAD(&ioc->reply_queue_list);
7985 _scsih_determine_hba_mpi_version(ioc);
7986 sprintf(ioc->name, "%s_cm%d", driver_name, ioc->id);
7988 /* init shost parameters */
7989 shost->max_cmd_len = 32;
7990 shost->max_lun = max_lun;
7991 shost->transportt = mpt3sas_transport_template;
7992 shost->unique_id = ioc->id;
7994 if (max_sectors != 0xFFFF) {
7995 if (max_sectors < 64) {
7996 shost->max_sectors = 64;
7997 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
7998 "for max_sectors, range is 64 to 32767. Assigning "
7999 "value of 64.\n", ioc->name, max_sectors);
8000 } else if (max_sectors > 32767) {
8001 shost->max_sectors = 32767;
8002 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8003 "for max_sectors, range is 64 to 32767. Assigning "
8004 "default value of 32767.\n", ioc->name,
8007 shost->max_sectors = max_sectors & 0xFFFE;
8009 "The max_sectors value is set to %d\n",
8010 ioc->name, shost->max_sectors);
8014 /* register EEDP capabilities with SCSI layer */
8016 scsi_host_set_prot(shost, prot_mask);
8018 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8019 | SHOST_DIF_TYPE2_PROTECTION
8020 | SHOST_DIF_TYPE3_PROTECTION);
8022 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8025 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8026 "fw_event%d", ioc->id);
8027 ioc->firmware_event_thread = alloc_ordered_workqueue(
8028 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8029 if (!ioc->firmware_event_thread) {
8030 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8031 ioc->name, __FILE__, __LINE__, __func__);
8033 goto out_thread_fail;
8036 ioc->is_driver_loading = 1;
8037 if ((mpt3sas_base_attach(ioc))) {
8038 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8039 ioc->name, __FILE__, __LINE__, __func__);
8041 goto out_attach_fail;
8043 rv = scsi_add_host(shost, &pdev->dev);
8045 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8046 ioc->name, __FILE__, __LINE__, __func__);
8047 goto out_add_shost_fail;
8050 scsi_scan_host(shost);
8053 mpt3sas_base_detach(ioc);
8055 destroy_workqueue(ioc->firmware_event_thread);
8057 list_del(&ioc->list);
8058 scsi_host_put(shost);
8064 * scsih_suspend - power management suspend main entry point
8065 * @pdev: PCI device struct
8066 * @state: PM state change to (usually PCI_D3)
8068 * Returns 0 success, anything else error.
8071 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8073 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8074 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8075 pci_power_t device_state;
8077 mpt3sas_base_stop_watchdog(ioc);
8078 flush_scheduled_work();
8079 scsi_block_requests(shost);
8080 device_state = pci_choose_state(pdev, state);
8082 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8083 ioc->name, pdev, pci_name(pdev), device_state);
8085 pci_save_state(pdev);
8086 mpt3sas_base_free_resources(ioc);
8087 pci_set_power_state(pdev, device_state);
8092 * scsih_resume - power management resume main entry point
8093 * @pdev: PCI device struct
8095 * Returns 0 success, anything else error.
8098 scsih_resume(struct pci_dev *pdev)
8100 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8101 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8102 pci_power_t device_state = pdev->current_state;
8106 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8107 ioc->name, pdev, pci_name(pdev), device_state);
8109 pci_set_power_state(pdev, PCI_D0);
8110 pci_enable_wake(pdev, PCI_D0, 0);
8111 pci_restore_state(pdev);
8113 r = mpt3sas_base_map_resources(ioc);
8117 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8118 scsi_unblock_requests(shost);
8119 mpt3sas_base_start_watchdog(ioc);
8122 #endif /* CONFIG_PM */
8125 * scsih_pci_error_detected - Called when a PCI error is detected.
8126 * @pdev: PCI device struct
8127 * @state: PCI channel state
8129 * Description: Called when a PCI error is detected.
8132 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8135 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8137 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8138 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8140 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
8144 case pci_channel_io_normal:
8145 return PCI_ERS_RESULT_CAN_RECOVER;
8146 case pci_channel_io_frozen:
8147 /* Fatal error, prepare for slot reset */
8148 ioc->pci_error_recovery = 1;
8149 scsi_block_requests(ioc->shost);
8150 mpt3sas_base_stop_watchdog(ioc);
8151 mpt3sas_base_free_resources(ioc);
8152 return PCI_ERS_RESULT_NEED_RESET;
8153 case pci_channel_io_perm_failure:
8154 /* Permanent error, prepare for device removal */
8155 ioc->pci_error_recovery = 1;
8156 mpt3sas_base_stop_watchdog(ioc);
8157 _scsih_flush_running_cmds(ioc);
8158 return PCI_ERS_RESULT_DISCONNECT;
8160 return PCI_ERS_RESULT_NEED_RESET;
8164 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8165 * @pdev: PCI device struct
8167 * Description: This routine is called by the pci error recovery
8168 * code after the PCI slot has been reset, just before we
8169 * should resume normal operations.
8172 scsih_pci_slot_reset(struct pci_dev *pdev)
8174 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8175 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8178 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8181 ioc->pci_error_recovery = 0;
8183 pci_restore_state(pdev);
8184 rc = mpt3sas_base_map_resources(ioc);
8186 return PCI_ERS_RESULT_DISCONNECT;
8188 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8191 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8192 (rc == 0) ? "success" : "failed");
8195 return PCI_ERS_RESULT_RECOVERED;
8197 return PCI_ERS_RESULT_DISCONNECT;
8201 * scsih_pci_resume() - resume normal ops after PCI reset
8202 * @pdev: pointer to PCI device
8204 * Called when the error recovery driver tells us that its
8205 * OK to resume normal operation. Use completion to allow
8206 * halted scsi ops to resume.
8209 scsih_pci_resume(struct pci_dev *pdev)
8211 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8212 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8214 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8216 pci_cleanup_aer_uncorrect_error_status(pdev);
8217 mpt3sas_base_start_watchdog(ioc);
8218 scsi_unblock_requests(ioc->shost);
8222 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8223 * @pdev: pointer to PCI device
8226 scsih_pci_mmio_enabled(struct pci_dev *pdev)
8228 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8229 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8231 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8234 /* TODO - dump whatever for debugging purposes */
8236 /* Request a slot reset. */
8237 return PCI_ERS_RESULT_NEED_RESET;
8241 * scsih_init - main entry point for this driver.
8243 * Returns 0 success, anything else error.
8250 mpt3sas_base_initialize_callback_handler();
8252 /* queuecommand callback hander */
8253 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8255 /* task managment callback handler */
8256 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8258 /* base internal commands callback handler */
8259 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8260 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8261 mpt3sas_port_enable_done);
8263 /* transport internal commands callback handler */
8264 transport_cb_idx = mpt3sas_base_register_callback_handler(
8265 mpt3sas_transport_done);
8267 /* scsih internal commands callback handler */
8268 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8270 /* configuration page API internal commands callback handler */
8271 config_cb_idx = mpt3sas_base_register_callback_handler(
8272 mpt3sas_config_done);
8274 /* ctl module callback handler */
8275 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8277 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8278 _scsih_tm_tr_complete);
8280 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8281 _scsih_tm_volume_tr_complete);
8283 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8284 _scsih_sas_control_complete);
8290 * scsih_exit - exit point for this driver (when it is a module).
8292 * Returns 0 success, anything else error.
8298 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8299 mpt3sas_base_release_callback_handler(tm_cb_idx);
8300 mpt3sas_base_release_callback_handler(base_cb_idx);
8301 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8302 mpt3sas_base_release_callback_handler(transport_cb_idx);
8303 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8304 mpt3sas_base_release_callback_handler(config_cb_idx);
8305 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8307 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8308 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8309 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8311 /* raid transport support */
8312 raid_class_release(mpt3sas_raid_template);
8313 sas_release_transport(mpt3sas_transport_template);