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 #ifndef SCSI_MPT2SAS
1169 if (sas_device->fast_path)
1170 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1173 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1179 * scsih_target_destroy - target destroy routine
1180 * @starget: scsi target struct
1185 scsih_target_destroy(struct scsi_target *starget)
1187 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1188 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1189 struct MPT3SAS_TARGET *sas_target_priv_data;
1190 struct _sas_device *sas_device;
1191 struct _raid_device *raid_device;
1192 unsigned long flags;
1193 struct sas_rphy *rphy;
1195 sas_target_priv_data = starget->hostdata;
1196 if (!sas_target_priv_data)
1199 if (starget->channel == RAID_CHANNEL) {
1200 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1201 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1204 raid_device->starget = NULL;
1205 raid_device->sdev = NULL;
1207 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1211 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1212 rphy = dev_to_rphy(starget->dev.parent);
1213 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1214 rphy->identify.sas_address);
1215 if (sas_device && (sas_device->starget == starget) &&
1216 (sas_device->id == starget->id) &&
1217 (sas_device->channel == starget->channel))
1218 sas_device->starget = NULL;
1220 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1223 kfree(sas_target_priv_data);
1224 starget->hostdata = NULL;
1228 * scsih_slave_alloc - device add routine
1229 * @sdev: scsi device struct
1231 * Returns 0 if ok. Any other return is assumed to be an error and
1232 * the device is ignored.
1235 scsih_slave_alloc(struct scsi_device *sdev)
1237 struct Scsi_Host *shost;
1238 struct MPT3SAS_ADAPTER *ioc;
1239 struct MPT3SAS_TARGET *sas_target_priv_data;
1240 struct MPT3SAS_DEVICE *sas_device_priv_data;
1241 struct scsi_target *starget;
1242 struct _raid_device *raid_device;
1243 struct _sas_device *sas_device;
1244 unsigned long flags;
1246 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1248 if (!sas_device_priv_data)
1251 sas_device_priv_data->lun = sdev->lun;
1252 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1254 starget = scsi_target(sdev);
1255 sas_target_priv_data = starget->hostdata;
1256 sas_target_priv_data->num_luns++;
1257 sas_device_priv_data->sas_target = sas_target_priv_data;
1258 sdev->hostdata = sas_device_priv_data;
1259 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1260 sdev->no_uld_attach = 1;
1262 shost = dev_to_shost(&starget->dev);
1263 ioc = shost_priv(shost);
1264 if (starget->channel == RAID_CHANNEL) {
1265 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1266 raid_device = _scsih_raid_device_find_by_id(ioc,
1267 starget->id, starget->channel);
1269 raid_device->sdev = sdev; /* raid is single lun */
1270 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1273 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1274 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1275 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1276 sas_target_priv_data->sas_address);
1277 if (sas_device && (sas_device->starget == NULL)) {
1278 sdev_printk(KERN_INFO, sdev,
1279 "%s : sas_device->starget set to starget @ %d\n",
1280 __func__, __LINE__);
1281 sas_device->starget = starget;
1283 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1290 * scsih_slave_destroy - device destroy routine
1291 * @sdev: scsi device struct
1296 scsih_slave_destroy(struct scsi_device *sdev)
1298 struct MPT3SAS_TARGET *sas_target_priv_data;
1299 struct scsi_target *starget;
1300 struct Scsi_Host *shost;
1301 struct MPT3SAS_ADAPTER *ioc;
1302 struct _sas_device *sas_device;
1303 unsigned long flags;
1305 if (!sdev->hostdata)
1308 starget = scsi_target(sdev);
1309 sas_target_priv_data = starget->hostdata;
1310 sas_target_priv_data->num_luns--;
1312 shost = dev_to_shost(&starget->dev);
1313 ioc = shost_priv(shost);
1315 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1316 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1317 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1318 sas_target_priv_data->sas_address);
1319 if (sas_device && !sas_target_priv_data->num_luns)
1320 sas_device->starget = NULL;
1321 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1324 kfree(sdev->hostdata);
1325 sdev->hostdata = NULL;
1329 * _scsih_display_sata_capabilities - sata capabilities
1330 * @ioc: per adapter object
1331 * @handle: device handle
1332 * @sdev: scsi device struct
1335 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1336 u16 handle, struct scsi_device *sdev)
1338 Mpi2ConfigReply_t mpi_reply;
1339 Mpi2SasDevicePage0_t sas_device_pg0;
1344 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1345 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1346 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1347 ioc->name, __FILE__, __LINE__, __func__);
1351 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1352 MPI2_IOCSTATUS_MASK;
1353 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1354 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1355 ioc->name, __FILE__, __LINE__, __func__);
1359 flags = le16_to_cpu(sas_device_pg0.Flags);
1360 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1362 sdev_printk(KERN_INFO, sdev,
1363 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1364 "sw_preserve(%s)\n",
1365 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1366 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1367 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1369 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1370 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1371 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1375 * raid transport support -
1376 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1377 * unloading the driver followed by a load - I beleive that the subroutine
1378 * raid_class_release() is not cleaning up properly.
1382 * scsih_is_raid - return boolean indicating device is raid volume
1383 * @dev the device struct object
1386 scsih_is_raid(struct device *dev)
1388 struct scsi_device *sdev = to_scsi_device(dev);
1390 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1394 * scsih_get_resync - get raid volume resync percent complete
1395 * @dev the device struct object
1398 scsih_get_resync(struct device *dev)
1400 struct scsi_device *sdev = to_scsi_device(dev);
1401 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1402 static struct _raid_device *raid_device;
1403 unsigned long flags;
1404 Mpi2RaidVolPage0_t vol_pg0;
1405 Mpi2ConfigReply_t mpi_reply;
1406 u32 volume_status_flags;
1407 u8 percent_complete;
1410 percent_complete = 0;
1412 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1413 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1416 handle = raid_device->handle;
1417 percent_complete = raid_device->percent_complete;
1419 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1424 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1425 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1426 sizeof(Mpi2RaidVolPage0_t))) {
1427 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1428 ioc->name, __FILE__, __LINE__, __func__);
1429 percent_complete = 0;
1433 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1434 if (!(volume_status_flags &
1435 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1436 percent_complete = 0;
1439 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1443 * scsih_get_state - get raid volume level
1444 * @dev the device struct object
1447 scsih_get_state(struct device *dev)
1449 struct scsi_device *sdev = to_scsi_device(dev);
1450 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1451 static struct _raid_device *raid_device;
1452 unsigned long flags;
1453 Mpi2RaidVolPage0_t vol_pg0;
1454 Mpi2ConfigReply_t mpi_reply;
1456 enum raid_state state = RAID_STATE_UNKNOWN;
1459 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1460 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1463 handle = raid_device->handle;
1464 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1469 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1470 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1471 sizeof(Mpi2RaidVolPage0_t))) {
1472 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1473 ioc->name, __FILE__, __LINE__, __func__);
1477 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1478 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1479 state = RAID_STATE_RESYNCING;
1483 switch (vol_pg0.VolumeState) {
1484 case MPI2_RAID_VOL_STATE_OPTIMAL:
1485 case MPI2_RAID_VOL_STATE_ONLINE:
1486 state = RAID_STATE_ACTIVE;
1488 case MPI2_RAID_VOL_STATE_DEGRADED:
1489 state = RAID_STATE_DEGRADED;
1491 case MPI2_RAID_VOL_STATE_FAILED:
1492 case MPI2_RAID_VOL_STATE_MISSING:
1493 state = RAID_STATE_OFFLINE;
1497 raid_set_state(mpt3sas_raid_template, dev, state);
1501 * _scsih_set_level - set raid level
1502 * @sdev: scsi device struct
1503 * @volume_type: volume type
1506 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1508 enum raid_level level = RAID_LEVEL_UNKNOWN;
1510 switch (volume_type) {
1511 case MPI2_RAID_VOL_TYPE_RAID0:
1512 level = RAID_LEVEL_0;
1514 case MPI2_RAID_VOL_TYPE_RAID10:
1515 level = RAID_LEVEL_10;
1517 case MPI2_RAID_VOL_TYPE_RAID1E:
1518 level = RAID_LEVEL_1E;
1520 case MPI2_RAID_VOL_TYPE_RAID1:
1521 level = RAID_LEVEL_1;
1525 raid_set_level(mpt3sas_raid_template, &sdev->sdev_gendev, level);
1530 * _scsih_get_volume_capabilities - volume capabilities
1531 * @ioc: per adapter object
1532 * @sas_device: the raid_device object
1534 * Returns 0 for success, else 1
1537 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1538 struct _raid_device *raid_device)
1540 Mpi2RaidVolPage0_t *vol_pg0;
1541 Mpi2RaidPhysDiskPage0_t pd_pg0;
1542 Mpi2SasDevicePage0_t sas_device_pg0;
1543 Mpi2ConfigReply_t mpi_reply;
1547 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1548 &num_pds)) || !num_pds) {
1549 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1550 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1555 raid_device->num_pds = num_pds;
1556 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1557 sizeof(Mpi2RaidVol0PhysDisk_t));
1558 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1560 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1561 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1566 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1567 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1568 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1569 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1575 raid_device->volume_type = vol_pg0->VolumeType;
1577 /* figure out what the underlying devices are by
1578 * obtaining the device_info bits for the 1st device
1580 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1581 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1582 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1583 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1584 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1585 le16_to_cpu(pd_pg0.DevHandle)))) {
1586 raid_device->device_info =
1587 le32_to_cpu(sas_device_pg0.DeviceInfo);
1598 * _scsih_enable_tlr - setting TLR flags
1599 * @ioc: per adapter object
1600 * @sdev: scsi device struct
1602 * Enabling Transaction Layer Retries for tape devices when
1603 * vpd page 0x90 is present
1607 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1611 if (sdev->type != TYPE_TAPE)
1614 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1617 sas_enable_tlr(sdev);
1618 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1619 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1625 * scsih_slave_configure - device configure routine.
1626 * @sdev: scsi device struct
1628 * Returns 0 if ok. Any other return is assumed to be an error and
1629 * the device is ignored.
1632 scsih_slave_configure(struct scsi_device *sdev)
1634 struct Scsi_Host *shost = sdev->host;
1635 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1636 struct MPT3SAS_DEVICE *sas_device_priv_data;
1637 struct MPT3SAS_TARGET *sas_target_priv_data;
1638 struct _sas_device *sas_device;
1639 struct _raid_device *raid_device;
1640 unsigned long flags;
1645 u16 handle, volume_handle = 0;
1646 u64 volume_wwid = 0;
1649 sas_device_priv_data = sdev->hostdata;
1650 sas_device_priv_data->configured_lun = 1;
1651 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1652 sas_target_priv_data = sas_device_priv_data->sas_target;
1653 handle = sas_target_priv_data->handle;
1655 /* raid volume handling */
1656 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1658 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1659 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1660 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1662 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1663 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1664 __LINE__, __func__));
1668 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1669 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1670 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1671 __LINE__, __func__));
1676 /* RAID Queue Depth Support
1677 * IS volume = underlying qdepth of drive type, either
1678 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1679 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1681 if (raid_device->device_info &
1682 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1683 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1686 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1687 if (raid_device->device_info &
1688 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1694 switch (raid_device->volume_type) {
1695 case MPI2_RAID_VOL_TYPE_RAID0:
1698 case MPI2_RAID_VOL_TYPE_RAID1E:
1699 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1700 if (ioc->manu_pg10.OEMIdentifier &&
1701 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1702 MFG10_GF0_R10_DISPLAY) &&
1703 !(raid_device->num_pds % 2))
1708 case MPI2_RAID_VOL_TYPE_RAID1:
1709 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1712 case MPI2_RAID_VOL_TYPE_RAID10:
1713 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1716 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1718 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1723 sdev_printk(KERN_INFO, sdev,
1724 "%s: handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1725 r_level, raid_device->handle,
1726 (unsigned long long)raid_device->wwid,
1727 raid_device->num_pds, ds);
1730 scsih_change_queue_depth(sdev, qdepth);
1732 /* raid transport support */
1733 _scsih_set_level(sdev, raid_device->volume_type);
1737 /* non-raid handling */
1738 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1739 if (mpt3sas_config_get_volume_handle(ioc, handle,
1741 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1742 "failure at %s:%d/%s()!\n", ioc->name,
1743 __FILE__, __LINE__, __func__));
1746 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1747 volume_handle, &volume_wwid)) {
1748 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1749 "failure at %s:%d/%s()!\n", ioc->name,
1750 __FILE__, __LINE__, __func__));
1755 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1756 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
1757 sas_device_priv_data->sas_target->sas_address);
1759 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1760 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1761 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1766 sas_device->volume_handle = volume_handle;
1767 sas_device->volume_wwid = volume_wwid;
1768 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1769 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1773 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1774 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1776 else if (sas_device->device_info &
1777 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1781 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1782 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1783 ds, handle, (unsigned long long)sas_device->sas_address,
1784 sas_device->phy, (unsigned long long)sas_device->device_name);
1785 if (sas_device->enclosure_handle != 0)
1786 sdev_printk(KERN_INFO, sdev,
1787 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1788 ds, (unsigned long long)
1789 sas_device->enclosure_logical_id, sas_device->slot);
1790 if (sas_device->connector_name[0] != '\0')
1791 sdev_printk(KERN_INFO, sdev,
1792 "%s: enclosure level(0x%04x), connector name( %s)\n",
1793 ds, sas_device->enclosure_level,
1794 sas_device->connector_name);
1796 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1799 _scsih_display_sata_capabilities(ioc, handle, sdev);
1802 scsih_change_queue_depth(sdev, qdepth);
1805 sas_read_port_mode_page(sdev);
1806 _scsih_enable_tlr(ioc, sdev);
1813 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1814 * @sdev: scsi device struct
1815 * @bdev: pointer to block device context
1816 * @capacity: device size (in 512 byte sectors)
1817 * @params: three element array to place output:
1818 * params[0] number of heads (max 255)
1819 * params[1] number of sectors (max 63)
1820 * params[2] number of cylinders
1825 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1826 sector_t capacity, int params[])
1836 dummy = heads * sectors;
1837 cylinders = capacity;
1838 sector_div(cylinders, dummy);
1841 * Handle extended translation size for logical drives
1844 if ((ulong)capacity >= 0x200000) {
1847 dummy = heads * sectors;
1848 cylinders = capacity;
1849 sector_div(cylinders, dummy);
1854 params[1] = sectors;
1855 params[2] = cylinders;
1861 * _scsih_response_code - translation of device response code
1862 * @ioc: per adapter object
1863 * @response_code: response code returned by the device
1868 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
1872 switch (response_code) {
1873 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1874 desc = "task management request completed";
1876 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1877 desc = "invalid frame";
1879 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1880 desc = "task management request not supported";
1882 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1883 desc = "task management request failed";
1885 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1886 desc = "task management request succeeded";
1888 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1889 desc = "invalid lun";
1892 desc = "overlapped tag attempted";
1894 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1895 desc = "task queued, however not sent to target";
1901 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
1902 ioc->name, response_code, desc);
1906 * _scsih_tm_done - tm completion routine
1907 * @ioc: per adapter object
1908 * @smid: system request message index
1909 * @msix_index: MSIX table index supplied by the OS
1910 * @reply: reply message frame(lower 32bit addr)
1913 * The callback handler when using scsih_issue_tm.
1915 * Return 1 meaning mf should be freed from _base_interrupt
1916 * 0 means the mf is freed from this function.
1919 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1921 MPI2DefaultReply_t *mpi_reply;
1923 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
1925 if (ioc->tm_cmds.smid != smid)
1927 mpt3sas_base_flush_reply_queues(ioc);
1928 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
1929 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
1931 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1932 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
1934 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
1935 complete(&ioc->tm_cmds.done);
1940 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
1941 * @ioc: per adapter object
1942 * @handle: device handle
1944 * During taskmangement request, we need to freeze the device queue.
1947 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1949 struct MPT3SAS_DEVICE *sas_device_priv_data;
1950 struct scsi_device *sdev;
1953 shost_for_each_device(sdev, ioc->shost) {
1956 sas_device_priv_data = sdev->hostdata;
1957 if (!sas_device_priv_data)
1959 if (sas_device_priv_data->sas_target->handle == handle) {
1960 sas_device_priv_data->sas_target->tm_busy = 1;
1962 ioc->ignore_loginfos = 1;
1968 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
1969 * @ioc: per adapter object
1970 * @handle: device handle
1972 * During taskmangement request, we need to freeze the device queue.
1975 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1977 struct MPT3SAS_DEVICE *sas_device_priv_data;
1978 struct scsi_device *sdev;
1981 shost_for_each_device(sdev, ioc->shost) {
1984 sas_device_priv_data = sdev->hostdata;
1985 if (!sas_device_priv_data)
1987 if (sas_device_priv_data->sas_target->handle == handle) {
1988 sas_device_priv_data->sas_target->tm_busy = 0;
1990 ioc->ignore_loginfos = 0;
1996 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
1997 * @ioc: per adapter struct
1998 * @device_handle: device handle
1999 * @channel: the channel assigned by the OS
2000 * @id: the id assigned by the OS
2002 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2003 * @smid_task: smid assigned to the task
2004 * @timeout: timeout in seconds
2005 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2008 * A generic API for sending task management requests to firmware.
2010 * The callback index is set inside `ioc->tm_cb_idx`.
2012 * Return SUCCESS or FAILED.
2015 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2016 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2017 enum mutex_type m_type)
2019 Mpi2SCSITaskManagementRequest_t *mpi_request;
2020 Mpi2SCSITaskManagementReply_t *mpi_reply;
2023 unsigned long timeleft;
2024 struct scsiio_tracker *scsi_lookup = NULL;
2027 if (m_type == TM_MUTEX_ON)
2028 mutex_lock(&ioc->tm_cmds.mutex);
2029 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2030 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2031 __func__, ioc->name);
2036 if (ioc->shost_recovery || ioc->remove_host ||
2037 ioc->pci_error_recovery) {
2038 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2039 __func__, ioc->name);
2044 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2045 if (ioc_state & MPI2_DOORBELL_USED) {
2046 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2047 "unexpected doorbell active!\n", ioc->name));
2048 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2050 rc = (!rc) ? SUCCESS : FAILED;
2054 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2055 mpt3sas_base_fault_info(ioc, ioc_state &
2056 MPI2_DOORBELL_DATA_MASK);
2057 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2059 rc = (!rc) ? SUCCESS : FAILED;
2063 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2065 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2066 ioc->name, __func__);
2071 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2072 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2074 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2075 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2076 ioc->name, handle, type, smid_task));
2077 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2078 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2079 ioc->tm_cmds.smid = smid;
2080 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2081 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2082 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2083 mpi_request->DevHandle = cpu_to_le16(handle);
2084 mpi_request->TaskType = type;
2085 mpi_request->TaskMID = cpu_to_le16(smid_task);
2086 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2087 mpt3sas_scsih_set_tm_flag(ioc, handle);
2088 init_completion(&ioc->tm_cmds.done);
2089 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2090 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2091 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2092 pr_err(MPT3SAS_FMT "%s: timeout\n",
2093 ioc->name, __func__);
2094 _debug_dump_mf(mpi_request,
2095 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2096 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2097 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2099 rc = (!rc) ? SUCCESS : FAILED;
2100 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2101 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2106 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2107 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2108 mpi_reply = ioc->tm_cmds.reply;
2109 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2110 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2111 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2112 le32_to_cpu(mpi_reply->IOCLogInfo),
2113 le32_to_cpu(mpi_reply->TerminationCount)));
2114 if (ioc->logging_level & MPT_DEBUG_TM) {
2115 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2116 if (mpi_reply->IOCStatus)
2117 _debug_dump_mf(mpi_request,
2118 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2123 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2125 if (scsi_lookup->scmd == NULL)
2130 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2131 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2136 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2137 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2138 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2143 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2151 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2152 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2153 if (m_type == TM_MUTEX_ON)
2154 mutex_unlock(&ioc->tm_cmds.mutex);
2159 if (m_type == TM_MUTEX_ON)
2160 mutex_unlock(&ioc->tm_cmds.mutex);
2165 * _scsih_tm_display_info - displays info about the device
2166 * @ioc: per adapter struct
2167 * @scmd: pointer to scsi command object
2169 * Called by task management callback handlers.
2172 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2174 struct scsi_target *starget = scmd->device->sdev_target;
2175 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2176 struct _sas_device *sas_device = NULL;
2177 unsigned long flags;
2178 char *device_str = NULL;
2182 device_str = "volume";
2184 scsi_print_command(scmd);
2185 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2186 starget_printk(KERN_INFO, starget,
2187 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2188 device_str, priv_target->handle,
2189 device_str, (unsigned long long)priv_target->sas_address);
2191 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2192 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2193 priv_target->sas_address);
2195 if (priv_target->flags &
2196 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2197 starget_printk(KERN_INFO, starget,
2198 "volume handle(0x%04x), "
2199 "volume wwid(0x%016llx)\n",
2200 sas_device->volume_handle,
2201 (unsigned long long)sas_device->volume_wwid);
2203 starget_printk(KERN_INFO, starget,
2204 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2206 (unsigned long long)sas_device->sas_address,
2208 if (sas_device->enclosure_handle != 0)
2209 starget_printk(KERN_INFO, starget,
2210 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2211 (unsigned long long)
2212 sas_device->enclosure_logical_id,
2214 if (sas_device->connector_name)
2215 starget_printk(KERN_INFO, starget,
2216 "enclosure level(0x%04x),connector name(%s)\n",
2217 sas_device->enclosure_level,
2218 sas_device->connector_name);
2220 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2225 * scsih_abort - eh threads main abort routine
2226 * @scmd: pointer to scsi command object
2228 * Returns SUCCESS if command aborted else FAILED
2231 scsih_abort(struct scsi_cmnd *scmd)
2233 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2234 struct MPT3SAS_DEVICE *sas_device_priv_data;
2239 sdev_printk(KERN_INFO, scmd->device,
2240 "attempting task abort! scmd(%p)\n", scmd);
2241 _scsih_tm_display_info(ioc, scmd);
2243 sas_device_priv_data = scmd->device->hostdata;
2244 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2245 sdev_printk(KERN_INFO, scmd->device,
2246 "device been deleted! scmd(%p)\n", scmd);
2247 scmd->result = DID_NO_CONNECT << 16;
2248 scmd->scsi_done(scmd);
2253 /* search for the command */
2254 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2256 scmd->result = DID_RESET << 16;
2261 /* for hidden raid components and volumes this is not supported */
2262 if (sas_device_priv_data->sas_target->flags &
2263 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2264 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2265 scmd->result = DID_RESET << 16;
2270 mpt3sas_halt_firmware(ioc);
2272 handle = sas_device_priv_data->sas_target->handle;
2273 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2274 scmd->device->id, scmd->device->lun,
2275 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2278 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2279 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2284 * scsih_dev_reset - eh threads main device reset routine
2285 * @scmd: pointer to scsi command object
2287 * Returns SUCCESS if command aborted else FAILED
2290 scsih_dev_reset(struct scsi_cmnd *scmd)
2292 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2293 struct MPT3SAS_DEVICE *sas_device_priv_data;
2294 struct _sas_device *sas_device;
2295 unsigned long flags;
2299 sdev_printk(KERN_INFO, scmd->device,
2300 "attempting device reset! scmd(%p)\n", scmd);
2301 _scsih_tm_display_info(ioc, scmd);
2303 sas_device_priv_data = scmd->device->hostdata;
2304 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2305 sdev_printk(KERN_INFO, scmd->device,
2306 "device been deleted! scmd(%p)\n", scmd);
2307 scmd->result = DID_NO_CONNECT << 16;
2308 scmd->scsi_done(scmd);
2313 /* for hidden raid components obtain the volume_handle */
2315 if (sas_device_priv_data->sas_target->flags &
2316 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2317 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2318 sas_device = _scsih_sas_device_find_by_handle(ioc,
2319 sas_device_priv_data->sas_target->handle);
2321 handle = sas_device->volume_handle;
2322 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2324 handle = sas_device_priv_data->sas_target->handle;
2327 scmd->result = DID_RESET << 16;
2332 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2333 scmd->device->id, scmd->device->lun,
2334 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2337 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2338 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2343 * scsih_target_reset - eh threads main target reset routine
2344 * @scmd: pointer to scsi command object
2346 * Returns SUCCESS if command aborted else FAILED
2349 scsih_target_reset(struct scsi_cmnd *scmd)
2351 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2352 struct MPT3SAS_DEVICE *sas_device_priv_data;
2353 struct _sas_device *sas_device;
2354 unsigned long flags;
2357 struct scsi_target *starget = scmd->device->sdev_target;
2359 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2361 _scsih_tm_display_info(ioc, scmd);
2363 sas_device_priv_data = scmd->device->hostdata;
2364 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2365 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2367 scmd->result = DID_NO_CONNECT << 16;
2368 scmd->scsi_done(scmd);
2373 /* for hidden raid components obtain the volume_handle */
2375 if (sas_device_priv_data->sas_target->flags &
2376 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2377 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2378 sas_device = _scsih_sas_device_find_by_handle(ioc,
2379 sas_device_priv_data->sas_target->handle);
2381 handle = sas_device->volume_handle;
2382 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2384 handle = sas_device_priv_data->sas_target->handle;
2387 scmd->result = DID_RESET << 16;
2392 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2393 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2397 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2398 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2404 * scsih_host_reset - eh threads main host reset routine
2405 * @scmd: pointer to scsi command object
2407 * Returns SUCCESS if command aborted else FAILED
2410 scsih_host_reset(struct scsi_cmnd *scmd)
2412 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2415 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2417 scsi_print_command(scmd);
2419 if (ioc->is_driver_loading) {
2420 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2426 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2428 r = (retval < 0) ? FAILED : SUCCESS;
2430 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2431 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2437 * _scsih_fw_event_add - insert and queue up fw_event
2438 * @ioc: per adapter object
2439 * @fw_event: object describing the event
2440 * Context: This function will acquire ioc->fw_event_lock.
2442 * This adds the firmware event object into link list, then queues it up to
2443 * be processed from user context.
2448 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2450 unsigned long flags;
2452 if (ioc->firmware_event_thread == NULL)
2455 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2456 INIT_LIST_HEAD(&fw_event->list);
2457 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2458 INIT_WORK(&fw_event->work, _firmware_event_work);
2459 queue_work(ioc->firmware_event_thread, &fw_event->work);
2460 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2464 * _scsih_fw_event_free - delete fw_event
2465 * @ioc: per adapter object
2466 * @fw_event: object describing the event
2467 * Context: This function will acquire ioc->fw_event_lock.
2469 * This removes firmware event object from link list, frees associated memory.
2474 _scsih_fw_event_free(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2477 unsigned long flags;
2479 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2480 list_del(&fw_event->list);
2482 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2487 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2488 * @ioc: per adapter object
2489 * @event_data: trigger event data
2494 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2495 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2497 struct fw_event_work *fw_event;
2499 if (ioc->is_driver_loading)
2501 fw_event = kzalloc(sizeof(*fw_event) + sizeof(*event_data),
2505 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2506 fw_event->ioc = ioc;
2507 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2508 _scsih_fw_event_add(ioc, fw_event);
2512 * _scsih_error_recovery_delete_devices - remove devices not responding
2513 * @ioc: per adapter object
2518 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2520 struct fw_event_work *fw_event;
2522 if (ioc->is_driver_loading)
2524 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2527 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2528 fw_event->ioc = ioc;
2529 _scsih_fw_event_add(ioc, fw_event);
2533 * mpt3sas_port_enable_complete - port enable completed (fake event)
2534 * @ioc: per adapter object
2539 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2541 struct fw_event_work *fw_event;
2543 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2546 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2547 fw_event->ioc = ioc;
2548 _scsih_fw_event_add(ioc, fw_event);
2552 * _scsih_fw_event_cleanup_queue - cleanup event queue
2553 * @ioc: per adapter object
2555 * Walk the firmware event queue, either killing timers, or waiting
2556 * for outstanding events to complete
2561 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2563 struct fw_event_work *fw_event, *next;
2565 if (list_empty(&ioc->fw_event_list) ||
2566 !ioc->firmware_event_thread || in_interrupt())
2569 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2570 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2571 _scsih_fw_event_free(ioc, fw_event);
2578 * _scsih_internal_device_block - block the sdev device
2579 * @sdev: per device object
2580 * @sas_device_priv_data : per device driver private data
2582 * make sure device is blocked without error, if not
2586 _scsih_internal_device_block(struct scsi_device *sdev,
2587 struct MPT3SAS_DEVICE *sas_device_priv_data)
2591 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2592 sas_device_priv_data->sas_target->handle);
2593 sas_device_priv_data->block = 1;
2595 r = scsi_internal_device_block(sdev);
2597 sdev_printk(KERN_WARNING, sdev,
2598 "device_block failed with return(%d) for handle(0x%04x)\n",
2599 sas_device_priv_data->sas_target->handle, r);
2603 * _scsih_internal_device_unblock - unblock the sdev device
2604 * @sdev: per device object
2605 * @sas_device_priv_data : per device driver private data
2606 * make sure device is unblocked without error, if not retry
2607 * by blocking and then unblocking
2611 _scsih_internal_device_unblock(struct scsi_device *sdev,
2612 struct MPT3SAS_DEVICE *sas_device_priv_data)
2616 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2617 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2618 sas_device_priv_data->block = 0;
2619 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2621 /* The device has been set to SDEV_RUNNING by SD layer during
2622 * device addition but the request queue is still stopped by
2623 * our earlier block call. We need to perform a block again
2624 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2626 sdev_printk(KERN_WARNING, sdev,
2627 "device_unblock failed with return(%d) for handle(0x%04x) "
2628 "performing a block followed by an unblock\n",
2629 sas_device_priv_data->sas_target->handle, r);
2630 sas_device_priv_data->block = 1;
2631 r = scsi_internal_device_block(sdev);
2633 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2634 "failed with return(%d) for handle(0x%04x)\n",
2635 sas_device_priv_data->sas_target->handle, r);
2637 sas_device_priv_data->block = 0;
2638 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2640 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2641 " failed with return(%d) for handle(0x%04x)\n",
2642 sas_device_priv_data->sas_target->handle, r);
2647 * _scsih_ublock_io_all_device - unblock every device
2648 * @ioc: per adapter object
2650 * change the device state from block to running
2653 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2655 struct MPT3SAS_DEVICE *sas_device_priv_data;
2656 struct scsi_device *sdev;
2658 shost_for_each_device(sdev, ioc->shost) {
2659 sas_device_priv_data = sdev->hostdata;
2660 if (!sas_device_priv_data)
2662 if (!sas_device_priv_data->block)
2665 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2666 "device_running, handle(0x%04x)\n",
2667 sas_device_priv_data->sas_target->handle));
2668 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2674 * _scsih_ublock_io_device - prepare device to be deleted
2675 * @ioc: per adapter object
2676 * @sas_addr: sas address
2678 * unblock then put device in offline state
2681 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2683 struct MPT3SAS_DEVICE *sas_device_priv_data;
2684 struct scsi_device *sdev;
2686 shost_for_each_device(sdev, ioc->shost) {
2687 sas_device_priv_data = sdev->hostdata;
2688 if (!sas_device_priv_data)
2690 if (sas_device_priv_data->sas_target->sas_address
2693 if (sas_device_priv_data->block)
2694 _scsih_internal_device_unblock(sdev,
2695 sas_device_priv_data);
2700 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2701 * @ioc: per adapter object
2702 * @handle: device handle
2704 * During device pull we need to appropiately set the sdev state.
2707 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2709 struct MPT3SAS_DEVICE *sas_device_priv_data;
2710 struct scsi_device *sdev;
2712 shost_for_each_device(sdev, ioc->shost) {
2713 sas_device_priv_data = sdev->hostdata;
2714 if (!sas_device_priv_data)
2716 if (sas_device_priv_data->block)
2718 _scsih_internal_device_block(sdev, sas_device_priv_data);
2723 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2724 * @ioc: per adapter object
2725 * @handle: device handle
2727 * During device pull we need to appropiately set the sdev state.
2730 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2732 struct MPT3SAS_DEVICE *sas_device_priv_data;
2733 struct scsi_device *sdev;
2734 struct _sas_device *sas_device;
2736 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2740 shost_for_each_device(sdev, ioc->shost) {
2741 sas_device_priv_data = sdev->hostdata;
2742 if (!sas_device_priv_data)
2744 if (sas_device_priv_data->sas_target->handle != handle)
2746 if (sas_device_priv_data->block)
2748 if (sas_device->pend_sas_rphy_add)
2750 _scsih_internal_device_block(sdev, sas_device_priv_data);
2755 * _scsih_block_io_to_children_attached_to_ex
2756 * @ioc: per adapter object
2757 * @sas_expander: the sas_device object
2759 * This routine set sdev state to SDEV_BLOCK for all devices
2760 * attached to this expander. This function called when expander is
2764 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2765 struct _sas_node *sas_expander)
2767 struct _sas_port *mpt3sas_port;
2768 struct _sas_device *sas_device;
2769 struct _sas_node *expander_sibling;
2770 unsigned long flags;
2775 list_for_each_entry(mpt3sas_port,
2776 &sas_expander->sas_port_list, port_list) {
2777 if (mpt3sas_port->remote_identify.device_type ==
2779 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2781 mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
2782 mpt3sas_port->remote_identify.sas_address);
2784 set_bit(sas_device->handle,
2785 ioc->blocking_handles);
2786 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2790 list_for_each_entry(mpt3sas_port,
2791 &sas_expander->sas_port_list, port_list) {
2793 if (mpt3sas_port->remote_identify.device_type ==
2794 SAS_EDGE_EXPANDER_DEVICE ||
2795 mpt3sas_port->remote_identify.device_type ==
2796 SAS_FANOUT_EXPANDER_DEVICE) {
2798 mpt3sas_scsih_expander_find_by_sas_address(
2799 ioc, mpt3sas_port->remote_identify.sas_address);
2800 _scsih_block_io_to_children_attached_to_ex(ioc,
2807 * _scsih_block_io_to_children_attached_directly
2808 * @ioc: per adapter object
2809 * @event_data: topology change event data
2811 * This routine set sdev state to SDEV_BLOCK for all devices
2812 * direct attached during device pull.
2815 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
2816 Mpi2EventDataSasTopologyChangeList_t *event_data)
2822 for (i = 0; i < event_data->NumEntries; i++) {
2823 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2826 reason_code = event_data->PHY[i].PhyStatus &
2827 MPI2_EVENT_SAS_TOPO_RC_MASK;
2828 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2829 _scsih_block_io_device(ioc, handle);
2834 * _scsih_tm_tr_send - send task management request
2835 * @ioc: per adapter object
2836 * @handle: device handle
2837 * Context: interrupt time.
2839 * This code is to initiate the device removal handshake protocol
2840 * with controller firmware. This function will issue target reset
2841 * using high priority request queue. It will send a sas iounit
2842 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2844 * This is designed to send muliple task management request at the same
2845 * time to the fifo. If the fifo is full, we will append the request,
2846 * and process it in a future completion.
2849 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2851 Mpi2SCSITaskManagementRequest_t *mpi_request;
2853 struct _sas_device *sas_device;
2854 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
2855 u64 sas_address = 0;
2856 unsigned long flags;
2857 struct _tr_list *delayed_tr;
2860 if (ioc->remove_host) {
2861 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2862 "%s: host has been removed: handle(0x%04x)\n",
2863 __func__, ioc->name, handle));
2865 } else if (ioc->pci_error_recovery) {
2866 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2867 "%s: host in pci error recovery: handle(0x%04x)\n",
2868 __func__, ioc->name,
2872 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2873 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2874 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2875 "%s: host is not operational: handle(0x%04x)\n",
2876 __func__, ioc->name,
2881 /* if PD, then return */
2882 if (test_bit(handle, ioc->pd_handles))
2885 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2886 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2887 if (sas_device && sas_device->starget &&
2888 sas_device->starget->hostdata) {
2889 sas_target_priv_data = sas_device->starget->hostdata;
2890 sas_target_priv_data->deleted = 1;
2891 sas_address = sas_device->sas_address;
2893 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2895 if (sas_target_priv_data) {
2896 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2897 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
2899 (unsigned long long)sas_address));
2900 if (sas_device->enclosure_handle != 0)
2901 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2902 "setting delete flag:enclosure logical id(0x%016llx),"
2903 " slot(%d)\n", ioc->name, (unsigned long long)
2904 sas_device->enclosure_logical_id,
2906 if (sas_device->connector_name)
2907 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2908 "setting delete flag: enclosure level(0x%04x),"
2909 " connector name( %s)\n", ioc->name,
2910 sas_device->enclosure_level,
2911 sas_device->connector_name));
2912 _scsih_ublock_io_device(ioc, sas_address);
2913 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
2916 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2918 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2921 INIT_LIST_HEAD(&delayed_tr->list);
2922 delayed_tr->handle = handle;
2923 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
2924 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2925 "DELAYED:tr:handle(0x%04x), (open)\n",
2926 ioc->name, handle));
2930 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2931 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
2932 ioc->name, handle, smid,
2933 ioc->tm_tr_cb_idx));
2934 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2935 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2936 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2937 mpi_request->DevHandle = cpu_to_le16(handle);
2938 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2939 mpt3sas_base_put_smid_hi_priority(ioc, smid);
2940 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
2944 * _scsih_tm_tr_complete -
2945 * @ioc: per adapter object
2946 * @smid: system request message index
2947 * @msix_index: MSIX table index supplied by the OS
2948 * @reply: reply message frame(lower 32bit addr)
2949 * Context: interrupt time.
2951 * This is the target reset completion routine.
2952 * This code is part of the code to initiate the device removal
2953 * handshake protocol with controller firmware.
2954 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
2956 * Return 1 meaning mf should be freed from _base_interrupt
2957 * 0 means the mf is freed from this function.
2960 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2964 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
2965 Mpi2SCSITaskManagementReply_t *mpi_reply =
2966 mpt3sas_base_get_reply_virt_addr(ioc, reply);
2967 Mpi2SasIoUnitControlRequest_t *mpi_request;
2971 if (ioc->remove_host) {
2972 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2973 "%s: host has been removed\n", __func__, ioc->name));
2975 } else if (ioc->pci_error_recovery) {
2976 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2977 "%s: host in pci error recovery\n", __func__,
2981 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
2982 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
2983 dewtprintk(ioc, pr_info(MPT3SAS_FMT
2984 "%s: host is not operational\n", __func__, ioc->name));
2987 if (unlikely(!mpi_reply)) {
2988 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
2989 ioc->name, __FILE__, __LINE__, __func__);
2992 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
2993 handle = le16_to_cpu(mpi_request_tm->DevHandle);
2994 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
2995 dewtprintk(ioc, pr_err(MPT3SAS_FMT
2996 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
2998 le16_to_cpu(mpi_reply->DevHandle), smid));
3002 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3003 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3004 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3005 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3006 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3007 le32_to_cpu(mpi_reply->IOCLogInfo),
3008 le32_to_cpu(mpi_reply->TerminationCount)));
3010 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3011 if (!smid_sas_ctrl) {
3012 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3013 ioc->name, __func__);
3017 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3018 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3019 ioc->name, handle, smid_sas_ctrl,
3020 ioc->tm_sas_control_cb_idx));
3021 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3022 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3023 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3024 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3025 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3026 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3028 return _scsih_check_for_pending_tm(ioc, smid);
3033 * _scsih_sas_control_complete - completion routine
3034 * @ioc: per adapter object
3035 * @smid: system request message index
3036 * @msix_index: MSIX table index supplied by the OS
3037 * @reply: reply message frame(lower 32bit addr)
3038 * Context: interrupt time.
3040 * This is the sas iounit control completion routine.
3041 * This code is part of the code to initiate the device removal
3042 * handshake protocol with controller firmware.
3044 * Return 1 meaning mf should be freed from _base_interrupt
3045 * 0 means the mf is freed from this function.
3048 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3049 u8 msix_index, u32 reply)
3051 Mpi2SasIoUnitControlReply_t *mpi_reply =
3052 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3054 if (likely(mpi_reply)) {
3055 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3056 "sc_complete:handle(0x%04x), (open) "
3057 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3058 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3059 le16_to_cpu(mpi_reply->IOCStatus),
3060 le32_to_cpu(mpi_reply->IOCLogInfo)));
3062 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3063 ioc->name, __FILE__, __LINE__, __func__);
3069 * _scsih_tm_tr_volume_send - send target reset request for volumes
3070 * @ioc: per adapter object
3071 * @handle: device handle
3072 * Context: interrupt time.
3074 * This is designed to send muliple task management request at the same
3075 * time to the fifo. If the fifo is full, we will append the request,
3076 * and process it in a future completion.
3079 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3081 Mpi2SCSITaskManagementRequest_t *mpi_request;
3083 struct _tr_list *delayed_tr;
3085 if (ioc->shost_recovery || ioc->remove_host ||
3086 ioc->pci_error_recovery) {
3087 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3088 "%s: host reset in progress!\n",
3089 __func__, ioc->name));
3093 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3095 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3098 INIT_LIST_HEAD(&delayed_tr->list);
3099 delayed_tr->handle = handle;
3100 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3101 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3102 "DELAYED:tr:handle(0x%04x), (open)\n",
3103 ioc->name, handle));
3107 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3108 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3109 ioc->name, handle, smid,
3110 ioc->tm_tr_volume_cb_idx));
3111 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3112 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3113 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3114 mpi_request->DevHandle = cpu_to_le16(handle);
3115 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3116 mpt3sas_base_put_smid_hi_priority(ioc, smid);
3120 * _scsih_tm_volume_tr_complete - target reset completion
3121 * @ioc: per adapter object
3122 * @smid: system request message index
3123 * @msix_index: MSIX table index supplied by the OS
3124 * @reply: reply message frame(lower 32bit addr)
3125 * Context: interrupt time.
3127 * Return 1 meaning mf should be freed from _base_interrupt
3128 * 0 means the mf is freed from this function.
3131 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3132 u8 msix_index, u32 reply)
3135 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3136 Mpi2SCSITaskManagementReply_t *mpi_reply =
3137 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3139 if (ioc->shost_recovery || ioc->remove_host ||
3140 ioc->pci_error_recovery) {
3141 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3142 "%s: host reset in progress!\n",
3143 __func__, ioc->name));
3146 if (unlikely(!mpi_reply)) {
3147 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3148 ioc->name, __FILE__, __LINE__, __func__);
3152 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3153 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3154 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3155 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3156 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3158 le16_to_cpu(mpi_reply->DevHandle), smid));
3162 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3163 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3164 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3165 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3166 le32_to_cpu(mpi_reply->IOCLogInfo),
3167 le32_to_cpu(mpi_reply->TerminationCount)));
3169 return _scsih_check_for_pending_tm(ioc, smid);
3174 * _scsih_check_for_pending_tm - check for pending task management
3175 * @ioc: per adapter object
3176 * @smid: system request message index
3178 * This will check delayed target reset list, and feed the
3181 * Return 1 meaning mf should be freed from _base_interrupt
3182 * 0 means the mf is freed from this function.
3185 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3187 struct _tr_list *delayed_tr;
3189 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3190 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3191 struct _tr_list, list);
3192 mpt3sas_base_free_smid(ioc, smid);
3193 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3194 list_del(&delayed_tr->list);
3199 if (!list_empty(&ioc->delayed_tr_list)) {
3200 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3201 struct _tr_list, list);
3202 mpt3sas_base_free_smid(ioc, smid);
3203 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3204 list_del(&delayed_tr->list);
3213 * _scsih_check_topo_delete_events - sanity check on topo events
3214 * @ioc: per adapter object
3215 * @event_data: the event data payload
3217 * This routine added to better handle cable breaker.
3219 * This handles the case where driver receives multiple expander
3220 * add and delete events in a single shot. When there is a delete event
3221 * the routine will void any pending add events waiting in the event queue.
3226 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3227 Mpi2EventDataSasTopologyChangeList_t *event_data)
3229 struct fw_event_work *fw_event;
3230 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3231 u16 expander_handle;
3232 struct _sas_node *sas_expander;
3233 unsigned long flags;
3237 for (i = 0 ; i < event_data->NumEntries; i++) {
3238 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3241 reason_code = event_data->PHY[i].PhyStatus &
3242 MPI2_EVENT_SAS_TOPO_RC_MASK;
3243 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3244 _scsih_tm_tr_send(ioc, handle);
3247 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3248 if (expander_handle < ioc->sas_hba.num_phys) {
3249 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3252 if (event_data->ExpStatus ==
3253 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3254 /* put expander attached devices into blocking state */
3255 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3256 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3258 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3259 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3261 handle = find_first_bit(ioc->blocking_handles,
3262 ioc->facts.MaxDevHandle);
3263 if (handle < ioc->facts.MaxDevHandle)
3264 _scsih_block_io_device(ioc, handle);
3265 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3266 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3267 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3269 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3272 /* mark ignore flag for pending events */
3273 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3274 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3275 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3278 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3279 fw_event->event_data;
3280 if (local_event_data->ExpStatus ==
3281 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3282 local_event_data->ExpStatus ==
3283 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3284 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3286 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3287 "setting ignoring flag\n", ioc->name));
3288 fw_event->ignore = 1;
3292 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3296 * _scsih_set_volume_delete_flag - setting volume delete flag
3297 * @ioc: per adapter object
3298 * @handle: device handle
3300 * This returns nothing.
3303 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3305 struct _raid_device *raid_device;
3306 struct MPT3SAS_TARGET *sas_target_priv_data;
3307 unsigned long flags;
3309 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3310 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3311 if (raid_device && raid_device->starget &&
3312 raid_device->starget->hostdata) {
3313 sas_target_priv_data =
3314 raid_device->starget->hostdata;
3315 sas_target_priv_data->deleted = 1;
3316 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3317 "setting delete flag: handle(0x%04x), "
3318 "wwid(0x%016llx)\n", ioc->name, handle,
3319 (unsigned long long) raid_device->wwid));
3321 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3325 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3326 * @handle: input handle
3327 * @a: handle for volume a
3328 * @b: handle for volume b
3330 * IR firmware only supports two raid volumes. The purpose of this
3331 * routine is to set the volume handle in either a or b. When the given
3332 * input handle is non-zero, or when a and b have not been set before.
3335 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3337 if (!handle || handle == *a || handle == *b)
3346 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3347 * @ioc: per adapter object
3348 * @event_data: the event data payload
3349 * Context: interrupt time.
3351 * This routine will send target reset to volume, followed by target
3352 * resets to the PDs. This is called when a PD has been removed, or
3353 * volume has been deleted or removed. When the target reset is sent
3354 * to volume, the PD target resets need to be queued to start upon
3355 * completion of the volume target reset.
3360 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3361 Mpi2EventDataIrConfigChangeList_t *event_data)
3363 Mpi2EventIrConfigElement_t *element;
3365 u16 handle, volume_handle, a, b;
3366 struct _tr_list *delayed_tr;
3371 /* Volume Resets for Deleted or Removed */
3372 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3373 for (i = 0; i < event_data->NumElements; i++, element++) {
3374 if (le32_to_cpu(event_data->Flags) &
3375 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3377 if (element->ReasonCode ==
3378 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3379 element->ReasonCode ==
3380 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3381 volume_handle = le16_to_cpu(element->VolDevHandle);
3382 _scsih_set_volume_delete_flag(ioc, volume_handle);
3383 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3387 /* Volume Resets for UNHIDE events */
3388 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3389 for (i = 0; i < event_data->NumElements; i++, element++) {
3390 if (le32_to_cpu(event_data->Flags) &
3391 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3393 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3394 volume_handle = le16_to_cpu(element->VolDevHandle);
3395 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3400 _scsih_tm_tr_volume_send(ioc, a);
3402 _scsih_tm_tr_volume_send(ioc, b);
3404 /* PD target resets */
3405 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3406 for (i = 0; i < event_data->NumElements; i++, element++) {
3407 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3409 handle = le16_to_cpu(element->PhysDiskDevHandle);
3410 volume_handle = le16_to_cpu(element->VolDevHandle);
3411 clear_bit(handle, ioc->pd_handles);
3413 _scsih_tm_tr_send(ioc, handle);
3414 else if (volume_handle == a || volume_handle == b) {
3415 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3416 BUG_ON(!delayed_tr);
3417 INIT_LIST_HEAD(&delayed_tr->list);
3418 delayed_tr->handle = handle;
3419 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3420 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3421 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3424 _scsih_tm_tr_send(ioc, handle);
3430 * _scsih_check_volume_delete_events - set delete flag for volumes
3431 * @ioc: per adapter object
3432 * @event_data: the event data payload
3433 * Context: interrupt time.
3435 * This will handle the case when the cable connected to entire volume is
3436 * pulled. We will take care of setting the deleted flag so normal IO will
3442 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3443 Mpi2EventDataIrVolume_t *event_data)
3447 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3449 state = le32_to_cpu(event_data->NewValue);
3450 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3451 MPI2_RAID_VOL_STATE_FAILED)
3452 _scsih_set_volume_delete_flag(ioc,
3453 le16_to_cpu(event_data->VolDevHandle));
3457 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3458 * @ioc: per adapter object
3459 * @event_data: the temp threshold event data
3460 * Context: interrupt time.
3465 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3466 Mpi2EventDataTemperature_t *event_data)
3468 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3469 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3470 " exceeded for Sensor: %d !!!\n", ioc->name,
3471 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3472 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3473 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3474 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3475 event_data->SensorNum);
3476 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3477 ioc->name, event_data->CurrentTemperature);
3482 * _scsih_flush_running_cmds - completing outstanding commands.
3483 * @ioc: per adapter object
3485 * The flushing out of all pending scmd commands following host reset,
3486 * where all IO is dropped to the floor.
3491 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3493 struct scsi_cmnd *scmd;
3497 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3498 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3502 mpt3sas_base_free_smid(ioc, smid);
3503 scsi_dma_unmap(scmd);
3504 if (ioc->pci_error_recovery)
3505 scmd->result = DID_NO_CONNECT << 16;
3507 scmd->result = DID_RESET << 16;
3508 scmd->scsi_done(scmd);
3510 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3515 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3516 * @ioc: per adapter object
3517 * @scmd: pointer to scsi command object
3518 * @mpi_request: pointer to the SCSI_IO reqest message frame
3520 * Supporting protection 1 and 3.
3525 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3526 Mpi2SCSIIORequest_t *mpi_request)
3529 unsigned char prot_op = scsi_get_prot_op(scmd);
3530 unsigned char prot_type = scsi_get_prot_type(scmd);
3531 Mpi25SCSIIORequest_t *mpi_request_3v =
3532 (Mpi25SCSIIORequest_t *)mpi_request;
3534 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3537 if (prot_op == SCSI_PROT_READ_STRIP)
3538 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3539 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3540 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3544 switch (prot_type) {
3545 case SCSI_PROT_DIF_TYPE1:
3546 case SCSI_PROT_DIF_TYPE2:
3549 * enable ref/guard checking
3550 * auto increment ref tag
3552 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3553 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3554 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3555 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3556 cpu_to_be32(scsi_get_lba(scmd));
3559 case SCSI_PROT_DIF_TYPE3:
3562 * enable guard checking
3564 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3569 mpi_request_3v->EEDPBlockSize =
3570 cpu_to_le16(scmd->device->sector_size);
3571 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3575 * _scsih_eedp_error_handling - return sense code for EEDP errors
3576 * @scmd: pointer to scsi command object
3577 * @ioc_status: ioc status
3582 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3586 switch (ioc_status) {
3587 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3590 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3593 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3600 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3602 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3603 SAM_STAT_CHECK_CONDITION;
3608 * scsih_qcmd - main scsi request entry point
3609 * @scmd: pointer to scsi command object
3610 * @done: function pointer to be invoked on completion
3612 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3614 * Returns 0 on success. If there's a failure, return either:
3615 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3616 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3619 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3621 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3622 struct MPT3SAS_DEVICE *sas_device_priv_data;
3623 struct MPT3SAS_TARGET *sas_target_priv_data;
3624 Mpi2SCSIIORequest_t *mpi_request;
3629 if (ioc->logging_level & MPT_DEBUG_SCSI)
3630 scsi_print_command(scmd);
3632 sas_device_priv_data = scmd->device->hostdata;
3633 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3634 scmd->result = DID_NO_CONNECT << 16;
3635 scmd->scsi_done(scmd);
3639 if (ioc->pci_error_recovery || ioc->remove_host) {
3640 scmd->result = DID_NO_CONNECT << 16;
3641 scmd->scsi_done(scmd);
3645 sas_target_priv_data = sas_device_priv_data->sas_target;
3647 /* invalid device handle */
3648 handle = sas_target_priv_data->handle;
3649 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3650 scmd->result = DID_NO_CONNECT << 16;
3651 scmd->scsi_done(scmd);
3656 /* host recovery or link resets sent via IOCTLs */
3657 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3658 return SCSI_MLQUEUE_HOST_BUSY;
3660 /* device has been deleted */
3661 else if (sas_target_priv_data->deleted) {
3662 scmd->result = DID_NO_CONNECT << 16;
3663 scmd->scsi_done(scmd);
3665 /* device busy with task managment */
3666 } else if (sas_target_priv_data->tm_busy ||
3667 sas_device_priv_data->block)
3668 return SCSI_MLQUEUE_DEVICE_BUSY;
3670 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3671 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3672 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3673 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3675 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3678 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3680 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3681 scmd->cmd_len != 32)
3682 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3684 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3686 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3687 ioc->name, __func__);
3690 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3691 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3692 _scsih_setup_eedp(ioc, scmd, mpi_request);
3694 if (scmd->cmd_len == 32)
3695 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3696 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3697 if (sas_device_priv_data->sas_target->flags &
3698 MPT_TARGET_FLAGS_RAID_COMPONENT)
3699 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3701 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3702 mpi_request->DevHandle = cpu_to_le16(handle);
3703 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3704 mpi_request->Control = cpu_to_le32(mpi_control);
3705 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3706 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3707 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3708 mpi_request->SenseBufferLowAddress =
3709 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3710 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3711 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3713 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3715 if (mpi_request->DataLength) {
3716 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3717 mpt3sas_base_free_smid(ioc, smid);
3721 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3723 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3724 #ifndef SCSI_MPT2SAS
3725 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3726 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3727 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3728 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3731 mpt3sas_base_put_smid_scsi_io(ioc, smid, handle);
3733 mpt3sas_base_put_smid_default(ioc, smid);
3737 return SCSI_MLQUEUE_HOST_BUSY;
3741 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3742 * @sense_buffer: sense data returned by target
3743 * @data: normalized skey/asc/ascq
3748 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3750 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3751 /* descriptor format */
3752 data->skey = sense_buffer[1] & 0x0F;
3753 data->asc = sense_buffer[2];
3754 data->ascq = sense_buffer[3];
3757 data->skey = sense_buffer[2] & 0x0F;
3758 data->asc = sense_buffer[12];
3759 data->ascq = sense_buffer[13];
3764 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
3765 * @ioc: per adapter object
3766 * @scmd: pointer to scsi command object
3767 * @mpi_reply: reply mf payload returned from firmware
3769 * scsi_status - SCSI Status code returned from target device
3770 * scsi_state - state info associated with SCSI_IO determined by ioc
3771 * ioc_status - ioc supplied status info
3776 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3777 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3781 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3782 MPI2_IOCSTATUS_MASK;
3783 u8 scsi_state = mpi_reply->SCSIState;
3784 u8 scsi_status = mpi_reply->SCSIStatus;
3785 char *desc_ioc_state = NULL;
3786 char *desc_scsi_status = NULL;
3787 char *desc_scsi_state = ioc->tmp_string;
3788 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3789 struct _sas_device *sas_device = NULL;
3790 unsigned long flags;
3791 struct scsi_target *starget = scmd->device->sdev_target;
3792 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3793 char *device_str = NULL;
3797 device_str = "volume";
3799 if (log_info == 0x31170000)
3802 switch (ioc_status) {
3803 case MPI2_IOCSTATUS_SUCCESS:
3804 desc_ioc_state = "success";
3806 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3807 desc_ioc_state = "invalid function";
3809 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3810 desc_ioc_state = "scsi recovered error";
3812 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3813 desc_ioc_state = "scsi invalid dev handle";
3815 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3816 desc_ioc_state = "scsi device not there";
3818 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3819 desc_ioc_state = "scsi data overrun";
3821 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3822 desc_ioc_state = "scsi data underrun";
3824 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3825 desc_ioc_state = "scsi io data error";
3827 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3828 desc_ioc_state = "scsi protocol error";
3830 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3831 desc_ioc_state = "scsi task terminated";
3833 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3834 desc_ioc_state = "scsi residual mismatch";
3836 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3837 desc_ioc_state = "scsi task mgmt failed";
3839 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3840 desc_ioc_state = "scsi ioc terminated";
3842 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3843 desc_ioc_state = "scsi ext terminated";
3845 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3846 desc_ioc_state = "eedp guard error";
3848 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3849 desc_ioc_state = "eedp ref tag error";
3851 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3852 desc_ioc_state = "eedp app tag error";
3855 desc_ioc_state = "unknown";
3859 switch (scsi_status) {
3860 case MPI2_SCSI_STATUS_GOOD:
3861 desc_scsi_status = "good";
3863 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3864 desc_scsi_status = "check condition";
3866 case MPI2_SCSI_STATUS_CONDITION_MET:
3867 desc_scsi_status = "condition met";
3869 case MPI2_SCSI_STATUS_BUSY:
3870 desc_scsi_status = "busy";
3872 case MPI2_SCSI_STATUS_INTERMEDIATE:
3873 desc_scsi_status = "intermediate";
3875 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3876 desc_scsi_status = "intermediate condmet";
3878 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3879 desc_scsi_status = "reservation conflict";
3881 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3882 desc_scsi_status = "command terminated";
3884 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3885 desc_scsi_status = "task set full";
3887 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3888 desc_scsi_status = "aca active";
3890 case MPI2_SCSI_STATUS_TASK_ABORTED:
3891 desc_scsi_status = "task aborted";
3894 desc_scsi_status = "unknown";
3898 desc_scsi_state[0] = '\0';
3900 desc_scsi_state = " ";
3901 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3902 strcat(desc_scsi_state, "response info ");
3903 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3904 strcat(desc_scsi_state, "state terminated ");
3905 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3906 strcat(desc_scsi_state, "no status ");
3907 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3908 strcat(desc_scsi_state, "autosense failed ");
3909 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3910 strcat(desc_scsi_state, "autosense valid ");
3912 scsi_print_command(scmd);
3914 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3915 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
3916 device_str, (unsigned long long)priv_target->sas_address);
3918 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3919 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
3920 priv_target->sas_address);
3923 "\tsas_address(0x%016llx), phy(%d)\n",
3924 ioc->name, (unsigned long long)
3925 sas_device->sas_address, sas_device->phy);
3926 if (sas_device->enclosure_handle != 0)
3928 "\tenclosure_logical_id(0x%016llx),"
3929 "slot(%d)\n", ioc->name,
3930 (unsigned long long)
3931 sas_device->enclosure_logical_id,
3933 if (sas_device->connector_name[0])
3935 "\tenclosure level(0x%04x),"
3936 " connector name( %s)\n", ioc->name,
3937 sas_device->enclosure_level,
3938 sas_device->connector_name);
3940 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3944 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
3945 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
3946 desc_ioc_state, ioc_status, smid);
3948 "\trequest_len(%d), underflow(%d), resid(%d)\n",
3949 ioc->name, scsi_bufflen(scmd), scmd->underflow,
3950 scsi_get_resid(scmd));
3952 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
3953 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3954 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3956 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
3957 ioc->name, desc_scsi_status,
3958 scsi_status, desc_scsi_state, scsi_state);
3960 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3961 struct sense_info data;
3962 _scsih_normalize_sense(scmd->sense_buffer, &data);
3964 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
3965 ioc->name, data.skey,
3966 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
3969 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3970 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3971 response_bytes = (u8 *)&response_info;
3972 _scsih_response_code(ioc, response_bytes[0]);
3977 * _scsih_turn_on_pfa_led - illuminate PFA LED
3978 * @ioc: per adapter object
3979 * @handle: device handle
3985 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3987 Mpi2SepReply_t mpi_reply;
3988 Mpi2SepRequest_t mpi_request;
3989 struct _sas_device *sas_device;
3991 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3995 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3996 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3997 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3998 mpi_request.SlotStatus =
3999 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4000 mpi_request.DevHandle = cpu_to_le16(handle);
4001 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4002 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4003 &mpi_request)) != 0) {
4004 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4005 __FILE__, __LINE__, __func__);
4008 sas_device->pfa_led_on = 1;
4010 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4011 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4012 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4013 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4014 le32_to_cpu(mpi_reply.IOCLogInfo)));
4019 * _scsih_turn_off_pfa_led - turn off Fault LED
4020 * @ioc: per adapter object
4021 * @sas_device: sas device whose PFA LED has to turned off
4027 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4028 struct _sas_device *sas_device)
4030 Mpi2SepReply_t mpi_reply;
4031 Mpi2SepRequest_t mpi_request;
4033 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4034 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4035 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4036 mpi_request.SlotStatus = 0;
4037 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4038 mpi_request.DevHandle = 0;
4039 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4040 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4041 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4042 &mpi_request)) != 0) {
4043 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4044 __FILE__, __LINE__, __func__);
4048 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4049 dewtprintk(ioc, printk(MPT3SAS_FMT
4050 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4051 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4052 le32_to_cpu(mpi_reply.IOCLogInfo)));
4057 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4058 * @ioc: per adapter object
4059 * @handle: device handle
4060 * Context: interrupt.
4065 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4067 struct fw_event_work *fw_event;
4069 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4072 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4073 fw_event->device_handle = handle;
4074 fw_event->ioc = ioc;
4075 _scsih_fw_event_add(ioc, fw_event);
4079 * _scsih_smart_predicted_fault - process smart errors
4080 * @ioc: per adapter object
4081 * @handle: device handle
4082 * Context: interrupt.
4087 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4089 struct scsi_target *starget;
4090 struct MPT3SAS_TARGET *sas_target_priv_data;
4091 Mpi2EventNotificationReply_t *event_reply;
4092 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4093 struct _sas_device *sas_device;
4095 unsigned long flags;
4097 /* only handle non-raid devices */
4098 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4099 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4101 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4104 starget = sas_device->starget;
4105 sas_target_priv_data = starget->hostdata;
4107 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4108 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4109 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4112 if (sas_device->enclosure_handle != 0)
4113 starget_printk(KERN_INFO, starget, "predicted fault, "
4114 "enclosure logical id(0x%016llx), slot(%d)\n",
4115 (unsigned long long)sas_device->enclosure_logical_id,
4117 if (sas_device->connector_name[0] != '\0')
4118 starget_printk(KERN_WARNING, starget, "predicted fault, "
4119 "enclosure level(0x%04x), connector name( %s)\n",
4120 sas_device->enclosure_level,
4121 sas_device->connector_name);
4122 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4124 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4125 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4127 /* insert into event log */
4128 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4129 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4130 event_reply = kzalloc(sz, GFP_KERNEL);
4132 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4133 ioc->name, __FILE__, __LINE__, __func__);
4137 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4138 event_reply->Event =
4139 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4140 event_reply->MsgLength = sz/4;
4141 event_reply->EventDataLength =
4142 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4143 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4144 event_reply->EventData;
4145 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4146 event_data->ASC = 0x5D;
4147 event_data->DevHandle = cpu_to_le16(handle);
4148 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4149 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4154 * _scsih_io_done - scsi request callback
4155 * @ioc: per adapter object
4156 * @smid: system request message index
4157 * @msix_index: MSIX table index supplied by the OS
4158 * @reply: reply message frame(lower 32bit addr)
4160 * Callback handler when using _scsih_qcmd.
4162 * Return 1 meaning mf should be freed from _base_interrupt
4163 * 0 means the mf is freed from this function.
4166 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4168 Mpi2SCSIIORequest_t *mpi_request;
4169 Mpi2SCSIIOReply_t *mpi_reply;
4170 struct scsi_cmnd *scmd;
4176 struct MPT3SAS_DEVICE *sas_device_priv_data;
4177 u32 response_code = 0;
4179 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4180 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4184 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4186 if (mpi_reply == NULL) {
4187 scmd->result = DID_OK << 16;
4191 sas_device_priv_data = scmd->device->hostdata;
4192 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4193 sas_device_priv_data->sas_target->deleted) {
4194 scmd->result = DID_NO_CONNECT << 16;
4197 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4199 /* turning off TLR */
4200 scsi_state = mpi_reply->SCSIState;
4201 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4203 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4204 if (!sas_device_priv_data->tlr_snoop_check) {
4205 sas_device_priv_data->tlr_snoop_check++;
4206 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
4207 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
4208 sas_device_priv_data->flags &=
4212 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4213 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4214 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4215 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4218 ioc_status &= MPI2_IOCSTATUS_MASK;
4219 scsi_status = mpi_reply->SCSIStatus;
4221 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4222 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4223 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4224 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4225 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4228 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4229 struct sense_info data;
4230 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4232 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4233 le32_to_cpu(mpi_reply->SenseCount));
4234 memcpy(scmd->sense_buffer, sense_data, sz);
4235 _scsih_normalize_sense(scmd->sense_buffer, &data);
4236 /* failure prediction threshold exceeded */
4237 if (data.asc == 0x5D)
4238 _scsih_smart_predicted_fault(ioc,
4239 le16_to_cpu(mpi_reply->DevHandle));
4240 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4242 if (!(ioc->logging_level & MPT_DEBUG_REPLY) &&
4243 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4244 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4245 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4246 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4248 switch (ioc_status) {
4249 case MPI2_IOCSTATUS_BUSY:
4250 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4251 scmd->result = SAM_STAT_BUSY;
4254 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4255 scmd->result = DID_NO_CONNECT << 16;
4258 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4259 if (sas_device_priv_data->block) {
4260 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4263 if (log_info == 0x31110630) {
4264 if (scmd->retries > 2) {
4265 scmd->result = DID_NO_CONNECT << 16;
4266 scsi_device_set_state(scmd->device,
4269 scmd->result = DID_SOFT_ERROR << 16;
4270 scmd->device->expecting_cc_ua = 1;
4273 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4274 scmd->result = DID_RESET << 16;
4277 scmd->result = DID_SOFT_ERROR << 16;
4279 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4280 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4281 scmd->result = DID_RESET << 16;
4284 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4285 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4286 scmd->result = DID_SOFT_ERROR << 16;
4288 scmd->result = (DID_OK << 16) | scsi_status;
4291 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4292 scmd->result = (DID_OK << 16) | scsi_status;
4294 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4297 if (xfer_cnt < scmd->underflow) {
4298 if (scsi_status == SAM_STAT_BUSY)
4299 scmd->result = SAM_STAT_BUSY;
4301 scmd->result = DID_SOFT_ERROR << 16;
4302 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4303 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4304 scmd->result = DID_SOFT_ERROR << 16;
4305 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4306 scmd->result = DID_RESET << 16;
4307 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4308 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4309 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4310 scmd->result = (DRIVER_SENSE << 24) |
4311 SAM_STAT_CHECK_CONDITION;
4312 scmd->sense_buffer[0] = 0x70;
4313 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4314 scmd->sense_buffer[12] = 0x20;
4315 scmd->sense_buffer[13] = 0;
4319 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4320 scsi_set_resid(scmd, 0);
4321 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4322 case MPI2_IOCSTATUS_SUCCESS:
4323 scmd->result = (DID_OK << 16) | scsi_status;
4324 if (response_code ==
4325 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4326 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4327 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4328 scmd->result = DID_SOFT_ERROR << 16;
4329 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4330 scmd->result = DID_RESET << 16;
4333 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4334 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4335 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4336 _scsih_eedp_error_handling(scmd, ioc_status);
4339 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4340 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4341 case MPI2_IOCSTATUS_INVALID_SGL:
4342 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4343 case MPI2_IOCSTATUS_INVALID_FIELD:
4344 case MPI2_IOCSTATUS_INVALID_STATE:
4345 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4346 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4348 scmd->result = DID_SOFT_ERROR << 16;
4353 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4354 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4358 scsi_dma_unmap(scmd);
4360 scmd->scsi_done(scmd);
4365 * _scsih_sas_host_refresh - refreshing sas host object contents
4366 * @ioc: per adapter object
4369 * During port enable, fw will send topology events for every device. Its
4370 * possible that the handles may change from the previous setting, so this
4371 * code keeping handles updating if changed.
4376 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4381 Mpi2ConfigReply_t mpi_reply;
4382 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4383 u16 attached_handle;
4386 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4387 "updating handles for sas_host(0x%016llx)\n",
4388 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4390 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4391 * sizeof(Mpi2SasIOUnit0PhyData_t));
4392 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4393 if (!sas_iounit_pg0) {
4394 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4395 ioc->name, __FILE__, __LINE__, __func__);
4399 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4400 sas_iounit_pg0, sz)) != 0)
4402 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4403 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4405 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4406 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4408 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4409 PhyData[0].ControllerDevHandle);
4410 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4411 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4413 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4414 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4415 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4416 attached_handle, i, link_rate);
4419 kfree(sas_iounit_pg0);
4423 * _scsih_sas_host_add - create sas host object
4424 * @ioc: per adapter object
4426 * Creating host side data object, stored in ioc->sas_hba
4431 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4434 Mpi2ConfigReply_t mpi_reply;
4435 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4436 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4437 Mpi2SasPhyPage0_t phy_pg0;
4438 Mpi2SasDevicePage0_t sas_device_pg0;
4439 Mpi2SasEnclosurePage0_t enclosure_pg0;
4442 u8 device_missing_delay;
4444 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4445 if (!ioc->sas_hba.num_phys) {
4446 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4447 ioc->name, __FILE__, __LINE__, __func__);
4451 /* sas_iounit page 0 */
4452 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4453 sizeof(Mpi2SasIOUnit0PhyData_t));
4454 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4455 if (!sas_iounit_pg0) {
4456 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4457 ioc->name, __FILE__, __LINE__, __func__);
4460 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4461 sas_iounit_pg0, sz))) {
4462 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4463 ioc->name, __FILE__, __LINE__, __func__);
4466 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4467 MPI2_IOCSTATUS_MASK;
4468 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4469 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4470 ioc->name, __FILE__, __LINE__, __func__);
4474 /* sas_iounit page 1 */
4475 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4476 sizeof(Mpi2SasIOUnit1PhyData_t));
4477 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4478 if (!sas_iounit_pg1) {
4479 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4480 ioc->name, __FILE__, __LINE__, __func__);
4483 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4484 sas_iounit_pg1, sz))) {
4485 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4486 ioc->name, __FILE__, __LINE__, __func__);
4489 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4490 MPI2_IOCSTATUS_MASK;
4491 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4492 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4493 ioc->name, __FILE__, __LINE__, __func__);
4497 ioc->io_missing_delay =
4498 sas_iounit_pg1->IODeviceMissingDelay;
4499 device_missing_delay =
4500 sas_iounit_pg1->ReportDeviceMissingDelay;
4501 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4502 ioc->device_missing_delay = (device_missing_delay &
4503 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4505 ioc->device_missing_delay = device_missing_delay &
4506 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4508 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4509 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4510 sizeof(struct _sas_phy), GFP_KERNEL);
4511 if (!ioc->sas_hba.phy) {
4512 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4513 ioc->name, __FILE__, __LINE__, __func__);
4516 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4517 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4519 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4520 ioc->name, __FILE__, __LINE__, __func__);
4523 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4524 MPI2_IOCSTATUS_MASK;
4525 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4526 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4527 ioc->name, __FILE__, __LINE__, __func__);
4532 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4533 PhyData[0].ControllerDevHandle);
4534 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4535 ioc->sas_hba.phy[i].phy_id = i;
4536 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4537 phy_pg0, ioc->sas_hba.parent_dev);
4539 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4540 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4541 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4542 ioc->name, __FILE__, __LINE__, __func__);
4545 ioc->sas_hba.enclosure_handle =
4546 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4547 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4549 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4550 ioc->name, ioc->sas_hba.handle,
4551 (unsigned long long) ioc->sas_hba.sas_address,
4552 ioc->sas_hba.num_phys) ;
4554 if (ioc->sas_hba.enclosure_handle) {
4555 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4556 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4557 ioc->sas_hba.enclosure_handle)))
4558 ioc->sas_hba.enclosure_logical_id =
4559 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4563 kfree(sas_iounit_pg1);
4564 kfree(sas_iounit_pg0);
4568 * _scsih_expander_add - creating expander object
4569 * @ioc: per adapter object
4570 * @handle: expander handle
4572 * Creating expander object, stored in ioc->sas_expander_list.
4574 * Return 0 for success, else error.
4577 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4579 struct _sas_node *sas_expander;
4580 Mpi2ConfigReply_t mpi_reply;
4581 Mpi2ExpanderPage0_t expander_pg0;
4582 Mpi2ExpanderPage1_t expander_pg1;
4583 Mpi2SasEnclosurePage0_t enclosure_pg0;
4586 u64 sas_address, sas_address_parent = 0;
4588 unsigned long flags;
4589 struct _sas_port *mpt3sas_port = NULL;
4596 if (ioc->shost_recovery || ioc->pci_error_recovery)
4599 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4600 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4601 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4602 ioc->name, __FILE__, __LINE__, __func__);
4606 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4607 MPI2_IOCSTATUS_MASK;
4608 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4609 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4610 ioc->name, __FILE__, __LINE__, __func__);
4614 /* handle out of order topology events */
4615 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4616 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4618 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4619 ioc->name, __FILE__, __LINE__, __func__);
4622 if (sas_address_parent != ioc->sas_hba.sas_address) {
4623 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4624 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4625 sas_address_parent);
4626 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4627 if (!sas_expander) {
4628 rc = _scsih_expander_add(ioc, parent_handle);
4634 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4635 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4636 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4638 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4643 sas_expander = kzalloc(sizeof(struct _sas_node),
4645 if (!sas_expander) {
4646 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4647 ioc->name, __FILE__, __LINE__, __func__);
4651 sas_expander->handle = handle;
4652 sas_expander->num_phys = expander_pg0.NumPhys;
4653 sas_expander->sas_address_parent = sas_address_parent;
4654 sas_expander->sas_address = sas_address;
4656 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4657 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4658 handle, parent_handle, (unsigned long long)
4659 sas_expander->sas_address, sas_expander->num_phys);
4661 if (!sas_expander->num_phys)
4663 sas_expander->phy = kcalloc(sas_expander->num_phys,
4664 sizeof(struct _sas_phy), GFP_KERNEL);
4665 if (!sas_expander->phy) {
4666 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4667 ioc->name, __FILE__, __LINE__, __func__);
4672 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4673 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4674 sas_address_parent);
4675 if (!mpt3sas_port) {
4676 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4677 ioc->name, __FILE__, __LINE__, __func__);
4681 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4683 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4684 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4685 &expander_pg1, i, handle))) {
4686 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4687 ioc->name, __FILE__, __LINE__, __func__);
4691 sas_expander->phy[i].handle = handle;
4692 sas_expander->phy[i].phy_id = i;
4694 if ((mpt3sas_transport_add_expander_phy(ioc,
4695 &sas_expander->phy[i], expander_pg1,
4696 sas_expander->parent_dev))) {
4697 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4698 ioc->name, __FILE__, __LINE__, __func__);
4704 if (sas_expander->enclosure_handle) {
4705 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4706 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4707 sas_expander->enclosure_handle)))
4708 sas_expander->enclosure_logical_id =
4709 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4712 _scsih_expander_node_add(ioc, sas_expander);
4718 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
4719 sas_address_parent);
4720 kfree(sas_expander);
4725 * mpt3sas_expander_remove - removing expander object
4726 * @ioc: per adapter object
4727 * @sas_address: expander sas_address
4732 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
4734 struct _sas_node *sas_expander;
4735 unsigned long flags;
4737 if (ioc->shost_recovery)
4740 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4741 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4744 list_del(&sas_expander->list);
4745 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4747 _scsih_expander_node_remove(ioc, sas_expander);
4751 * _scsih_done - internal SCSI_IO callback handler.
4752 * @ioc: per adapter object
4753 * @smid: system request message index
4754 * @msix_index: MSIX table index supplied by the OS
4755 * @reply: reply message frame(lower 32bit addr)
4757 * Callback handler when sending internal generated SCSI_IO.
4758 * The callback index passed is `ioc->scsih_cb_idx`
4760 * Return 1 meaning mf should be freed from _base_interrupt
4761 * 0 means the mf is freed from this function.
4764 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4766 MPI2DefaultReply_t *mpi_reply;
4768 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4769 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
4771 if (ioc->scsih_cmds.smid != smid)
4773 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
4775 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4776 mpi_reply->MsgLength*4);
4777 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
4779 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
4780 complete(&ioc->scsih_cmds.done);
4787 #define MPT3_MAX_LUNS (255)
4791 * _scsih_check_access_status - check access flags
4792 * @ioc: per adapter object
4793 * @sas_address: sas address
4794 * @handle: sas device handle
4795 * @access_flags: errors returned during discovery of the device
4797 * Return 0 for success, else failure
4800 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
4801 u16 handle, u8 access_status)
4806 switch (access_status) {
4807 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4808 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4811 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4812 desc = "sata capability failed";
4814 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4815 desc = "sata affiliation conflict";
4817 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4818 desc = "route not addressable";
4820 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4821 desc = "smp error not addressable";
4823 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4824 desc = "device blocked";
4826 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4827 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4828 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4829 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4830 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4831 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4832 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4833 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4834 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4835 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4836 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4837 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4838 desc = "sata initialization failed";
4849 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
4850 ioc->name, desc, (unsigned long long)sas_address, handle);
4855 * _scsih_check_device - checking device responsiveness
4856 * @ioc: per adapter object
4857 * @parent_sas_address: sas address of parent expander or sas host
4858 * @handle: attached device handle
4859 * @phy_numberv: phy number
4860 * @link_rate: new link rate
4865 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
4866 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
4868 Mpi2ConfigReply_t mpi_reply;
4869 Mpi2SasDevicePage0_t sas_device_pg0;
4870 struct _sas_device *sas_device;
4872 unsigned long flags;
4874 struct scsi_target *starget;
4875 struct MPT3SAS_TARGET *sas_target_priv_data;
4879 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4880 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4883 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4884 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4887 /* wide port handling ~ we need only handle device once for the phy that
4888 * is matched in sas device page zero
4890 if (phy_number != sas_device_pg0.PhyNum)
4893 /* check if this is end device */
4894 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4895 if (!(_scsih_is_end_device(device_info)))
4898 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4899 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4900 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
4904 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4908 if (unlikely(sas_device->handle != handle)) {
4909 starget = sas_device->starget;
4910 sas_target_priv_data = starget->hostdata;
4911 starget_printk(KERN_INFO, starget,
4912 "handle changed from(0x%04x) to (0x%04x)!!!\n",
4913 sas_device->handle, handle);
4914 sas_target_priv_data->handle = handle;
4915 sas_device->handle = handle;
4916 if (sas_device_pg0.Flags &
4917 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
4918 sas_device->enclosure_level =
4919 le16_to_cpu(sas_device_pg0.EnclosureLevel);
4920 memcpy(&sas_device->connector_name[0],
4921 &sas_device_pg0.ConnectorName[0], 4);
4923 sas_device->enclosure_level = 0;
4924 sas_device->connector_name[0] = '\0';
4928 /* check if device is present */
4929 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4930 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4932 "device is not present handle(0x%04x), flags!!!\n",
4934 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4938 /* check if there were any issues with discovery */
4939 if (_scsih_check_access_status(ioc, sas_address, handle,
4940 sas_device_pg0.AccessStatus)) {
4941 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4945 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4946 _scsih_ublock_io_device(ioc, sas_address);
4951 * _scsih_add_device - creating sas device object
4952 * @ioc: per adapter object
4953 * @handle: sas device handle
4954 * @phy_num: phy number end device attached to
4955 * @is_pd: is this hidden raid component
4957 * Creating end device object, stored in ioc->sas_device_list.
4959 * Returns 0 for success, non-zero for failure.
4962 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
4965 Mpi2ConfigReply_t mpi_reply;
4966 Mpi2SasDevicePage0_t sas_device_pg0;
4967 Mpi2SasEnclosurePage0_t enclosure_pg0;
4968 struct _sas_device *sas_device;
4972 unsigned long flags;
4974 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4975 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4976 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4977 ioc->name, __FILE__, __LINE__, __func__);
4981 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4982 MPI2_IOCSTATUS_MASK;
4983 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4984 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4985 ioc->name, __FILE__, __LINE__, __func__);
4989 /* check if this is end device */
4990 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4991 if (!(_scsih_is_end_device(device_info)))
4993 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4995 /* check if device is present */
4996 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4997 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4998 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5003 /* check if there were any issues with discovery */
5004 if (_scsih_check_access_status(ioc, sas_address, handle,
5005 sas_device_pg0.AccessStatus))
5008 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5009 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5011 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5016 sas_device = kzalloc(sizeof(struct _sas_device),
5019 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5020 ioc->name, __FILE__, __LINE__, __func__);
5024 sas_device->handle = handle;
5025 if (_scsih_get_sas_address(ioc,
5026 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5027 &sas_device->sas_address_parent) != 0)
5028 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5029 ioc->name, __FILE__, __LINE__, __func__);
5030 sas_device->enclosure_handle =
5031 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5032 if (sas_device->enclosure_handle != 0)
5034 le16_to_cpu(sas_device_pg0.Slot);
5035 sas_device->device_info = device_info;
5036 sas_device->sas_address = sas_address;
5037 sas_device->phy = sas_device_pg0.PhyNum;
5038 #ifndef SCSI_MPT2SAS
5039 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5040 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5043 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5044 sas_device->enclosure_level =
5045 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5046 memcpy(&sas_device->connector_name[0],
5047 &sas_device_pg0.ConnectorName[0], 4);
5049 sas_device->enclosure_level = 0;
5050 sas_device->connector_name[0] = '\0';
5052 /* get enclosure_logical_id */
5053 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5054 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5055 sas_device->enclosure_handle)))
5056 sas_device->enclosure_logical_id =
5057 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5059 /* get device name */
5060 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5062 if (ioc->wait_for_discovery_to_complete)
5063 _scsih_sas_device_init_add(ioc, sas_device);
5065 _scsih_sas_device_add(ioc, sas_device);
5071 * _scsih_remove_device - removing sas device object
5072 * @ioc: per adapter object
5073 * @sas_device_delete: the sas_device object
5078 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5079 struct _sas_device *sas_device)
5081 struct MPT3SAS_TARGET *sas_target_priv_data;
5083 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5084 (sas_device->pfa_led_on)) {
5085 _scsih_turn_off_pfa_led(ioc, sas_device);
5086 sas_device->pfa_led_on = 0;
5088 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5089 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5090 ioc->name, __func__,
5091 sas_device->handle, (unsigned long long)
5092 sas_device->sas_address));
5093 if (sas_device->enclosure_handle != 0)
5094 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5095 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5096 ioc->name, __func__,
5097 (unsigned long long)sas_device->enclosure_logical_id,
5099 if (sas_device->connector_name[0] != '\0')
5100 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5101 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5102 ioc->name, __func__,
5103 sas_device->enclosure_level,
5104 sas_device->connector_name));
5106 if (sas_device->starget && sas_device->starget->hostdata) {
5107 sas_target_priv_data = sas_device->starget->hostdata;
5108 sas_target_priv_data->deleted = 1;
5109 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5110 sas_target_priv_data->handle =
5111 MPT3SAS_INVALID_DEVICE_HANDLE;
5113 mpt3sas_transport_port_remove(ioc,
5114 sas_device->sas_address,
5115 sas_device->sas_address_parent);
5118 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5119 ioc->name, sas_device->handle,
5120 (unsigned long long) sas_device->sas_address);
5121 if (sas_device->enclosure_handle != 0)
5123 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5125 (unsigned long long)sas_device->enclosure_logical_id,
5127 if (sas_device->connector_name[0] != '\0')
5129 "removing enclosure level(0x%04x), connector name( %s)\n",
5130 ioc->name, sas_device->enclosure_level,
5131 sas_device->connector_name);
5133 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5134 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5135 ioc->name, __func__,
5136 sas_device->handle, (unsigned long long)
5137 sas_device->sas_address));
5138 if (sas_device->enclosure_handle != 0)
5139 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5140 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5141 ioc->name, __func__,
5142 (unsigned long long)sas_device->enclosure_logical_id,
5144 if (sas_device->connector_name[0] != '\0')
5145 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5146 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5147 ioc->name, __func__, sas_device->enclosure_level,
5148 sas_device->connector_name));
5154 * _scsih_sas_topology_change_event_debug - debug for topology event
5155 * @ioc: per adapter object
5156 * @event_data: event data payload
5160 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5161 Mpi2EventDataSasTopologyChangeList_t *event_data)
5167 char *status_str = NULL;
5168 u8 link_rate, prev_link_rate;
5170 switch (event_data->ExpStatus) {
5171 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5174 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5175 status_str = "remove";
5177 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5179 status_str = "responding";
5181 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5182 status_str = "remove delay";
5185 status_str = "unknown status";
5188 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5189 ioc->name, status_str);
5190 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5191 "start_phy(%02d), count(%d)\n",
5192 le16_to_cpu(event_data->ExpanderDevHandle),
5193 le16_to_cpu(event_data->EnclosureHandle),
5194 event_data->StartPhyNum, event_data->NumEntries);
5195 for (i = 0; i < event_data->NumEntries; i++) {
5196 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5199 phy_number = event_data->StartPhyNum + i;
5200 reason_code = event_data->PHY[i].PhyStatus &
5201 MPI2_EVENT_SAS_TOPO_RC_MASK;
5202 switch (reason_code) {
5203 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5204 status_str = "target add";
5206 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5207 status_str = "target remove";
5209 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5210 status_str = "delay target remove";
5212 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5213 status_str = "link rate change";
5215 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5216 status_str = "target responding";
5219 status_str = "unknown";
5222 link_rate = event_data->PHY[i].LinkRate >> 4;
5223 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5224 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5225 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5226 handle, status_str, link_rate, prev_link_rate);
5232 * _scsih_sas_topology_change_event - handle topology changes
5233 * @ioc: per adapter object
5234 * @fw_event: The fw_event_work object
5239 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5240 struct fw_event_work *fw_event)
5243 u16 parent_handle, handle;
5245 u8 phy_number, max_phys;
5246 struct _sas_node *sas_expander;
5248 unsigned long flags;
5249 u8 link_rate, prev_link_rate;
5250 Mpi2EventDataSasTopologyChangeList_t *event_data =
5251 (Mpi2EventDataSasTopologyChangeList_t *)
5252 fw_event->event_data;
5254 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5255 _scsih_sas_topology_change_event_debug(ioc, event_data);
5257 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5260 if (!ioc->sas_hba.num_phys)
5261 _scsih_sas_host_add(ioc);
5263 _scsih_sas_host_refresh(ioc);
5265 if (fw_event->ignore) {
5266 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5267 "ignoring expander event\n", ioc->name));
5271 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5273 /* handle expander add */
5274 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5275 if (_scsih_expander_add(ioc, parent_handle) != 0)
5278 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5279 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5282 sas_address = sas_expander->sas_address;
5283 max_phys = sas_expander->num_phys;
5284 } else if (parent_handle < ioc->sas_hba.num_phys) {
5285 sas_address = ioc->sas_hba.sas_address;
5286 max_phys = ioc->sas_hba.num_phys;
5288 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5291 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5293 /* handle siblings events */
5294 for (i = 0; i < event_data->NumEntries; i++) {
5295 if (fw_event->ignore) {
5296 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5297 "ignoring expander event\n", ioc->name));
5300 if (ioc->remove_host || ioc->pci_error_recovery)
5302 phy_number = event_data->StartPhyNum + i;
5303 if (phy_number >= max_phys)
5305 reason_code = event_data->PHY[i].PhyStatus &
5306 MPI2_EVENT_SAS_TOPO_RC_MASK;
5307 if ((event_data->PHY[i].PhyStatus &
5308 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5309 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5311 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5314 link_rate = event_data->PHY[i].LinkRate >> 4;
5315 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5316 switch (reason_code) {
5317 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5319 if (ioc->shost_recovery)
5322 if (link_rate == prev_link_rate)
5325 mpt3sas_transport_update_links(ioc, sas_address,
5326 handle, phy_number, link_rate);
5328 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5331 _scsih_check_device(ioc, sas_address, handle,
5332 phy_number, link_rate);
5335 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5337 if (ioc->shost_recovery)
5340 mpt3sas_transport_update_links(ioc, sas_address,
5341 handle, phy_number, link_rate);
5343 _scsih_add_device(ioc, handle, phy_number, 0);
5346 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5348 _scsih_device_remove_by_handle(ioc, handle);
5353 /* handle expander removal */
5354 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5356 mpt3sas_expander_remove(ioc, sas_address);
5362 * _scsih_sas_device_status_change_event_debug - debug for device event
5363 * @event_data: event data payload
5369 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5370 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5372 char *reason_str = NULL;
5374 switch (event_data->ReasonCode) {
5375 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5376 reason_str = "smart data";
5378 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5379 reason_str = "unsupported device discovered";
5381 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5382 reason_str = "internal device reset";
5384 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5385 reason_str = "internal task abort";
5387 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5388 reason_str = "internal task abort set";
5390 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5391 reason_str = "internal clear task set";
5393 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5394 reason_str = "internal query task";
5396 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5397 reason_str = "sata init failure";
5399 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5400 reason_str = "internal device reset complete";
5402 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5403 reason_str = "internal task abort complete";
5405 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5406 reason_str = "internal async notification";
5408 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5409 reason_str = "expander reduced functionality";
5411 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5412 reason_str = "expander reduced functionality complete";
5415 reason_str = "unknown reason";
5418 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5419 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5420 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5421 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5422 le16_to_cpu(event_data->TaskTag));
5423 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5424 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5425 event_data->ASC, event_data->ASCQ);
5430 * _scsih_sas_device_status_change_event - handle device status change
5431 * @ioc: per adapter object
5432 * @fw_event: The fw_event_work object
5438 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5439 struct fw_event_work *fw_event)
5441 struct MPT3SAS_TARGET *target_priv_data;
5442 struct _sas_device *sas_device;
5444 unsigned long flags;
5445 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5446 (Mpi2EventDataSasDeviceStatusChange_t *)
5447 fw_event->event_data;
5449 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5450 _scsih_sas_device_status_change_event_debug(ioc,
5453 /* In MPI Revision K (0xC), the internal device reset complete was
5454 * implemented, so avoid setting tm_busy flag for older firmware.
5456 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5459 if (event_data->ReasonCode !=
5460 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5461 event_data->ReasonCode !=
5462 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5465 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5466 sas_address = le64_to_cpu(event_data->SASAddress);
5467 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
5470 if (!sas_device || !sas_device->starget) {
5471 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5475 target_priv_data = sas_device->starget->hostdata;
5476 if (!target_priv_data) {
5477 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5481 if (event_data->ReasonCode ==
5482 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5483 target_priv_data->tm_busy = 1;
5485 target_priv_data->tm_busy = 0;
5486 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5490 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5492 * @ioc: per adapter object
5493 * @event_data: event data payload
5499 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5500 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5502 char *reason_str = NULL;
5504 switch (event_data->ReasonCode) {
5505 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5506 reason_str = "enclosure add";
5508 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5509 reason_str = "enclosure remove";
5512 reason_str = "unknown reason";
5516 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5517 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5518 " number slots(%d)\n", ioc->name, reason_str,
5519 le16_to_cpu(event_data->EnclosureHandle),
5520 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5521 le16_to_cpu(event_data->StartSlot));
5525 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5526 * @ioc: per adapter object
5527 * @fw_event: The fw_event_work object
5533 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5534 struct fw_event_work *fw_event)
5536 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5537 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5538 (Mpi2EventDataSasEnclDevStatusChange_t *)
5539 fw_event->event_data);
5543 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5544 * @ioc: per adapter object
5545 * @fw_event: The fw_event_work object
5551 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5552 struct fw_event_work *fw_event)
5554 struct scsi_cmnd *scmd;
5555 struct scsi_device *sdev;
5558 struct MPT3SAS_DEVICE *sas_device_priv_data;
5559 u32 termination_count;
5561 Mpi2SCSITaskManagementReply_t *mpi_reply;
5562 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5563 (Mpi2EventDataSasBroadcastPrimitive_t *)
5564 fw_event->event_data;
5566 unsigned long flags;
5569 u8 task_abort_retries;
5571 mutex_lock(&ioc->tm_cmds.mutex);
5573 "%s: enter: phy number(%d), width(%d)\n",
5574 ioc->name, __func__, event_data->PhyNum,
5575 event_data->PortWidth);
5577 _scsih_block_io_all_device(ioc);
5579 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5580 mpi_reply = ioc->tm_cmds.reply;
5581 broadcast_aen_retry:
5583 /* sanity checks for retrying this loop */
5584 if (max_retries++ == 5) {
5585 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5586 ioc->name, __func__));
5588 } else if (max_retries > 1)
5589 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5590 ioc->name, __func__, max_retries - 1));
5592 termination_count = 0;
5594 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5595 if (ioc->shost_recovery)
5597 scmd = _scsih_scsi_lookup_get(ioc, smid);
5600 sdev = scmd->device;
5601 sas_device_priv_data = sdev->hostdata;
5602 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5604 /* skip hidden raid components */
5605 if (sas_device_priv_data->sas_target->flags &
5606 MPT_TARGET_FLAGS_RAID_COMPONENT)
5609 if (sas_device_priv_data->sas_target->flags &
5610 MPT_TARGET_FLAGS_VOLUME)
5613 handle = sas_device_priv_data->sas_target->handle;
5614 lun = sas_device_priv_data->lun;
5617 if (ioc->shost_recovery)
5620 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5621 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5622 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5625 sdev_printk(KERN_WARNING, sdev,
5626 "mpt3sas_scsih_issue_tm: FAILED when sending "
5627 "QUERY_TASK: scmd(%p)\n", scmd);
5628 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5629 goto broadcast_aen_retry;
5631 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5632 & MPI2_IOCSTATUS_MASK;
5633 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5634 sdev_printk(KERN_WARNING, sdev,
5635 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5637 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5638 goto broadcast_aen_retry;
5641 /* see if IO is still owned by IOC and target */
5642 if (mpi_reply->ResponseCode ==
5643 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5644 mpi_reply->ResponseCode ==
5645 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5646 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5649 task_abort_retries = 0;
5651 if (task_abort_retries++ == 60) {
5652 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5653 "%s: ABORT_TASK: giving up\n", ioc->name,
5655 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5656 goto broadcast_aen_retry;
5659 if (ioc->shost_recovery)
5662 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5663 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5666 sdev_printk(KERN_WARNING, sdev,
5667 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5668 "scmd(%p)\n", scmd);
5672 if (task_abort_retries > 1)
5673 sdev_printk(KERN_WARNING, sdev,
5674 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5676 task_abort_retries - 1, scmd);
5678 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5679 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5682 if (ioc->broadcast_aen_pending) {
5683 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5684 "%s: loop back due to pending AEN\n",
5685 ioc->name, __func__));
5686 ioc->broadcast_aen_pending = 0;
5687 goto broadcast_aen_retry;
5691 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5694 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5695 "%s - exit, query_count = %d termination_count = %d\n",
5696 ioc->name, __func__, query_count, termination_count));
5698 ioc->broadcast_aen_busy = 0;
5699 if (!ioc->shost_recovery)
5700 _scsih_ublock_io_all_device(ioc);
5701 mutex_unlock(&ioc->tm_cmds.mutex);
5705 * _scsih_sas_discovery_event - handle discovery events
5706 * @ioc: per adapter object
5707 * @fw_event: The fw_event_work object
5713 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
5714 struct fw_event_work *fw_event)
5716 Mpi2EventDataSasDiscovery_t *event_data =
5717 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
5719 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5720 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
5721 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5723 if (event_data->DiscoveryStatus)
5724 pr_info("discovery_status(0x%08x)",
5725 le32_to_cpu(event_data->DiscoveryStatus));
5729 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5730 !ioc->sas_hba.num_phys) {
5731 if (disable_discovery > 0 && ioc->shost_recovery) {
5732 /* Wait for the reset to complete */
5733 while (ioc->shost_recovery)
5736 _scsih_sas_host_add(ioc);
5740 #ifndef SCSI_MPT2SAS
5742 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
5743 * @ioc: per adapter object
5744 * @handle: device handle for physical disk
5745 * @phys_disk_num: physical disk number
5747 * Return 0 for success, else failure.
5750 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
5752 Mpi2RaidActionRequest_t *mpi_request;
5753 Mpi2RaidActionReply_t *mpi_reply;
5760 mutex_lock(&ioc->scsih_cmds.mutex);
5762 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
5763 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
5764 ioc->name, __func__);
5768 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
5770 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
5772 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
5773 ioc->name, __func__);
5774 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5779 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5780 ioc->scsih_cmds.smid = smid;
5781 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
5783 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
5784 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
5785 mpi_request->PhysDiskNum = phys_disk_num;
5787 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
5788 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
5789 handle, phys_disk_num));
5791 init_completion(&ioc->scsih_cmds.done);
5792 mpt3sas_base_put_smid_default(ioc, smid);
5793 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
5795 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
5796 pr_err(MPT3SAS_FMT "%s: timeout\n",
5797 ioc->name, __func__);
5798 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
5804 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
5806 mpi_reply = ioc->scsih_cmds.reply;
5807 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5808 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5809 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5812 ioc_status &= MPI2_IOCSTATUS_MASK;
5813 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5814 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5815 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
5816 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
5820 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5821 "IR RAID_ACTION: completed successfully\n",
5826 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
5827 mutex_unlock(&ioc->scsih_cmds.mutex);
5830 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
5834 /* End of not defined SCSI_MPT2SAS */
5838 * _scsih_reprobe_lun - reprobing lun
5839 * @sdev: scsi device struct
5840 * @no_uld_attach: sdev->no_uld_attach flag setting
5844 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5847 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5848 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5849 sdev->no_uld_attach ? "hidding" : "exposing");
5850 rc = scsi_device_reprobe(sdev);
5854 * _scsih_sas_volume_add - add new volume
5855 * @ioc: per adapter object
5856 * @element: IR config element data
5862 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
5863 Mpi2EventIrConfigElement_t *element)
5865 struct _raid_device *raid_device;
5866 unsigned long flags;
5868 u16 handle = le16_to_cpu(element->VolDevHandle);
5871 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
5874 "failure at %s:%d/%s()!\n", ioc->name,
5875 __FILE__, __LINE__, __func__);
5879 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5880 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5881 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5886 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5889 "failure at %s:%d/%s()!\n", ioc->name,
5890 __FILE__, __LINE__, __func__);
5894 raid_device->id = ioc->sas_id++;
5895 raid_device->channel = RAID_CHANNEL;
5896 raid_device->handle = handle;
5897 raid_device->wwid = wwid;
5898 _scsih_raid_device_add(ioc, raid_device);
5899 if (!ioc->wait_for_discovery_to_complete) {
5900 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5901 raid_device->id, 0);
5903 _scsih_raid_device_remove(ioc, raid_device);
5905 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5906 _scsih_determine_boot_device(ioc, raid_device, 1);
5907 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5912 * _scsih_sas_volume_delete - delete volume
5913 * @ioc: per adapter object
5914 * @handle: volume device handle
5920 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5922 struct _raid_device *raid_device;
5923 unsigned long flags;
5924 struct MPT3SAS_TARGET *sas_target_priv_data;
5925 struct scsi_target *starget = NULL;
5927 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5928 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5930 if (raid_device->starget) {
5931 starget = raid_device->starget;
5932 sas_target_priv_data = starget->hostdata;
5933 sas_target_priv_data->deleted = 1;
5935 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
5936 ioc->name, raid_device->handle,
5937 (unsigned long long) raid_device->wwid);
5938 list_del(&raid_device->list);
5941 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5943 scsi_remove_target(&starget->dev);
5947 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5948 * @ioc: per adapter object
5949 * @element: IR config element data
5955 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
5956 Mpi2EventIrConfigElement_t *element)
5958 struct _sas_device *sas_device;
5959 struct scsi_target *starget = NULL;
5960 struct MPT3SAS_TARGET *sas_target_priv_data;
5961 unsigned long flags;
5962 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5964 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5965 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5967 sas_device->volume_handle = 0;
5968 sas_device->volume_wwid = 0;
5969 clear_bit(handle, ioc->pd_handles);
5970 if (sas_device->starget && sas_device->starget->hostdata) {
5971 starget = sas_device->starget;
5972 sas_target_priv_data = starget->hostdata;
5973 sas_target_priv_data->flags &=
5974 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5977 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5981 /* exposing raid component */
5983 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
5987 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5988 * @ioc: per adapter object
5989 * @element: IR config element data
5995 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
5996 Mpi2EventIrConfigElement_t *element)
5998 struct _sas_device *sas_device;
5999 struct scsi_target *starget = NULL;
6000 struct MPT3SAS_TARGET *sas_target_priv_data;
6001 unsigned long flags;
6002 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6003 u16 volume_handle = 0;
6004 u64 volume_wwid = 0;
6006 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6008 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6011 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6012 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6014 set_bit(handle, ioc->pd_handles);
6015 if (sas_device->starget && sas_device->starget->hostdata) {
6016 starget = sas_device->starget;
6017 sas_target_priv_data = starget->hostdata;
6018 sas_target_priv_data->flags |=
6019 MPT_TARGET_FLAGS_RAID_COMPONENT;
6020 sas_device->volume_handle = volume_handle;
6021 sas_device->volume_wwid = volume_wwid;
6024 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6028 #ifndef SCSI_MPT2SAS
6029 /* hiding raid component */
6030 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6033 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6037 * _scsih_sas_pd_delete - delete pd component
6038 * @ioc: per adapter object
6039 * @element: IR config element data
6045 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6046 Mpi2EventIrConfigElement_t *element)
6048 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6050 _scsih_device_remove_by_handle(ioc, handle);
6054 * _scsih_sas_pd_add - remove pd component
6055 * @ioc: per adapter object
6056 * @element: IR config element data
6062 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6063 Mpi2EventIrConfigElement_t *element)
6065 struct _sas_device *sas_device;
6066 unsigned long flags;
6067 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6068 Mpi2ConfigReply_t mpi_reply;
6069 Mpi2SasDevicePage0_t sas_device_pg0;
6074 set_bit(handle, ioc->pd_handles);
6076 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6077 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6078 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6080 #ifndef SCSI_MPT2SAS
6081 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6086 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6087 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6088 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6089 ioc->name, __FILE__, __LINE__, __func__);
6093 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6094 MPI2_IOCSTATUS_MASK;
6095 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6096 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6097 ioc->name, __FILE__, __LINE__, __func__);
6101 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6102 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6103 mpt3sas_transport_update_links(ioc, sas_address, handle,
6104 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6106 #ifndef SCSI_MPT2SAS
6107 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6109 _scsih_add_device(ioc, handle, 0, 1);
6113 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6114 * @ioc: per adapter object
6115 * @event_data: event data payload
6121 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6122 Mpi2EventDataIrConfigChangeList_t *event_data)
6124 Mpi2EventIrConfigElement_t *element;
6127 char *reason_str = NULL, *element_str = NULL;
6129 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6131 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6132 ioc->name, (le32_to_cpu(event_data->Flags) &
6133 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6134 "foreign" : "native", event_data->NumElements);
6135 for (i = 0; i < event_data->NumElements; i++, element++) {
6136 switch (element->ReasonCode) {
6137 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6140 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6141 reason_str = "remove";
6143 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6144 reason_str = "no change";
6146 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6147 reason_str = "hide";
6149 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6150 reason_str = "unhide";
6152 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6153 reason_str = "volume_created";
6155 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6156 reason_str = "volume_deleted";
6158 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6159 reason_str = "pd_created";
6161 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6162 reason_str = "pd_deleted";
6165 reason_str = "unknown reason";
6168 element_type = le16_to_cpu(element->ElementFlags) &
6169 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6170 switch (element_type) {
6171 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6172 element_str = "volume";
6174 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6175 element_str = "phys disk";
6177 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6178 element_str = "hot spare";
6181 element_str = "unknown element";
6184 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6185 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6186 reason_str, le16_to_cpu(element->VolDevHandle),
6187 le16_to_cpu(element->PhysDiskDevHandle),
6188 element->PhysDiskNum);
6193 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6194 * @ioc: per adapter object
6195 * @fw_event: The fw_event_work object
6201 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6202 struct fw_event_work *fw_event)
6204 Mpi2EventIrConfigElement_t *element;
6207 Mpi2EventDataIrConfigChangeList_t *event_data =
6208 (Mpi2EventDataIrConfigChangeList_t *)
6209 fw_event->event_data;
6211 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6212 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6214 foreign_config = (le32_to_cpu(event_data->Flags) &
6215 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6217 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6218 if (ioc->shost_recovery) {
6219 #ifndef SCSI_MPT2SAS
6220 for (i = 0; i < event_data->NumElements; i++, element++) {
6221 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6222 _scsih_ir_fastpath(ioc,
6223 le16_to_cpu(element->PhysDiskDevHandle),
6224 element->PhysDiskNum);
6229 for (i = 0; i < event_data->NumElements; i++, element++) {
6231 switch (element->ReasonCode) {
6232 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6233 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6234 if (!foreign_config)
6235 _scsih_sas_volume_add(ioc, element);
6237 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6238 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6239 if (!foreign_config)
6240 _scsih_sas_volume_delete(ioc,
6241 le16_to_cpu(element->VolDevHandle));
6243 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6244 _scsih_sas_pd_hide(ioc, element);
6246 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6247 _scsih_sas_pd_expose(ioc, element);
6249 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6250 _scsih_sas_pd_add(ioc, element);
6252 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6253 _scsih_sas_pd_delete(ioc, element);
6260 * _scsih_sas_ir_volume_event - IR volume event
6261 * @ioc: per adapter object
6262 * @fw_event: The fw_event_work object
6268 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6269 struct fw_event_work *fw_event)
6272 unsigned long flags;
6273 struct _raid_device *raid_device;
6277 Mpi2EventDataIrVolume_t *event_data =
6278 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6280 if (ioc->shost_recovery)
6283 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6286 handle = le16_to_cpu(event_data->VolDevHandle);
6287 state = le32_to_cpu(event_data->NewValue);
6288 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6289 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6290 ioc->name, __func__, handle,
6291 le32_to_cpu(event_data->PreviousValue), state));
6293 case MPI2_RAID_VOL_STATE_MISSING:
6294 case MPI2_RAID_VOL_STATE_FAILED:
6295 _scsih_sas_volume_delete(ioc, handle);
6298 case MPI2_RAID_VOL_STATE_ONLINE:
6299 case MPI2_RAID_VOL_STATE_DEGRADED:
6300 case MPI2_RAID_VOL_STATE_OPTIMAL:
6302 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6303 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6304 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6309 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6312 "failure at %s:%d/%s()!\n", ioc->name,
6313 __FILE__, __LINE__, __func__);
6317 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6320 "failure at %s:%d/%s()!\n", ioc->name,
6321 __FILE__, __LINE__, __func__);
6325 raid_device->id = ioc->sas_id++;
6326 raid_device->channel = RAID_CHANNEL;
6327 raid_device->handle = handle;
6328 raid_device->wwid = wwid;
6329 _scsih_raid_device_add(ioc, raid_device);
6330 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6331 raid_device->id, 0);
6333 _scsih_raid_device_remove(ioc, raid_device);
6336 case MPI2_RAID_VOL_STATE_INITIALIZING:
6343 * _scsih_sas_ir_physical_disk_event - PD event
6344 * @ioc: per adapter object
6345 * @fw_event: The fw_event_work object
6351 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6352 struct fw_event_work *fw_event)
6354 u16 handle, parent_handle;
6356 struct _sas_device *sas_device;
6357 unsigned long flags;
6358 Mpi2ConfigReply_t mpi_reply;
6359 Mpi2SasDevicePage0_t sas_device_pg0;
6361 Mpi2EventDataIrPhysicalDisk_t *event_data =
6362 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6365 if (ioc->shost_recovery)
6368 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6371 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6372 state = le32_to_cpu(event_data->NewValue);
6374 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6375 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6376 ioc->name, __func__, handle,
6377 le32_to_cpu(event_data->PreviousValue), state));
6379 case MPI2_RAID_PD_STATE_ONLINE:
6380 case MPI2_RAID_PD_STATE_DEGRADED:
6381 case MPI2_RAID_PD_STATE_REBUILDING:
6382 case MPI2_RAID_PD_STATE_OPTIMAL:
6383 case MPI2_RAID_PD_STATE_HOT_SPARE:
6385 set_bit(handle, ioc->pd_handles);
6386 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6387 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6388 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6393 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6394 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6396 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6397 ioc->name, __FILE__, __LINE__, __func__);
6401 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6402 MPI2_IOCSTATUS_MASK;
6403 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6404 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6405 ioc->name, __FILE__, __LINE__, __func__);
6409 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6410 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6411 mpt3sas_transport_update_links(ioc, sas_address, handle,
6412 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6414 _scsih_add_device(ioc, handle, 0, 1);
6418 case MPI2_RAID_PD_STATE_OFFLINE:
6419 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6420 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6427 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6428 * @ioc: per adapter object
6429 * @event_data: event data payload
6435 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6436 Mpi2EventDataIrOperationStatus_t *event_data)
6438 char *reason_str = NULL;
6440 switch (event_data->RAIDOperation) {
6441 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6442 reason_str = "resync";
6444 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6445 reason_str = "online capacity expansion";
6447 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6448 reason_str = "consistency check";
6450 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6451 reason_str = "background init";
6453 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6454 reason_str = "make data consistent";
6461 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6462 "\thandle(0x%04x), percent complete(%d)\n",
6463 ioc->name, reason_str,
6464 le16_to_cpu(event_data->VolDevHandle),
6465 event_data->PercentComplete);
6469 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6470 * @ioc: per adapter object
6471 * @fw_event: The fw_event_work object
6477 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6478 struct fw_event_work *fw_event)
6480 Mpi2EventDataIrOperationStatus_t *event_data =
6481 (Mpi2EventDataIrOperationStatus_t *)
6482 fw_event->event_data;
6483 static struct _raid_device *raid_device;
6484 unsigned long flags;
6487 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6488 _scsih_sas_ir_operation_status_event_debug(ioc,
6491 /* code added for raid transport support */
6492 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6494 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6495 handle = le16_to_cpu(event_data->VolDevHandle);
6496 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6498 raid_device->percent_complete =
6499 event_data->PercentComplete;
6500 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6505 * _scsih_prep_device_scan - initialize parameters prior to device scan
6506 * @ioc: per adapter object
6508 * Set the deleted flag prior to device scan. If the device is found during
6509 * the scan, then we clear the deleted flag.
6512 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6514 struct MPT3SAS_DEVICE *sas_device_priv_data;
6515 struct scsi_device *sdev;
6517 shost_for_each_device(sdev, ioc->shost) {
6518 sas_device_priv_data = sdev->hostdata;
6519 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6520 sas_device_priv_data->sas_target->deleted = 1;
6525 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6526 * @ioc: per adapter object
6527 * @sas_device_pg0: SAS Device page 0
6529 * After host reset, find out whether devices are still responding.
6530 * Used in _scsih_remove_unresponsive_sas_devices.
6535 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
6536 Mpi2SasDevicePage0_t *sas_device_pg0)
6538 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6539 struct scsi_target *starget;
6540 struct _sas_device *sas_device;
6541 unsigned long flags;
6543 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6544 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6545 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
6546 (sas_device->slot == sas_device_pg0->Slot)) {
6547 sas_device->responding = 1;
6548 starget = sas_device->starget;
6549 if (starget && starget->hostdata) {
6550 sas_target_priv_data = starget->hostdata;
6551 sas_target_priv_data->tm_busy = 0;
6552 sas_target_priv_data->deleted = 0;
6554 sas_target_priv_data = NULL;
6556 starget_printk(KERN_INFO, starget,
6557 "handle(0x%04x), sas_addr(0x%016llx)\n",
6558 sas_device_pg0->DevHandle,
6559 (unsigned long long)
6560 sas_device->sas_address);
6562 if (sas_device->enclosure_handle != 0)
6563 starget_printk(KERN_INFO, starget,
6564 "enclosure logical id(0x%016llx),"
6566 (unsigned long long)
6567 sas_device->enclosure_logical_id,
6570 if (sas_device_pg0->Flags &
6571 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6572 sas_device->enclosure_level =
6573 le16_to_cpu(sas_device_pg0->EnclosureLevel);
6574 memcpy(&sas_device->connector_name[0],
6575 &sas_device_pg0->ConnectorName[0], 4);
6577 sas_device->enclosure_level = 0;
6578 sas_device->connector_name[0] = '\0';
6581 if (sas_device->handle == sas_device_pg0->DevHandle)
6583 pr_info("\thandle changed from(0x%04x)!!!\n",
6584 sas_device->handle);
6585 sas_device->handle = sas_device_pg0->DevHandle;
6586 if (sas_target_priv_data)
6587 sas_target_priv_data->handle =
6588 sas_device_pg0->DevHandle;
6593 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6597 * _scsih_search_responding_sas_devices -
6598 * @ioc: per adapter object
6600 * After host reset, find out whether devices are still responding.
6606 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6608 Mpi2SasDevicePage0_t sas_device_pg0;
6609 Mpi2ConfigReply_t mpi_reply;
6614 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6616 if (list_empty(&ioc->sas_device_list))
6620 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6621 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6623 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6624 MPI2_IOCSTATUS_MASK;
6625 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6627 handle = sas_device_pg0.DevHandle =
6628 le16_to_cpu(sas_device_pg0.DevHandle);
6629 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6630 if (!(_scsih_is_end_device(device_info)))
6632 sas_device_pg0.SASAddress =
6633 le64_to_cpu(sas_device_pg0.SASAddress);
6634 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
6635 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
6639 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6644 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6645 * @ioc: per adapter object
6646 * @wwid: world wide identifier for raid volume
6647 * @handle: device handle
6649 * After host reset, find out whether devices are still responding.
6650 * Used in _scsih_remove_unresponsive_raid_devices.
6655 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6658 struct MPT3SAS_TARGET *sas_target_priv_data;
6659 struct scsi_target *starget;
6660 struct _raid_device *raid_device;
6661 unsigned long flags;
6663 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6664 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6665 if (raid_device->wwid == wwid && raid_device->starget) {
6666 starget = raid_device->starget;
6667 if (starget && starget->hostdata) {
6668 sas_target_priv_data = starget->hostdata;
6669 sas_target_priv_data->deleted = 0;
6671 sas_target_priv_data = NULL;
6672 raid_device->responding = 1;
6673 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6674 starget_printk(KERN_INFO, raid_device->starget,
6675 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6676 (unsigned long long)raid_device->wwid);
6677 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6678 if (raid_device->handle == handle) {
6679 spin_unlock_irqrestore(&ioc->raid_device_lock,
6683 pr_info("\thandle changed from(0x%04x)!!!\n",
6684 raid_device->handle);
6685 raid_device->handle = handle;
6686 if (sas_target_priv_data)
6687 sas_target_priv_data->handle = handle;
6688 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6692 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6696 * _scsih_search_responding_raid_devices -
6697 * @ioc: per adapter object
6699 * After host reset, find out whether devices are still responding.
6705 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
6707 Mpi2RaidVolPage1_t volume_pg1;
6708 Mpi2RaidVolPage0_t volume_pg0;
6709 Mpi2RaidPhysDiskPage0_t pd_pg0;
6710 Mpi2ConfigReply_t mpi_reply;
6715 if (!ioc->ir_firmware)
6718 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
6721 if (list_empty(&ioc->raid_device_list))
6725 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6726 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6727 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6728 MPI2_IOCSTATUS_MASK;
6729 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6731 handle = le16_to_cpu(volume_pg1.DevHandle);
6733 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6734 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6735 sizeof(Mpi2RaidVolPage0_t)))
6738 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6739 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6740 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6741 _scsih_mark_responding_raid_device(ioc,
6742 le64_to_cpu(volume_pg1.WWID), handle);
6745 /* refresh the pd_handles */
6746 phys_disk_num = 0xFF;
6747 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6748 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6749 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6751 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6752 MPI2_IOCSTATUS_MASK;
6753 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6755 phys_disk_num = pd_pg0.PhysDiskNum;
6756 handle = le16_to_cpu(pd_pg0.DevHandle);
6757 set_bit(handle, ioc->pd_handles);
6760 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
6765 * _scsih_mark_responding_expander - mark a expander as responding
6766 * @ioc: per adapter object
6767 * @sas_address: sas address
6770 * After host reset, find out whether devices are still responding.
6771 * Used in _scsih_remove_unresponsive_expanders.
6776 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
6779 struct _sas_node *sas_expander;
6780 unsigned long flags;
6783 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6784 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6785 if (sas_expander->sas_address != sas_address)
6787 sas_expander->responding = 1;
6788 if (sas_expander->handle == handle)
6790 pr_info("\texpander(0x%016llx): handle changed" \
6791 " from(0x%04x) to (0x%04x)!!!\n",
6792 (unsigned long long)sas_expander->sas_address,
6793 sas_expander->handle, handle);
6794 sas_expander->handle = handle;
6795 for (i = 0 ; i < sas_expander->num_phys ; i++)
6796 sas_expander->phy[i].handle = handle;
6800 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6804 * _scsih_search_responding_expanders -
6805 * @ioc: per adapter object
6807 * After host reset, find out whether devices are still responding.
6813 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
6815 Mpi2ExpanderPage0_t expander_pg0;
6816 Mpi2ConfigReply_t mpi_reply;
6821 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
6823 if (list_empty(&ioc->sas_expander_list))
6827 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6828 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6830 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6831 MPI2_IOCSTATUS_MASK;
6832 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6835 handle = le16_to_cpu(expander_pg0.DevHandle);
6836 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6837 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
6839 (unsigned long long)sas_address);
6840 _scsih_mark_responding_expander(ioc, sas_address, handle);
6844 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
6848 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6849 * @ioc: per adapter object
6854 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6856 struct _sas_device *sas_device, *sas_device_next;
6857 struct _sas_node *sas_expander, *sas_expander_next;
6858 struct _raid_device *raid_device, *raid_device_next;
6859 struct list_head tmp_list;
6860 unsigned long flags;
6862 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
6865 /* removing unresponding end devices */
6866 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
6868 list_for_each_entry_safe(sas_device, sas_device_next,
6869 &ioc->sas_device_list, list) {
6870 if (!sas_device->responding)
6871 mpt3sas_device_remove_by_sas_address(ioc,
6872 sas_device->sas_address);
6874 sas_device->responding = 0;
6877 /* removing unresponding volumes */
6878 if (ioc->ir_firmware) {
6879 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
6881 list_for_each_entry_safe(raid_device, raid_device_next,
6882 &ioc->raid_device_list, list) {
6883 if (!raid_device->responding)
6884 _scsih_sas_volume_delete(ioc,
6885 raid_device->handle);
6887 raid_device->responding = 0;
6891 /* removing unresponding expanders */
6892 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
6894 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6895 INIT_LIST_HEAD(&tmp_list);
6896 list_for_each_entry_safe(sas_expander, sas_expander_next,
6897 &ioc->sas_expander_list, list) {
6898 if (!sas_expander->responding)
6899 list_move_tail(&sas_expander->list, &tmp_list);
6901 sas_expander->responding = 0;
6903 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6904 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
6906 list_del(&sas_expander->list);
6907 _scsih_expander_node_remove(ioc, sas_expander);
6910 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
6913 /* unblock devices */
6914 _scsih_ublock_io_all_device(ioc);
6918 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
6919 struct _sas_node *sas_expander, u16 handle)
6921 Mpi2ExpanderPage1_t expander_pg1;
6922 Mpi2ConfigReply_t mpi_reply;
6925 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6926 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6927 &expander_pg1, i, handle))) {
6928 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6929 ioc->name, __FILE__, __LINE__, __func__);
6933 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
6934 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6935 expander_pg1.NegotiatedLinkRate >> 4);
6940 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6941 * @ioc: per adapter object
6946 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
6948 Mpi2ExpanderPage0_t expander_pg0;
6949 Mpi2SasDevicePage0_t sas_device_pg0;
6950 Mpi2RaidVolPage1_t volume_pg1;
6951 Mpi2RaidVolPage0_t volume_pg0;
6952 Mpi2RaidPhysDiskPage0_t pd_pg0;
6953 Mpi2EventIrConfigElement_t element;
6954 Mpi2ConfigReply_t mpi_reply;
6957 u16 handle, parent_handle;
6959 struct _sas_device *sas_device;
6960 struct _sas_node *expander_device;
6961 static struct _raid_device *raid_device;
6963 unsigned long flags;
6965 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
6967 _scsih_sas_host_refresh(ioc);
6969 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
6973 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6974 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6975 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6976 MPI2_IOCSTATUS_MASK;
6977 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6978 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
6979 "ioc_status(0x%04x), loginfo(0x%08x)\n",
6980 ioc->name, ioc_status,
6981 le32_to_cpu(mpi_reply.IOCLogInfo));
6984 handle = le16_to_cpu(expander_pg0.DevHandle);
6985 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6986 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
6987 ioc, le64_to_cpu(expander_pg0.SASAddress));
6988 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6989 if (expander_device)
6990 _scsih_refresh_expander_links(ioc, expander_device,
6993 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
6994 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
6995 handle, (unsigned long long)
6996 le64_to_cpu(expander_pg0.SASAddress));
6997 _scsih_expander_add(ioc, handle);
6998 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
6999 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7000 handle, (unsigned long long)
7001 le64_to_cpu(expander_pg0.SASAddress));
7005 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7008 if (!ioc->ir_firmware)
7011 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7014 phys_disk_num = 0xFF;
7015 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7016 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7018 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7019 MPI2_IOCSTATUS_MASK;
7020 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7021 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7022 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7023 ioc->name, ioc_status,
7024 le32_to_cpu(mpi_reply.IOCLogInfo));
7027 phys_disk_num = pd_pg0.PhysDiskNum;
7028 handle = le16_to_cpu(pd_pg0.DevHandle);
7029 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7030 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7031 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7034 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7035 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7038 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7039 MPI2_IOCSTATUS_MASK;
7040 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7041 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7042 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7043 ioc->name, ioc_status,
7044 le32_to_cpu(mpi_reply.IOCLogInfo));
7047 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7048 if (!_scsih_get_sas_address(ioc, parent_handle,
7050 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7051 " handle (0x%04x), sas_addr(0x%016llx)\n",
7052 ioc->name, handle, (unsigned long long)
7053 le64_to_cpu(sas_device_pg0.SASAddress));
7054 mpt3sas_transport_update_links(ioc, sas_address,
7055 handle, sas_device_pg0.PhyNum,
7056 MPI2_SAS_NEG_LINK_RATE_1_5);
7057 set_bit(handle, ioc->pd_handles);
7059 /* This will retry adding the end device.
7060 * _scsih_add_device() will decide on retries and
7061 * return "1" when it should be retried
7063 while (_scsih_add_device(ioc, handle, retry_count++,
7067 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7068 " handle (0x%04x), sas_addr(0x%016llx)\n",
7069 ioc->name, handle, (unsigned long long)
7070 le64_to_cpu(sas_device_pg0.SASAddress));
7074 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7077 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7081 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7082 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7083 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7084 MPI2_IOCSTATUS_MASK;
7085 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7086 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7087 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7088 ioc->name, ioc_status,
7089 le32_to_cpu(mpi_reply.IOCLogInfo));
7092 handle = le16_to_cpu(volume_pg1.DevHandle);
7093 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7094 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7095 le64_to_cpu(volume_pg1.WWID));
7096 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7099 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7100 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7101 sizeof(Mpi2RaidVolPage0_t)))
7103 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7104 MPI2_IOCSTATUS_MASK;
7105 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7106 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7107 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7108 ioc->name, ioc_status,
7109 le32_to_cpu(mpi_reply.IOCLogInfo));
7112 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7113 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7114 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7115 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7116 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7117 element.VolDevHandle = volume_pg1.DevHandle;
7119 "\tBEFORE adding volume: handle (0x%04x)\n",
7120 ioc->name, volume_pg1.DevHandle);
7121 _scsih_sas_volume_add(ioc, &element);
7123 "\tAFTER adding volume: handle (0x%04x)\n",
7124 ioc->name, volume_pg1.DevHandle);
7128 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7133 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7138 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7139 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7141 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7142 MPI2_IOCSTATUS_MASK;
7143 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7144 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7145 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7146 ioc->name, ioc_status,
7147 le32_to_cpu(mpi_reply.IOCLogInfo));
7150 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7151 if (!(_scsih_is_end_device(
7152 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7154 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7155 sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
7156 le64_to_cpu(sas_device_pg0.SASAddress));
7157 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7160 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7161 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7162 pr_info(MPT3SAS_FMT "\tBEFORE 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));
7166 mpt3sas_transport_update_links(ioc, sas_address, handle,
7167 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7169 /* This will retry adding the end device.
7170 * _scsih_add_device() will decide on retries and
7171 * return "1" when it should be retried
7173 while (_scsih_add_device(ioc, handle, retry_count++,
7177 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7178 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7179 handle, (unsigned long long)
7180 le64_to_cpu(sas_device_pg0.SASAddress));
7183 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7186 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7189 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7190 * @ioc: per adapter object
7191 * @reset_phase: phase
7193 * The handler for doing any required cleanup or initialization.
7195 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7196 * MPT3_IOC_DONE_RESET
7201 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7203 switch (reset_phase) {
7204 case MPT3_IOC_PRE_RESET:
7205 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7206 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7208 case MPT3_IOC_AFTER_RESET:
7209 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7210 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7211 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7212 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7213 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7214 complete(&ioc->scsih_cmds.done);
7216 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7217 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7218 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7219 complete(&ioc->tm_cmds.done);
7222 _scsih_fw_event_cleanup_queue(ioc);
7223 _scsih_flush_running_cmds(ioc);
7225 case MPT3_IOC_DONE_RESET:
7226 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7227 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7228 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7229 !ioc->sas_hba.num_phys)) {
7230 _scsih_prep_device_scan(ioc);
7231 _scsih_search_responding_sas_devices(ioc);
7232 _scsih_search_responding_raid_devices(ioc);
7233 _scsih_search_responding_expanders(ioc);
7234 _scsih_error_recovery_delete_devices(ioc);
7241 * _mpt3sas_fw_work - delayed task for processing firmware events
7242 * @ioc: per adapter object
7243 * @fw_event: The fw_event_work object
7249 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7251 /* the queue is being flushed so ignore this event */
7252 if (ioc->remove_host ||
7253 ioc->pci_error_recovery) {
7254 _scsih_fw_event_free(ioc, fw_event);
7258 switch (fw_event->event) {
7259 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7260 mpt3sas_process_trigger_data(ioc,
7261 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7262 fw_event->event_data);
7264 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7265 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7267 _scsih_remove_unresponding_sas_devices(ioc);
7268 _scsih_scan_for_devices_after_reset(ioc);
7270 case MPT3SAS_PORT_ENABLE_COMPLETE:
7271 ioc->start_scan = 0;
7272 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7273 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7275 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7276 "port enable: complete from worker thread\n",
7279 case MPT3SAS_TURN_ON_PFA_LED:
7280 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7282 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7283 _scsih_sas_topology_change_event(ioc, fw_event);
7285 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7286 _scsih_sas_device_status_change_event(ioc, fw_event);
7288 case MPI2_EVENT_SAS_DISCOVERY:
7289 _scsih_sas_discovery_event(ioc, fw_event);
7291 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7292 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7294 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7295 _scsih_sas_enclosure_dev_status_change_event(ioc,
7298 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7299 _scsih_sas_ir_config_change_event(ioc, fw_event);
7301 case MPI2_EVENT_IR_VOLUME:
7302 _scsih_sas_ir_volume_event(ioc, fw_event);
7304 case MPI2_EVENT_IR_PHYSICAL_DISK:
7305 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7307 case MPI2_EVENT_IR_OPERATION_STATUS:
7308 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7311 _scsih_fw_event_free(ioc, fw_event);
7315 * _firmware_event_work
7316 * @ioc: per adapter object
7317 * @work: The fw_event_work object
7320 * wrappers for the work thread handling firmware events
7326 _firmware_event_work(struct work_struct *work)
7328 struct fw_event_work *fw_event = container_of(work,
7329 struct fw_event_work, work);
7331 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7335 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7336 * @ioc: per adapter object
7337 * @msix_index: MSIX table index supplied by the OS
7338 * @reply: reply message frame(lower 32bit addr)
7339 * Context: interrupt.
7341 * This function merely adds a new work task into ioc->firmware_event_thread.
7342 * The tasks are worked from _firmware_event_work in user context.
7344 * Return 1 meaning mf should be freed from _base_interrupt
7345 * 0 means the mf is freed from this function.
7348 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7351 struct fw_event_work *fw_event;
7352 Mpi2EventNotificationReply_t *mpi_reply;
7356 /* events turned off due to host reset or driver unloading */
7357 if (ioc->remove_host || ioc->pci_error_recovery)
7360 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7362 if (unlikely(!mpi_reply)) {
7363 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7364 ioc->name, __FILE__, __LINE__, __func__);
7368 event = le16_to_cpu(mpi_reply->Event);
7370 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7371 mpt3sas_trigger_event(ioc, event, 0);
7375 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7377 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7378 (Mpi2EventDataSasBroadcastPrimitive_t *)
7379 mpi_reply->EventData;
7381 if (baen_data->Primitive !=
7382 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7385 if (ioc->broadcast_aen_busy) {
7386 ioc->broadcast_aen_pending++;
7389 ioc->broadcast_aen_busy = 1;
7393 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7394 _scsih_check_topo_delete_events(ioc,
7395 (Mpi2EventDataSasTopologyChangeList_t *)
7396 mpi_reply->EventData);
7398 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7399 _scsih_check_ir_config_unhide_events(ioc,
7400 (Mpi2EventDataIrConfigChangeList_t *)
7401 mpi_reply->EventData);
7403 case MPI2_EVENT_IR_VOLUME:
7404 _scsih_check_volume_delete_events(ioc,
7405 (Mpi2EventDataIrVolume_t *)
7406 mpi_reply->EventData);
7409 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7410 case MPI2_EVENT_IR_OPERATION_STATUS:
7411 case MPI2_EVENT_SAS_DISCOVERY:
7412 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7413 case MPI2_EVENT_IR_PHYSICAL_DISK:
7416 case MPI2_EVENT_TEMP_THRESHOLD:
7417 _scsih_temp_threshold_events(ioc,
7418 (Mpi2EventDataTemperature_t *)
7419 mpi_reply->EventData);
7422 default: /* ignore the rest */
7426 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7427 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7429 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7430 ioc->name, __FILE__, __LINE__, __func__);
7434 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7435 fw_event->ioc = ioc;
7436 fw_event->VF_ID = mpi_reply->VF_ID;
7437 fw_event->VP_ID = mpi_reply->VP_ID;
7438 fw_event->event = event;
7439 _scsih_fw_event_add(ioc, fw_event);
7444 * _scsih_expander_node_remove - removing expander device from list.
7445 * @ioc: per adapter object
7446 * @sas_expander: the sas_device object
7447 * Context: Calling function should acquire ioc->sas_node_lock.
7449 * Removing object and freeing associated memory from the
7450 * ioc->sas_expander_list.
7455 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7456 struct _sas_node *sas_expander)
7458 struct _sas_port *mpt3sas_port, *next;
7460 /* remove sibling ports attached to this expander */
7461 list_for_each_entry_safe(mpt3sas_port, next,
7462 &sas_expander->sas_port_list, port_list) {
7463 if (ioc->shost_recovery)
7465 if (mpt3sas_port->remote_identify.device_type ==
7467 mpt3sas_device_remove_by_sas_address(ioc,
7468 mpt3sas_port->remote_identify.sas_address);
7469 else if (mpt3sas_port->remote_identify.device_type ==
7470 SAS_EDGE_EXPANDER_DEVICE ||
7471 mpt3sas_port->remote_identify.device_type ==
7472 SAS_FANOUT_EXPANDER_DEVICE)
7473 mpt3sas_expander_remove(ioc,
7474 mpt3sas_port->remote_identify.sas_address);
7477 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7478 sas_expander->sas_address_parent);
7481 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7483 sas_expander->handle, (unsigned long long)
7484 sas_expander->sas_address);
7486 kfree(sas_expander->phy);
7487 kfree(sas_expander);
7491 * _scsih_ir_shutdown - IR shutdown notification
7492 * @ioc: per adapter object
7494 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7495 * the host system is shutting down.
7500 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7502 Mpi2RaidActionRequest_t *mpi_request;
7503 Mpi2RaidActionReply_t *mpi_reply;
7506 /* is IR firmware build loaded ? */
7507 if (!ioc->ir_firmware)
7510 /* are there any volumes ? */
7511 if (list_empty(&ioc->raid_device_list))
7514 mutex_lock(&ioc->scsih_cmds.mutex);
7516 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7517 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7518 ioc->name, __func__);
7521 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7523 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7525 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7526 ioc->name, __func__);
7527 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7531 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7532 ioc->scsih_cmds.smid = smid;
7533 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7535 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7536 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7538 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7539 init_completion(&ioc->scsih_cmds.done);
7540 mpt3sas_base_put_smid_default(ioc, smid);
7541 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7543 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7544 pr_err(MPT3SAS_FMT "%s: timeout\n",
7545 ioc->name, __func__);
7549 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7550 mpi_reply = ioc->scsih_cmds.reply;
7552 "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7553 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7554 le32_to_cpu(mpi_reply->IOCLogInfo));
7558 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7559 mutex_unlock(&ioc->scsih_cmds.mutex);
7563 * scsih_remove - detach and remove add host
7564 * @pdev: PCI device struct
7566 * Routine called when unloading the driver.
7569 void scsih_remove(struct pci_dev *pdev)
7571 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7572 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7573 struct _sas_port *mpt3sas_port, *next_port;
7574 struct _raid_device *raid_device, *next;
7575 struct MPT3SAS_TARGET *sas_target_priv_data;
7576 struct workqueue_struct *wq;
7577 unsigned long flags;
7579 ioc->remove_host = 1;
7580 _scsih_fw_event_cleanup_queue(ioc);
7582 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7583 wq = ioc->firmware_event_thread;
7584 ioc->firmware_event_thread = NULL;
7585 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7587 destroy_workqueue(wq);
7589 /* release all the volumes */
7590 _scsih_ir_shutdown(ioc);
7591 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7593 if (raid_device->starget) {
7594 sas_target_priv_data =
7595 raid_device->starget->hostdata;
7596 sas_target_priv_data->deleted = 1;
7597 scsi_remove_target(&raid_device->starget->dev);
7599 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7600 ioc->name, raid_device->handle,
7601 (unsigned long long) raid_device->wwid);
7602 _scsih_raid_device_remove(ioc, raid_device);
7605 /* free ports attached to the sas_host */
7606 list_for_each_entry_safe(mpt3sas_port, next_port,
7607 &ioc->sas_hba.sas_port_list, port_list) {
7608 if (mpt3sas_port->remote_identify.device_type ==
7610 mpt3sas_device_remove_by_sas_address(ioc,
7611 mpt3sas_port->remote_identify.sas_address);
7612 else if (mpt3sas_port->remote_identify.device_type ==
7613 SAS_EDGE_EXPANDER_DEVICE ||
7614 mpt3sas_port->remote_identify.device_type ==
7615 SAS_FANOUT_EXPANDER_DEVICE)
7616 mpt3sas_expander_remove(ioc,
7617 mpt3sas_port->remote_identify.sas_address);
7620 /* free phys attached to the sas_host */
7621 if (ioc->sas_hba.num_phys) {
7622 kfree(ioc->sas_hba.phy);
7623 ioc->sas_hba.phy = NULL;
7624 ioc->sas_hba.num_phys = 0;
7627 sas_remove_host(shost);
7628 scsi_remove_host(shost);
7629 mpt3sas_base_detach(ioc);
7630 list_del(&ioc->list);
7631 scsi_host_put(shost);
7635 * scsih_shutdown - routine call during system shutdown
7636 * @pdev: PCI device struct
7641 scsih_shutdown(struct pci_dev *pdev)
7643 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7644 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7645 struct workqueue_struct *wq;
7646 unsigned long flags;
7648 ioc->remove_host = 1;
7649 _scsih_fw_event_cleanup_queue(ioc);
7651 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7652 wq = ioc->firmware_event_thread;
7653 ioc->firmware_event_thread = NULL;
7654 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7656 destroy_workqueue(wq);
7658 _scsih_ir_shutdown(ioc);
7659 mpt3sas_base_detach(ioc);
7664 * _scsih_probe_boot_devices - reports 1st device
7665 * @ioc: per adapter object
7667 * If specified in bios page 2, this routine reports the 1st
7668 * device scsi-ml or sas transport for persistent boot device
7669 * purposes. Please refer to function _scsih_determine_boot_device()
7672 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
7676 struct _sas_device *sas_device;
7677 struct _raid_device *raid_device;
7679 u64 sas_address_parent;
7681 unsigned long flags;
7684 /* no Bios, return immediately */
7685 if (!ioc->bios_pg3.BiosVersion)
7690 if (ioc->req_boot_device.device) {
7691 device = ioc->req_boot_device.device;
7692 is_raid = ioc->req_boot_device.is_raid;
7693 } else if (ioc->req_alt_boot_device.device) {
7694 device = ioc->req_alt_boot_device.device;
7695 is_raid = ioc->req_alt_boot_device.is_raid;
7696 } else if (ioc->current_boot_device.device) {
7697 device = ioc->current_boot_device.device;
7698 is_raid = ioc->current_boot_device.is_raid;
7705 raid_device = device;
7706 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7707 raid_device->id, 0);
7709 _scsih_raid_device_remove(ioc, raid_device);
7711 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7712 sas_device = device;
7713 handle = sas_device->handle;
7714 sas_address_parent = sas_device->sas_address_parent;
7715 sas_address = sas_device->sas_address;
7716 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7717 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7719 if (!mpt3sas_transport_port_add(ioc, handle,
7720 sas_address_parent)) {
7721 _scsih_sas_device_remove(ioc, sas_device);
7722 } else if (!sas_device->starget) {
7723 if (!ioc->is_driver_loading) {
7724 mpt3sas_transport_port_remove(ioc,
7726 sas_address_parent);
7727 _scsih_sas_device_remove(ioc, sas_device);
7734 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7735 * @ioc: per adapter object
7737 * Called during initial loading of the driver.
7740 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
7742 struct _raid_device *raid_device, *raid_next;
7745 list_for_each_entry_safe(raid_device, raid_next,
7746 &ioc->raid_device_list, list) {
7747 if (raid_device->starget)
7749 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7750 raid_device->id, 0);
7752 _scsih_raid_device_remove(ioc, raid_device);
7757 * _scsih_probe_sas - reporting sas devices to sas transport
7758 * @ioc: per adapter object
7760 * Called during initial loading of the driver.
7763 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
7765 struct _sas_device *sas_device, *next;
7766 unsigned long flags;
7768 /* SAS Device List */
7769 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7772 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
7773 sas_device->sas_address_parent)) {
7774 list_del(&sas_device->list);
7777 } else if (!sas_device->starget) {
7779 * When asyn scanning is enabled, its not possible to
7780 * remove devices while scanning is turned on due to an
7781 * oops in scsi_sysfs_add_sdev()->add_device()->
7782 * sysfs_addrm_start()
7784 if (!ioc->is_driver_loading) {
7785 mpt3sas_transport_port_remove(ioc,
7786 sas_device->sas_address,
7787 sas_device->sas_address_parent);
7788 list_del(&sas_device->list);
7794 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7795 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7796 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7801 * _scsih_probe_devices - probing for devices
7802 * @ioc: per adapter object
7804 * Called during initial loading of the driver.
7807 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
7809 u16 volume_mapping_flags;
7811 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7812 return; /* return when IOC doesn't support initiator mode */
7814 _scsih_probe_boot_devices(ioc);
7816 if (ioc->ir_firmware) {
7817 volume_mapping_flags =
7818 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7819 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7820 if (volume_mapping_flags ==
7821 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7822 _scsih_probe_raid(ioc);
7823 _scsih_probe_sas(ioc);
7825 _scsih_probe_sas(ioc);
7826 _scsih_probe_raid(ioc);
7829 _scsih_probe_sas(ioc);
7833 * scsih_scan_start - scsi lld callback for .scan_start
7834 * @shost: SCSI host pointer
7836 * The shost has the ability to discover targets on its own instead
7837 * of scanning the entire bus. In our implemention, we will kick off
7838 * firmware discovery.
7841 scsih_scan_start(struct Scsi_Host *shost)
7843 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7845 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7846 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
7848 if (disable_discovery > 0)
7851 ioc->start_scan = 1;
7852 rc = mpt3sas_port_enable(ioc);
7855 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
7859 * scsih_scan_finished - scsi lld callback for .scan_finished
7860 * @shost: SCSI host pointer
7861 * @time: elapsed time of the scan in jiffies
7863 * This function will be called periodicallyn until it returns 1 with the
7864 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7865 * we wait for firmware discovery to complete, then return 1.
7868 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7870 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7872 if (disable_discovery > 0) {
7873 ioc->is_driver_loading = 0;
7874 ioc->wait_for_discovery_to_complete = 0;
7878 if (time >= (300 * HZ)) {
7879 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7881 "port enable: FAILED with timeout (timeout=300s)\n",
7883 ioc->is_driver_loading = 0;
7887 if (ioc->start_scan)
7890 if (ioc->start_scan_failed) {
7892 "port enable: FAILED with (ioc_status=0x%08x)\n",
7893 ioc->name, ioc->start_scan_failed);
7894 ioc->is_driver_loading = 0;
7895 ioc->wait_for_discovery_to_complete = 0;
7896 ioc->remove_host = 1;
7900 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
7901 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
7903 if (ioc->wait_for_discovery_to_complete) {
7904 ioc->wait_for_discovery_to_complete = 0;
7905 _scsih_probe_devices(ioc);
7907 mpt3sas_base_start_watchdog(ioc);
7908 ioc->is_driver_loading = 0;
7913 _scsih_determine_hba_mpi_version(struct MPT3SAS_ADAPTER *ioc) {
7915 switch (ioc->pdev->device) {
7916 case MPI2_MFGPAGE_DEVID_SAS2004:
7917 case MPI2_MFGPAGE_DEVID_SAS2008:
7918 case MPI2_MFGPAGE_DEVID_SAS2108_1:
7919 case MPI2_MFGPAGE_DEVID_SAS2108_2:
7920 case MPI2_MFGPAGE_DEVID_SAS2108_3:
7921 case MPI2_MFGPAGE_DEVID_SAS2116_1:
7922 case MPI2_MFGPAGE_DEVID_SAS2116_2:
7923 case MPI2_MFGPAGE_DEVID_SAS2208_1:
7924 case MPI2_MFGPAGE_DEVID_SAS2208_2:
7925 case MPI2_MFGPAGE_DEVID_SAS2208_3:
7926 case MPI2_MFGPAGE_DEVID_SAS2208_4:
7927 case MPI2_MFGPAGE_DEVID_SAS2208_5:
7928 case MPI2_MFGPAGE_DEVID_SAS2208_6:
7929 case MPI2_MFGPAGE_DEVID_SAS2308_1:
7930 case MPI2_MFGPAGE_DEVID_SAS2308_2:
7931 case MPI2_MFGPAGE_DEVID_SAS2308_3:
7932 ioc->hba_mpi_version_belonged = MPI2_VERSION;
7934 case MPI25_MFGPAGE_DEVID_SAS3004:
7935 case MPI25_MFGPAGE_DEVID_SAS3008:
7936 case MPI25_MFGPAGE_DEVID_SAS3108_1:
7937 case MPI25_MFGPAGE_DEVID_SAS3108_2:
7938 case MPI25_MFGPAGE_DEVID_SAS3108_5:
7939 case MPI25_MFGPAGE_DEVID_SAS3108_6:
7940 ioc->hba_mpi_version_belonged = MPI25_VERSION;
7946 * scsih_probe - attach and add scsi host
7947 * @pdev: PCI device struct
7948 * @id: pci device id
7950 * Returns 0 success, anything else error.
7953 scsih_probe(struct pci_dev *pdev, struct Scsi_Host *shost)
7955 struct MPT3SAS_ADAPTER *ioc;
7958 /* init local params */
7959 ioc = shost_priv(shost);
7960 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
7961 INIT_LIST_HEAD(&ioc->list);
7962 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
7964 ioc->id = mpt_ids++;
7967 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7968 ioc->tm_cb_idx = tm_cb_idx;
7969 ioc->ctl_cb_idx = ctl_cb_idx;
7970 ioc->base_cb_idx = base_cb_idx;
7971 ioc->port_enable_cb_idx = port_enable_cb_idx;
7972 ioc->transport_cb_idx = transport_cb_idx;
7973 ioc->scsih_cb_idx = scsih_cb_idx;
7974 ioc->config_cb_idx = config_cb_idx;
7975 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7976 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7977 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7978 ioc->logging_level = logging_level;
7979 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
7980 /* misc semaphores and spin locks */
7981 mutex_init(&ioc->reset_in_progress_mutex);
7982 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7983 spin_lock_init(&ioc->scsi_lookup_lock);
7984 spin_lock_init(&ioc->sas_device_lock);
7985 spin_lock_init(&ioc->sas_node_lock);
7986 spin_lock_init(&ioc->fw_event_lock);
7987 spin_lock_init(&ioc->raid_device_lock);
7988 spin_lock_init(&ioc->diag_trigger_lock);
7990 INIT_LIST_HEAD(&ioc->sas_device_list);
7991 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7992 INIT_LIST_HEAD(&ioc->sas_expander_list);
7993 INIT_LIST_HEAD(&ioc->fw_event_list);
7994 INIT_LIST_HEAD(&ioc->raid_device_list);
7995 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7996 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7997 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7998 INIT_LIST_HEAD(&ioc->reply_queue_list);
8000 _scsih_determine_hba_mpi_version(ioc);
8001 sprintf(ioc->name, "%s_cm%d", driver_name, ioc->id);
8003 /* init shost parameters */
8004 shost->max_cmd_len = 32;
8005 shost->max_lun = max_lun;
8006 shost->transportt = mpt3sas_transport_template;
8007 shost->unique_id = ioc->id;
8009 if (max_sectors != 0xFFFF) {
8010 if (max_sectors < 64) {
8011 shost->max_sectors = 64;
8012 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8013 "for max_sectors, range is 64 to 32767. Assigning "
8014 "value of 64.\n", ioc->name, max_sectors);
8015 } else if (max_sectors > 32767) {
8016 shost->max_sectors = 32767;
8017 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8018 "for max_sectors, range is 64 to 32767. Assigning "
8019 "default value of 32767.\n", ioc->name,
8022 shost->max_sectors = max_sectors & 0xFFFE;
8024 "The max_sectors value is set to %d\n",
8025 ioc->name, shost->max_sectors);
8029 /* register EEDP capabilities with SCSI layer */
8031 scsi_host_set_prot(shost, prot_mask);
8033 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8034 | SHOST_DIF_TYPE2_PROTECTION
8035 | SHOST_DIF_TYPE3_PROTECTION);
8037 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8040 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8041 "fw_event%d", ioc->id);
8042 ioc->firmware_event_thread = alloc_ordered_workqueue(
8043 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8044 if (!ioc->firmware_event_thread) {
8045 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8046 ioc->name, __FILE__, __LINE__, __func__);
8048 goto out_thread_fail;
8051 ioc->is_driver_loading = 1;
8052 if ((mpt3sas_base_attach(ioc))) {
8053 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8054 ioc->name, __FILE__, __LINE__, __func__);
8056 goto out_attach_fail;
8058 rv = scsi_add_host(shost, &pdev->dev);
8060 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8061 ioc->name, __FILE__, __LINE__, __func__);
8062 goto out_add_shost_fail;
8065 scsi_scan_host(shost);
8068 mpt3sas_base_detach(ioc);
8070 destroy_workqueue(ioc->firmware_event_thread);
8072 list_del(&ioc->list);
8073 scsi_host_put(shost);
8079 * scsih_suspend - power management suspend main entry point
8080 * @pdev: PCI device struct
8081 * @state: PM state change to (usually PCI_D3)
8083 * Returns 0 success, anything else error.
8086 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8088 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8089 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8090 pci_power_t device_state;
8092 mpt3sas_base_stop_watchdog(ioc);
8093 flush_scheduled_work();
8094 scsi_block_requests(shost);
8095 device_state = pci_choose_state(pdev, state);
8097 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8098 ioc->name, pdev, pci_name(pdev), device_state);
8100 pci_save_state(pdev);
8101 mpt3sas_base_free_resources(ioc);
8102 pci_set_power_state(pdev, device_state);
8107 * scsih_resume - power management resume main entry point
8108 * @pdev: PCI device struct
8110 * Returns 0 success, anything else error.
8113 scsih_resume(struct pci_dev *pdev)
8115 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8116 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8117 pci_power_t device_state = pdev->current_state;
8121 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8122 ioc->name, pdev, pci_name(pdev), device_state);
8124 pci_set_power_state(pdev, PCI_D0);
8125 pci_enable_wake(pdev, PCI_D0, 0);
8126 pci_restore_state(pdev);
8128 r = mpt3sas_base_map_resources(ioc);
8132 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8133 scsi_unblock_requests(shost);
8134 mpt3sas_base_start_watchdog(ioc);
8137 #endif /* CONFIG_PM */
8140 * scsih_pci_error_detected - Called when a PCI error is detected.
8141 * @pdev: PCI device struct
8142 * @state: PCI channel state
8144 * Description: Called when a PCI error is detected.
8147 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8150 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8152 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8153 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8155 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
8159 case pci_channel_io_normal:
8160 return PCI_ERS_RESULT_CAN_RECOVER;
8161 case pci_channel_io_frozen:
8162 /* Fatal error, prepare for slot reset */
8163 ioc->pci_error_recovery = 1;
8164 scsi_block_requests(ioc->shost);
8165 mpt3sas_base_stop_watchdog(ioc);
8166 mpt3sas_base_free_resources(ioc);
8167 return PCI_ERS_RESULT_NEED_RESET;
8168 case pci_channel_io_perm_failure:
8169 /* Permanent error, prepare for device removal */
8170 ioc->pci_error_recovery = 1;
8171 mpt3sas_base_stop_watchdog(ioc);
8172 _scsih_flush_running_cmds(ioc);
8173 return PCI_ERS_RESULT_DISCONNECT;
8175 return PCI_ERS_RESULT_NEED_RESET;
8179 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8180 * @pdev: PCI device struct
8182 * Description: This routine is called by the pci error recovery
8183 * code after the PCI slot has been reset, just before we
8184 * should resume normal operations.
8187 scsih_pci_slot_reset(struct pci_dev *pdev)
8189 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8190 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8193 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8196 ioc->pci_error_recovery = 0;
8198 pci_restore_state(pdev);
8199 rc = mpt3sas_base_map_resources(ioc);
8201 return PCI_ERS_RESULT_DISCONNECT;
8203 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8206 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8207 (rc == 0) ? "success" : "failed");
8210 return PCI_ERS_RESULT_RECOVERED;
8212 return PCI_ERS_RESULT_DISCONNECT;
8216 * scsih_pci_resume() - resume normal ops after PCI reset
8217 * @pdev: pointer to PCI device
8219 * Called when the error recovery driver tells us that its
8220 * OK to resume normal operation. Use completion to allow
8221 * halted scsi ops to resume.
8224 scsih_pci_resume(struct pci_dev *pdev)
8226 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8227 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8229 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8231 pci_cleanup_aer_uncorrect_error_status(pdev);
8232 mpt3sas_base_start_watchdog(ioc);
8233 scsi_unblock_requests(ioc->shost);
8237 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8238 * @pdev: pointer to PCI device
8241 scsih_pci_mmio_enabled(struct pci_dev *pdev)
8243 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8244 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8246 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8249 /* TODO - dump whatever for debugging purposes */
8251 /* Request a slot reset. */
8252 return PCI_ERS_RESULT_NEED_RESET;
8256 * scsih_init - main entry point for this driver.
8258 * Returns 0 success, anything else error.
8265 mpt3sas_base_initialize_callback_handler();
8267 /* queuecommand callback hander */
8268 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8270 /* task managment callback handler */
8271 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8273 /* base internal commands callback handler */
8274 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8275 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8276 mpt3sas_port_enable_done);
8278 /* transport internal commands callback handler */
8279 transport_cb_idx = mpt3sas_base_register_callback_handler(
8280 mpt3sas_transport_done);
8282 /* scsih internal commands callback handler */
8283 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8285 /* configuration page API internal commands callback handler */
8286 config_cb_idx = mpt3sas_base_register_callback_handler(
8287 mpt3sas_config_done);
8289 /* ctl module callback handler */
8290 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8292 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8293 _scsih_tm_tr_complete);
8295 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8296 _scsih_tm_volume_tr_complete);
8298 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8299 _scsih_sas_control_complete);
8305 * scsih_exit - exit point for this driver (when it is a module).
8307 * Returns 0 success, anything else error.
8313 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8314 mpt3sas_base_release_callback_handler(tm_cb_idx);
8315 mpt3sas_base_release_callback_handler(base_cb_idx);
8316 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8317 mpt3sas_base_release_callback_handler(transport_cb_idx);
8318 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8319 mpt3sas_base_release_callback_handler(config_cb_idx);
8320 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8322 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8323 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8324 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8326 /* raid transport support */
8327 raid_class_release(mpt3sas_raid_template);
8328 sas_release_transport(mpt3sas_transport_template);